Skip to content

Commit

Permalink
support alpha releases with patches
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Aug 22, 2024
1 parent 43875ec commit ea710d4
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 32 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)"
Expand Down
14 changes: 4 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
39 changes: 39 additions & 0 deletions bin/package-version
Original file line number Diff line number Diff line change
@@ -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())
61 changes: 61 additions & 0 deletions bin/patch-uwsgi-packaging
Original file line number Diff line number Diff line change
@@ -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())
13 changes: 0 additions & 13 deletions patch-uwsgi-packaging.sh

This file was deleted.

40 changes: 40 additions & 0 deletions patches/00-avoid-interleaving-pyuwsgi-threadstate.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
commit bfa363472bfb861a02bdeefc7477fcab04091c66
Author: Anthony Sottile <[email protected]>
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

0 comments on commit ea710d4

Please sign in to comment.