Skip to content

Commit

Permalink
pep0722 installer
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Aug 30, 2023
1 parent 1e54f18 commit 933889d
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 7 deletions.
5 changes: 5 additions & 0 deletions packages.d/pygame/pygame.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ then
# cython3 / merged
# wget -O- https://patch-diff.githubusercontent.com/raw/pygame-community/pygame-ce/pull/2395.diff | patch -p1


# zerodiv mixer.music
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
diff --git a/src_c/pixelcopy.c b/src_c/pixelcopy.c
index e33eae33..f5f6697e 100644
Expand Down
2 changes: 1 addition & 1 deletion pygbag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path


__version__ = "0.0.0"
__version__ = "0.7.3"

# make aio available

Expand Down
3 changes: 3 additions & 0 deletions pygbag/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ async def custom_async_input():

# simulate .requestAnimationFrame() infinite loop

# make aiohttp happy
aio.started = True

while not aio.exit:
next = time.time() + 0.016
try:
Expand Down
2 changes: 1 addition & 1 deletion pygbag/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
if devmode:
sys.argv.remove("--dev")
DEFAULT_PORT = 8666
DEFAULT_CDN = f"http://localhost:8000/archives/{cdn_version}/"
DEFAULT_CDN = f"http://localhost:8000/pygbag/0.0/"
DEFAULT_TMPL = "static/wip.tmpl"
print(
f"""
Expand Down
4 changes: 2 additions & 2 deletions pygbag/support/cross/__EMSCRIPTEN__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def shed_yield():
from embed_browser import Audio, File, Object
from embed_browser import fetch, console, prompt, alert, confirm

# pyodide compat
sys.modules["js"] = sys.modules["embed_browser"]
# broad pyodide compat
sys.modules["js"] = this # instead of just sys.modules["embed_browser"]

Object_type = type(Object())
except Exception as e:
Expand Down
6 changes: 6 additions & 0 deletions pygbag/support/cross/aio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,12 @@ def create_task(coro, *, name=None, context=None):
#
run_called = False

def is_running():
global started
return started

# prevent warnings in aiohttp
loop.is_running = is_running

def run(coro, *, debug=False):
global paused, loop, started, step, DEBUG, run_called, exit
Expand Down
5 changes: 4 additions & 1 deletion pygbag/support/cross/aio/filelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ async def __aenter__(self):
async with session.get(self.url) as response:
assert response.status == 200
# For large files use response.content.read(chunk_size) instead.
self.filelike = io.StringIO( (await response.read()).decode())
if "b" in self.mode:
self.filelike = io.BytesIO( await response.read())
else:
self.filelike = io.StringIO( (await response.read()).decode())

return self.filelike

Expand Down
79 changes: 78 additions & 1 deletion pygbag/support/cross/aio/pep0722.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# https://peps.python.org/pep-0722/ – Dependency specification for single-file scripts
# https://peps.python.org/pep-0508/ – Dependency specification for Python Software Packages

import sys
import os
from pathlib import Path

import re
Expand Down Expand Up @@ -63,11 +65,47 @@ async def async_imports_init():



HISTORY = []

def install(pkg_file, sconf=None):
global HISTORY
from installer import install
from installer.destinations import SchemeDictionaryDestination
from installer.sources import WheelFile

# Handler for installation directories and writing into them.
destination = SchemeDictionaryDestination(
sconf or __import_("sysconfig").get_paths(),
interpreter=sys.executable,
script_kind="posix",
)

try:
with WheelFile.open(pkg_file) as source:
install(
source=source,
destination=destination,
# Additional metadata that is generated by the installation tool.
additional_metadata={
"INSTALLER": b"pygbag",
},
)
HISTORY.append(pkg_file)
except FileExistsError:
print(f"38: {pkg_file} already installed")
except Exception as ex:
pdb(f"82: cannot install {pkg_file}")
sys.print_exception(ex)


async def check_list(filename):
global PKG_INDEXES
from aio.filelike import fopen

print()
print('-'*11,"required packages",'-'*10)
maybe_missing = []

for req in read_dependency_block(filename):
dep = str(req)

Expand All @@ -82,7 +120,46 @@ async def check_list(filename):
print('-'*40)
print()

if len(maybe_missing) and len(Config.PKG_INDEXES):
# nothing to do
if not len(maybe_missing):
return

# TODO: prio over pypi
if not len(Config.PKG_INDEXES):
await async_imports_init()


print("="*40)

sconf = __import__("sysconfig").get_paths()

for k,v in sconf.items():
print(k,v)

env = Path(os.getcwd()) / "env"
env.mkdir(exist_ok=True)
sys.path.append(env)
sconf["purelib"] = sconf["platlib"] = env.as_posix()

importlib.invalidate_caches()

for pkg in maybe_missing:
print("searching",pkg)
wheel_url = ''
async with fopen(f"https://pypi.org/simple/{pkg}/") as html:
for line in html.readlines():
if line.find('href=')>0:
if line.find('-py3-none-any.whl')>0:
wheel_url = line.split('"',2)[1]
wheel_pkg,wheel_hash = wheel_url.rsplit('/',1)[-1].split('#',1)

print(wheel_pkg, wheel_url)

target_filename = f'/tmp/{wheel_pkg}'
async with fopen(wheel_url,"rb") as pkg:
with open(target_filename,'wb') as target:
target.write(pkg.read())
install(target_filename, sconf)


print("="*40)
7 changes: 6 additions & 1 deletion scripts/vendoring.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ export LC_ALL=C

export SYS_PYTHON=${SYS_PYTHON:-$(which python3)}

if $CI
then
export PYGBAG_BUILD=0.0
else
export PYGBAG_BUILD=$($SYS_PYTHON -c "print(__import__('pygbag').__version__)"|tail -n 1|cut -f1-2 -d.)
fi

export PYGBAG_BUILD=$($SYS_PYTHON -c "print(__import__('pygbag').__version__)"|tail -n 1|cut -f1-2 -d.)
export DIST_DIR=$(pwd)/build/web/archives/${PYGBAG_BUILD}
mkdir -p $DIST_DIR

Expand Down

0 comments on commit 933889d

Please sign in to comment.