11#! /usr/bin/env bash
2- #  this script is run by GitHub Actions in a plain `focal` container; it installs the
3- #  minimal requirements for tox and hands over to the py3-old tox environment.
2+ #  this script is run by GitHub Actions in a plain `focal` container; it
3+ #  - installs the minimal system requirements, and poetry;
4+ #  - patches the project definition file to refer to old versions only;
5+ #  - creates a venv with these old versions using poetry; and finally
6+ #  - invokes `trial` to run the tests with old deps.
47
58#  Prevent tzdata from asking for user input
69export  DEBIAN_FRONTEND=noninteractive
@@ -9,12 +12,70 @@ set -ex
912
1013apt-get update
1114apt-get install -y \
12-         python3 python3-dev python3-pip python3-venv \
13-         libxml2-dev libxslt-dev xmlsec1 zlib1g-dev tox  libjpeg-dev libwebp-dev
15+         python3 python3-dev python3-pip python3-venv pipx  \
16+         libxml2-dev libxslt-dev xmlsec1 zlib1g-dev libjpeg-dev libwebp-dev
1417
1518export  LANG=" C.UTF-8" 
1619
1720#  Prevent virtualenv from auto-updating pip to an incompatible version
1821export  VIRTUALENV_NO_DOWNLOAD=1
1922
20- exec  tox -e py3-old
23+ #  TODO: in the future, we could use an implementation of
24+ #    https://github.com/python-poetry/poetry/issues/3527
25+ #    https://github.com/pypa/pip/issues/8085
26+ #  to select the lowest possible versions, rather than resorting to this sed script.
27+ 
28+ #  Patch the project definitions in-place:
29+ #  - Replace all lower and tilde bounds with exact bounds
30+ #  - Make the pyopenssl 17.0, which is the oldest version that works with
31+ #    a `cryptography` compiled against OpenSSL 1.1.
32+ #  - Delete all lines referring to psycopg2 --- so no testing of postgres support.
33+ #  - Omit systemd: we're not logging to journal here.
34+ 
35+ #  TODO: also replace caret bounds, see https://python-poetry.org/docs/dependency-specification/#version-constraints
36+ #  We don't use these yet, but IIRC they are the default bound used when you `poetry add`.
37+ #  The sed expression 's/\^/==/g' ought to do the trick. But it would also change
38+ #  `python = "^3.7"` to `python = "==3.7", which would mean we fail because olddeps
39+ #  runs on 3.8 (#12343).
40+ 
41+ sed -i \
42+    -e " s/[~>]=/==/g" 
43+    -e " /psycopg2/d" 
44+    -e ' s/pyOpenSSL = "==16.0.0"/pyOpenSSL = "==17.0.0"/' 
45+    -e ' /systemd/d' 
46+    pyproject.toml
47+ 
48+ #  Use poetry to do the installation. This ensures that the versions are all mutually
49+ #  compatible (as far the package metadata declares, anyway); pip's package resolver
50+ #  is more lax.
51+ # 
52+ #  Rather than `poetry install --no-dev`, we drop all dev dependencies from the
53+ #  toml file. This means we don't have to ensure compatibility between old deps and
54+ #  dev tools.
55+ 
56+ pip install --user toml
57+ 
58+ REMOVE_DEV_DEPENDENCIES=" 
59+ import toml 
60+ with open('pyproject.toml', 'r') as f: 
61+     data = toml.loads(f.read()) 
62+ 
63+ del data['tool']['poetry']['dev-dependencies'] 
64+ 
65+ with open('pyproject.toml', 'w') as f: 
66+     toml.dump(data, f) 
67+ " 
68+ python3 -c " $REMOVE_DEV_DEPENDENCIES " 
69+ 
70+ pipx install poetry==1.1.12
71+ ~ /.local/bin/poetry lock
72+ 
73+ echo  " ::group::Patched pyproject.toml" 
74+ cat pyproject.toml
75+ echo  " ::endgroup::" 
76+ echo  " ::group::Lockfile after patch" 
77+ cat poetry.lock
78+ echo  " ::endgroup::" 
79+ 
80+ ~ /.local/bin/poetry install -E " all test" 
81+ ~ /.local/bin/poetry run trial --jobs=2 tests
0 commit comments