|
4 | 4 | import shlex |
5 | 5 | import shutil |
6 | 6 | from argparse import ArgumentParser, BooleanOptionalAction |
| 7 | +from contextlib import suppress |
7 | 8 | from glob import iglob |
8 | 9 | from pathlib import Path |
9 | 10 | from typing import cast |
@@ -157,28 +158,42 @@ def lint(session: nox.Session): |
157 | 158 | @nox.session(name="pip-compile", python=["3.11"]) |
158 | 159 | @nox.parametrize(["req"], requirements_files, requirements_files) |
159 | 160 | 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") |
164 | 177 |
|
165 | | - # Use --upgrade by default unless a user passes -P. |
166 | 178 | 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. |
170 | 179 | check_mode = "--check" in args |
171 | 180 | 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. |
173 | 182 | args.remove("--check") |
174 | 183 | elif not any( |
175 | 184 | arg.startswith(("-P", "--upgrade-package", "--no-upgrade")) for arg in args |
176 | 185 | ): |
| 186 | + # Use --upgrade by default unless the user passes a conflicting flag. |
177 | 187 | 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") |
178 | 191 |
|
179 | 192 | # fmt: off |
180 | 193 | session.run( |
181 | | - "pip-compile", |
| 194 | + "uv", "pip", "compile", |
| 195 | + "--universal", |
| 196 | + "--quiet", |
182 | 197 | "--output-file", f"tests/{req}.txt", |
183 | 198 | *args, |
184 | 199 | f"tests/{req}.in", |
|
0 commit comments