Skip to content

Commit e692d72

Browse files
committed
Fix tagged metapackage builds and preserve toolkit patch coverage
Signed-off-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
1 parent b74179c commit e692d72

2 files changed

Lines changed: 60 additions & 53 deletions

File tree

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,71 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
import runpy
4+
import os
55
import shutil
6+
import subprocess
7+
import sys
8+
import tarfile
9+
from email import message_from_bytes
610
from pathlib import Path
7-
from unittest.mock import Mock
11+
from zipfile import ZipFile
812

913
import pytest
10-
import setuptools
11-
import setuptools_scm
1214
from packaging.requirements import Requirement
13-
from packaging.version import Version
1415

1516

16-
@pytest.fixture
17-
def standalone_source(tmp_path, monkeypatch):
18-
package = Path(__file__).resolve().parents[3] / "cuda_python"
19-
for name in ("setup.py", "pyproject.toml"):
20-
shutil.copyfile(package / name, tmp_path / name)
21-
monkeypatch.chdir(tmp_path)
22-
return tmp_path
17+
@pytest.mark.agent_authored(model="gpt-6")
18+
def test_tagged_maintenance_sdist_keeps_version_and_dependencies_without_selector(tmp_path):
19+
source = Path(__file__).resolve().parents[3] / "cuda_python"
20+
checkout = tmp_path / "checkout"
21+
package = checkout / "cuda_python"
22+
package.mkdir(parents=True)
23+
for filename in ("setup.py", "pyproject.toml", "DESCRIPTION.rst", "LICENSE"):
24+
shutil.copyfile(source / filename, package / filename)
2325

26+
env = os.environ.copy()
27+
env.pop("CUDA_PYTHON_BUILD_MAJOR", None)
28+
for args in (("init", "--quiet"), ("add", "."), ("commit", "--quiet", "-m", "Release"), ("tag", "v12.9.11")):
29+
subprocess.run( # noqa: S603
30+
[ # noqa: S607
31+
"git",
32+
"-c",
33+
"user.name=CI test",
34+
"-c",
35+
"user.email=ci-test@example.invalid",
36+
"-c",
37+
"commit.gpgsign=false",
38+
"-c",
39+
"tag.gpgsign=false",
40+
"-c",
41+
"core.hooksPath=/dev/null",
42+
*args,
43+
],
44+
cwd=checkout,
45+
env=env,
46+
check=True,
47+
capture_output=True,
48+
)
2449

25-
@pytest.mark.parametrize(("requested_major", "expected_major"), ((None, 13), ("12", 12)))
26-
@pytest.mark.agent_authored(model="gpt-6.1-sol")
27-
def test_source_build_selects_bindings_and_major_specific_dependencies(
28-
standalone_source, monkeypatch, requested_major, expected_major
29-
):
30-
if requested_major is None:
31-
monkeypatch.delenv("CUDA_PYTHON_BUILD_MAJOR", raising=False)
32-
else:
33-
monkeypatch.setenv("CUDA_PYTHON_BUILD_MAJOR", requested_major)
34-
setup = Mock()
35-
monkeypatch.setattr(setuptools, "setup", setup)
36-
monkeypatch.setattr(
37-
setuptools_scm,
38-
"get_version",
39-
lambda **options: options["git_describe_command"][-1].removeprefix("v").replace("*", "0"),
50+
subprocess.run(
51+
[sys.executable, "-c", "from setuptools.build_meta import build_sdist; build_sdist('dist')"],
52+
cwd=package,
53+
env=env,
54+
check=True,
4055
)
41-
42-
runpy.run_path(str(standalone_source / "setup.py"))
43-
44-
metadata = setup.call_args.kwargs
45-
assert Version(metadata["version"]).major == expected_major
46-
dependencies = {req.name: req for req in map(Requirement, metadata["install_requires"])}
47-
expected = {"cuda-bindings", "cuda-core", "cuda-pathfinder"} if expected_major >= 13 else {"cuda-bindings"}
48-
assert dependencies.keys() == expected
49-
assert metadata["version"] in dependencies["cuda-bindings"].specifier
50-
51-
52-
@pytest.mark.agent_authored(model="gpt-6.1-sol")
53-
def test_maintenance_sdist_keeps_its_dependencies_without_a_build_selector(standalone_source, monkeypatch):
54-
(standalone_source / "PKG-INFO").write_text(
55-
"Metadata-Version: 2.4\nName: cuda-python\nVersion: 12.9.11\n", encoding="utf-8"
56+
unpacked = tmp_path / "unpacked"
57+
with tarfile.open(next((package / "dist").glob("*.tar.gz"))) as archive:
58+
archive.extractall(unpacked, filter="data")
59+
standalone = next(unpacked.iterdir())
60+
subprocess.run(
61+
[sys.executable, "-c", "from setuptools.build_meta import build_wheel; build_wheel('dist')"],
62+
cwd=standalone,
63+
env=env,
64+
check=True,
5665
)
57-
monkeypatch.delenv("CUDA_PYTHON_BUILD_MAJOR", raising=False)
58-
setup = Mock()
59-
monkeypatch.setattr(setuptools, "setup", setup)
60-
61-
runpy.run_path(str(standalone_source / "setup.py"))
62-
63-
metadata = setup.call_args.kwargs
64-
assert Version(metadata["version"]).major == 12
65-
assert {Requirement(value).name for value in metadata["install_requires"]} == {"cuda-bindings"}
66+
with ZipFile(next((standalone / "dist").glob("*.whl"))) as wheel:
67+
metadata = message_from_bytes(
68+
wheel.read(next(name for name in wheel.namelist() if name.endswith(".dist-info/METADATA")))
69+
)
70+
assert metadata["Version"] == "12.9.11"
71+
assert {Requirement(value).name for value in metadata.get_all("Requires-Dist", [])} == {"cuda-bindings"}

‎cuda_python/AGENTS.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ monorepo.
2020
component packages rather than here.
2121
- Be careful when changing dependency/version logic in `setup.py`; preserve
2222
compatibility between metapackage versioning and subpackage constraints.
23-
- Git source builds default to CUDA 13; set `CUDA_PYTHON_BUILD_MAJOR=12` to
24-
select CUDA 12. Selectors live in `pyproject.toml`. Standalone sdists retain
23+
- Git source builds use CUDA 12 at an unambiguous CUDA 12 tag and otherwise
24+
default to CUDA 13. Set `CUDA_PYTHON_BUILD_MAJOR` to select either major
25+
explicitly. Selectors live in `pyproject.toml`. Standalone sdists retain
2526
their fixed version, which also determines their dependency major. Check
2627
default CUDA 13, explicit CUDA 12, and CUDA 12 sdist rebuilds when changing
2728
this shared packaging logic.

0 commit comments

Comments
 (0)