diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6eb3f92..e624906 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,12 +6,12 @@ jobs: build: runs-on: ubuntu-22.04 env: - SDK_VERSION: 3.1.54.1bi + SDK_VERSION: 3.1.56.0bi SYS_PYTHON: /usr/bin/python3 PACKAGES: emsdk hpy pygame BUILD_STATIC: emsdk hpy STATIC: false - BUILDS: 3.11 3.12 3.13 + BUILDS: 3.12 3.13 CYTHON: Cython-3.0.8-py2.py3-none-any.whl LD_VENDOR: -sUSE_GLFW=3 @@ -36,17 +36,17 @@ jobs: sudo apt-get update 2>&1 >/dev/null sudo apt-get install -y bash git curl wget lz4 pv 2>&1 >/dev/null - - - name: build 3.11 packages - run: | - cd $GITHUB_WORKSPACE - PYBUILD=3.11 PACKAGES="emsdk hpy _ctypes pygame" BUILD_STATIC="emsdk _ctypes hpy" bash ./scripts/build-pkg.sh - - - name: build 3.11 loader - run: | - cd $GITHUB_WORKSPACE - PYBUILD=3.11 PACKAGES="emsdk hpy _ctypes pygame" BUILD_STATIC="emsdk _ctypes hpy" bash ./scripts/build-loader.sh - +# +# - name: build 3.11 packages +# run: | +# cd $GITHUB_WORKSPACE +# PYBUILD=3.11 PACKAGES="emsdk hpy _ctypes pygame" BUILD_STATIC="emsdk _ctypes hpy" bash ./scripts/build-pkg.sh +# +# - name: build 3.11 loader +# run: | +# cd $GITHUB_WORKSPACE +# PYBUILD=3.11 PACKAGES="emsdk hpy _ctypes pygame" BUILD_STATIC="emsdk _ctypes hpy" bash ./scripts/build-loader.sh +# - name: build 3.12 packages run: | diff --git a/packages.d/hpy/hpy.sh b/packages.d/hpy/hpy.sh index e30cdb8..3e65780 100755 --- a/packages.d/hpy/hpy.sh +++ b/packages.d/hpy/hpy.sh @@ -57,52 +57,59 @@ popd pushd external/hpy -# build for host simulator +# build and install for host simulator ${HPY} setup.py install -# build for wasm -${SDKROOT}/python3-wasm setup.py install - +# ${SDKROOT}/python3-wasm setup.py install +${SDKROOT}/python3-wasm setup.py build # link static . ${SDKROOT}/emsdk/emsdk_env.sh $SDKROOT/emsdk/upstream/emscripten/emar rcs /opt/python-wasm-sdk/prebuilt/emsdk/libhpy${PYMAJOR}.${PYMINOR}.a \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/debug/src/_debugmod.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/debug/src/autogen_debug_wrappers.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/debug/src/debug_ctx.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/debug/src/debug_ctx_cpython.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/debug/src/debug_handles.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/debug/src/dhqueue.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/debug/src/memprotect.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/debug/src/stacktrace.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/devel/src/runtime/argparse.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/devel/src/runtime/buildvalue.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/devel/src/runtime/ctx_bytes.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/devel/src/runtime/ctx_call.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/devel/src/runtime/ctx_capsule.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/devel/src/runtime/ctx_contextvar.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/devel/src/runtime/ctx_err.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/devel/src/runtime/ctx_eval.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/devel/src/runtime/ctx_listbuilder.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/devel/src/runtime/ctx_long.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/devel/src/runtime/ctx_module.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/devel/src/runtime/ctx_object.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/devel/src/runtime/ctx_tracker.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/devel/src/runtime/ctx_tuple.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/devel/src/runtime/ctx_tuplebuilder.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/devel/src/runtime/ctx_type.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/devel/src/runtime/format.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/devel/src/runtime/helpers.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/devel/src/runtime/structseq.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/trace/src/_tracemod.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/trace/src/autogen_trace_func_table.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/trace/src/autogen_trace_wrappers.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/trace/src/trace_ctx.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/universal/src/ctx.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/universal/src/ctx_meth.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/universal/src/ctx_misc.o \ - build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-311/hpy/universal/src/hpymodule.o + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/debug/src/_debugmod.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/debug/src/autogen_debug_wrappers.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/debug/src/debug_ctx.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/debug/src/debug_ctx_cpython.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/debug/src/debug_handles.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/debug/src/dhqueue.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/debug/src/memprotect.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/debug/src/stacktrace.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/devel/src/runtime/argparse.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/devel/src/runtime/buildvalue.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/devel/src/runtime/ctx_bytes.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/devel/src/runtime/ctx_call.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/devel/src/runtime/ctx_capsule.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/devel/src/runtime/ctx_contextvar.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/devel/src/runtime/ctx_err.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/devel/src/runtime/ctx_eval.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/devel/src/runtime/ctx_listbuilder.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/devel/src/runtime/ctx_long.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/devel/src/runtime/ctx_module.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/devel/src/runtime/ctx_object.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/devel/src/runtime/ctx_tracker.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/devel/src/runtime/ctx_tuple.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/devel/src/runtime/ctx_tuplebuilder.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/devel/src/runtime/ctx_type.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/devel/src/runtime/format.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/devel/src/runtime/helpers.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/devel/src/runtime/structseq.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/trace/src/_tracemod.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/trace/src/autogen_trace_func_table.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/trace/src/autogen_trace_wrappers.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/trace/src/trace_ctx.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/universal/src/ctx.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/universal/src/ctx_meth.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/universal/src/ctx_misc.o \ + build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/universal/src/hpymodule.o + +if [ -f /pp ] +then + # build wheel for wasm + ${SDKROOT}/python3-wasm -m build --no-isolation . + + mv dist/*wasm*whl /data/git/archives/repo/pkg/ +fi popd diff --git a/scripts/build-loader.sh b/scripts/build-loader.sh index dc645e8..a3c03ed 100755 --- a/scripts/build-loader.sh +++ b/scripts/build-loader.sh @@ -4,7 +4,19 @@ . ${CONFIG:-$SDKROOT/config} -# +if [ -f vendor/vendor.sh ] +then + echo " vendor build" + if ${ABI3:-false} + then + echo " vendor build (abi3) $PYBUILD" + if echo $PYBUILD|grep -v -q 3.12$ + then + echo "abi3 vendor build only, skipping $PYBUILD" + exit 0 + fi + fi +fi ln -s $(pwd)/src/pygbag $(pwd)/pygbag @@ -236,7 +248,9 @@ then # TODO: test -sWEBGL2_BACKWARDS_COMPATIBILITY_EMULATION - LDFLAGS="-sUSE_GLFW=3 -sUSE_WEBGL2 -sMIN_WEBGL_VERSION=2 -sOFFSCREENCANVAS_SUPPORT=1 -sFULL_ES2 -sFULL_ES3" +# + + LDFLAGS="-sUSE_GLFW=3 -sUSE_WEBGL2 -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -sOFFSCREENCANVAS_SUPPORT=1 -sFULL_ES2 -sFULL_ES3" LDFLAGS="$LDFLAGS -lsqlite3" diff --git a/scripts/build-pkg.sh b/scripts/build-pkg.sh index 52ab361..79dfd1f 100755 --- a/scripts/build-pkg.sh +++ b/scripts/build-pkg.sh @@ -2,6 +2,20 @@ . scripts/vendoring.sh +if [ -f vendor/vendor.sh ] +then + echo " vendor build" + if ${ABI3:-false} + then + echo " vendor build (abi3) $PYBUILD" + if echo $PYBUILD|grep -v -q 3.12$ + then + echo "abi3 vendor build only, skipping $PYBUILD" + exit 0 + fi + fi +fi + export PYMAJOR=$(echo -n $PYBUILD|cut -d. -f1) export PYMINOR=$(echo -n $PYBUILD|cut -d. -f2) diff --git a/scripts/build-pkpy.sh b/scripts/build-pkpy.sh index 202352e..4ff9600 100755 --- a/scripts/build-pkpy.sh +++ b/scripts/build-pkpy.sh @@ -1,4 +1,11 @@ #!/bin/bash + +if [ -f vendor/vendor.sh ] +then + echo "vendor build, skipping" + exit 0 +fi + reset PW=$(realpath patchwork/pykpocket) diff --git a/src/pygbag/aio.py b/src/pygbag/aio.py index 6e7f2bd..2451744 100644 --- a/src/pygbag/aio.py +++ b/src/pygbag/aio.py @@ -34,7 +34,9 @@ if aio.pep0723.Config.dev_mode: aio.pep0723.Config.PKG_INDEXES.extend(["http://localhost:8000/archives/repo/"]) else: - aio.pep0723.Config.PKG_INDEXES.extend(["https://pygame-web.github.io/archives/repo/"]) + aio.pep0723.Config.PKG_INDEXES.extend([ + os.environ.get('PYGPY', "https://pygame-web.github.io/archives/repo/"), + ]) import pygbag.__main__ diff --git a/src/pygbag/app.py b/src/pygbag/app.py index 48e5c95..06e7120 100644 --- a/src/pygbag/app.py +++ b/src/pygbag/app.py @@ -36,6 +36,7 @@ DEFAULT_CONSOLE = 25 DEFAULT_LINES = 57 DEFAULT_COLUMNS = 132 +DEFAULT_PYBUILD = "3.12" CACHE_ROOT = Path("build") CACHE_PATH = CACHE_ROOT / "web-cache" @@ -161,17 +162,21 @@ def make_cache_dirs(): if clear_cache: win32 = sys.platform == "win32" - if shutil.rmtree.avoids_symlink_attacks or win32: - if cache_dir.is_dir(): + if cache_dir.is_dir(): + if shutil.rmtree.avoids_symlink_attacks or win32: if win32: warnings.warn("clear cache : rmtree is not safe on that system (win32)") shutil.rmtree(cache_dir.as_posix()) - else: - print( - "115: cannot clear cache : rmtree is not safe on that system", - file=sys.stderr, - ) - raise SystemExit(115) + else: + print( + "171: cannot clear cache : rmtree is not safe on that system", + file=sys.stderr, + ) + print( + "175: Please remove build folder manually", + file=sys.stderr, + ) + raise SystemExit(115) # rebuild make_cache_dirs() @@ -210,8 +215,8 @@ async def main_run(app_folder, mainscript, cdn=DEFAULT_CDN): parser.add_argument( "--PYBUILD", - default="3.11", - help="Specify python version [default:%s]" % "3.11", + default=DEFAULT_PYBUILD, + help="Specify python version [default:%s]" % DEFAULT_PYBUILD, ) parser.add_argument( diff --git a/src/pygbag/filtering.py b/src/pygbag/filtering.py index 9576f35..064f6d3 100644 --- a/src/pygbag/filtering.py +++ b/src/pygbag/filtering.py @@ -16,6 +16,7 @@ /.github /.vscode /.idea +/.DS_Store /dist /build /venv @@ -26,7 +27,7 @@ "\n" ) -SKIP_EXT = ["pyc", "pyx", "pyd", "pyi", "exe", "log", "blend", "DS_Store"] +SKIP_EXT = ["pyc", "pyx", "pyd", "pyi", "exe", "bak", "log", "blend", "DS_Store"] def filter(walked): diff --git a/src/pygbag/optimizing.py b/src/pygbag/optimizing.py index ba8a7ad..a13012c 100644 --- a/src/pygbag/optimizing.py +++ b/src/pygbag/optimizing.py @@ -44,7 +44,10 @@ def optimize(folder, filenames, **kw): def optimize(folder, filenames, **kw): global BAD - print("optimizing", folder) + if "--no_opt" in sys.argv: + print("NOT optimizing", folder) + else: + print("optimizing", folder) png_quality = 50 done_list = [] @@ -57,10 +60,13 @@ def optimize(folder, filenames, **kw): except ImportError: warnings.warn(f"Black not found for processing {folder=}") - if os.popen("pngquant 2>&1").read().count("pngfile"): - print(f" -> with pngquant --quality {png_quality}", folder) + if "--no_opt" in sys.argv: + pass else: - png_quality = -1 + if os.popen("pngquant 2>&1").read().count("pngfile"): + print(f" -> with pngquant --quality {png_quality}", folder) + else: + png_quality = -1 has_ffmpeg = os.popen("ffmpeg -version").read().count("version") diff --git a/src/pygbag/support/cpythonrc.py b/src/pygbag/support/cpythonrc.py index 97c7114..1a272b8 100644 --- a/src/pygbag/support/cpythonrc.py +++ b/src/pygbag/support/cpythonrc.py @@ -17,9 +17,9 @@ PYCONFIG_PKG_INDEXES_DEV = ["http://localhost:/archives/repo/"] -PYCONFIG_PKG_INDEXES = ["https://pygame-web.github.io/archives/repo/"] +# normal index or PYGPY env is handled after env conversion around line 255 -# the sim does not preload assets and cannot access currentline +# the sim does not ospreload assets and cannot access currentline # unless using https://github.com/pmp-p/aioprompt/blob/master/aioprompt/__init__.py # or a thread @@ -252,6 +252,10 @@ def dump_code(): os.environ["APPDATA"] = home del home +# now in pep0723 +#PYCONFIG_PKG_INDEXES = [ +# os.environ.get('PYGPY', "https://pygame-web.github.io/archives/repo/"), +#] PyConfig["imports_ready"] = False PyConfig["pygbag"] = 0 @@ -682,8 +686,11 @@ async def preload_code(cls, code, callback=None, loaderhome=".", hint=""): env = Path(sconf["purelib"]) if not len(Config.repos): - if not len(Config.PKG_INDEXES): - Config.PKG_INDEXES = PyConfig.pkg_indexes + await aio.pep0723.async_repos() + + # TODO switch to METADATA:Requires-Dist + # see https://github.com/pygame-web/pygbag/issues/156 + for cdn in Config.PKG_INDEXES: async with platform.fopen(Path(cdn) / Config.REPO_DATA) as source: Config.repos.append(json.loads(source.read())) @@ -960,7 +967,6 @@ def __eq__(self, other): platform.fopen = aio.filelike.fopen platform.sopen = aio.filelike.sopen - if not aio.cross.simulator: def fix_url(maybe_url): @@ -1067,9 +1073,10 @@ def urlretrieve(maybe_url, filename=None, reporthook=None, data=None): PyConfig.pkg_indexes.append(redirect) print("807: DEV MODE ON", PyConfig.pkg_indexes) - else: - # address cdn - PyConfig.pkg_indexes = PYCONFIG_PKG_INDEXES +# now in pep0723 +# else: +# # address cdn +# PyConfig.pkg_indexes = PYCONFIG_PKG_INDEXES from platform import window, document, ffi @@ -1130,8 +1137,6 @@ class TopLevel_async_handler(aio.toplevel.AsyncInteractiveConsole): from pathlib import Path - # repodata = "repodata.json" - def eval(self, source): for count, line in enumerate(source.split("\n")): if not count: @@ -1143,7 +1148,7 @@ def eval(self, source): if count: self.line = None self.buffer.insert(0, "#") - # self.buffer.append("") + DBG(f"1039: {count} lines queued for async eval") @classmethod @@ -1208,13 +1213,13 @@ def list_imports(cls, code=None, file=None, hint=""): if not len(aio.pep0723.Config.pkg_repolist): print( """ -1170: pep0723 REPOSITORY MISSING +1208: pep0723 REPOSITORY MISSING """ ) else: DBG( f""" -1175: list_imports {len(code)=} {file=} {hint=}") +1214: list_imports {len(code)=} {file=} {hint=}") {aio.pep0723.Config.pkg_repolist[0]['-CDN-']=} """ @@ -1475,6 +1480,7 @@ def log(*argv, **kw): async def import_site(__file__, run=True): import builtins + if builtins.LOCK: platform.window.console.error("1473: import_site IS NOT RE ENTRANT") return @@ -1643,4 +1649,4 @@ async def main(): shell.interactive(prompt=True) return None finally: - LOCK = False + builtins.LOCK = False diff --git a/src/pygbag/support/cross/aio/pep0723.py b/src/pygbag/support/cross/aio/pep0723.py index 7b740a2..76e39bb 100644 --- a/src/pygbag/support/cross/aio/pep0723.py +++ b/src/pygbag/support/cross/aio/pep0723.py @@ -59,6 +59,7 @@ class Config: READ_723 = True BLOCK_RE_722 = r"(?i)^#\s+script\s+dependencies:\s*$" BLOCK_RE_723 = r"(?m)^# /// (?P[a-zA-Z0-9-]+)$\s(?P(^#(| .*)$\s)+)^# ///$" + PKG_BASE_DEFAULT = "https://pygame-web.github.io/archives/repo/" PKG_INDEXES = [] REPO_INDEX = "index.json" REPO_DATA = "repodata.json" @@ -174,31 +175,35 @@ def install(pkg_file, sconf=None): sys.print_exception(ex) -async def async_imports_init(): - ... - - -# see pythonrc +# see cpythonrc # if not len(Config.repos): # for cdn in (Config.PKG_INDEXES or PyConfig.pkg_indexes): # async with platform.fopen(Path(cdn) / Config.REPO_DATA) as source: # Config.repos.append(json.loads(source.read())) # # DBG("1203: FIXME (this is pyodide maintened stuff, use PEP723 asap) referenced packages :", len(cls.repos[0]["packages"])) -# async def async_repos(): abitag = f"cp{sys.version_info.major}{sys.version_info.minor}" - apitag = __import__("sysconfig").get_config_var("HOST_GNU_TYPE") apitag = apitag.replace("-", "_") - print("163: async_repos", Config.PKG_INDEXES) + + # user can override "PYPI" index + if os.environ.get('PYGPI',""): + Config.PKG_INDEXES= [os.environ.get('PYGPI')] + + # default to "official" cdn + if not len(Config.PKG_INDEXES): + Config.PKG_INDEXES = [ Config.PKG_BASE_DEFAULT ] + + print("200: async_repos", Config.PKG_INDEXES) + for repo in Config.PKG_INDEXES: if apitag.find("mvp") > 0: idx = f"{repo}index.json" else: - idx = f"{repo}index-bi.json" + idx = f"{repo}index-090bi.json" async with fopen(idx, "r", encoding="UTF-8") as index: try: data = index.read() @@ -208,7 +213,7 @@ async def async_repos(): data = data.replace("", apitag) repo = json.loads(data) except: - pdb(f"110: {repo=}: malformed json index {data}") + pdb(f"216: {repo=}: malformed json index {data}") continue if repo not in Config.pkg_repolist: Config.pkg_repolist.append(repo) @@ -224,7 +229,7 @@ async def async_repos(): if not aio.cross.simulator: import platform - print("193:", platform.window.location.href) + print("232:", platform.window.location.href) if platform.window.location.href.startswith("http://localhost:8"): for idx, repo in enumerate(Config.pkg_repolist): repo["-CDN-"] = "http://localhost:8000/archives/repo/" @@ -238,7 +243,7 @@ async def async_repos(): print( f""" -=============== REDIRECTION TO DEV HOST {repo['-CDN-']} ================ +====== REDIRECT TO DEV HOST {repo['-CDN-']} ======== {abitag=} {apitag=} @@ -274,7 +279,7 @@ async def pip_install(pkg, sysconf={}): if pkg in HISTORY: return - print("253: searching", pkg) + print("282: searching", pkg) if not sysconf: sysconf = sconf @@ -286,7 +291,7 @@ async def pip_install(pkg, sysconf={}): pkg = Config.mapping[pkg.lower()] if pkg in HISTORY: return - print("279: package renamed to", pkg) + print("294: package renamed to", pkg) if pkg in platform.patches: if not pkg in PATCHLIST: @@ -306,13 +311,13 @@ async def pip_install(pkg, sysconf={}): if line.find("py3-none-any.whl") > 0: wheel_url = line.split('"', 2)[1] else: - print("283: ERROR: cannot find package :", pkg) + print("308: ERROR: cannot find package :", pkg) except FileNotFoundError: print("285: ERROR: cannot find package :", pkg) return except: - print("289: ERROR: cannot find package :", pkg) + print("320: ERROR: cannot find package :", pkg) return if wheel_url: @@ -322,12 +327,10 @@ async def pip_install(pkg, sysconf={}): if pkg not in HISTORY: HISTORY.append(pkg) except: - print("299: INVALID", pkg, "from", wheel_url) - + print("324: INVALID", pkg, "from", wheel_url) PYGAME = 0 - async def parse_code(code, env): global PATCHLIST, PYGAME @@ -378,7 +381,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, env, sconf + global PATCHLIST, async_repos, env, sconf print() print("-" * 11, "computing required packages", "-" * 10) @@ -386,12 +389,11 @@ async def check_list(code=None, filename=None): # so do patching here patchlevel = platform_wasm.todo.patch() if patchlevel: - print("264:parse_code() patches loaded :", list(patchlevel.keys())) + print("392: parse_code() patches loaded :", list(patchlevel.keys())) platform_wasm.todo.patch = lambda: None # and only do that once and for all. - await async_imports_init() await async_repos() - del async_imports_init, async_repos + del async_repos # mandatory importlib.invalidate_caches() diff --git a/src/pygbag/support/pygbag_fsm.py b/src/pygbag/support/pygbag_fsm.py index 9e81e6c..2c573d2 100644 --- a/src/pygbag/support/pygbag_fsm.py +++ b/src/pygbag/support/pygbag_fsm.py @@ -13,7 +13,7 @@ class Draft(object): ... -@dataclass() +@dataclass class FSM(Machine): states: tuple initial: str diff --git a/src/pygbag/support/pyodide.py b/src/pygbag/support/pyodide.py index 182b4ed..d66fbc3 100644 --- a/src/pygbag/support/pyodide.py +++ b/src/pygbag/support/pyodide.py @@ -23,10 +23,16 @@ class m_pyodide: import pyodide class m_canvas: - def getCanvas3D(self, name='canvas',width=1024,height=1024): - canvas = platform.document.getElementById("canvas") - canvas.width = width - canvas.height = height + def getCanvas3D(self, name='canvas',width=0,height=0): + canvas = platform.document.getElementById(name) + try: + width = width or canvas.width + height = height or canvas.height + #print(f"canvas size was previously set to : {width=} x {height=}") + except: + pass + canvas.width = width or 1024 + canvas.height = height or 1024 return canvas class m_pyodide_js: diff --git a/static/default.tmpl b/static/default.tmpl index 2205ea5..0965875 100644 --- a/static/default.tmpl +++ b/static/default.tmpl @@ -1,4 +1,4 @@ -