diff --git a/pygbag/__init__.py b/pygbag/__init__.py index 53db400..9d8f720 100644 --- a/pygbag/__init__.py +++ b/pygbag/__init__.py @@ -7,7 +7,7 @@ from pathlib import Path -__version__ = "0.8.3" +__version__ = "0.8.4" # hack to test git cdn build without upgrading pygbag # beware can have side effects when file packager behaviour must change ! diff --git a/pygbag/support/cross/__EMSCRIPTEN__.py b/pygbag/support/cross/__EMSCRIPTEN__.py index b77669d..6f64a07 100644 --- a/pygbag/support/cross/__EMSCRIPTEN__.py +++ b/pygbag/support/cross/__EMSCRIPTEN__.py @@ -26,9 +26,9 @@ def shed_yield(): # those __dunder__ are usually the same used in C conventions. -#try: +# try: # __UPY__ -#except: +# except: # if hasattr(sys.implementation, "_mpy"): # builtins.__UPY__ = this # else: diff --git a/pygbag/support/cross/aio/__init__.py b/pygbag/support/cross/aio/__init__.py index 4ff25ad..896ecfc 100644 --- a/pygbag/support/cross/aio/__init__.py +++ b/pygbag/support/cross/aio/__init__.py @@ -3,7 +3,6 @@ import inspect - DEBUG = True NICE = 0.010 @@ -40,6 +39,7 @@ def pdb(*argv): from .filelike import * else: import utime + time_time = utime.ticks_ms @@ -152,8 +152,11 @@ def overloaded(i, *attrs): __run__ = run if __UPY__: - def _set_running_loop(l):pass - sys.modules['asyncio.events'] = aio + + def _set_running_loop(l): + pass + + sys.modules["asyncio.events"] = aio aio.get_running_loop = aio.get_event_loop events = aio else: @@ -170,8 +173,8 @@ def _set_running_loop(l):pass loop = get_event_loop() -#import asyncio.events -#asyncio.events._set_running_loop(loop) +# import asyncio.events +# asyncio.events._set_running_loop(loop) _set_running_loop(loop) diff --git a/pygbag/support/cross/aio/cross.py b/pygbag/support/cross/aio/cross.py index 3568995..e40b3d7 100644 --- a/pygbag/support/cross/aio/cross.py +++ b/pygbag/support/cross/aio/cross.py @@ -29,7 +29,6 @@ def print_exception(e, out=sys.stderr, **kw): del print_exception - if not defined("__WASM__"): try: # that sym cannot be overloaded in the simulator @@ -53,7 +52,6 @@ def print_exception(e, out=sys.stderr, **kw): define("__wasi__", __wasi__) - # this *is* the cpython way if hasattr(sys, "getandroidapilevel"): platform_impl = defined("__ANDROID__") @@ -133,9 +131,6 @@ def print_exception(e, out=sys.stderr, **kw): sys.modules["platform"] = platform_impl - - - if not __UPY__: # setup exception display with same syntax as upy import traceback diff --git a/pygbag/support/cross/aio/filelike.py b/pygbag/support/cross/aio/filelike.py index 2e1d320..20d2ec2 100644 --- a/pygbag/support/cross/aio/filelike.py +++ b/pygbag/support/cross/aio/filelike.py @@ -3,6 +3,7 @@ if not __UPY__: import socket + socket.setdefaulttimeout(0.0) else: print("7: usocket implementation required") @@ -11,7 +12,6 @@ import os # unlink - import aio import platform @@ -58,7 +58,6 @@ def mktemp(suffix=""): class fopen: if __WASM__ and hasattr(platform, "ffi"): - flags = platform.ffi( { "redirect": "follow", diff --git a/pygbag/support/cross/aio/toplevel.py b/pygbag/support/cross/aio/toplevel.py index c1a9340..211983d 100644 --- a/pygbag/support/cross/aio/toplevel.py +++ b/pygbag/support/cross/aio/toplevel.py @@ -17,7 +17,6 @@ embed = False if not __UPY__: - import code def install(pkg_file, sconf=None): @@ -50,7 +49,6 @@ def install(pkg_file, sconf=None): pdb(f"49: cannot install {pkg_file}") sys.print_exception(ex) - async def get_repo_pkg(pkg_file, pkg, resume, ex): global HISTORY @@ -107,7 +105,6 @@ async def get_repo_pkg(pkg_file, pkg, resume, ex): sys.print_exception(ex, limit=-1) return None - class AsyncInteractiveConsole(code.InteractiveConsole): instance = None console = None @@ -317,5 +314,6 @@ async def start_toplevel(cls, shell, console=True, ns="__main__"): cls.start_console(shell, ns=ns) else: + class AsyncInteractiveConsole: ... diff --git a/pygbag/support/pythonrc.py b/pygbag/support/pythonrc.py index 457d16f..689a414 100644 --- a/pygbag/support/pythonrc.py +++ b/pygbag/support/pythonrc.py @@ -196,7 +196,7 @@ def dump_code(): aio.cross.simulator = False sys.argv.clear() - sys.argv.extend( PyConfig.pop("argv", []) ) + sys.argv.extend(PyConfig.pop("argv", [])) except Exception as e: @@ -206,7 +206,7 @@ def dump_code(): PyConfig["dev_mode"] = 1 PyConfig["run_filename"] = "main.py" -# TODO: use location of python js module. + # TODO: use location of python js module. if __UPY__: PyConfig["executable"] = "upy" else: @@ -843,12 +843,12 @@ async def exec(cls, sub, **env): # end shell - if __UPY__: import types + class SimpleNamespace: def __init__(self, **kwargs): - for k,v in kwargs.items(): + for k, v in kwargs.items(): setattr(self, k, v) def __repr__(self): @@ -858,6 +858,7 @@ def __repr__(self): def __eq__(self, other): return self.__dict__ == other.__dict__ + types.SimpleNamespace = SimpleNamespace else: from types import SimpleNamespace @@ -1015,9 +1016,9 @@ def File(path): pdb("1010: missing os.umask") pdb("1011: missing zipfile") - import aio.toplevel - #import ast + + # import ast from pathlib import Path class TopLevel_async_handler(aio.toplevel.AsyncInteractiveConsole): @@ -1085,6 +1086,7 @@ def eval(self, source): @classmethod def scan_imports(cls, code, filename, load_try=False, hint=""): import ast + required = [] try: root = ast.parse(code, filename) diff --git a/pygbag/testserver.py b/pygbag/testserver.py index c95f0f2..ca0a723 100644 --- a/pygbag/testserver.py +++ b/pygbag/testserver.py @@ -36,9 +36,9 @@ CACHE = None # does not support {x=} -#try: +# try: # from future_fstrings import fstring_decode -#except: +# except: fstring_decode = False @@ -85,9 +85,11 @@ def do_HEAD(self): def send_head(self): global VERB, CDN, PROXY, BCDN, BPROXY, AUTO_REBUILD path = self.translate_path(self.path) - print(f""" + print( + f""" -{self.path=} {path=}""") +{self.path=} {path=}""" + ) f = None if os.path.isdir(path): diff --git a/scripts/build-rootfs.sh b/scripts/build-rootfs.sh index 8d9fc38..bffa36c 100755 --- a/scripts/build-rootfs.sh +++ b/scripts/build-rootfs.sh @@ -117,6 +117,10 @@ import tty # cffi import copy +# datetime +import datetime +import _strptime + # numpy import secrets diff --git a/static/pythons.js b/static/pythons.js index 31c643b..380ac0d 100644 --- a/static/pythons.js +++ b/static/pythons.js @@ -2264,12 +2264,13 @@ console.warn("TODO: merge/replace location options over script options") } // resolve python executable, cmdline first then script - var pystr = "cpython" + const default_version = "3.11" + var pystr = "cpython" + default_version - if (vm.cpy_argv.length && vm.cpy_argv[0].search('py')>=0) { + if (vm.cpy_argv.length && (vm.cpy_argv[0].search('py')>=0)) { pystr = vm.cpy_argv[0] } else { - if (cfg.python.search('py')>=0) { + if (cfg.python && (cfg.python.search('py')>=0)) { pystr = cfg.python } // fallback to cpython @@ -2277,7 +2278,7 @@ console.warn("TODO: merge/replace location options over script options") if (pystr.search('cpython3')>=0) { vm.script.interpreter = "cpython" - config.PYBUILD = pystr.substr(7) || "3.11" + config.PYBUILD = pystr.substr(7) || default_version } else { if (pystr.search('python3')>=0) { vm.script.interpreter = "python" @@ -2288,7 +2289,7 @@ console.warn("TODO: merge/replace location options over script options") config.PYBUILD = pystr.substr(4) || "3.4" } else { vm.script.interpreter = config.python || "cpython" - config.PYBUILD = pystr.substr(7) || "3.11" + config.PYBUILD = pystr.substr(7) || default_version } } }