Skip to content

Commit

Permalink
rename sitecustomize to custom_site, fix shell.source
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Oct 21, 2022
1 parent 34dc8bc commit 154955a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
3 changes: 1 addition & 2 deletions pygbag/support/cross/__EMSCRIPTEN__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,11 @@ def js(code, delay=0):
# ========================================== DOM EVENTS ===============

if is_browser:
# implement "new"
# implement "js.new"

def new(oclass, *argv):
from embed_browser import Reflect, Array
return Reflect.construct(oclass, Array(*argv) )
builtins.new = new


# dom events
Expand Down
33 changes: 22 additions & 11 deletions pygbag/support/pythonrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,18 @@ def wget(cls, *argv, **env):
filename = None
for arg in map(str, argv):
if arg.startswith("-O"):
filename = arg[2:].lstrip()
filename = arg[2:].strip()
yield f'saving to "{filename}"'
break

for arg in map(str, argv):
if arg.startswith("-O"):
continue
fn = filename or str(argv[0]).rsplit('/')[-1]
filename, _ = urllib.request.urlretrieve(str(arg), filename=fn)
try:
filename, _ = urllib.request.urlretrieve(str(arg), filename=fn)
except Exception as e:
yield e

return True

Expand Down Expand Up @@ -355,7 +360,7 @@ def sha256sum(cls, *argv):
yield f"{hx} {arg}"

@classmethod
def exec(cls, cmd, *argv, **env):
def spawn(cls, cmd, *argv, **env):
global pgzrun
# TODO extract env from __main__ snapshot
if cmd.endswith(".py"):
Expand All @@ -365,7 +370,7 @@ def exec(cls, cmd, *argv, **env):
)
cls.stop()
pgzrun = None
aio.defer(cls.exec, (cmd, *argv), env, delay=500)
aio.defer(cls.spawn, (cmd, *argv), env, delay=500)

else:
execfile(cmd)
Expand Down Expand Up @@ -541,21 +546,25 @@ async def perf_index():
print(f"last frame : {aio.spent / 0.016666666666666666:.4f}")

@classmethod
async def exec(cls, sub, *args):
if inspect.isgeneratorfunction(sub):
for _ in sub(*args):
async def exec(cls, sub, *argv):
if inspect.isgenerator(sub):
for _ in sub:
print(_)
return
elif inspect.isgeneratorfunction(sub):
for _ in sub(*argv):
print(_)
return
elif inspect.iscoroutinefunction(sub):
await sub(*args)
return

from collections.abc import Iterator
if isinstance(object, Iterator):
if isinstance(sub, Iterator):
for _ in sub:
print(_)
return
elif isinstance(sub, [str, Path]):
elif isinstance(sub, (str, Path,) ):
# subprocess
print("N/I", sub)
else:
Expand All @@ -566,9 +575,11 @@ async def exec(cls, sub, *args):
async def preload(cls, main, callback=None):
# get a relevant list of modules likely to be imported
# and prefetch them if found in repo trees
await TopLevel_async_handler.async_imports(*TopLevel_async_handler.list_imports(None, main), callback=callback)
imports = TopLevel_async_handler.list_imports(code=None, file=main)
print(f"579: {list(imports)}")
await TopLevel_async_handler.async_imports(*imports, callback=callback)
PyConfig.imports_ready = True

return True

@classmethod
async def source(cls, main, *args):
Expand Down

0 comments on commit 154955a

Please sign in to comment.