Skip to content

Commit

Permalink
0.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Aug 18, 2024
1 parent 9da289f commit 4b113af
Show file tree
Hide file tree
Showing 22 changed files with 112 additions and 104 deletions.
7 changes: 0 additions & 7 deletions scripts/build-loader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,6 @@ END
done
popd
fi
#echo "
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# emsdk tot js gen temp fix
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#"
# sed -i 's/_glfwSetWindowContentScaleCallback_sig=iii/_glfwSetWindowContentScaleCallback_sig="iii"/g' \
# ${DIST_DIR}/python${PYMAJOR}${PYMINOR}/${MODE}.js
du -hs ${DIST_DIR}/*
else
echo "pymain+loader linking failed"
Expand Down
4 changes: 2 additions & 2 deletions src/pygbag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
VERSION = "0.0.0"

# make aio available
if not sys.platform in ('emscripten','wasi'):
if not sys.platform in ("emscripten", "wasi"):
# must be first for readline
sys.path.insert(0, str(Path(__file__).parent / "support" ))
sys.path.insert(0, str(Path(__file__).parent / "support"))
sys.path.append(str(Path(__file__).parent / "support/cross"))


Expand Down
6 changes: 2 additions & 4 deletions src/pygbag/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ class fake_EventTarget:
clients = {}
events = []

async def process(self):
...
async def process(self): ...

def patch_platform_system():
return "Emscripten"
Expand Down Expand Up @@ -180,8 +179,7 @@ def system(cls):
return "Linux"

@classmethod
def no_op(cls, *argv, **kw):
...
def no_op(cls, *argv, **kw): ...

run = no_op

Expand Down
8 changes: 5 additions & 3 deletions src/pygbag/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
if aio.pep0723.Config.dev_mode:
aio.pep0723.Config.PKG_INDEXES.extend(["http://localhost:8000/archives/repo/"])
else:
aio.pep0723.Config.PKG_INDEXES.extend([
os.environ.get('PYGPY', "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__

Expand Down
12 changes: 6 additions & 6 deletions src/pygbag/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@

from .__init__ import VERSION

if '--no_ssl_check' in sys.argv:
if "--no_ssl_check" in sys.argv:
import ssl

# ssl local server testing.
ssl._create_default_https_context = ssl._create_unverified_context
#os.environ["REQUESTS_CA_BUNDLE"]="/etc/ssl/certs/ca-bundle.crt"
# os.environ["REQUESTS_CA_BUNDLE"]="/etc/ssl/certs/ca-bundle.crt"
sys.argv.remove("--no_ssl_check")

import pygbag
Expand Down Expand Up @@ -396,12 +397,11 @@ async def main_run(app_folder, mainscript, cdn=DEFAULT_CDN):
"spdx": "cookiecutter.spdx",
"version": VERSION,
"PYBUILD": args.PYBUILD,
"COLUMNS" : args.COLUMNS,
"LINES" : args.LINES,
"CONSOLE" : args.CONSOLE,
"COLUMNS": args.COLUMNS,
"LINES": args.LINES,
"CONSOLE": args.CONSOLE,
}


pygbag.config = CC

await pack.archive(f"{app_name}.apk", app_folder, build_dir)
Expand Down
2 changes: 2 additions & 0 deletions src/pygbag/gathering.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
from pathlib import Path


class Error(Exception):
pass


def gather(root: Path, *kw):
if root.is_file():
if root.name == "main.py":
Expand Down
2 changes: 1 addition & 1 deletion src/pygbag/optimizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"wav": "ogg",
"bmp": "png",
"mp3": "ogg",
"xm" : "ogg",
"xm": "ogg",
}


Expand Down
12 changes: 4 additions & 8 deletions src/pygbag/support/_xterm_parser/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@
class MessageTarget(Protocol):
"""Protocol that must be followed by objects that can receive messages."""

async def _post_message(self, message: "Message") -> bool:
...
async def _post_message(self, message: "Message") -> bool: ...

def post_message(self, message: "Message") -> bool:
...
def post_message(self, message: "Message") -> bool: ...


class EventTarget(Protocol):
async def _post_message(self, message: "Message") -> bool:
...
async def _post_message(self, message: "Message") -> bool: ...

def post_message(self, message: "Message") -> bool:
...
def post_message(self, message: "Message") -> bool: ...


class UnusedParameter:
Expand Down
28 changes: 15 additions & 13 deletions src/pygbag/support/cpythonrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def dump_code():
else:

# for the various emulations/tools provided
sys.path.append('/data/data/org.python/assets')
sys.path.append("/data/data/org.python/assets")

PyConfig["pkg_repolist"] = []

Expand Down Expand Up @@ -253,9 +253,9 @@ def dump_code():
del home

# now in pep0723
#PYCONFIG_PKG_INDEXES = [
# PYCONFIG_PKG_INDEXES = [
# os.environ.get('PYGPY', "https://pygame-web.github.io/archives/repo/"),
#]
# ]

PyConfig["imports_ready"] = False
PyConfig["pygbag"] = 0
Expand Down Expand Up @@ -688,8 +688,8 @@ async def preload_code(cls, code, callback=None, loaderhome=".", hint=""):
if not len(Config.repos):
await aio.pep0723.async_repos()

# TODO switch to METADATA:Requires-Dist
# see https://github.com/pygame-web/pygbag/issues/156
# 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:
Expand All @@ -708,13 +708,13 @@ async def preload_code(cls, code, callback=None, loaderhome=".", hint=""):
DBG(f"635: {maybe_wanted=} known failed {aio.pep0723.hint_failed=}")

# FIXME use an hybrid wheel
if 'pyodide' in aio.pep0723.hint_failed:
if "pyodide" in aio.pep0723.hint_failed:

for no_need in ('_zengl','pyodide','beautifulsoup4'):
for no_need in ("_zengl", "pyodide", "beautifulsoup4"):
if no_need in maybe_wanted:
maybe_wanted.remove(no_need)
# force
maybe_wanted.append('beautifulsoup4')
maybe_wanted.append("beautifulsoup4")

for dep in maybe_wanted:
if not dep in deps:
Expand Down Expand Up @@ -1073,10 +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)
# now in pep0723
# 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

Expand Down Expand Up @@ -1375,6 +1375,7 @@ def __call__(self, callid, fn, *argv, **env):
return None

print(f"{self.__dlref}.{fn}({argv},{env}) {callid=}")

async def rv():
obj = await platform.jsiter(window.dlcall(callid, jshex))
return json.loads(obj)
Expand Down Expand Up @@ -1475,6 +1476,7 @@ def log(*argv, **kw):
LOCK
except:
import builtins

builtins.LOCK = False


Expand Down Expand Up @@ -1617,7 +1619,7 @@ async def main():
local = tmpdir / file
break
DBG("1862: import_site: found ", local)
elif str(source).startswith('http'):
elif str(source).startswith("http"):
print("Remote file :", source)
local = tmpdir / "remote.py"
await shell.exec(shell.wget(f"-O{local}", source))
Expand Down
4 changes: 2 additions & 2 deletions src/pygbag/support/cross/__EMSCRIPTEN__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def requestAnimationFrame(fn):
async def main():
while not aio.exit:
if len(AnimatedFrames):
frames.append( AnimatedFrames.pop(0) )
frames.append(AnimatedFrames.pop(0))
await asyncio.sleep(0)

asyncio.run(main())
Expand All @@ -105,7 +105,7 @@ async def main():

# just a workaround until bridge support js "options" from **kw
def ffi(arg=0xDEADBEEF, **kw):
if arg==0xDEADBEEF:
if arg == 0xDEADBEEF:
return window.JSON.parse(json.dumps(kw))
return window.JSON.parse(json.dumps(arg))

Expand Down
3 changes: 1 addition & 2 deletions src/pygbag/support/cross/aio/clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class tui:
out = sys.__stdout__.write
else:

def out(self, *argv, **kw):
...
def out(self, *argv, **kw): ...

try:
LINES = int(os.environ.get("LINES", 200))
Expand Down
53 changes: 28 additions & 25 deletions src/pygbag/support/cross/aio/pep0723.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@


class Config:
READ_722 = False
# READ_722 = False
READ_723 = True
BLOCK_RE_722 = r"(?i)^#\s+script\s+dependencies:\s*$"
# BLOCK_RE_722 = r"(?i)^#\s+script\s+dependencies:\s*$"
BLOCK_RE_723 = r"(?m)^# /// (?P<type>[a-zA-Z0-9-]+)$\s(?P<content>(^#(| .*)$\s)+)^# ///$"
PKG_BASE_DEFAULT = "https://pygame-web.github.io/archives/repo/"
PKG_INDEXES = []
Expand All @@ -72,8 +72,8 @@ class Config:
"pygame_ce": "pygame.base",
"python_i18n": "i18n",
"pillow": "PIL",
"pyglm" : "glm",
"opencv_python" : "cv2",
"pyglm": "glm",
"opencv_python": "cv2",
}


Expand Down Expand Up @@ -110,7 +110,7 @@ def read_dependency_block_723(code):
content = []
for line in code.split("\n"):
if not has_block:
if line.strip() in ["# /// pyproject","# /// script"]:
if line.strip() in ["# /// pyproject", "# /// script"]:
has_block = True
continue

Expand Down Expand Up @@ -192,12 +192,12 @@ async def async_repos():
apitag = apitag.replace("-", "_")

# user can override "PYPI" index
if os.environ.get('PYGPI',""):
Config.PKG_INDEXES= [os.environ.get('PYGPI')]
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 ]
Config.PKG_INDEXES = [Config.PKG_BASE_DEFAULT]

print("200: async_repos", Config.PKG_INDEXES)

Expand All @@ -218,18 +218,18 @@ async def async_repos():
if repo not in Config.pkg_repolist:
Config.pkg_repolist.append(repo)
except FileNotFoundError:
print("\n"*4)
print("!"*75)
print("\n" * 4)
print("!" * 75)
print("Sorry, there is no pygbag package repository for your python version")
print("!"*75,"\n"*4)
print("!" * 75, "\n" * 4)
raise SystemExit


if not aio.cross.simulator:
rewritecdn = ""
import platform
if os.environ.get('PYGPI',""):
rewritecdn = os.environ.get('PYGPI')

if os.environ.get("PYGPI", ""):
rewritecdn = os.environ.get("PYGPI")
elif platform.window.location.href.startswith("http://localhost:8"):
rewritecdn = "http://localhost:8000/archives/repo/"

Expand All @@ -238,6 +238,7 @@ async def async_repos():
for idx, repo in enumerate(Config.pkg_repolist):
repo["-CDN-"] = rewritecdn


async def install_pkg(sysconf, wheel_url, wheel_pkg):
target_filename = f"/tmp/{wheel_pkg}"
async with fopen(wheel_url, "rb") as pkg:
Expand Down Expand Up @@ -321,20 +322,21 @@ async def pip_install(pkg, sysconf={}):

PYGAME = 0


async def parse_code(code, env):
global PATCHLIST, PYGAME

maybe_missing = []

if Config.READ_722:
for req in read_dependency_block_722(code):
pkg = str(req)
if (env / pkg).is_dir():
print("found in env :", pkg)
continue
elif pkg not in maybe_missing:
# do not change case ( eg PIL )
maybe_missing.append(pkg.lower().replace("-", "_"))
# if Config.READ_722:
# for req in read_dependency_block_722(code):
# pkg = str(req)
# if (env / pkg).is_dir():
# print("found in env :", pkg)
# continue
# elif pkg not in maybe_missing:
# # do not change case ( eg PIL )
# maybe_missing.append(pkg.lower().replace("-", "_"))

if Config.READ_723:
for req in read_dependency_block_723(code):
Expand Down Expand Up @@ -436,12 +438,13 @@ async def check_list(code=None, filename=None):
if not aio.cross.simulator:
import platform
import asyncio

print(f'# 439: Scanning {sconf["platlib"]} for WebAssembly library')
platform.explore(sconf["platlib"], verbose=True)
for compilation in range(1+embed.preloading()):
for compilation in range(1 + embed.preloading()):

await asyncio.sleep(0)
if embed.preloading()<=0:
if embed.preloading() <= 0:
break
else:
print("# 442: ERROR: remaining wasm {embed.preloading()}")
Expand Down
3 changes: 1 addition & 2 deletions src/pygbag/support/cross/aio/toplevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,4 @@ async def start_toplevel(cls, shell, console=True, ns="__main__"):
else:
# TODO upy event driven async repl

class AsyncInteractiveConsole:
...
class AsyncInteractiveConsole: ...
5 changes: 3 additions & 2 deletions src/pygbag/support/pygbag_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def get(self):
platform.shell.interactive(True)
aio.toplevel.handler.muted = False

clear(LINES, CONSOLE-1) # , '>C> ')
clear(LINES, CONSOLE - 1) # , '>C> ')
return self

__ALL__ = [ ui, ux ]

__ALL__ = [ui, ux]
Loading

0 comments on commit 4b113af

Please sign in to comment.