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

Commit b88cfe6

Browse files
David Robertsonsquahtx
andauthored
Require poetry>=1.3.2 (#14860)
* Upgrade to new lockfile format Now requires poetry >= 1.2.2 to read and poetry >= 1.3.0 to write. Cheat sheet: ``` poetry --version poetry show > scratch/before pipx upgrade poetry poetry --version poetry show > scratch/after diff scratch{before,after} && echo "no change!" ``` * Use Poetry 1.3.2 when reading or writing lockfile * Remove unneeded(?) poetry dep for cibuildwheel * Update docs * Remove redundant call to setup-python * Remove outdated comments related to Poetry 1.x * Remove outdated docs line was fixed in #13082 * Minor improvements to poetry cheat sheet * Invoke setup-python-poetry with explicit version Not sure about this. It's hardcoding versions everywhere. * Changelog * Check the lockfile is version 2.0 Might one day incorporate other checks like #14742 * Typo fixes, thanks Sean Co-authored-by: Sean Quah <[email protected]> Co-authored-by: Sean Quah <[email protected]>
1 parent f820740 commit b88cfe6

File tree

14 files changed

+1548
-1493
lines changed

14 files changed

+1548
-1493
lines changed

.ci/scripts/check_lockfile.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#! /usr/bin/env python
2+
import sys
3+
4+
if sys.version_info < (3, 11):
5+
raise RuntimeError("Requires at least Python 3.11, to import tomllib")
6+
7+
import tomllib
8+
9+
with open("poetry.lock", "rb") as f:
10+
lockfile = tomllib.load(f)
11+
12+
try:
13+
lock_version = lockfile["metadata"]["lock-version"]
14+
assert lock_version == "2.0"
15+
except Exception:
16+
print(
17+
"""\
18+
Lockfile is not version 2.0. You probably need to upgrade poetry on your local box
19+
and re-run `poetry lock --no-update`. See the Poetry cheat sheet at
20+
https://matrix-org.github.io/synapse/develop/development/dependencies.html
21+
"""
22+
)
23+
raise

.ci/scripts/prepare_old_deps.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ with open('pyproject.toml', 'w') as f:
5353
"
5454
python3 -c "$REMOVE_DEV_DEPENDENCIES"
5555

56-
pip install poetry==1.2.0
56+
pip install poetry==1.3.2
5757
poetry lock
5858

5959
echo "::group::Patched pyproject.toml"

.github/workflows/latest_deps.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- uses: matrix-org/setup-python-poetry@v1
3838
with:
3939
python-version: "3.x"
40-
poetry-version: "1.2.0"
40+
poetry-version: "1.3.2"
4141
extras: "all"
4242
# Dump installed versions for debugging.
4343
- run: poetry run pip list > before.txt

.github/workflows/release-artifacts.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ jobs:
127127
python-version: "3.x"
128128

129129
- name: Install cibuildwheel
130-
run: python -m pip install cibuildwheel==2.9.0 poetry==1.2.0
130+
run: python -m pip install cibuildwheel==2.9.0
131131

132132
- name: Set up QEMU to emulate aarch64
133133
if: matrix.arch == 'aarch64'

.github/workflows/tests.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ jobs:
3333
runs-on: ubuntu-latest
3434
steps:
3535
- uses: actions/checkout@v3
36-
- uses: actions/setup-python@v4
37-
with:
38-
python-version: "3.x"
3936
- uses: matrix-org/setup-python-poetry@v1
4037
with:
38+
python-version: "3.x"
39+
poetry-version: "1.3.2"
4140
extras: "all"
4241
- run: poetry run scripts-dev/generate_sample_config.sh --check
4342
- run: poetry run scripts-dev/config-lint.sh
@@ -52,6 +51,15 @@ jobs:
5251
- run: "pip install 'click==8.1.1' 'GitPython>=3.1.20'"
5352
- run: scripts-dev/check_schema_delta.py --force-colors
5453

54+
check-lockfile:
55+
runs-on: ubuntu-latest
56+
steps:
57+
- uses: actions/checkout@v3
58+
- uses: actions/setup-python@v4
59+
with:
60+
python-version: "3.x"
61+
- run: .ci/scripts/check_lockfile.py
62+
5563
lint:
5664
uses: "matrix-org/backend-meta/.github/workflows/python-poetry-ci.yml@v2"
5765
with:
@@ -88,6 +96,7 @@ jobs:
8896
ref: ${{ github.event.pull_request.head.sha }}
8997
- uses: matrix-org/setup-python-poetry@v1
9098
with:
99+
poetry-version: "1.3.2"
91100
extras: "all"
92101
- run: poetry run scripts-dev/check_pydantic_models.py
93102

@@ -163,6 +172,7 @@ jobs:
163172
- lint-pydantic
164173
- check-sampleconfig
165174
- check-schema-delta
175+
- check-lockfile
166176
- lint-clippy
167177
- lint-rustfmt
168178
runs-on: ubuntu-latest
@@ -219,6 +229,7 @@ jobs:
219229
- uses: matrix-org/setup-python-poetry@v1
220230
with:
221231
python-version: ${{ matrix.job.python-version }}
232+
poetry-version: "1.3.2"
222233
extras: ${{ matrix.job.extras }}
223234
- name: Await PostgreSQL
224235
if: ${{ matrix.job.postgres-version }}
@@ -294,6 +305,7 @@ jobs:
294305
- uses: matrix-org/setup-python-poetry@v1
295306
with:
296307
python-version: '3.7'
308+
poetry-version: "1.3.2"
297309
extras: "all test"
298310

299311
- run: poetry run trial -j6 tests
@@ -328,6 +340,7 @@ jobs:
328340
- uses: matrix-org/setup-python-poetry@v1
329341
with:
330342
python-version: ${{ matrix.python-version }}
343+
poetry-version: "1.3.2"
331344
extras: ${{ matrix.extras }}
332345
- run: poetry run trial --jobs=2 tests
333346
- name: Dump logs
@@ -419,6 +432,7 @@ jobs:
419432
- run: sudo apt-get -qq install xmlsec1 postgresql-client
420433
- uses: matrix-org/setup-python-poetry@v1
421434
with:
435+
poetry-version: "1.3.2"
422436
extras: "postgres"
423437
- run: .ci/scripts/test_export_data_command.sh
424438
env:
@@ -470,6 +484,7 @@ jobs:
470484
- uses: matrix-org/setup-python-poetry@v1
471485
with:
472486
python-version: ${{ matrix.python-version }}
487+
poetry-version: "1.3.2"
473488
extras: "postgres"
474489
- run: .ci/scripts/test_synapse_port_db.sh
475490
id: run_tester_script

.github/workflows/twisted_trunk.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ jobs:
148148
run: |
149149
set -x
150150
DEBIAN_FRONTEND=noninteractive sudo apt-get install -yqq python3 pipx
151-
pipx install poetry==1.2.0
151+
pipx install poetry==1.3.2
152152
153153
poetry remove -n twisted
154154
poetry add -n --extras tls git+https://github.com/twisted/twisted.git#trunk

changelog.d/14860.removal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Poetry 1.3.2 or higher is now required when `poetry install`ing from source.

debian/build_virtualenv

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ case $(dpkg-architecture -q DEB_HOST_ARCH) in
3131
esac
3232

3333
# Manually install Poetry and export a pip-compatible `requirements.txt`
34-
# We need a Poetry pre-release as the export command is buggy in < 1.2
3534
TEMP_VENV="$(mktemp -d)"
3635
python3 -m venv "$TEMP_VENV"
3736
source "$TEMP_VENV/bin/activate"
3837
pip install -U pip
39-
pip install poetry==1.2.0
38+
pip install poetry==1.3.2
4039
poetry export \
4140
--extras all \
4241
--extras test \

debian/changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
matrix-synapse-py3 (1.75.1) UNRELEASED; urgency=medium
2+
3+
* Use Poetry 1.3.2 to manage the bundled virtualenv included with this package.
4+
5+
-- Synapse Packaging team <[email protected]> Tue, 17 Jan 2023 15:08:00 +0000
6+
17
matrix-synapse-py3 (1.75.0) stable; urgency=medium
28

39
* New Synapse release 1.75.0.

docker/Dockerfile

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,8 @@
1717

1818
# Irritatingly, there is no blessed guide on how to distribute an application with its
1919
# poetry-managed environment in a docker image. We have opted for
20-
# `poetry export | pip install -r /dev/stdin`, but there are known bugs in
21-
# in `poetry export` whose fixes (scheduled for poetry 1.2) have yet to be released.
22-
# In case we get bitten by those bugs in the future, the recommendations here might
23-
# be useful:
24-
# https://github.com/python-poetry/poetry/discussions/1879#discussioncomment-216865
25-
# https://stackoverflow.com/questions/53835198/integrating-python-poetry-with-docker?answertab=scoredesc
26-
27-
20+
# `poetry export | pip install -r /dev/stdin`, but beware: we have experienced bugs in
21+
# in `poetry export` in the past.
2822

2923
ARG PYTHON_VERSION=3.9
3024

@@ -49,7 +43,7 @@ RUN \
4943
# We install poetry in its own build stage to avoid its dependencies conflicting with
5044
# synapse's dependencies.
5145
RUN --mount=type=cache,target=/root/.cache/pip \
52-
pip install --user "poetry==1.2.0"
46+
pip install --user "poetry==1.3.2"
5347

5448
WORKDIR /synapse
5549

docs/development/contributing_guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pipx install poetry
6767
but see poetry's [installation instructions](https://python-poetry.org/docs/#installation)
6868
for other installation methods.
6969

70-
Synapse requires Poetry version 1.2.0 or later.
70+
Developing Synapse requires Poetry version 1.3.2 or later.
7171

7272
Next, open a terminal and install dependencies as follows:
7373

docs/development/dependencies.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
This is a quick cheat sheet for developers on how to use [`poetry`](https://python-poetry.org/).
44

5+
# Installing
6+
7+
See the [contributing guide](contributing_guide.md#4-install-the-dependencies).
8+
9+
Developers should use Poetry 1.3.2 or higher. If you encounter problems related
10+
to poetry, please [double-check your poetry version](#check-the-version-of-poetry-with-poetry---version).
11+
512
# Background
613

714
Synapse uses a variety of third-party Python packages to function as a homeserver.
@@ -123,7 +130,7 @@ context of poetry's venv, without having to run `poetry shell` beforehand.
123130
## ...reset my venv to the locked environment?
124131

125132
```shell
126-
poetry install --extras all --remove-untracked
133+
poetry install --all-extras --sync
127134
```
128135

129136
## ...delete everything and start over from scratch?
@@ -183,7 +190,6 @@ Either:
183190
- manually update `pyproject.toml`; then `poetry lock --no-update`; or else
184191
- `poetry add packagename`. See `poetry add --help`; note the `--dev`,
185192
`--extras` and `--optional` flags in particular.
186-
- **NB**: this specifies the new package with a version given by a "caret bound". This won't get forced to its lowest version in the old deps CI job: see [this TODO](https://github.com/matrix-org/synapse/blob/4e1374373857f2f7a911a31c50476342d9070681/.ci/scripts/test_old_deps.sh#L35-L39).
187193

188194
Include the updated `pyproject.toml` and `poetry.lock` files in your commit.
189195

@@ -196,7 +202,7 @@ poetry remove packagename
196202
```
197203

198204
ought to do the trick. Alternatively, manually update `pyproject.toml` and
199-
`poetry lock --no-update`. Include the updated `pyproject.toml` and poetry.lock`
205+
`poetry lock --no-update`. Include the updated `pyproject.toml` and `poetry.lock`
200206
files in your commit.
201207

202208
## ...update the version range for an existing dependency?
@@ -240,9 +246,6 @@ poetry export --extras all
240246

241247
Be wary of bugs in `poetry export` and `pip install -r requirements.txt`.
242248

243-
Note: `poetry export` will be made a plugin in Poetry 1.2. Additional config may
244-
be required.
245-
246249
## ...build a test wheel?
247250

248251
I usually use
@@ -260,7 +263,7 @@ doesn't require poetry. (It's what we use in CI too). However, you could try
260263

261264
## Check the version of poetry with `poetry --version`.
262265

263-
The minimum version of poetry supported by Synapse is 1.2.
266+
The minimum version of poetry supported by Synapse is 1.3.2.
264267

265268
It can also be useful to check the version of `poetry-core` in use. If you've
266269
installed `poetry` with `pipx`, try `pipx runpip poetry list | grep

docs/upgrade.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ and vice versa.
100100
Once all workers are upgraded to v1.76 (or downgraded to v1.75), account data
101101
and device replication will resume as normal.
102102
103+
## Minimum version of Poetry is now 1.3.2
104+
105+
The minimum supported version of Poetry is now 1.3.2 (previously 1.2.0, [since
106+
Synapse 1.67](#upgrading-to-v1670)). If you have used `poetry install` to
107+
install Synapse from a source checkout, you should upgrade poetry: see its
108+
[installation instructions](https://python-poetry.org/docs/#installation).
109+
For all other installation methods, no acction is required.
103110
104111
# Upgrading to v1.74.0
105112

0 commit comments

Comments
 (0)