Skip to content

Commit

Permalink
3.1.50.1bi test
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Nov 22, 2023
1 parent daa4091 commit a4abc17
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
build:
runs-on: ubuntu-22.04
env:
SDK_VERSION: 3.1.49.0bi
SDK_VERSION: 3.1.50.1bi
SYS_PYTHON: /usr/bin/python3
PACKAGES: emsdk hpy _ctypes pygame
BUILD_STATIC: emsdk _ctypes hpy
Expand Down
6 changes: 6 additions & 0 deletions pygbag/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ def truc(*argv, **kw):
fakehost.window.get_terminal_console = truc
fakehost.window.RAW_MODE = 0

def set_raw_mode(mode):
import platform as fakehost
fakehost.window.RAW_MODE = mode
fakehost.window.set_raw_mode = set_raw_mode
fakehost.window.set_raw_mode(0)

import aio.filelike

Expand Down Expand Up @@ -181,6 +186,7 @@ def no_op(cls, *argv, **kw):
sys.modules["__EMSCRIPTEN__"] = __EMSCRIPTEN__
sys.modules["embed"] = __EMSCRIPTEN__


print(" =============== pythonrc =================")
with open(support / "pythonrc.py", "r") as file:
exec(file.read(), globals(), globals())
Expand Down
24 changes: 20 additions & 4 deletions pygbag/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,24 @@
# to allow "import pygbag.aio as asyncio"
sys.modules["pygbag.aio"] = aio


# if not wasm cpu then run caller in simulator and block.

if hasattr(os, "uname") and not os.uname().machine.startswith("wasm"):
import time
from pathlib import Path

import aioconsole
try:
import aioconsole, aiohttp
except:
print(f"""
pygbag simulator rely on both aioconsole and aiohttp
please use :
{sys.interpreter} -m pip install aioconsole aiohttp
""")
raise SystemExit



import aio.pep0723

Expand All @@ -23,9 +33,15 @@
else:
aio.pep0723.Config.PKG_INDEXES.extend(["https://pygame-web.github.io/archives/repo/"])


import pygbag.__main__

async def custom_async_input():
import platform
if platform.window.RAW_MODE:
# TODO: FIXME: implement embed.os_read and debug focus handler
#return await asyncio.sleep(0)
...
return await aioconsole.ainput("››› ")

aio.loop.create_task(
Expand Down
94 changes: 48 additions & 46 deletions pygbag/support/cross/aio/pep0723.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sys
import os
from pathlib import Path
import glob

import re
print(sys.path)
Expand All @@ -25,6 +26,27 @@
import platform
import platform_wasm.todo


# TODO: maybe control wheel cache with $XDG_CACHE_HOME/pip


# store installed wheel somewhere
env = Path(os.getcwd()) / "build" / "env"
env.mkdir(parents=True, exist_ok=True)

# we want host to load wasm packages too
# so make pure/bin folder first for imports

if env.as_posix() not in sys.path:
sys.path.insert(0, env.as_posix())

sconf = __import__("sysconfig").get_paths()
sconf["purelib"] = sconf["platlib"] = env.as_posix()

if sconf["platlib"] not in sys.path:
sys.path.append(sconf["platlib"])


PATCHLIST = []
HISTORY = []

Expand Down Expand Up @@ -225,13 +247,15 @@ async def install_pkg(sysconf, wheel_url, wheel_pkg):
install(target_filename, sysconf)

# FIXME: HISTORY and invalidate caches
async def pip_install(pkg, sconf={}):
async def pip_install(pkg, sysconf={}):
global sconf
if pkg in HISTORY:
return
print("225: searching", pkg)

if not sconf:
sconf = __import__("sysconfig").get_paths()
print("253: searching", pkg)

if not sysconf:
sysconf = sconf

wheel_url = ""

Expand All @@ -245,21 +269,6 @@ async def pip_install(pkg, sconf={}):
for repo in Config.pkg_repolist:
if pkg in repo:
wheel_url = f"{repo['-CDN-']}{repo[pkg]}#"
# pkg_file = f"/tmp/{repo[want].rsplit('/',1)[-1]}"
# if pkg_file in aio.toplevel.HISTORY:
# break

# cfg = {"io": "url", "type": "fs", "path": pkg_file}
# print(f"1205: async_get_pkg({pkg_url})")
#
# track = platform.window.MM.prepare(pkg_url, json.dumps(cfg))
#
# try:
# await cls.pv(track)
# zipfile.ZipFile(pkg_file).close()
# break
# except (IOError, zipfile.BadZipFile):
# pdb(f"1294: network error on {repo['-CDN-']}, cannot install {pkg_file}")

# try to get a pure python wheel from pypi
if not wheel_url:
Expand All @@ -283,7 +292,9 @@ async def pip_install(pkg, sconf={}):
if wheel_url:
try:
wheel_pkg, wheel_hash = wheel_url.rsplit("/", 1)[-1].split("#", 1)
await install_pkg(sconf, wheel_url, wheel_pkg)
await install_pkg(sysconf, wheel_url, wheel_pkg)
if pkg not in HISTORY:
HISTORY.append(pkg)
except:
print("212: INVALID", pkg, "from", wheel_url)

Expand All @@ -301,7 +312,7 @@ async def parse_code(code, env):
continue
elif pkg not in maybe_missing:
# do not change case ( eg PIL )
maybe_missing.append(pkg)
maybe_missing.append(pkg.lower().replace('-','_'))

if Config.READ_723:
for req in read_dependency_block_723(code):
Expand All @@ -311,7 +322,7 @@ async def parse_code(code, env):
continue
elif pkg not in maybe_missing:
# do not change case ( eg PIL )
maybe_missing.append(pkg)
maybe_missing.append(pkg.lower().replace('-','_'))

still_missing = []

Expand All @@ -322,7 +333,7 @@ async def parse_code(code, env):
PATCHLIST.append(dep)

if not importlib.util.find_spec(dep) and dep not in still_missing:
still_missing.append(dep.lower())
still_missing.append(dep)
else:
print("found in path :", dep)

Expand All @@ -332,7 +343,7 @@ async def parse_code(code, env):
# parse_code does the patching
# this is not called by pythonrc
async def check_list(code=None, filename=None):
global PATCHLIST, async_imports_init, async_repos
global PATCHLIST, async_imports_init, async_repos, env, sconf
print()
print("-" * 11, "computing required packages", "-" * 10)

Expand All @@ -349,22 +360,6 @@ async def check_list(code=None, filename=None):
del async_imports_init, async_repos


# store installed wheel somewhere
env = Path(os.getcwd()) / "build" / "env"
env.mkdir(parents=True, exist_ok=True)

# we want host to load wasm packages too
# so make pure/bin folder first for imports

if env.as_posix() not in sys.path:
sys.path.insert(0, env.as_posix())

sconf = __import__("sysconfig").get_paths()
sconf["purelib"] = sconf["platlib"] = env.as_posix()

if sconf["platlib"] not in sys.path:
sys.path.append(sconf["platlib"])

# mandatory
importlib.invalidate_caches()

Expand Down Expand Up @@ -398,18 +393,28 @@ async def check_list(code=None, filename=None):
still_missing.append(pkg)

for pkg in still_missing:
if (env / pkg).is_dir():
di = f"{(env / pkg).as_posix()}-*.dist-info"
gg = glob.glob( di)
if gg:
print("found in env :", gg[0].rsplit('/',1)[-1])
continue

pkg_final = pkg.replace('-','_')
if (env / pkg_final).is_dir():
print("found in env :", pkg)
continue
await pip_install(pkg)
await pip_install(pkg, sconf)

import platform

# apply any patches
while len(PATCHLIST):
dep = PATCHLIST.pop(0)
print(f"314: patching {dep}")
platform.patches.pop(dep)()
try:
platform.patches.pop(dep)()
except Exception as e:
sys.print_exception(e)

print("-" * 40)
print()
Expand All @@ -430,7 +435,4 @@ async def check_list(code=None, filename=None):






# aio.pep0723
10 changes: 4 additions & 6 deletions pygbag/support/pythonrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,7 @@ async def preload_code(cls, code, callback=None, hint=""):
from aio.pep0723 import Config

if not aio.cross.simulator:
# don't use an env path, but site-packages instead
# we can only do purelib for now until pypi host wasm wheels
# env path is set by pep0723
sconf = __import__("sysconfig").get_paths()
env = Path(sconf["purelib"])

Expand All @@ -651,10 +650,9 @@ async def preload_code(cls, code, callback=None, hint=""):
DBG("650: FIXME (this is pyodide maintened stuff, use (auto)PEP723 asap)")
print("651: referenced packages :", len(Config.repos[0]["packages"]))

DBG(f"644: aio.pep0723.check_list {env=}")
#deps = await aio.pep0723.parse_code(code, env)
deps = await aio.pep0723.check_list(code) #, env)
DBG(f"646: aio.pep0723.pip_install {deps=}")
DBG(f"654: aio.pep0723.check_list {aio.pep0723.env=}")
deps = await aio.pep0723.check_list(code)
DBG(f"656: aio.pep0723.pip_install {deps=}")

# auto import plumbing to avoid rely too much on import error
maybe_wanted = list(TopLevel_async_handler.list_imports(code, file=None, hint=hint))
Expand Down
5 changes: 4 additions & 1 deletion scripts/build-loader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ then

cat > final_link.sh <<END
#!/bin/bash
emcc $FINAL_OPTS $LOPTS -D__PYDK__=1 -DNDEBUG \\
emcc \\
$FINAL_OPTS \\
$LOPTS \\
-D__PYDK__=1 -DNDEBUG \\
-sTOTAL_MEMORY=256MB -sSTACK_SIZE=4MB -sALLOW_TABLE_GROWTH -sALLOW_MEMORY_GROWTH \\
$CF_SDL \\
--use-preload-plugins \\
Expand Down
20 changes: 15 additions & 5 deletions static/pythons.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,31 @@ function reverse(s){
return s.split("").reverse().join("");
}


// please comment here if you find a bug
// https://stackoverflow.com/questions/5202085/javascript-equivalent-of-pythons-rsplit

String.prototype.rsplit = function(sep, maxsplit) {
var result = []
if ( (sep === undefined) ) {
var src = this
var nullsep = false

if ( (sep === undefined) || (sep === null) || (!sep) ) {
sep = " "
maxsplit = 0
nullsep = true
src = src.replaceAll(sep+sep,sep)
src = src.replaceAll(sep+sep,sep)
}

if (nullsep && !src)
return []

if (maxsplit === 0 )
return [this]
return [src]

var data = this.split(sep)
maxsplit = maxsplit || -1

var data = src.split(sep)


if (!maxsplit || (maxsplit<0) || (data.length==maxsplit+1) )
Expand All @@ -123,7 +134,6 @@ String.prototype.rsplit = function(sep, maxsplit) {
return [this]
}


function jsimport(url, sync) {
const jsloader=document.createElement('script')
jsloader.setAttribute("type","text/javascript")
Expand Down
2 changes: 1 addition & 1 deletion static/vt/xterm-addon-image.js

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions static/vt/xterm.css
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
right: 0;
z-index: 10;
color: transparent;
pointer-events: none;
}

.xterm .live-region {
Expand All @@ -160,7 +161,9 @@
}

.xterm-dim {
opacity: 0.5;
/* Dim should not apply to background, so the opacity of the foreground color is applied
* explicitly in the generated class and reset to 1 here */
opacity: 1 !important;
}

.xterm-underline-1 { text-decoration: underline; }
Expand All @@ -169,6 +172,16 @@
.xterm-underline-4 { text-decoration: dotted underline; }
.xterm-underline-5 { text-decoration: dashed underline; }

.xterm-overline {
text-decoration: overline;
}

.xterm-overline.xterm-underline-1 { text-decoration: overline underline; }
.xterm-overline.xterm-underline-2 { text-decoration: overline double underline; }
.xterm-overline.xterm-underline-3 { text-decoration: overline wavy underline; }
.xterm-overline.xterm-underline-4 { text-decoration: overline dotted underline; }
.xterm-overline.xterm-underline-5 { text-decoration: overline dashed underline; }

.xterm-strikethrough {
text-decoration: line-through;
}
Expand All @@ -178,8 +191,12 @@
position: absolute;
}

.xterm-screen .xterm-decoration-container .xterm-decoration.xterm-decoration-top-layer {
z-index: 7;
}

.xterm-decoration-overview-ruler {
z-index: 7;
z-index: 8;
position: absolute;
top: 0;
right: 0;
Expand Down
2 changes: 1 addition & 1 deletion static/vt/xterm.js

Large diffs are not rendered by default.

Loading

0 comments on commit a4abc17

Please sign in to comment.