Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 4e13743

Browse files
David Robertsonrichvdh
andauthored
Poetry: select olddeps using poetry (#12407)
Co-authored-by: Richard van der Hoff <[email protected]>
1 parent 3ad74b6 commit 4e13743

File tree

4 files changed

+70
-29
lines changed

4 files changed

+70
-29
lines changed

.ci/scripts/test_old_deps.sh

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
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
69
export DEBIAN_FRONTEND=noninteractive
@@ -9,12 +12,70 @@ set -ex
912

1013
apt-get update
1114
apt-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

1518
export LANG="C.UTF-8"
1619

1720
# Prevent virtualenv from auto-updating pip to an incompatible version
1821
export 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

.github/workflows/tests.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,19 @@ jobs:
128128
|| true
129129
130130
trial-olddeps:
131+
# Note: sqlite only; no postgres
131132
if: ${{ !cancelled() && !failure() }} # Allow previous steps to be skipped, but not fail
132133
needs: linting-done
133134
runs-on: ubuntu-latest
134135
steps:
135136
- uses: actions/checkout@v2
136137
- name: Test with old deps
137138
uses: docker://ubuntu:focal # For old python and sqlite
139+
# Note: focal seems to be using 3.8, but the oldest is 3.7?
140+
# See https://github.com/matrix-org/synapse/issues/12343
138141
with:
139142
workdir: /github/workspace
140143
entrypoint: .ci/scripts/test_old_deps.sh
141-
env:
142-
TRIAL_FLAGS: "--jobs=2"
143144
- name: Dump logs
144145
# Logs are most useful when the command fails, always include them.
145146
if: ${{ always() }}

changelog.d/12407.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Run the olddeps CI job using Poetry.

tox.ini

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -105,29 +105,7 @@ commands =
105105
# )
106106
usedevelop=true
107107

108-
# A test suite for the oldest supported versions of Python libraries, to catch
109-
# any uses of APIs not available in them.
110-
[testenv:py3-old]
111-
skip_install = true
112-
usedevelop = false
113-
deps =
114-
Automat == 0.8.0
115-
lxml
116-
# markupsafe 2.1 introduced a change that breaks Jinja 2.x. Since we depend on
117-
# Jinja >= 2.9, it means this test suite will fail if markupsafe >= 2.1 is installed.
118-
markupsafe < 2.1
119-
{[base]deps}
120-
121-
commands =
122-
# Make all greater-thans equals so we test the oldest version of our direct
123-
# dependencies, but make the pyopenssl 17.0, which can work against an
124-
# OpenSSL 1.1 compiled cryptography (as older ones don't compile on Travis).
125-
/bin/sh -c 'python -m synapse.python_dependencies | sed -e "s/>=/==/g" -e "/psycopg2/d" -e "s/pyopenssl==16.0.0/pyopenssl==17.0.0/" | xargs -d"\n" pip install'
126-
127-
# Install Synapse itself. This won't update any libraries.
128-
pip install -e ".[test]"
129108

130-
{[testenv]commands}
131109

132110
[testenv:benchmark]
133111
deps =

0 commit comments

Comments
 (0)