Skip to content

Commit

Permalink
0.8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Oct 28, 2023
1 parent 250afa3 commit 03019ab
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 332 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ jobs:
build:
runs-on: ubuntu-22.04
env:
SDK_VERSION: 3.1.47.2bi
SDK_VERSION: 3.1.48.0bi
SYS_PYTHON: /usr/bin/python3
PACKAGES: emsdk hpy _ctypes pygame
BUILD_STATIC: emsdk _ctypes hpy
STATIC: false
BUILDS: 3.11 3.12
CYTHON: Cython-3.0.1-py2.py3-none-any.whl
CYTHON: Cython-3.0.4-py2.py3-none-any.whl
LD_VENDOR: -sUSE_GLFW=3

steps:
- uses: actions/checkout@v3.3.0
- uses: actions/checkout@v4.1.0
- name: pygame-wasm-builder prepare
run: |
pwd
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include pygbag/support *
19 changes: 18 additions & 1 deletion pygbag/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ async def import_site(sourcefile=None, simulator=False, async_input=None, async_
module directory : {mod_dir}
platform support : {support}
{sys.argv=}
{sourcefile=}
"""
)

Expand Down Expand Up @@ -87,14 +89,18 @@ def __del__(self):
pass

def __repr__(self):
return "\nNoOp:%s:" % self.__descr
return "\nNoOp: %s" % self.__descr

__str__ = __repr__

# fake host document.window
import platform as fakehost

def truc(*argv, **kw):
print("truc", argv, kw)

fakehost.window = NoOp("platform.window")
fakehost.window.get_terminal_console = truc

import aio.filelike

Expand Down Expand Up @@ -167,9 +173,12 @@ def no_op(cls, *argv, **kw):
sys.modules["__EMSCRIPTEN__"] = __EMSCRIPTEN__
sys.modules["embed"] = __EMSCRIPTEN__

print(" =============== pythonrc =================")
with open(support / "pythonrc.py", "r") as file:
exec(file.read(), globals(), globals())

print(" =============== /pythonrc =================")

import zipfile
import aio.toplevel
import ast
Expand Down Expand Up @@ -219,6 +228,14 @@ async def raw_input(self, prompt=">>> "):
return maybe
return None

async def async_get_pkg(cls, want, ex, resume):
print(
"""
224:TODO: PEP723
async def async_get_pkg(cls, want, ex, resume)
"""
)

# start async top level machinery and add a console.
await TopLevel_async_handler.start_toplevel(platform.shell, console=True)
ns = vars(__import__(__name__))
Expand Down
9 changes: 5 additions & 4 deletions pygbag/aio.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import sys

import os
import aio

# to allow "import pygbag.aio as asyncio"
sys.modules["pygbag.aio"] = aio

# if not wasm cpu then run caller in simulator and block.
if not __import__("os").uname().machine.startswith("wasm"):

if hasattr(os, "uname") and not os.uname().machine.startswith("wasm"):
import time
from pathlib import Path

Expand All @@ -27,10 +28,10 @@ async def custom_async_input():

aio.loop.create_task(
pygbag.__main__.import_site(
sourcefile=sys.argv[-1],
sourcefile=sys.argv[0],
simulator=True,
async_input=custom_async_input,
async_pkg=aio.pep0723.check_list(filename=sys.argv[-1]),
async_pkg=aio.pep0723.check_list(filename=sys.argv[0]),
)
)

Expand Down
106 changes: 68 additions & 38 deletions pygbag/support/cross/aio/pep0723.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@

from aio.filelike import fopen

import platform

print(platform)

import platform_wasm.todo

PATCHLIST = []


class Config:
READ_722 = False
Expand Down Expand Up @@ -181,7 +189,8 @@ async def install_pkg(sysconf, wheel_url, wheel_pkg):


async def pip_install(pkg, sconf={}):
print("searching", pkg)
print("185: searching TODO: install from repo in found key", pkg)

if not sconf:
sconf = __import__("sysconfig").get_paths()

Expand All @@ -196,21 +205,28 @@ async def pip_install(pkg, sconf={}):
else:
print("270: ERROR: cannot find package :", pkg)
except FileNotFoundError:
print("190: ERROR: cannot find package :", pkg)
print("200: ERROR: cannot find package :", pkg)
return

except:
print("194: ERROR: cannot find package :", pkg)
print("204: ERROR: cannot find package :", pkg)
return

try:
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)
if wheel_url:
try:
wheel_pkg, wheel_hash = wheel_url.rsplit("/", 1)[-1].split("#", 1)
await install_pkg(sconf, wheel_url, wheel_pkg)
except:
print("212: INVALID", pkg, "from", wheel_url)


async def parse_code(code, env):
global PATCHLIST

# pythonrc is calling aio.pep0723.parse_code not check_list
# so do patching here
platform_wasm.todo.patch()

maybe_missing = []

if Config.READ_722:
Expand All @@ -235,7 +251,12 @@ async def parse_code(code, env):

still_missing = []

import platform

for dep in maybe_missing:
if dep in platform.patches:
PATCHLIST.append(dep)

if not importlib.util.find_spec(dep) and dep not in still_missing:
still_missing.append(dep.lower())
else:
Expand All @@ -244,7 +265,10 @@ async def parse_code(code, env):
return still_missing


# parse_code does the patching
# this is not called by pythonrc
async def check_list(code=None, filename=None):
global PATCHLIST
print()
print("-" * 11, "computing required packages", "-" * 10)

Expand All @@ -267,42 +291,48 @@ async def check_list(code=None, filename=None):

still_missing = await parse_code(code, env)

# nothing to do
if not len(still_missing):
return
# is there something to do ?
if len(still_missing):
importlib.invalidate_caches()

importlib.invalidate_caches()
# only do that once and for all.
if not len(Config.repos):
await async_imports_init()
await async_repos()

# only do that once and for all.
if not len(Config.repos):
await async_imports_init()
await async_repos()
# TODO: check for possible upgrade of env/* pkg

# TODO: check for possible upgrade of env/* pkg
maybe_missing = still_missing
still_missing = []

maybe_missing = still_missing
still_missing = []
for pkg in maybe_missing:
hit = ""
for repo in Config.pkg_repolist:
wheel_pkg = repo.get(pkg, "")
if wheel_pkg:
wheel_url = repo["-CDN-"] + "/" + wheel_pkg
wheel_pkg = wheel_url.rsplit("/", 1)[-1]
await install_pkg(sconf, wheel_url, wheel_pkg)
hit = pkg

for pkg in maybe_missing:
hit = ""
for repo in Config.pkg_repolist:
wheel_pkg = repo.get(pkg, "")
if wheel_pkg:
wheel_url = repo["-CDN-"] + "/" + wheel_pkg
wheel_pkg = wheel_url.rsplit("/", 1)[-1]
await install_pkg(sconf, wheel_url, wheel_pkg)
hit = pkg

if len(hit):
print("found on pygbag repo and installed to env :", hit)
else:
still_missing.append(pkg)
if len(hit):
print("found on pygbag repo and installed to env :", hit)
else:
still_missing.append(pkg)

for pkg in still_missing:
if (env / pkg).is_dir():
print("found in env :", pkg)
continue
await pip_install(pkg)
for pkg in still_missing:
if (env / pkg).is_dir():
print("found in env :", pkg)
continue
await pip_install(pkg)

import platform

# apply any patches
while len(PATCHLIST):
dep = PATCHLIST.pop(0)
print(f"314: patching {dep}")
platform.patches.pop(dep)()

print("-" * 40)
print()
Loading

0 comments on commit 03019ab

Please sign in to comment.