From b6fffb1a9b01f1ce59afe860effafb33f2465044 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Thu, 22 Aug 2024 12:15:58 -0400 Subject: [PATCH] support alpha releases with patches --- .github/workflows/build.yml | 10 +-- Makefile | 14 ++--- README.md | 2 +- bin/package-version | 39 ++++++++++++ bin/patch-uwsgi-packaging | 61 +++++++++++++++++++ patch-uwsgi-packaging.sh | 13 ---- ...oid-interleaving-pyuwsgi-threadstate.patch | 40 ++++++++++++ 7 files changed, 147 insertions(+), 32 deletions(-) create mode 100755 bin/package-version create mode 100755 bin/patch-uwsgi-packaging delete mode 100755 patch-uwsgi-packaging.sh create mode 100644 patches/00-avoid-interleaving-pyuwsgi-threadstate.patch diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 15b33b3..983aec5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,22 +13,16 @@ jobs: runs-on: ubuntu-latest outputs: sdist_name: ${{ steps.build_sdist.outputs.sdist_name }} - append_version: ${{ steps.build_sdist.outputs.append_version }} steps: - uses: actions/checkout@v4 with: submodules: true - - name: Patch packaging - run: ./patch-uwsgi-packaging.sh uwsgi - - name: Build sdist id: build_sdist run: | - git submodule update --init make sdist - echo "sdist_name=pyuwsgi-$(make print-version)" >> "$GITHUB_OUTPUT" - echo "append_version=$(cat append-version)" >> "$GITHUB_OUTPUT" + echo "sdist_name=pyuwsgi-$(bin/package-version)" >> "$GITHUB_OUTPUT" - uses: actions/upload-artifact@v3 with: @@ -90,7 +84,7 @@ jobs: env: CIBW_ARCHS: ${{ matrix.arch }} CIBW_SKIP: cp36-* cp38-macosx_arm64 cp313-* pp* - CIBW_ENVIRONMENT: APPEND_VERSION=${{ needs.build_sdist.outputs.append_version }} UWSGI_PROFILE=pyuwsginossl + CIBW_ENVIRONMENT: UWSGI_PROFILE=pyuwsginossl CIBW_TEST_COMMAND: "pyuwsgi --help" CIBW_BEFORE_BUILD_MACOS: "find . -name '*.o' -delete && IS_MACOS=1 ./pre_build.sh" CIBW_BEFORE_BUILD_LINUX: "find . -name '*.o' -delete && ./pre_build.sh && (yum install -y zlib-devel || apk add zlib-dev)" diff --git a/Makefile b/Makefile index a273291..19a746e 100644 --- a/Makefile +++ b/Makefile @@ -6,10 +6,8 @@ SHELL := bash .SUFFIXES: # Figure out what version we're building -UPSTREAM_VERSION := $(shell cd uwsgi; python setup.pyuwsgi.py --version) -APPEND_VERSION := $(shell cat append-version) -VERSION := $(UPSTREAM_VERSION)$(APPEND_VERSION) -HASH := $(shell cd uwsgi; git rev-parse HEAD) +VERSION := $(shell bin/package-version) +HASH := $(shell git -C uwsgi rev-parse HEAD) # Grab a clean checkout of uWSGI build/$(HASH).tar.gz: @@ -20,22 +18,18 @@ build/$(HASH).tar.gz: build/pyuwsgi-$(VERSION): build/$(HASH).tar.gz cd build; tar xzf $(HASH).tar.gz mv build/uwsgi-$(HASH) build/pyuwsgi-$(VERSION) - APPEND_VERSION=$(APPEND_VERSION) ./patch-uwsgi-packaging.sh build/pyuwsgi-$(VERSION) + bin/patch-uwsgi-packaging build/pyuwsgi-$(VERSION) echo "graft ." > build/pyuwsgi-$(VERSION)/MANIFEST.in # Create sdist from patched uWSGI dist/pyuwsgi-$(VERSION).tar.gz: build/pyuwsgi-$(VERSION) mkdir -p dist - cd build/pyuwsgi-$(VERSION); python setup.py sdist + cd build/pyuwsgi-$(VERSION); python3 setup.py sdist mv build/pyuwsgi-$(VERSION)/dist/pyuwsgi-$(VERSION).tar.gz $@ .PHONY: sdist sdist: dist/pyuwsgi-$(VERSION).tar.gz -.PHONY: print-version -print-version: - @echo $(VERSION) - .PHONY: update update: cd uwsgi; git pull diff --git a/README.md b/README.md index 52701bd..84c3397 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ pip install -U setuptools twine To cut a new release: -1. Update `./append-version` to add a post-release tag (`.post1` for example) to the upstream uWSGI version (or leave empty to match the upstream version!) +1. Update `SERIAL` in `bin/package-version` to add a post-release tag to the upstream uWSGI version 2. Run `make update` to update uWSGI. uWSGI should be pinned to the [latest release](https://github.com/unbit/uwsgi/releases). 3. Push changes and wait for GH Actions to finish. 4. If GH Actions succeeds, tag the commit with the uWSGI version number and push the tag. diff --git a/bin/package-version b/bin/package-version new file mode 100755 index 0000000..f8e839b --- /dev/null +++ b/bin/package-version @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +import os.path +import subprocess +import sys + +_ROOT = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) + +# if 0: use the upstream version +# if >0: append `.post1` / `.a1` as needed +SERIAL = 1 + + +def main() -> int: + upstream = subprocess.check_output( + (sys.executable, 'setup.pyuwsgi.py', '--version'), + cwd=os.path.join(_ROOT, 'uwsgi'), + ).strip().decode() + + if os.path.exists('patches') and os.listdir('patches'): + if not SERIAL: + raise SystemExit('SERIAL must be >0 if there are patches!') + append = 'a' + # increment the final version segment to indicate a future pre-release + parts = upstream.split('.') + parts[-1] = str(int(parts[-1]) + 1) + upstream = '.'.join(parts) + else: + append = '.post' + + if SERIAL: + print(f'{upstream}{append}{SERIAL}') + else: + print(upstream) + + return 0 + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/bin/patch-uwsgi-packaging b/bin/patch-uwsgi-packaging new file mode 100755 index 0000000..76ba1dc --- /dev/null +++ b/bin/patch-uwsgi-packaging @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +import argparse +import os.path +import shutil +import subprocess + +_ROOT = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) + + +def root_path(*s: str) -> str: + return os.path.join(_ROOT, *s) + + +_PACKAGE_VERSION = os.path.join(_ROOT, 'bin', 'package-version') + + +def main() -> int: + parser = argparse.ArgumentParser() + parser.add_argument('uwsgi_dir') + args = parser.parse_args() + + version = subprocess.check_output(_PACKAGE_VERSION).strip().decode() + + def uwsgi_path(*s: str) -> str: + return os.path.join(args.uwsgi_dir, *s) + + # copy our setup.py over with the adjusted `version=` + found_version_line = False + with open(uwsgi_path('setup.py'), 'w') as setup_dest: + with open(root_path('setup.py')) as setup_src: + for line in setup_src: + if line == ' version=uwsgiconfig.uwsgi_version + "",\n': + found_version_line = True + line = f' version={version!r},\n' + setup_dest.write(line) + if not found_version_line: + raise AssertionError('failed to find `version=...` line in setup.py') + + # create a pyuwsginossl build configuration + with open(uwsgi_path('buildconf', 'pyuwsginossl.ini'), 'w') as ini_dest: + with open(uwsgi_path('buildconf', 'pyuwsgi.ini')) as ini_src: + shutil.copyfileobj(ini_src, ini_dest) + ini_dest.write('ssl = false\n') + + # remove stale PKG-INFO + os.remove(uwsgi_path('PKG-INFO')) + + # apply patches (if applicable) + if os.path.exists('patches'): + patches = sorted(os.listdir(root_path('patches'))) + for patch in patches: + subprocess.check_call( + ('patch', '-p1', '-i', root_path('patches', patch)), + cwd=uwsgi_path(), + ) + + return 0 + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/patch-uwsgi-packaging.sh b/patch-uwsgi-packaging.sh deleted file mode 100755 index bd0fee6..0000000 --- a/patch-uwsgi-packaging.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -set -euf -o pipefail - -SRC=$1 -APPEND_VERSION=${APPEND_VERSION:-""} - -cp setup.py $SRC/setup.py -sed -i.bak 's/uwsgiconfig\.uwsgi_version/uwsgiconfig.uwsgi_version + "'$APPEND_VERSION'"/' $SRC/setup.py -rm $SRC/setup.py.bak -cp $SRC/buildconf/pyuwsgi.ini $SRC/buildconf/pyuwsginossl.ini -echo "ssl = false" >> $SRC/buildconf/pyuwsginossl.ini -rm $SRC/PKG-INFO diff --git a/patches/00-avoid-interleaving-pyuwsgi-threadstate.patch b/patches/00-avoid-interleaving-pyuwsgi-threadstate.patch new file mode 100644 index 0000000..542c5d0 --- /dev/null +++ b/patches/00-avoid-interleaving-pyuwsgi-threadstate.patch @@ -0,0 +1,40 @@ +commit bfa363472bfb861a02bdeefc7477fcab04091c66 +Author: Anthony Sottile +Date: Mon Aug 19 15:50:31 2024 -0400 + + avoid interleaving pywsgi threadstate + +diff --git a/plugins/pyuwsgi/pyuwsgi.c b/plugins/pyuwsgi/pyuwsgi.c +index 7a4f2249..11732e04 100644 +--- a/plugins/pyuwsgi/pyuwsgi.c ++++ b/plugins/pyuwsgi/pyuwsgi.c +@@ -126,13 +126,6 @@ PyObject *pyuwsgi_setup(PyObject * self, PyObject * args, PyObject * kwds) { + return NULL; + } + +- +- //TODO: ...??? +- // actually do the thing! +- PyThreadState *_tstate = PyThreadState_Get(); +- uwsgi_setup(orig_argc, orig_argv, environ); +- PyThreadState_Swap(_tstate); +- + Py_INCREF(self); + return self; + } +@@ -143,6 +136,7 @@ PyObject *pyuwsgi_init(PyObject * self, PyObject * args, PyObject * kwds) { + return NULL; + } + ++ uwsgi_setup(orig_argc, orig_argv, environ); + int rc = uwsgi_run(); + + // never(?) here +@@ -156,6 +150,7 @@ PyObject *pyuwsgi_run(PyObject * self, PyObject * args, PyObject * kwds) { + return NULL; + } + ++ uwsgi_setup(orig_argc, orig_argv, environ); + int rc = uwsgi_run(); + + // never(?) here