diff options
author | Claudia Pellegrino | 2025-04-05 21:41:05 +0200 |
---|---|---|
committer | Claudia Pellegrino | 2025-04-05 21:41:05 +0200 |
commit | afd7ac5dbb68481942e46f3fd5bcd302bee6bffa (patch) | |
tree | f908540fb2de947561bd22f46de6f7897d200ef2 | |
parent | 362354022b7e9af3c9d9fa7369b3ada3d239506e (diff) | |
download | aur-afd7ac5dbb68481942e46f3fd5bcd302bee6bffa.tar.gz |
Let installer generate the launcher; de-vendor it
-rw-r--r-- | .SRCINFO | 8 | ||||
-rw-r--r-- | PKGBUILD | 41 | ||||
-rw-r--r-- | github-pr-53.patch | 113 | ||||
-rw-r--r-- | pyproject.toml.template | 3 | ||||
-rw-r--r-- | shrinko8 | 9 |
5 files changed, 139 insertions, 35 deletions
@@ -1,7 +1,7 @@ pkgbase = shrinko8 pkgdesc = Shrink (minify) Pico-8 carts, as well as other tools (e.g. linting, format conversion) pkgver = 1.2.2d - pkgrel = 2 + pkgrel = 3 url = https://github.com/thisismypassport/shrinko8 arch = any license = MIT @@ -17,13 +17,13 @@ pkgbase = shrinko8 options = !strip source = shrinko8-1.2.2d.tar.gz::https://github.com/thisismypassport/shrinko8/archive/v1.2.2d.tar.gz source = __init__.py.template + source = github-pr-53.patch source = pyproject.toml.template - source = shrinko8 source = test_cart.p8 sha512sums = 9861e6922f690aa6a110c380d50a063ca3f6d93e08d53951f9fcd492b627633de95828e78cf09c18084c318d29740c2777042ebe97488e7ce22284e8ac3e4429 sha512sums = dcc8fa017109c70a96f6356d786f343de2ad3c478bec90a44d714688039eb6b26ceb552d464588a80d73b27961521bd6a4bd9ba79f113ab2e28438e9d1000e39 - sha512sums = 185284f60dad6e7172a588416d770e7129d7bcc0ce86bfae1fb7d09cafeb0f6d19ff14dada0844f1fd557510671ff3631f488f2687b4da631488e0421fc61cdb - sha512sums = c00dc0e42044d30c5b99888ac4d6f1a563decfbc357b0f6057c6417b0c0c2d225a64ad3e5bd3f7017b97c92384cca8e48e240778654e0bb516d89776c1ca24a7 + sha512sums = 5bb73e52f7474b65d59f41f2b4ee6c152d31d9fa5c40cdc58ce4a09ec0bb63780a63bc0b7d403d09192ab0f51ed2b75e183c9722e3b0d9e0b3e851ca1cae978d + sha512sums = 4e741fd1a70c234878f32364ba5f418b5210a3d8d676565194109efd0f9f3f593b534b1870328a2e0c463d20d626e6979ca4a1f20261acc2c57db0b1edb7c0ba sha512sums = b51c0ed94ffec9f0aa93d09bd6e4fcb155c69dd5dcfc5e155156227e5574f872bd61d541bfe6b98150c78bd8d4142f964c9bbd3c304c8daf58c9f8f21b59f2e6 pkgname = shrinko8 @@ -2,7 +2,7 @@ pkgname=shrinko8 pkgver=1.2.2d -pkgrel=2 +pkgrel=3 pkgdesc='Shrink (minify) Pico-8 carts, as well as other tools (e.g. linting, format conversion)' arch=('any') url='https://github.com/thisismypassport/shrinko8' @@ -20,20 +20,21 @@ options=('!debug' '!strip') source=( "${pkgname}-${pkgver}.tar.gz::https://github.com/thisismypassport/shrinko8/archive/v${pkgver}.tar.gz" '__init__.py.template' + 'github-pr-53.patch' 'pyproject.toml.template' - 'shrinko8' 'test_cart.p8' ) sha512sums=('9861e6922f690aa6a110c380d50a063ca3f6d93e08d53951f9fcd492b627633de95828e78cf09c18084c318d29740c2777042ebe97488e7ce22284e8ac3e4429' 'dcc8fa017109c70a96f6356d786f343de2ad3c478bec90a44d714688039eb6b26ceb552d464588a80d73b27961521bd6a4bd9ba79f113ab2e28438e9d1000e39' - '185284f60dad6e7172a588416d770e7129d7bcc0ce86bfae1fb7d09cafeb0f6d19ff14dada0844f1fd557510671ff3631f488f2687b4da631488e0421fc61cdb' - 'c00dc0e42044d30c5b99888ac4d6f1a563decfbc357b0f6057c6417b0c0c2d225a64ad3e5bd3f7017b97c92384cca8e48e240778654e0bb516d89776c1ca24a7' + '5bb73e52f7474b65d59f41f2b4ee6c152d31d9fa5c40cdc58ce4a09ec0bb63780a63bc0b7d403d09192ab0f51ed2b75e183c9722e3b0d9e0b3e851ca1cae978d' + '4e741fd1a70c234878f32364ba5f418b5210a3d8d676565194109efd0f9f3f593b534b1870328a2e0c463d20d626e6979ca4a1f20261acc2c57db0b1edb7c0ba' 'b51c0ed94ffec9f0aa93d09bd6e4fcb155c69dd5dcfc5e155156227e5574f872bd61d541bfe6b98150c78bd8d4142f964c9bbd3c304c8daf58c9f8f21b59f2e6') prepare() { local _pep440_conforming_version="${pkgver%[a-z]}+${pkgver##*[0-9]}" cd "${srcdir}/${pkgname}-${pkgver}" + rm -rf shrinko8 tests # pyinstaller bundles dependencies and the Python runtime, so we # use setuptools instead @@ -42,21 +43,23 @@ prepare() { <<< "version=${_pep440_conforming_version}" echo >&2 'Preparing Python namespace compatibility fix' - mkdir -pv shrinko8 + mkdir -v shrinko8 j2 -f env -o 'shrinko8/__init__.py' '../__init__.py.template' - \ <<< "version=${_pep440_conforming_version}" + # Remove this patch once the upstream maintainer has merged PR #53 + # and included it in a stable release. + # See also: https://github.com/thisismypassport/shrinko8/pull/53 + echo >&2 'Adding support for generated main executable' + patch -p1 < ../github-pr-53.patch + echo >&2 'Preparing Python packages' xargs < 'files.lst' bash -c 'mv -v $@ shrinko8/' _ - mkdir -pv tests + mkdir -v tests mv -v run_tests.py test_utils.py test_input test_compare \ tests/ } -_site_packages() { - python -c 'import site; print(site.getsitepackages()[0])' -} - build() { cd "${srcdir}/${pkgname}-${pkgver}" @@ -66,16 +69,14 @@ build() { check() { cd "$(mktemp -d)" - echo >&2 'Installing wheel into a temporary directory' - python -m installer --destdir=. \ - "${srcdir}/${pkgname}-${pkgver}/dist"/*.whl - PYTHONPATH="${PWD}/$(_site_packages)" - export PYTHONPATH + echo >&2 'Installing wheel into a temporary environment' + python -m venv --system-site-packages test-env + test-env/bin/python -m installer \ + "${srcdir}/${pkgname}-${pkgver}/dist"/*.whl echo >&2 'Running minification test' - python "${srcdir}/shrinko8" \ - -m "${srcdir}/test_cart.p8" test_cart_minified.p8 + test-env/bin/shrinko8 -m "${srcdir}/test_cart.p8" test_cart_minified.p8 if [[ "$(wc -c < 'test_cart_minified.p8')" -gt 117 ]]; then printf >&2 '%s\n' 'Unexpected minification output:' '===' cat >&2 'test_cart_minified.p8' @@ -84,8 +85,7 @@ check() { fi echo >&2 'Running PNG generation test' - python "${srcdir}/shrinko8" \ - -m "${srcdir}/test_cart.p8" test_cart.p8.png + test-env/bin/shrinko8 -m "${srcdir}/test_cart.p8" test_cart.p8.png } package() { @@ -93,9 +93,6 @@ package() { echo >&2 'Packaging the wheel' python -I -m installer --destdir="${pkgdir}" dist/*.whl - echo >&2 'Packaging the executable' - install -D -m 755 -t "${pkgdir}/usr/bin" "../${pkgname}" - echo >&2 'Packaging the README' install -D -m 644 -t "${pkgdir}/usr/share/doc/${pkgname}" \ 'README.md' diff --git a/github-pr-53.patch b/github-pr-53.patch new file mode 100644 index 000000000000..3272017a2abc --- /dev/null +++ b/github-pr-53.patch @@ -0,0 +1,113 @@ +From dcafca6f32ddee913160d1f2e3ea9e2819b5a972 Mon Sep 17 00:00:00 2001 +From: Claudia Pellegrino <claui@users.noreply.github.com> +Date: Sat, 5 Apr 2025 20:53:52 +0200 +Subject: [PATCH] Allow `main()` to be called with zero arguments +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Standard packaging tools such as pip or PyPA’s `installer` use a feature +called entry points, so they can automatically generate platform +executables on the fly [1] [2] as the user installs a wheel. That allows +users to type e.g. `shrinko8` instead of `python shrinko8.py`. + +Entry points are functions that offer a zero-arguments form. [3] [4] +Contrary to languages such as C or Java, an entry point in Python +doesn’t conveniently receive command-line arguments via function +parameters. Instead, it is expected to actively query the arguments from +e.g. `sys.argv` if need be. + +Adding a zero-argument form to `main` is a first step towards making +shrinko8 compatible with standard packaging tools, and helps in case you +ever decide to publish shrinko8 on PyPI and allow users to `pip install` +it. + +It also makes it a little easier for system-level package maintainers to +package `shrinko8` and `shrinkotron` as executables. + +[1]: https://github.com/pypa/pip/blob/06c8024bc50b198b91cad6df80d72a742d524e3d/src/pip/_vendor/distlib/scripts.py#L42-L49 + +[2]: https://github.com/pypa/installer/blob/7656f5d41943c21757243efa9deef636591bada2/src/installer/scripts.py#L35-L43 + +[3]: https://discuss.python.org/t/why-do-script-entrypoints-require-a-function-be-specified/14090 + +[4]: https://packaging.python.org/en/latest/specifications/entry-points/ +--- + run_tests.py | 7 ++++--- + shrinko.py | 5 +++-- + shrinko8.py | 2 +- + shrinkotron.py | 2 +- + 4 files changed, 9 insertions(+), 7 deletions(-) + +diff --git a/run_tests.py b/run_tests.py +index 426ed28..6b50d76 100644 +--- a/run_tests.py ++++ b/run_tests.py +@@ -1,6 +1,6 @@ + #!/usr/bin/env python3 + from test_utils import * +-import argparse, fnmatch ++import argparse, fnmatch, sys + + parser = argparse.ArgumentParser() + parser.add_argument("--measure", action="store_true", help="print the input/output counts for successful tests") +@@ -271,8 +271,9 @@ def run(): + run_test("TRON_constmin", "consttron.p64", "consttronmin.p64", "--minify", "--avoid-base64", target=Target.picotron) + run_test("TRON_load", "loadtron.p64", "loadtron.p64", "--minify-safe-only", target=Target.picotron) + +-def main(raw_args): ++def main(raw_args=None): + global g_opts ++ raw_args = raw_args if raw_args else sys.argv[1:] + g_opts = parser.parse_args(raw_args) + init_tests(g_opts) + +@@ -290,4 +291,4 @@ def main(raw_args): + return end_tests() + + if __name__ == "__main__": +- sys.exit(main(sys.argv[1:])) ++ sys.exit(main()) +diff --git a/shrinko.py b/shrinko.py +index 080a14a..c34522e 100644 +--- a/shrinko.py ++++ b/shrinko.py +@@ -9,7 +9,7 @@ + from picotron_defs import PicotronContext, Cart64Source, get_default_picotron_version + from picotron_cart import Cart64Format, read_cart64, write_cart64, merge_cart64, filter_cart64, preproc_cart64 + from picotron_cart import write_cart64_compressed_size, write_cart64_version +-import argparse ++import argparse, sys + + k_version = 'v1.2.3c' + +@@ -651,7 +651,8 @@ def handle_output(args, cart, extra_carts): + + parser = create_parser() + +- def main(raw_args): ++ def main(raw_args=None): ++ raw_args = raw_args if raw_args else sys.argv[1:] + try: + if not raw_args: # help is better than usage + parser.print_help(sys.stderr) +diff --git a/shrinko8.py b/shrinko8.py +index dac5fa3..8109ee3 100644 +--- a/shrinko8.py ++++ b/shrinko8.py +@@ -6,4 +6,4 @@ + main = create_main(Language.pico8) + + if __name__ == "__main__": +- sys.exit(main(sys.argv[1:])) ++ sys.exit(main()) +diff --git a/shrinkotron.py b/shrinkotron.py +index c565d74..5ec911c 100644 +--- a/shrinkotron.py ++++ b/shrinkotron.py +@@ -6,4 +6,4 @@ + main = create_main(Language.picotron) + + if __name__ == "__main__": +- sys.exit(main(sys.argv[1:])) ++ sys.exit(main()) diff --git a/pyproject.toml.template b/pyproject.toml.template index d7324bf80b35..21c75b38fef3 100644 --- a/pyproject.toml.template +++ b/pyproject.toml.template @@ -6,6 +6,9 @@ requires = ["setuptools"] name = "shrinko8" version = "{{ version }}" +[project.scripts] +shrinko8 = "shrinko8.shrinko8:main" + [tool.setuptools] packages = ["shrinko8"] diff --git a/shrinko8 b/shrinko8 deleted file mode 100644 index 0158e22bd030..000000000000 --- a/shrinko8 +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -import re -import sys - -from shrinko8.shrinko8 import main -if __name__ == "__main__": - sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0]) - sys.exit(main(sys.argv[1:])) |