Skip to content

Commit efd49d7

Browse files
authored
tests: switch to uv pip-compile for lockfiles (#2084)
* tests: switch to uv pip-compile for lockfiles This switches the nox pip-compile session and lockfiles to use uv pip compile (written in Rust and much faster) instead of pip-compile from pip-tools for our dependency update jobs. As a side effect, this addresses the issue brought up in #1950 (comment), as we're no longer using pip-compile that can break anytime pip changes the private/internal APIs that pip-tools relies on. I re-generated the lockfiles with `--no-upgrade` to avoid extraneous changes in this PR. The only additions are the formatting of comments in the lockfile and colorama. colorama was added as a result of `uv pip-compile`'s `--universal` flag which creates "universal" lockfiles that include dependencies of other platforms, architectures, and Python versions than those of the system used to generate the lockfile. `--universal` should create more consistent results for contributors who use other systems (e.g., Mac OS or a newer Python version than the one used in CI). Fixes: #1755 * nox pip_compile: improve code comments Suggested-by: Don Naro <[email protected]>
1 parent 188f4fd commit efd49d7

12 files changed

+71
-71
lines changed

.pip-tools.toml

Lines changed: 0 additions & 5 deletions
This file was deleted.

noxfile.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import shlex
55
import shutil
66
from argparse import ArgumentParser, BooleanOptionalAction
7+
from contextlib import suppress
78
from glob import iglob
89
from pathlib import Path
910
from typing import cast
@@ -157,28 +158,42 @@ def lint(session: nox.Session):
157158
@nox.session(name="pip-compile", python=["3.11"])
158159
@nox.parametrize(["req"], requirements_files, requirements_files)
159160
def pip_compile(session: nox.Session, req: str):
160-
# .pip-tools.toml was introduced in v7
161-
# pip 24.3 causes a regression in pip-compile.
162-
# See https://github.com/jazzband/pip-tools/issues/2131.
163-
session.install("pip-tools >= 7", "pip < 24.3")
161+
"""
162+
Update dependency lockfiles in tests/ directory with uv pip compile.
163+
In addition to the usual flags supported by uv pip compile,
164+
this nox session implements two custom custom flags:
165+
166+
--no-upgrade
167+
By default, the noxfile passes --upgrade to uv pip compile which
168+
updates all package versions in the lockfiles.
169+
Pass --no-upgrade to keep existing package versions as they are and
170+
only make the most minimal changes to sync the lockfiles with the input
171+
(.in) files.
172+
--check
173+
Run uv pip compile without --upgrade and fail if any changes were made.
174+
This ensures the lockfiles are in sync with the input files.
175+
"""
176+
install(session, req="pip-compile")
164177

165-
# Use --upgrade by default unless a user passes -P.
166178
args = list(session.posargs)
167-
168-
# Support a custom --check flag to fail if pip-compile made any changes
169-
# so we can check that that lockfiles are in sync with the input (.in) files.
170179
check_mode = "--check" in args
171180
if check_mode:
172-
# Remove from args, as pip-compile doesn't actually support --check.
181+
# Remove from args, as pip compile doesn't actually support --check.
173182
args.remove("--check")
174183
elif not any(
175184
arg.startswith(("-P", "--upgrade-package", "--no-upgrade")) for arg in args
176185
):
186+
# Use --upgrade by default unless the user passes a conflicting flag.
177187
args.append("--upgrade")
188+
# Like --check, also remove --no-upgrade from args if it's present.
189+
with suppress(ValueError):
190+
args.remove("--no-upgrade")
178191

179192
# fmt: off
180193
session.run(
181-
"pip-compile",
194+
"uv", "pip", "compile",
195+
"--universal",
196+
"--quiet",
182197
"--output-file", f"tests/{req}.txt",
183198
*args,
184199
f"tests/{req}.in",

tests/formatters.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
#
2-
# This file is autogenerated by pip-compile with Python 3.11
3-
# by the following command:
4-
#
5-
# pip-compile --allow-unsafe --output-file=tests/formatters.txt --strip-extras tests/formatters.in
6-
#
1+
# This file was autogenerated by uv via the following command:
2+
# uv pip compile --universal --output-file tests/formatters.txt tests/formatters.in
73
black==24.10.0
84
# via -r tests/formatters.in
95
click==8.1.7
106
# via black
7+
colorama==0.4.6 ; platform_system == 'Windows'
8+
# via click
119
isort==5.13.2
1210
# via -r tests/formatters.in
1311
mypy-extensions==1.0.0

tests/pip-compile.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Pin the version of uv used for the pip-compile nox session
2+
uv

tests/pip-compile.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This file was autogenerated by uv via the following command:
2+
# uv pip compile --universal --output-file tests/pip-compile.txt tests/pip-compile.in
3+
uv==0.4.28
4+
# via -r tests/pip-compile.in

tests/pr_labeler.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
#
2-
# This file is autogenerated by pip-compile with Python 3.11
3-
# by the following command:
4-
#
5-
# pip-compile --allow-unsafe --output-file=tests/pr_labeler.txt --strip-extras tests/pr_labeler.in
6-
#
1+
# This file was autogenerated by uv via the following command:
2+
# uv pip compile --universal --output-file tests/pr_labeler.txt tests/pr_labeler.in
73
certifi==2024.8.30
84
# via requests
95
cffi==1.17.1
@@ -16,6 +12,8 @@ click==8.1.7
1612
# via typer-slim
1713
codeowners==0.7.0
1814
# via -r tests/pr_labeler.in
15+
colorama==0.4.6 ; platform_system == 'Windows'
16+
# via click
1917
cryptography==43.0.1
2018
# via pyjwt
2119
deprecated==1.2.14

tests/requirements-relaxed.txt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
#
2-
# This file is autogenerated by pip-compile with Python 3.11
3-
# by the following command:
4-
#
5-
# pip-compile --allow-unsafe --output-file=tests/requirements-relaxed.txt --strip-extras tests/requirements-relaxed.in
6-
#
1+
# This file was autogenerated by uv via the following command:
2+
# uv pip compile --universal --output-file tests/requirements-relaxed.txt tests/requirements-relaxed.in
73
aiofiles==24.1.0
84
# via
95
# antsibull-core
@@ -55,6 +51,11 @@ charset-normalizer==3.4.0
5551
# via requests
5652
click==8.1.7
5753
# via sphinx-intl
54+
colorama==0.4.6 ; (platform_system != 'Windows' and sys_platform == 'win32') or platform_system == 'Windows' or os_name == 'nt'
55+
# via
56+
# build
57+
# click
58+
# sphinx
5859
docutils==0.21.2
5960
# via
6061
# antsibull-changelog
@@ -129,6 +130,8 @@ semantic-version==2.10.0
129130
# antsibull-changelog
130131
# antsibull-core
131132
# antsibull-docs
133+
setuptools==75.6.0
134+
# via sphinx-intl
132135
six==1.16.0
133136
# via twiggy
134137
snowballstemmer==2.2.0
@@ -181,7 +184,3 @@ urllib3==2.2.3
181184
# via requests
182185
yarl==1.18.0
183186
# via aiohttp
184-
185-
# The following packages are considered to be unsafe in a requirements file:
186-
setuptools==75.6.0
187-
# via sphinx-intl

tests/requirements.txt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
#
2-
# This file is autogenerated by pip-compile with Python 3.11
3-
# by the following command:
4-
#
5-
# pip-compile --allow-unsafe --output-file=tests/requirements.txt --strip-extras tests/requirements.in
6-
#
1+
# This file was autogenerated by uv via the following command:
2+
# uv pip compile --universal --output-file tests/requirements.txt tests/requirements.in
73
aiofiles==24.1.0
84
# via
95
# antsibull-core
@@ -57,6 +53,11 @@ charset-normalizer==3.4.0
5753
# via requests
5854
click==8.1.7
5955
# via sphinx-intl
56+
colorama==0.4.6 ; (platform_system != 'Windows' and sys_platform == 'win32') or platform_system == 'Windows' or os_name == 'nt'
57+
# via
58+
# build
59+
# click
60+
# sphinx
6061
docutils==0.18.1
6162
# via
6263
# antsibull-changelog
@@ -131,6 +132,8 @@ semantic-version==2.10.0
131132
# antsibull-changelog
132133
# antsibull-core
133134
# antsibull-docs
135+
setuptools==75.6.0
136+
# via sphinx-intl
134137
six==1.16.0
135138
# via twiggy
136139
snowballstemmer==2.2.0
@@ -187,7 +190,3 @@ urllib3==2.2.3
187190
# via requests
188191
yarl==1.18.0
189192
# via aiohttp
190-
191-
# The following packages are considered to be unsafe in a requirements file:
192-
setuptools==75.6.0
193-
# via sphinx-intl

tests/spelling.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
#
2-
# This file is autogenerated by pip-compile with Python 3.11
3-
# by the following command:
4-
#
5-
# pip-compile --allow-unsafe --output-file=tests/spelling.txt --strip-extras tests/spelling.in
6-
#
1+
# This file was autogenerated by uv via the following command:
2+
# uv pip compile --universal --output-file tests/spelling.txt tests/spelling.in
73
codespell==2.3.0
84
# via -r tests/spelling.in

tests/static.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
#
2-
# This file is autogenerated by pip-compile with Python 3.11
3-
# by the following command:
4-
#
5-
# pip-compile --allow-unsafe --output-file=tests/static.txt --strip-extras tests/static.in
6-
#
1+
# This file was autogenerated by uv via the following command:
2+
# uv pip compile --universal --output-file tests/static.txt tests/static.in
73
ruff==0.8.1
84
# via -r tests/static.in

0 commit comments

Comments
 (0)