Skip to content

Commit 680440d

Browse files
committed
fix(ci): make SDK artifact tests portable
1 parent 618f6b3 commit 680440d

1 file changed

Lines changed: 50 additions & 23 deletions

File tree

tests/test_sdk_release_boundary.py

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
import importlib.util
55
import json
66
import os
7+
import shutil
78
import subprocess
9+
import sys
810
import zipfile
11+
from email.parser import BytesParser
12+
from email.policy import default
913
from pathlib import Path
1014

1115
from base.challenge_sdk.app_factory import create_challenge_app
@@ -18,6 +22,44 @@
1822
from base.challenge_sdk.version import ARTIFACT_VERSION, RELEASE_MANIFEST
1923

2024

25+
def _build_wheel(repository: Path, wheelhouse: Path, environment: dict[str, str]) -> None:
26+
uv = shutil.which("uv")
27+
if uv is not None:
28+
command = [uv, "build", "--wheel", "--out-dir", str(wheelhouse)]
29+
else:
30+
command = [
31+
sys.executable,
32+
"-m",
33+
"pip",
34+
"wheel",
35+
"--no-deps",
36+
"--wheel-dir",
37+
str(wheelhouse),
38+
str(repository),
39+
]
40+
subprocess.run(
41+
command,
42+
cwd=repository,
43+
check=True,
44+
capture_output=True,
45+
text=True,
46+
env=environment,
47+
)
48+
49+
50+
def _base_requirement_from_wheel(wheel: Path) -> str:
51+
with zipfile.ZipFile(wheel) as archive:
52+
metadata_path = next(
53+
name for name in archive.namelist() if name.endswith(".dist-info/METADATA")
54+
)
55+
metadata = BytesParser(policy=default).parsebytes(archive.read(metadata_path))
56+
return next(
57+
requirement
58+
for requirement in metadata.get_all("Requires-Dist", [])
59+
if requirement.startswith("base @ ")
60+
)
61+
62+
2163
def test_prism_uses_only_the_canonical_base_sdk() -> None:
2264
assert importlib.util.find_spec("prism_challenge.sdk") is None
2365
assert importlib.metadata.version("base") == ARTIFACT_VERSION
@@ -41,14 +83,9 @@ def test_prism_wheel_contains_no_vendored_sdk(tmp_path: Path) -> None:
4183
repository = Path(__file__).resolve().parents[1]
4284
wheelhouse = tmp_path / "wheelhouse"
4385
wheelhouse.mkdir()
86+
clean_environment = {key: value for key, value in os.environ.items() if key != "PYTHONPATH"}
4487

45-
subprocess.run(
46-
["uv", "build", "--wheel", "--out-dir", str(wheelhouse)],
47-
cwd=repository,
48-
check=True,
49-
capture_output=True,
50-
text=True,
51-
)
88+
_build_wheel(repository, wheelhouse, clean_environment)
5289
wheel = next(wheelhouse.glob("prism_challenge-*.whl"))
5390
with zipfile.ZipFile(wheel) as archive:
5491
names = archive.namelist()
@@ -58,46 +95,36 @@ def test_prism_wheel_contains_no_vendored_sdk(tmp_path: Path) -> None:
5895

5996
def test_clean_artifacts_resolve_one_base_sdk(tmp_path: Path) -> None:
6097
prism_repository = Path(__file__).resolve().parents[1]
61-
base_repository = prism_repository.parent / "platform"
6298
wheelhouse = tmp_path / "wheelhouse"
6399
environment = tmp_path / "environment"
64100
wheelhouse.mkdir()
65101
clean_environment = {key: value for key, value in os.environ.items() if key != "PYTHONPATH"}
66102

67-
for repository in (base_repository, prism_repository):
68-
subprocess.run(
69-
["uv", "build", "--wheel", "--out-dir", str(wheelhouse)],
70-
cwd=repository,
71-
check=True,
72-
capture_output=True,
73-
text=True,
74-
env=clean_environment,
75-
)
76-
base_wheel = next(wheelhouse.glob("base-*.whl"))
103+
_build_wheel(prism_repository, wheelhouse, clean_environment)
77104
prism_wheel = next(wheelhouse.glob("prism_challenge-*.whl"))
105+
base_requirement = _base_requirement_from_wheel(prism_wheel)
78106

79107
subprocess.run(
80-
["uv", "venv", "--python", "3.12", str(environment)],
108+
[sys.executable, "-m", "venv", str(environment)],
81109
check=True,
82110
capture_output=True,
83111
text=True,
84112
env=clean_environment,
85113
)
86114
python = environment / "bin" / "python"
87115
subprocess.run(
88-
["uv", "pip", "install", "--python", str(python), str(base_wheel)],
116+
[str(python), "-m", "pip", "install", base_requirement],
89117
check=True,
90118
capture_output=True,
91119
text=True,
92120
env=clean_environment,
93121
)
94122
subprocess.run(
95123
[
96-
"uv",
124+
str(python),
125+
"-m",
97126
"pip",
98127
"install",
99-
"--python",
100-
str(python),
101128
"--no-deps",
102129
str(prism_wheel),
103130
],

0 commit comments

Comments
 (0)