Skip to content

Commit

Permalink
add nofix #116 workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Sep 25, 2023
1 parent e122389 commit 5862345
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 64 deletions.
6 changes: 3 additions & 3 deletions pygbag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys

# some Linux distro are stuck in the past. Better safe than sorry
sys.stdout.reconfigure(encoding='utf-8')
sys.stdout.reconfigure(encoding="utf-8")

from pathlib import Path

Expand Down Expand Up @@ -32,10 +32,12 @@
try:
# embed builtin module handles I/O on wasm
import embed

# aio function implemented only on stackless WaPy
sched_yield
except:
import builtins

builtins.sched_yield = lambda: None

import sys, traceback
Expand All @@ -59,5 +61,3 @@ def ESC(*argv):
def CSI(*argv):
for arg in argv:
ESC(f"[{arg}")


3 changes: 0 additions & 3 deletions pygbag/support/cross/__EMSCRIPTEN__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def shed_yield():
builtins.__UPY__ = None



# force use a fixed, tested version of uasyncio to avoid non-determinism
if __UPY__:
sys.modules["sys"] = sys
Expand Down Expand Up @@ -101,7 +100,6 @@ async def jsprom(prom):
builtins.__EMSCRIPTEN__ = None



def init_platform(embed):
# simulator won't run javascript for now
if not hasattr(embed, "run_script"):
Expand Down Expand Up @@ -159,7 +157,6 @@ def build(self, evt_name, jsondata):
sys.print_exception(e)
print(jsondata)


# def dispatchEvent
async def rpc(self, method, *argv):
import inspect
Expand Down
11 changes: 4 additions & 7 deletions pygbag/support/cross/aio/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ def make_src_dst(base_url, base_path, path, target):
dst = target.copy()
dst.extend(path[1:])

preload_list.append([ base_path + "/".join(path), "/".join(dst)])
preload_list.append([base_path + "/".join(path), "/".join(dst)])
if debug:
print(preload_list[-1], "write", current, last)

for l in map(str.rstrip, tree.split("\n")):

if not silent:
print("HTMLFS:", base_url, base_path, "=>", target)

Expand All @@ -62,9 +61,9 @@ def make_src_dst(base_url, base_path, path, target):

base_path, trail = map(str.strip, l.split(" ~", 1))

base_path = base_path.strip('/')
base_path = base_path.strip("/")

trail = trail.strip('/')
trail = trail.strip("/")

# set destination
target = [trail]
Expand All @@ -86,8 +85,7 @@ def make_src_dst(base_url, base_path, path, target):
preload_list.append([base_url, "."])
continue


if l.find(' ')<0:
if l.find(" ") < 0:
continue

pos, elem = l.rsplit(" ", 1)
Expand Down Expand Up @@ -156,7 +154,6 @@ async def preload(chroot=None, chdir=True, silent=FS_SILENT, debug=FS_DEBUG, sta
print(f"153: REMOTE {full_url} LOCAL: {filename}")

if not filename.is_file():

filename.parent.mkdir(parents=True, exist_ok=True)
if sys.platform in ("emscripten", "wasi"):
async with platform.fopen(full_url, "rb") as source:
Expand Down
8 changes: 4 additions & 4 deletions pygbag/support/cross/aio/filelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import io
import socket

import os #unlink
import os # unlink

socket.setdefaulttimeout(0.0)

Expand Down Expand Up @@ -75,7 +75,7 @@ async def __aexit__(self, *exc):
try:
os.unlink(self.tmpfile)
except FileNotFoundError as e:
print("78: Async I/O error : file not found", self.url)
print("78: Async I/O error : file not found", self.url)
del self.filelike, self.url, self.mode, self.tmpfile

if __WASM__:
Expand All @@ -88,7 +88,7 @@ async def __aenter__(self):
try:
content = await platform.jsiter(cf)
except Exception as e:
print("91:",e)
print("91:", e)

if "b" in self.mode:
self.filelike = open(content, "rb")
Expand Down Expand Up @@ -128,7 +128,7 @@ async def __aenter__(self):


class sopen:
def __init__(self, url, mode, tmout): #=6):
def __init__(self, url, mode, tmout): # =6):
self.host, port = url.rsplit(":", 1)
self.port = int(port)
if __WASM__ and __import__("platform").is_browser:
Expand Down
5 changes: 2 additions & 3 deletions pygbag/support/cross/aio/pep0723.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ async def async_repos():
Config.pkg_repolist.append(repo)

if not aio.cross.simulator:
if window.location.href.startswith('https://pmp-p.ddns.net/pygbag'):
if window.location.href.startswith("https://pmp-p.ddns.net/pygbag"):
print(" =============== REDIRECTION TO DEV HOST ================ ")
for idx, repo in enumerate(PyConfig.pkg_repolist):
repo["-CDN-"] = "https://pmp-p.ddns.net/archives/repo/"
Expand Down Expand Up @@ -207,7 +207,7 @@ async def pip_install(pkg, sconf={}):
wheel_pkg, wheel_hash = wheel_url.rsplit("/", 1)[-1].split("#", 1)
await install_pkg(sconf, wheel_url, wheel_pkg)
except:
print("INVALID", pkg, 'from',wheel_url)
print("INVALID", pkg, "from", wheel_url)


async def parse_code(code, env):
Expand Down Expand Up @@ -262,7 +262,6 @@ async def check_list(code=None, filename=None):
# mandatory
importlib.invalidate_caches()


if code is None:
code = open(filename, "r").read()

Expand Down
30 changes: 20 additions & 10 deletions pygbag/support/cross/aio/toplevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def install(pkg_file, sconf=None):
)
HISTORY.append(pkg_file)
except FileExistsError:
print(f"38: {pkg_file} already installed")
print(f"47: {pkg_file} already installed")
except Exception as ex:
pdb(f"82: cannot install {pkg_file}")
pdb(f"49: cannot install {pkg_file}")
sys.print_exception(ex)


Expand All @@ -72,7 +72,7 @@ async def get_repo_pkg(pkg_file, pkg, resume, ex):
try:
aio.toplevel.install(pkg_file, sconf)
except Exception as rx:
pdb(f"failed to install {pkg_file}")
pdb(f"75: failed to install {pkg_file}")
sys.print_exception(rx)

# let wasm compilation happen
Expand All @@ -87,10 +87,10 @@ async def get_repo_pkg(pkg_file, pkg, resume, ex):
pdb(f"failed to preload {pkg_file}")
sys.print_exception(rx)
else:
print(f"84: {pkg_file} already installed")
print(f"90: {pkg_file} already installed")

if pkg in platform.patches:
print("88:", pkg, "requires patching")
print("93:", pkg, "requires patching")
platform.patches.pop(pkg)()

if resume and ex:
Expand Down Expand Up @@ -212,6 +212,10 @@ def prompt(self):
embed.prompt()

async def interact(self):

# multiline input clumsy sentinel
last_line = ""

try:
sys.ps1
except AttributeError:
Expand Down Expand Up @@ -241,17 +245,22 @@ async def interact(self):
break
else:
if self.push(self.line):
prompt = sys.ps2
if embed:
embed.set_ps2()
self.one_liner = False
if self.one_liner:
prompt = sys.ps2
if embed:
embed.set_ps2()
print("Sorry, multi line input editing is not supported", file=sys.stderr)
self.one_liner = False
self.resetbuffer()
else:
continue
else:
prompt = sys.ps1

except KeyboardInterrupt:
self.write("\nKeyboardInterrupt\n")
self.resetbuffer()
more = 0
self.one_liner = True

if aio.exit:
return
Expand All @@ -275,6 +284,7 @@ async def interact(self):
sys.print_exception(ex)

self.prompt()

aio.exit_now(0)

@classmethod
Expand Down
3 changes: 1 addition & 2 deletions pygbag/support/cross/aio/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def calls(frame, event, arg):

co = frame.f_code
func_name = co.co_name
if func_name in ("write","raw_input","process"):
if func_name in ("write", "raw_input", "process"):
return
func_line_no = frame.f_lineno
func_filename = co.co_filename
Expand All @@ -40,7 +40,6 @@ def calls(frame, event, arg):
if func_filename.find("/aio/") > 0:
return


caller = frame.f_back
if caller:
caller_line_no = caller.f_lineno
Expand Down
Loading

0 comments on commit 5862345

Please sign in to comment.