Skip to content

Commit beef27e

Browse files
committed
Use pip to detect if common wheels need regenerating
1 parent 9548a41 commit beef27e

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

noxfile.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ def run_with_protected_pip(session: nox.Session, *arguments: str) -> None:
4444
session.run_install(*command, env=env, silent=True)
4545

4646

47-
def should_update_common_wheels() -> bool:
47+
def should_update_common_wheels(session: nox.Session) -> bool:
48+
"""Determine if the common wheels cache needs to be updated.
49+
50+
The cache is invalidated if:
51+
1. It doesn't exist yet
52+
2. pyproject.toml was modified after the cache was created
53+
3. The cached wheels cannot satisfy the current Python version's requirements
54+
"""
4855
# If the cache hasn't been created, create it.
4956
if not os.path.exists(LOCATIONS["common-wheels"]):
5057
return True
@@ -54,6 +61,34 @@ def should_update_common_wheels() -> bool:
5461
pyproject_updated_at = os.path.getmtime("pyproject.toml")
5562
need_to_repopulate = pyproject_updated_at > cache_last_populated_at
5663

64+
if not need_to_repopulate:
65+
# Check all common wheels are available for the current Python version,
66+
# by using --ignore-installed and --dry-run against the common-wheels
67+
# directory.
68+
result = session.run(
69+
"python",
70+
LOCATIONS["protected-pip"],
71+
"install",
72+
"--dry-run",
73+
"--ignore-installed",
74+
"--no-index",
75+
"--find-links",
76+
LOCATIONS["common-wheels"],
77+
"--group",
78+
"test-common-wheels",
79+
env={"VIRTUAL_ENV": session.virtualenv.location},
80+
silent=True,
81+
success_codes=[0, 1], # Accept both success and failure and check result
82+
)
83+
84+
# Result is the stdout of the pip install command.
85+
if result is None or "Would install" not in result:
86+
session.log(
87+
"Regenerating common wheels as cached wheels "
88+
"cannot satisfy test-common-wheels"
89+
)
90+
need_to_repopulate = True
91+
5792
# Clear the stale cache.
5893
if need_to_repopulate:
5994
shutil.rmtree(LOCATIONS["common-wheels"], ignore_errors=True)
@@ -67,7 +102,7 @@ def should_update_common_wheels() -> bool:
67102
@nox.session(python=["3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "pypy3"])
68103
def test(session: nox.Session) -> None:
69104
# Get the common wheels.
70-
if should_update_common_wheels():
105+
if should_update_common_wheels(session):
71106
# fmt: off
72107
run_with_protected_pip(
73108
session,

0 commit comments

Comments
 (0)