From 4938de49dc7681b6ff35916805d31c21035e2523 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Fri, 1 Apr 2022 10:59:00 -0600 Subject: Get the zipapp support working correctly [ci skip] Needed to pass a different source and also pass an entry point to the zipapp.create_archive method. Signed-off-by: Mats Wichmann --- CHANGES.txt | 2 ++ RELEASE.txt | 5 +++-- site_scons/scons_local_package.py | 15 +++++++-------- site_scons/zip_utils.py | 28 ++++++++++++++++++---------- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 1512700..ecc82a4 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -96,6 +96,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER - The single-file Util module was split into a package with a few functional areas getting their own files - Util.py had grown to over 2100 lines. + - Add a zipapp package of scons-local: can use SCons from a local + file which does not need unpacking. diff --git a/RELEASE.txt b/RELEASE.txt index ecf23c3..e9f2d02 100644 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -90,8 +90,9 @@ PACKAGING requirements_pkg.txt are the requirements to do a full build (including docs build) with an intent to create the packages. - Moved rpm and debian directories under packaging -- Added logic to help packagers enable reproducible builds into packaging/etc/. Please - read packaging/etc/README.txt if you are interested. +- Added logic to help packagers enable reproducible builds into packaging/etc/. + Please read packaging/etc/README.txt if you are interested. +- A zipapp of scons-local is now also built. DOCUMENTATION diff --git a/site_scons/scons_local_package.py b/site_scons/scons_local_package.py index 0a5d008..8eca758 100644 --- a/site_scons/scons_local_package.py +++ b/site_scons/scons_local_package.py @@ -28,9 +28,8 @@ from Utilities import is_windows def get_local_package_file_list(): - """ - Get list of all files which should be included in scons-local package - """ + """Get list of all files which should be included in scons-local package""" + s_files = glob("SCons/**", recursive=True) # import pdb; pdb.set_trace() @@ -102,20 +101,20 @@ def create_local_packages(env): PSV='.', ) - - do_zipapp = False + do_zipapp = True # Q: maybe an external way to specify whether to build? if do_zipapp: # We need to descend into the versioned directory for zipapp, # but we don't know the version. env.Glob lets us expand that. - # The action isn't going to use the sources here, but including - # them makes sure the deps work out right. + # The action isn't going to use the sources, but including + # them makes sure SCons has populated the dir we're going to zip. app_dir = env.Glob(f"{build_local_dir}/scons-local-*")[0] zipapp = env.Command( target='#build/dist/scons-local-${VERSION}.pyz', source=installed_files, action=zipappit, CD=app_dir, - PSV='SCons', + PSV='.', + entry='SCons.Script.Main:main', ) if is_windows(): diff --git a/site_scons/zip_utils.py b/site_scons/zip_utils.py index 754029c..a38a68f 100644 --- a/site_scons/zip_utils.py +++ b/site_scons/zip_utils.py @@ -32,11 +32,11 @@ import zipapp def zipit(env, target, source): - """ - zip *source* into *target*, using some values from *env* + """Action function to zip *source* into *target* - *env* values: `CD` is the directory to work in, - `PSV` is the directory name to walk down to find the files + Values extracted from *env*: + *CD*: the directory to work in + *PSV*: the directory name to walk down to find the files """ print(f"Zipping {target[0]}:") @@ -59,6 +59,8 @@ def zipit(env, target, source): def unzipit(env, target, source): + """Action function to unzip *source*""" + print(f"Unzipping {source[0]}:") zf = zipfile.ZipFile(str(source[0]), 'r') for name in zf.namelist(): @@ -76,18 +78,24 @@ def unzipit(env, target, source): def zipappit(env, target, source): - """ - Create a zipapp *target* from specified directory. + """Action function to Create a zipapp *target* from specified directory. - *env* values: ``"CD"`` is the Dir node for the place we want to work. - ``"PSV"`` is the directory name to point :meth:`zipapp.create_archive` at - (note *source* is unused here in favor of PSV) + Values extracted from *env*: + *CD*: the Dir node for the place we want to work. + *PSV*: the directory name to point :meth:`zipapp.create_archive` at + (note *source* is unused here in favor of PSV) + *main*: the entry point for the zipapp """ print(f"Creating zipapp {target[0]}:") dest = target[0].abspath olddir = os.getcwd() os.chdir(env['CD'].abspath) try: - zipapp.create_archive(env['PSV'], dest, "/usr/bin/env python") + zipapp.create_archive( + source=env['PSV'], + target=dest, + main=env['entry'], + interpreter="/usr/bin/env python", + ) finally: os.chdir(olddir) -- cgit v0.12