|
22 | 22 | import datetime |
23 | 23 | import enum |
24 | 24 | import itertools |
25 | | -import shlex |
26 | 25 | import subprocess |
27 | 26 | import sys |
28 | 27 | from collections.abc import Iterator |
@@ -248,44 +247,55 @@ def main() -> None: |
248 | 247 | f"{d.status:^6} {d.policy_version!s:10} ({policy_date:10})" |
249 | 248 | ) |
250 | 249 |
|
| 250 | + # These packages need upgrading |
251 | 251 | upgrade_args = list(itertools.chain.from_iterable( |
252 | 252 | ['--upgrade-package', f'{d.package_name}~={d.policy_version}'] |
253 | 253 | for d in dependencies |
254 | 254 | if d.status is VersionStatus.older |
255 | 255 | )) |
| 256 | + |
| 257 | + # These packages should be kept where they are |
256 | 258 | maintain_args = list(itertools.chain.from_iterable( |
257 | 259 | ['--upgrade-package', f'{d.package_name}~={d.requirements_version}'] |
258 | 260 | for d in dependencies |
259 | 261 | if d.status in {VersionStatus.current, VersionStatus.newer} |
260 | 262 | )) |
261 | | - if upgrade_args: |
262 | | - ignored_args = list(itertools.chain.from_iterable( |
263 | | - ['--unsafe-package', ignored] |
264 | | - for ignored in IGNORE_DEPS |
265 | | - )) |
266 | | - cmd = [ |
267 | | - 'pip-compile', |
268 | | - '--quiet', |
269 | | - '--extra', 'complete', |
270 | | - '--strip-extras', |
271 | | - '--unsafe-package', 'emsarray', |
272 | | - '--no-allow-unsafe', |
273 | | - # '--no-header', |
274 | | - # '--no-annotate', |
275 | | - '--output-file', requirements_file, |
276 | | - ] + upgrade_args + maintain_args + ignored_args + [ |
277 | | - 'pyproject.toml', |
278 | | - ] |
279 | | - print('$', shlex.join(cmd)) |
280 | | - subprocess.check_call(cmd) |
281 | | - cmd = [ |
282 | | - 'sed', |
283 | | - '-i', |
284 | | - 's/==/~=/', |
285 | | - requirements_file, |
286 | | - ] |
287 | | - print('$', shlex.join(cmd)) |
288 | | - subprocess.check_call(cmd) |
| 263 | + # These packages should be installed fresh every time, so ignore them for now. |
| 264 | + ignored_args = list(itertools.chain.from_iterable( |
| 265 | + ['--unsafe-package', ignored] |
| 266 | + for ignored in IGNORE_DEPS |
| 267 | + )) |
| 268 | + cmd = [ |
| 269 | + 'pip-compile', |
| 270 | + '--quiet', |
| 271 | + '--extra', 'complete', |
| 272 | + '--strip-extras', |
| 273 | + '--unsafe-package', 'emsarray', |
| 274 | + '--no-allow-unsafe', |
| 275 | + # '--no-header', |
| 276 | + # '--no-annotate', |
| 277 | + '--output-file', requirements_file, |
| 278 | + ] + upgrade_args + maintain_args + ignored_args + [ |
| 279 | + 'pyproject.toml', |
| 280 | + ] |
| 281 | + |
| 282 | + # pip-compile always prints '==' specifiers, |
| 283 | + # but we want the latest point release in the minimum policy version. |
| 284 | + subprocess.check_call(cmd) |
| 285 | + cmd = [ |
| 286 | + 'sed', |
| 287 | + '-i', |
| 288 | + 's/==/~=/', |
| 289 | + requirements_file, |
| 290 | + ] |
| 291 | + subprocess.check_call(cmd) |
| 292 | + |
| 293 | + # CI will install strictly the requirements present in this file and none more, |
| 294 | + # so append the ignored deps at the end with no version specifiers. |
| 295 | + with open(requirements_file, "a") as f: |
| 296 | + for ignored in IGNORE_DEPS: |
| 297 | + f.write(ignored) |
| 298 | + f.write("\n") |
289 | 299 |
|
290 | 300 | if errors: |
291 | 301 | print("\nErrors:") |
|
0 commit comments