Skip to content

Commit

Permalink
Merge branch 'pygame-web:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
electronstudio authored Apr 5, 2024
2 parents 120728c + 0477f7d commit 9d2e36f
Show file tree
Hide file tree
Showing 23 changed files with 316 additions and 297 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
build:
runs-on: ubuntu-22.04
env:
SDK_VERSION: 3.1.55.1bi
SDK_VERSION: 3.1.57.2bi
SYS_PYTHON: /usr/bin/python3
PACKAGES: emsdk hpy pygame
BUILD_STATIC: emsdk hpy
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,5 @@ dmypy.json
/dist
/ATTIC
/platform_wasm
/assets
/testing
9 changes: 5 additions & 4 deletions packages.d/hpy/hpy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pushd external/hpy
${HPY} setup.py install

# ${SDKROOT}/python3-wasm setup.py install
${SDKROOT}/python3-wasm setup.py build
PYTHONOPTIMIZE=TRUE ${SDKROOT}/python3-wasm -O setup.py build

# link static
. ${SDKROOT}/emsdk/emsdk_env.sh
Expand Down Expand Up @@ -103,12 +103,13 @@ ${SDKROOT}/python3-wasm setup.py build
build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/universal/src/ctx_misc.o \
build/temp.wasm32-${WASM_FLAVOUR}-emscripten-cpython-${PYMAJOR}${PYMINOR}/hpy/universal/src/hpymodule.o

if [ -f /pp ]
# local publish
if [ -d $WHEELS ]
then
# build wheel for wasm
${SDKROOT}/python3-wasm -m build --no-isolation .
PYTHONOPTIMIZE=TRUE ${SDKROOT}/python3-wasm -m build --no-isolation .

mv dist/*wasm*whl /data/git/archives/repo/pkg/
mv dist/*wasm*whl $WHEELS/cp${PYMAJOR}${PYMINOR}/
fi

popd
Expand Down
20 changes: 17 additions & 3 deletions packages.d/pygame/pygame.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ else
fi
fi

if echo $PYBUILD|grep -q 3.13$
then
$HPY -m pip install --upgrade --force git+https://github.com/cython/cython.git
echo
fi


mkdir -p external
pushd $(pwd)/external

Expand All @@ -73,6 +80,12 @@ then
#unsure
wget -O- https://patch-diff.githubusercontent.com/raw/pmp-p/pygame-ce-wasm/pull/3.diff | patch -p1

# new cython
wget -O- https://patch-diff.githubusercontent.com/raw/pmp-p/pygame-ce-wasm/pull/6.diff | patch -p1

# added Vector2.from_polar and Vector3.from_spherical classmethods
wget -O- https://patch-diff.githubusercontent.com/raw/pygame-community/pygame-ce/pull/2141.diff | patch -p1

patch -p1 << END
diff --git a/src_c/static.c b/src_c/static.c
index 03cc7c61..a00a51a7 100644
Expand Down Expand Up @@ -103,7 +116,8 @@ END


# zerodiv mixer.music / merged
# wget -O - https://patch-diff.githubusercontent.com/raw/pygame-community/pygame-ce/pull/2426.diff | patch -p1
# wget -O- https://patch-diff.githubusercontent.com/raw/pygame-community/pygame-ce/pull/2426.diff | patch -p1


# weird exception not raised correctly in test/pixelcopy_test
patch -p1 <<END
Expand Down Expand Up @@ -247,7 +261,7 @@ then
emcc -shared -Os -g0 -fpic -o ${TARGET_FILE} $SDKROOT/prebuilt/emsdk/libpygame${PYMAJOR}.${PYMINOR}.a $SDL2

# github CI does not build wheel for now.
if [ -d /data/git/archives/repo/pkg ]
if [ -d /data/git/archives/repo/cp${TAG} ]
then
mkdir -p $TARGET_FOLDER
/bin/cp -rf testing/pygame_static-1.0-cp${TAG}-cp${TAG}-wasm32_mvp_emscripten/. ${TARGET_FOLDER}/
Expand All @@ -259,7 +273,7 @@ then
then
/data/git/archives/repo/norm.sh
else
whl=/data/git/archives/repo/pkg/$(basename $(pwd)).whl
whl=/data/git/archives/repo/cp${TAG}/$(basename $(pwd)).whl
[ -f $whl ] && rm $whl
zip $whl -r .
fi
Expand Down
15 changes: 6 additions & 9 deletions scripts/build-loader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ LOPTS="-sMAIN_MODULE=1"
echo " ************************************"
if [ -f dev ]
then
export COPTS="-O1 -g1 -fPIC"
export COPTS="-O0 -g4 -fPIC --source-map-base http://localhost:8000/maps/"
echo " building DEBUG $COPTS"
LOPTS="$LOPTS -sASSERTIONS=0"
ALWAYS_FS="--preload-file ${ALWAYS_CODE}@/data/data/org.python/assets"
# ALWAYS_FS="--preload-file ${ALWAYS_CODE}@/data/data/org.python/assets"
else
export COPTS="-Os -g0 -fPIC"
echo " building RELEASE $COPTS"
Expand Down Expand Up @@ -248,7 +248,9 @@ then

# TODO: test -sWEBGL2_BACKWARDS_COMPATIBILITY_EMULATION

LDFLAGS="-sUSE_GLFW=3 -sUSE_WEBGL2 -sMIN_WEBGL_VERSION=2 -sOFFSCREENCANVAS_SUPPORT=1 -sFULL_ES2 -sFULL_ES3"
#

LDFLAGS="-sUSE_GLFW=3 -sUSE_WEBGL2 -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -sOFFSCREENCANVAS_SUPPORT=1 -sFULL_ES2 -sFULL_ES3"

LDFLAGS="$LDFLAGS -lsqlite3"

Expand Down Expand Up @@ -296,7 +298,7 @@ then
emcc \\
$FINAL_OPTS \\
$LOPTS \\
-D__PYDK__=1 -DNDEBUG \\
-D__PYDK__=1 -DNDEBUG \\
-sTOTAL_MEMORY=256MB -sSTACK_SIZE=4MB -sALLOW_TABLE_GROWTH -sALLOW_MEMORY_GROWTH \\
-sEXPORTED_RUNTIME_METHODS=FS \\
$CF_SDL \\
Expand All @@ -310,13 +312,8 @@ emcc \\
-o ${DIST_DIR}/${DISTRO}${PYMAJOR}${PYMINOR}/${MODE}.js build/${MODE}.o \\
$LDFLAGS -lembind
# -lfreetype
# --bind -fno-rtti
# -sERROR_ON_UNDEFINED_SYMBOLS=0
# -sGL_ENABLE_GET_PROC_ADDRESS
# --bind -fno-rtti
Expand Down
10 changes: 8 additions & 2 deletions scripts/build-rootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ import distutils.spawn
#matplotlib
import uuid
# psycopg
import zoneinfo
# pandas
import tarfile
#arcade
import ctypes.util
Expand Down Expand Up @@ -168,8 +174,8 @@ import optparse
# bokeh
import hmac
#ursina
import imghdr
#ursina, not in 3.13
# import imghdr
# pep722
import pyparsing
Expand Down
6 changes: 4 additions & 2 deletions src/pygbag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from pathlib import Path

VERSION = "0.8.7"
VERSION = "0.9.2"

# hack to test git cdn build without upgrading pygbag
# beware can have side effects when file packager behaviour must change !
Expand All @@ -24,7 +24,9 @@
VERSION = "0.0.0"

# make aio available

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


Expand Down
4 changes: 3 additions & 1 deletion src/pygbag/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
if aio.pep0723.Config.dev_mode:
aio.pep0723.Config.PKG_INDEXES.extend(["http://localhost:8000/archives/repo/"])
else:
aio.pep0723.Config.PKG_INDEXES.extend(["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
3 changes: 2 additions & 1 deletion src/pygbag/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/.github
/.vscode
/.idea
/.DS_Store
/dist
/build
/venv
Expand All @@ -26,7 +27,7 @@
"\n"
)

SKIP_EXT = ["pyc", "pyx", "pyd", "pyi", "exe", "log", "blend", "DS_Store"]
SKIP_EXT = ["pyc", "pyx", "pyd", "pyi", "exe", "bak", "log", "blend", "DS_Store"]


def filter(walked):
Expand Down
6 changes: 2 additions & 4 deletions src/pygbag/gathering.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
from os import walk
import os
from pathlib import Path


class Error(Exception):
pass


def gather(root: Path, *kw):
if root.is_file():
if root.name == "main.py":
raise Error("project must be a folder or an archive")

for current, dirnames, filenames in walk(root):
for current, dirnames, filenames in os.walk(root):
rel = Path("/").joinpath(Path(current).relative_to(root))

# print(rel, len(dirnames), len(filenames))
Expand Down
28 changes: 20 additions & 8 deletions src/pygbag/support/cpythonrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@


PYCONFIG_PKG_INDEXES_DEV = ["http://localhost:<port>/archives/repo/"]
PYCONFIG_PKG_INDEXES = ["https://pygame-web.github.io/archives/repo/"]
# normal index or PYGPY env is handled after env conversion around line 255

# the sim does not preload assets and cannot access currentline
# the sim does not ospreload assets and cannot access currentline
# unless using https://github.com/pmp-p/aioprompt/blob/master/aioprompt/__init__.py
# or a thread

Expand Down Expand Up @@ -252,6 +252,10 @@ def dump_code():
os.environ["APPDATA"] = home
del home

# now in pep0723
#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 @@ -682,8 +686,11 @@ async def preload_code(cls, code, callback=None, loaderhome=".", hint=""):
env = Path(sconf["purelib"])

if not len(Config.repos):
if not len(Config.PKG_INDEXES):
Config.PKG_INDEXES = PyConfig.pkg_indexes
await aio.pep0723.async_repos()

# 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:
Config.repos.append(json.loads(source.read()))
Expand Down Expand Up @@ -1066,9 +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)
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 @@ -1579,12 +1587,12 @@ async def main():
DBG(f"1830: {local=} {source=} {is_py=} {hint=}")

if local is None:

ext = str(source).rsplit(".")[-1].lower()

if ext == "py":
local = tmpdir / source.rsplit("/", 1)[-1]
await shell.exec(shell.wget(f"-O{local}", source))

# TODO: test tar.bz2 lzma tar.xz
elif ext in ("zip", "gz", "tar", "apk", "jar"):
DBG(f"1841: found archive source {source=}")
Expand All @@ -1609,6 +1617,10 @@ async def main():
local = tmpdir / file
break
DBG("1862: import_site: found ", local)
elif str(source).startswith('http'):
print("Remote file :", source)
local = tmpdir / "remote.py"
await shell.exec(shell.wget(f"-O{local}", source))
else:
# maybe base64 or frozen code in html.
...
Expand Down
Loading

0 comments on commit 9d2e36f

Please sign in to comment.