Skip to content

Commit

Permalink
Merge branch 'pygame-web:main' into raylib
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p authored Sep 20, 2024
2 parents 852f50a + bb6e455 commit 85e54d0
Show file tree
Hide file tree
Showing 34 changed files with 356 additions and 170 deletions.
16 changes: 3 additions & 13 deletions .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.64.0bi
SDK_VERSION: 3.1.66.2bi
SYS_PYTHON: /usr/bin/python3
PACKAGES: emsdk hpy pygame
BUILD_STATIC: emsdk hpy
Expand Down Expand Up @@ -76,26 +76,16 @@ jobs:
- name: publishing
run: |
cd $GITHUB_WORKSPACE
touch build/web/archives/.nojekyll
echo "<html></html>" > build/web/archives/index.html
- name: make wheel
run: |
cd $GITHUB_WORKSPACE
/opt/python-wasm-sdk/python3-wasm -m build --no-isolation .
- name: Upload sdk to Github Releases
if: github.event_name == 'release'
uses: svenstaro/upload-release-action@2.3.0
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: $GITHUB_WORKSPACE/dist/*
file_glob: true
tag: ${{ github.ref }}


- name : "Upload to GitHub pages"
uses: JamesIves/github-pages-deploy-action@v4.4.1
uses: JamesIves/github-pages-deploy-action@v4.6.3
with:
branch: gh-pages
folder: build/web/archives

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ dmypy.json

/0.0
/.eric6project
/src
# /src
/dist
/ATTIC
/platform_wasm
Expand Down
Empty file added .nojekyll
Empty file.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Serving python files from [/data/git/pygbag/test/build/web]
with no security/performance in mind, i'm just a test tool : don't rely on me
usage: __main__.py [-h] [--bind ADDRESS] [--PYBUILD PYBUILD] [--app_name APP_NAME] [--ume_block UME_BLOCK] [--can_close CAN_CLOSE] [--cache CACHE] [--package PACKAGE] [--title TITLE] [--version VERSION] [--build] [--html] [--no_opt] [--archive] [--icon ICON] [--cdn CDN] [--template TEMPLATE] [--ssl SSL]
[--port [PORT]]
[--port [PORT]] [--disable-sound-format-error]
options:
-h, --help show this help message and exit
Expand All @@ -103,6 +103,7 @@ options:
--template TEMPLATE index.html template [default:default.tmpl]
--ssl SSL enable ssl with server.pem and key.pem
--port [PORT] Specify alternate port [default: 8000]
--disable-sound-format-error audio files with a common unsupported format found in the assets won't raise an exception
```

unlisted developper options:
Expand Down
18 changes: 18 additions & 0 deletions packages.d/pygame/pygame.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ then
# zerodiv mixer.music / merged
# wget -O- https://patch-diff.githubusercontent.com/raw/pygame-community/pygame-ce/pull/2426.diff | patch -p1

patch -p1 <<END
diff --git a/src_c/key.c b/src_c/key.c
index 3a2435d2..a353c24f 100644
--- a/src_c/key.c
+++ b/src_c/key.c
@@ -150,8 +150,10 @@ static PyTypeObject pgScancodeWrapper_Type = {
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "pygame.key.ScancodeWrapper",
.tp_repr = (reprfunc)pg_scancodewrapper_repr,
.tp_as_mapping = &pg_scancodewrapper_mapping,
+/*
.tp_iter = (getiterfunc)pg_iter_raise,
.tp_iternext = (iternextfunc)pg_iter_raise,
+*/
#ifdef PYPY_VERSION
.tp_new = pg_scancodewrapper_new,
#endif
END


# weird exception not raised correctly in test/pixelcopy_test
patch -p1 <<END
Expand Down
30 changes: 15 additions & 15 deletions scripts/build-loader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ then
fi
fi

ln -s $(pwd)/src/pygbag $(pwd)/pygbag
ln -sf $(pwd)/src/pygbag $(pwd)/pygbag

pushd src/pygbag/support
cp -r _xterm_parser ${SDKROOT}/prebuilt/emsdk/common/site-packages/
Expand Down Expand Up @@ -231,9 +231,9 @@ echo CPY_CFLAGS=$CPY_CFLAGS



if [ -f /data/git/pygbag/integration/${INTEGRATION}.h ]
if [ -f ${WORKSPACE}/integration/${INTEGRATION}.h ]
then
LNK_TEST=/data/git/pygbag/integration/${INTEGRATION}
LNK_TEST=${WORKSPACE}/integration/${INTEGRATION}
else
LNK_TEST=/tmp/pygbag_integration_test
fi
Expand All @@ -242,15 +242,22 @@ INC_TEST="${LNK_TEST}.h"
MAIN_TEST="${LNK_TEST}.c"


touch ${INT_TEST} ${INC_TEST} ${MAIN_TEST}
touch ${INT_TEST} ${INC_TEST} ${LNK_TEST} ${MAIN_TEST}

# -L${SDKROOT}/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/pic only !

if emcc -fPIC -std=gnu99 -D__PYDK__=1 -DNDEBUG $MIMALLOC $CPY_CFLAGS $CF_SDL $CPOPTS \
-DINC_TEST=$INC_TEST -DMAIN_TEST=$MAIN_TEST \
-c -fwrapv -Wall -Werror=implicit-function-declaration -fvisibility=hidden \
-I${PYDIR}/internal -I${PYDIR} -I./support -I./external/hpy/hpy/devel/include -DPy_BUILD_CORE\
-I${PYDIR}/internal -I${PYDIR} -I./support -I./external/hpy/hpy/devel/include -DPy_BUILD_CORE \
-o build/${MODE}.o support/__EMSCRIPTEN__-pymain.c
then
STDLIBFS="--preload-file build/stdlib-rootfs/python${PYBUILD}@/usr/lib/python${PYBUILD}"
if echo $PYBUILD | grep -q 13$
then
STDLIBFS="--preload-file build/stdlib-rootfs/python${PYBUILD}t@/usr/lib/python${PYBUILD}t"
else
STDLIBFS="--preload-file build/stdlib-rootfs/python${PYBUILD}@/usr/lib/python${PYBUILD}"
fi

# \
# --preload-file /usr/share/terminfo/x/xterm@/usr/share/terminfo/x/xterm \
Expand Down Expand Up @@ -287,6 +294,8 @@ then
if [ -f $cpylib ]
then
LDFLAGS="$LDFLAGS $cpylib"
else
echo " Not found : $cpylib"
fi
done

Expand All @@ -311,8 +320,6 @@ then
# EXTRA_EXPORTED_RUNTIME_METHODS => EXPORTED_RUNTIME_METHODS after 3.1.52




PG=/pgdata
cat > final_link.sh <<END
#!/bin/bash
Expand Down Expand Up @@ -378,13 +385,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
6 changes: 3 additions & 3 deletions scripts/vendoring.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export VENDOR=${VENDOR:-pygbag}
export PACKAGES=${PACKAGES:-emsdk hpy pygame}

export SDKROOT=${SDKROOT:-/opt/python-wasm-sdk}
export SDK_VERSION=${SDK_VERSION:-3.1.52.0bi}
export CYTHON=${CYTHON:-Cython-3.0.1-py2.py3-none-any.whl}
export PYBUILD=${PYBUILD:-3.11}
export SDK_VERSION=${SDK_VERSION:-3.1.64.1bi}
export CYTHON=${CYTHON:-Cython-3.0.10-py2.py3-none-any.whl}
export PYBUILD=${PYBUILD:-3.12}
export LC_ALL=C

export SYS_PYTHON=${SYS_PYTHON:-$(which python3)}
Expand Down
6 changes: 3 additions & 3 deletions src/pygbag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
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"))


# WaPy<=>CPython compat
# WaPy/Micropython <=> CPython compat

import builtins

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
54 changes: 48 additions & 6 deletions src/pygbag/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@
from datetime import datetime

from .__init__ import VERSION
from .example_config import EXAMPLE_CONFIG

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

from . import pack
from . import web
from .config_types import Config


from config_to_object import load_config


devmode = "--dev" in sys.argv
Expand Down Expand Up @@ -313,6 +319,8 @@ async def main_run(app_folder, mainscript, cdn=DEFAULT_CDN):
help="web site to cache locally [default:%s]" % cdn,
)

parser.add_argument("--ini", default=False, action="store_true", help="Initialize an example pygbag.ini config file")

parser.add_argument(
"--template",
default=DEFAULT_TMPL,
Expand All @@ -330,6 +338,13 @@ async def main_run(app_folder, mainscript, cdn=DEFAULT_CDN):
help="Specify alternate port [default: 8000]",
)

parser.add_argument(
"--disable-sound-format-error",
action="store_true",
default=False,
help="audio files with a common unsupported format found in the assets won't raise an exception",
)

args = parser.parse_args()

# when in browser IDE everything should be done in allowed folder
Expand Down Expand Up @@ -396,15 +411,42 @@ 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,
"INI": args.ini,
}

if args.ini:
if not os.path.exists("pygbag.ini"):
with open("pygbag.ini", "w") as f:
f.write(EXAMPLE_CONFIG)
else:
print("ERROR: You already have an pygbag.ini file. Please delete it before attempting to init a fresh config.")
raise SystemExit

if os.path.exists("pygbag.ini"):
config: Config = load_config("pygbag.ini")
ignore_files = config.DEPENDENCIES.ignorefiles
ignore_dirs = config.DEPENDENCIES.ignoredirs
else:
print("WARNING: No pygbag.ini found! See: https://pygame-web.github.io/wiki/pygbag-configuration")
ignore_files = []
ignore_dirs = []

for ignore_arr in [ignore_files, ignore_dirs]:
for ignored in ignore_arr:
if ignored.strip().find(" ") != -1: # has space in folder/file name
print(f"|{ignored}|")
print("ERROR! You cannot use folder/files with spaces in it.")
raise SystemExit # maybe use a custom pygbag exception

pygbag.config = CC

await pack.archive(f"{app_name}.apk", app_folder, build_dir)
print(f"Ignored dirs: {ignore_dirs}")
print(f"Ignored files: {ignore_files}")

await pack.archive(f"{app_name}.apk", app_folder, ignore_dirs, ignore_files, build_dir)

def cache_file(remote_url, suffix):
nonlocal cache_dir
Expand Down
12 changes: 12 additions & 0 deletions src/pygbag/config_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Automatically generated type hinting file for a .ini file
# Generated with config-to-object https://pypi.org/project/config-to-object/1.0.0/
# Run "ini_typefile your_config.ini type_file.py" to create a new type file

from typing import NamedTuple, List, Tuple

class DEPENDENCIES(NamedTuple):
ignoredirs:List[str]
ignorefiles:List[str]

class Config(NamedTuple):
DEPENDENCIES:DEPENDENCIES
6 changes: 6 additions & 0 deletions src/pygbag/example.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# An example .ini file for pygbag configs

[DEPENDENCIES]
ignoreDirs = ["Folder1", "Folder2", "Folder3"]
ignoreFiles = ["File1","File2", "File3"]
# run `ini_typefile example.ini config_types.py` to regenerate the type hints for the ini file
4 changes: 4 additions & 0 deletions src/pygbag/example_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
EXAMPLE_CONFIG = """[DEPENDENCIES]
ignoreDirs = ["ignoreThisFolder","ignoreThisFolder2","ignoreThisFolder3"]
ignoreFiles = ["File1.ignorethis", "File2.ignorethis", "File3.ignorethis"]
"""
Loading

0 comments on commit 85e54d0

Please sign in to comment.