|
1 | 1 | # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
2 | 2 | # SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
4 | | -import runpy |
| 4 | +import os |
5 | 5 | import shutil |
| 6 | +import subprocess |
| 7 | +import sys |
| 8 | +import tarfile |
| 9 | +from email import message_from_bytes |
6 | 10 | from pathlib import Path |
7 | | -from unittest.mock import Mock |
| 11 | +from zipfile import ZipFile |
8 | 12 |
|
9 | 13 | import pytest |
10 | | -import setuptools |
11 | | -import setuptools_scm |
12 | 14 | from packaging.requirements import Requirement |
13 | | -from packaging.version import Version |
14 | 15 |
|
15 | 16 |
|
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) |
23 | 25 |
|
| 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 | + ) |
24 | 49 |
|
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, |
40 | 55 | ) |
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, |
56 | 65 | ) |
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"} |
0 commit comments