Skip to content

Commit 8c28aa4

Browse files
committed
work around promising main stuff in 3.1.74
1 parent 64d4aa4 commit 8c28aa4

File tree

5 files changed

+44
-72
lines changed

5 files changed

+44
-72
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ ____
134134
NOTES:
135135
- pygbag only provides support for pygame-ce ( pygame community edition )
136136

137-
- safari/chrome mobile will not run until version ios 15.x
137+
- safari/chrome mobile will not run until version ios 15.x. Regarding iOS: This project is tested with BrowserStack when possible.
138138

139139
- first load will be slower, because setting up local cache from cdn to avoid
140140
useless network transfer for getting pygame and cpython prebuilts.

src/pygbag/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from pathlib import Path
1111

12-
VERSION = "0.9.2"
12+
VERSION = "0.9.3"
1313

1414
__version__ = VERSION
1515

src/pygbag/support/cpythonrc.py

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -699,28 +699,15 @@ async def preload_code(cls, code, callback=None, loaderhome=".", hint=""):
699699
sconf = __import__("sysconfig").get_paths()
700700
env = Path(sconf["purelib"])
701701

702-
if not len(Config.repos):
703-
await aio.pep0723.async_repos()
704-
705-
# TODO switch to METADATA:Requires-Dist
706-
# see https://github.com/pygame-web/pygbag/issues/156
707-
708-
for cdn in Config.PKG_INDEXES:
709-
async with platform.fopen(Path(cdn) / Config.REPO_DATA) as source:
710-
Config.repos.append(json.loads(source.read()))
711-
712-
DBG("650: FIXME (this is pyodide maintened stuff, use (auto)PEP723 asap)")
713-
print("651: referenced packages :", len(Config.repos[0]["packages"]))
714-
715-
DBG(f"654: aio.pep0723.check_list {aio.pep0723.env=}")
702+
DBG(f"702: aio.pep0723.check_list {aio.pep0723.env=}")
716703
deps = await aio.pep0723.check_list(code)
717704

718-
DBG(f"656: aio.pep0723.pip_install {deps=}")
705+
DBG(f"705: aio.pep0723.pip_install {deps=}")
719706

720707
# auto import plumbing to avoid rely too much on import error
721708
maybe_wanted = list(TopLevel_async_handler.list_imports(code, file=None, hint=hint))
722709

723-
DBG(f"723: {maybe_wanted=} known failed {aio.pep0723.hint_failed=} {aio.pep0723.HISTORY=}")
710+
DBG(f"710: {maybe_wanted=} known failed {aio.pep0723.hint_failed=} {aio.pep0723.HISTORY=}")
724711

725712
# FIXME use an hybrid wheel
726713
if "pyodide" in aio.pep0723.hint_failed:
@@ -1534,19 +1521,17 @@ async def import_site(__file__, run=True):
15341521
# or the user script (script mode).
15351522

15361523
if Path(__file__).is_file():
1537-
DBG(f"1755: shell.source({__file__=})")
15381524
await shell.source(__file__)
15391525

15401526
# allow to set user site customization network, or embedded js to be processed
15411527
await asyncio.sleep(0)
15421528

15431529
if PyConfig.user_site_directory:
1544-
DBG(f"1768: {__file__=} done, giving hand to user_site")
15451530
return __file__
15461531
else:
1547-
DBG(f"1764: {__file__=} done : now trying user sources")
1532+
DBG(f"1545: {__file__=} done : now trying user sources")
15481533
else:
1549-
DBG(f"1767: {__file__=} NOT FOUND : now trying user sources")
1534+
DBG(f"1547: {__file__=} NOT FOUND : now trying user sources")
15501535

15511536
# NOW CHECK OTHER SOURCES
15521537

@@ -1607,8 +1592,6 @@ async def main():
16071592
else:
16081593
source = sys.argv[0]
16091594

1610-
DBG(f"1830: {local=} {source=} {is_py=} {hint=}")
1611-
16121595
if local is None:
16131596

16141597
ext = str(source).rsplit(".")[-1].lower()
@@ -1646,9 +1629,7 @@ async def main():
16461629
await shell.exec(shell.wget(f"-O{local}", source))
16471630
else:
16481631
# maybe base64 or frozen code in html.
1649-
...
1650-
1651-
DBG(f"1867: {local=} {source=} {is_py=} {hint=}")
1632+
pass
16521633

16531634
if local and local.is_file():
16541635
pdir = str(local.parent)

src/pygbag/support/cross/aio/pep0723.py

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class Config:
6161
PKG_BASE_DEFAULT = "https://pygame-web.github.io/archives/repo/"
6262
PKG_INDEXES = []
6363
REPO_INDEX = "index.json"
64-
REPO_DATA = "repodata.json"
6564
repos = []
6665
pkg_repolist = []
6766
dev_mode = ".-X.dev." in ".".join([""] + sys.orig_argv + [""])
@@ -71,9 +70,8 @@ class Config:
7170
Requires_Failures = []
7271

7372
mapping = {
74-
"pygame": "pygame.base",
75-
"pygame_ce": "pygame.base",
76-
"pygame_static": "pygame.base",
73+
"pygame": "pygame_ce",
74+
"pygame.base": "pygame_ce",
7775
"python_i18n": "i18n",
7876
"pillow": "PIL",
7977
"pyglm": "glm",
@@ -89,7 +87,8 @@ def read_dependency_block_723(code):
8987
content = []
9088
for line in code.split("\n"):
9189
if not has_block:
92-
if line.strip() in ["# /// pyproject", "# /// script"]:
90+
# compat with draft PEP for pyproject
91+
if line.rstrip() in ["# /// pyproject", "# /// script"]:
9392
has_block = True
9493
continue
9594

@@ -103,6 +102,7 @@ def read_dependency_block_723(code):
103102
struct = tomllib.loads("\n".join(content))
104103

105104
print(json.dumps(struct, sort_keys=True, indent=4))
105+
# compat with draft PEP
106106
if struct.get("project", None):
107107
struct = struct.get("project", {"dependencies": []})
108108
deps = struct.get("dependencies", [])
@@ -147,15 +147,6 @@ def install(pkg_file, sconf=None):
147147
sys.print_exception(ex)
148148

149149

150-
# see cpythonrc
151-
# if not len(Config.repos):
152-
# for cdn in (Config.PKG_INDEXES or PyConfig.pkg_indexes):
153-
# async with platform.fopen(Path(cdn) / Config.REPO_DATA) as source:
154-
# Config.repos.append(json.loads(source.read()))
155-
#
156-
# DBG("1203: FIXME (this is pyodide maintened stuff, use PEP723 asap) referenced packages :", len(cls.repos[0]["packages"]))
157-
158-
159150
async def async_repos():
160151
abitag = f"cp{sys.version_info.major}{sys.version_info.minor}"
161152
apitag = __import__("sysconfig").get_config_var("HOST_GNU_TYPE")
@@ -171,28 +162,31 @@ async def async_repos():
171162

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

165+
174166
for repo in Config.PKG_INDEXES:
175-
idx = f"{repo}index-0.9.2-{abitag}.json"
176-
try:
177-
async with fopen(idx, "r", encoding="UTF-8") as index:
178-
try:
179-
data = index.read()
180-
if isinstance(data, bytes):
181-
data = data.decode()
182-
data = data.replace("<abi>", abitag)
183-
data = data.replace("<api>", apitag)
184-
repo = json.loads(data)
185-
except:
186-
pdb(f"213: {idx=}: malformed json index {data}")
187-
continue
188-
if repo not in Config.pkg_repolist:
189-
Config.pkg_repolist.append(repo)
190-
except FileNotFoundError:
191-
print("\n" * 4)
192-
print("!" * 75)
193-
print("Sorry, there is no pygbag package repository for your python version")
194-
print("!" * 75, "\n" * 4)
195-
#raise SystemExit
167+
merged = {}
168+
for pygver in ('0.9.2', '0.9.3'):
169+
idx = f"{repo}index-{pygver}-{abitag}.json"
170+
try:
171+
async with fopen(idx, "r", encoding="UTF-8") as index:
172+
try:
173+
data = index.read()
174+
if isinstance(data, bytes):
175+
data = data.decode()
176+
data = data.replace("<abi>", abitag)
177+
data = data.replace("<api>", apitag)
178+
merged.update( json.loads(data) )
179+
except Exception as e:
180+
pdb(f"213: {idx=}: malformed json index {data}", e)
181+
continue
182+
except FileNotFoundError:
183+
print("\n" * 4)
184+
print("!" * 75)
185+
print("Sorry, there is no pygbag package repository for your python version")
186+
print("!" * 75, "\n" * 4)
187+
#raise SystemExit
188+
if merged:
189+
Config.pkg_repolist.append(merged)
196190

197191
if not aio.cross.simulator:
198192
rewritecdn = ""
@@ -462,20 +456,20 @@ async def check_list(code=None, filename=None):
462456
import platform
463457
import asyncio
464458

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

469463
await asyncio.sleep(0)
470464
if embed.preloading() <= 0:
471465
break
472466
else:
473-
print("# 442: ERROR: remaining wasm {embed.preloading()}")
467+
print("# 463: ERROR: remaining wasm {embed.preloading()}")
474468
await asyncio.sleep(0)
475469

476470
do_patches()
477471

478-
print("-" * 40)
472+
print("-" * 79)
479473
print()
480474

481475
return still_missing

static/pythons.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"use strict";
22

3+
WebAssembly.promising = null
4+
35
/* BF2 is still broken see https://github.com/jvilk/BrowserFS/issues/325
46
import { configure, BFSRequire, EmscriptenFS } from './browserfs.mjs';
57
//import { Buffer } from 'buffer';
@@ -87,7 +89,7 @@ window.addEventListener("error", function (e) {
8789
})
8890

8991
window.addEventListener('unhandledrejection', function (e) {
90-
alert("Error occurred: " + e.reason.message);
92+
alert("Rejection occurred: " + e.reason.message);
9193
})
9294

9395
function reverse(s){
@@ -413,7 +415,7 @@ async function postrun(vm) {
413415
window.VM = vm
414416

415417
var pyrc_url = vm.config.cdn + VM.script.interpreter + "rc.py"
416-
418+
console.log("Maybe RC", pyrc_url)
417419
await fetch(pyrc_url, {})
418420
.then( response => checkStatus(response) && response.arrayBuffer() )
419421
.then( buffer => run_pyrc(new Uint8Array(buffer)) )
@@ -2306,12 +2308,7 @@ async function onload() {
23062308
if (window.custom_onload)
23072309
window.custom_onload(debug_hidden)
23082310

2309-
23102311
window.busy--;
2311-
if (!config.quiet)
2312-
vm.vt.xterm.write('OK\r\nPlease \x1B[1;3;31mwait\x1B[0m ...\r\n')
2313-
2314-
23152312

23162313
if (window.window_resize)
23172314
window_resize(vm.config.gui_divider)

0 commit comments

Comments
 (0)