Skip to content

Commit

Permalink
add _strptime
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Oct 12, 2023
1 parent f9da862 commit 640aa21
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 33 deletions.
2 changes: 1 addition & 1 deletion pygbag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 !
Expand Down
4 changes: 2 additions & 2 deletions pygbag/support/cross/__EMSCRIPTEN__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 8 additions & 5 deletions pygbag/support/cross/aio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import inspect



DEBUG = True
NICE = 0.010

Expand Down Expand Up @@ -40,6 +39,7 @@ def pdb(*argv):
from .filelike import *
else:
import utime

time_time = utime.ticks_ms


Expand Down Expand Up @@ -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:
Expand All @@ -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)


Expand Down
5 changes: 0 additions & 5 deletions pygbag/support/cross/aio/cross.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__")
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pygbag/support/cross/aio/filelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

if not __UPY__:
import socket

socket.setdefaulttimeout(0.0)
else:
print("7: usocket implementation required")
Expand All @@ -11,7 +12,6 @@
import os # unlink



import aio
import platform

Expand Down Expand Up @@ -58,7 +58,6 @@ def mktemp(suffix=""):

class fopen:
if __WASM__ and hasattr(platform, "ffi"):

flags = platform.ffi(
{
"redirect": "follow",
Expand Down
4 changes: 1 addition & 3 deletions pygbag/support/cross/aio/toplevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
embed = False

if not __UPY__:

import code

def install(pkg_file, sconf=None):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -317,5 +314,6 @@ async def start_toplevel(cls, shell, console=True, ns="__main__"):
cls.start_console(shell, ns=ns)

else:

class AsyncInteractiveConsole:
...
14 changes: 8 additions & 6 deletions pygbag/support/pythonrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -858,6 +858,7 @@ def __repr__(self):

def __eq__(self, other):
return self.__dict__ == other.__dict__

types.SimpleNamespace = SimpleNamespace
else:
from types import SimpleNamespace
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions pygbag/testserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
CACHE = None

# does not support {x=}
#try:
# try:
# from future_fstrings import fstring_decode
#except:
# except:
fstring_decode = False


Expand Down Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions scripts/build-rootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ import tty
# cffi
import copy
# datetime
import datetime
import _strptime
# numpy
import secrets
Expand Down
11 changes: 6 additions & 5 deletions static/pythons.js
Original file line number Diff line number Diff line change
Expand Up @@ -2264,20 +2264,21 @@ 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
}

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"
Expand All @@ -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
}
}
}
Expand Down

0 comments on commit 640aa21

Please sign in to comment.