|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +""" |
| 5 | +Run pose-transform smoke under isolated NumPy versions (1.23.x and 2.x). |
| 6 | +
|
| 7 | +NumPy 1.23 adds the public ``numpy.from_dlpack`` API used by the transform path. |
| 8 | +CTest sets ``PYTHONPATH`` to the built ``python_package`` tree; each test spawns |
| 9 | +``uv run --no-project`` with a pinned NumPy. |
| 10 | +
|
| 11 | +Python version comes from the **same interpreter as pytest** (CI matrix / |
| 12 | +``ISAAC_TELEOP_PYTHON_VERSION``), not a hard-coded list. That keeps ``uv run`` |
| 13 | +aligned with the wheel ABI under ``PYTHONPATH`` (native extensions match). |
| 14 | +
|
| 15 | +The NumPy **1.23.5** pin is **skipped** on Python 3.12+ (no viable wheels / install |
| 16 | +for that interpreter). NumPy **2.x** runs on every matrix Python. |
| 17 | +""" |
| 18 | + |
| 19 | +from __future__ import annotations |
| 20 | + |
| 21 | +import os |
| 22 | +import shutil |
| 23 | +import subprocess |
| 24 | +import sys |
| 25 | +from pathlib import Path |
| 26 | + |
| 27 | +import pytest |
| 28 | + |
| 29 | +_SMOKE = Path(__file__).resolve().parent / "transform_numpy_version_smoke.py" |
| 30 | + |
| 31 | + |
| 32 | +@pytest.mark.parametrize( |
| 33 | + ("numpy_pin", "version_key"), |
| 34 | + [ |
| 35 | + ("numpy==1.23.5", "1.23"), |
| 36 | + ("numpy>=2.0.0,<3", "2"), |
| 37 | + ], |
| 38 | +) |
| 39 | +def test_head_transform_smoke_isolated_numpy(numpy_pin: str, version_key: str) -> None: |
| 40 | + if shutil.which("uv") is None: |
| 41 | + pytest.skip("uv not on PATH") |
| 42 | + if "PYTHONPATH" not in os.environ: |
| 43 | + pytest.skip( |
| 44 | + "PYTHONPATH unset (run under CTest or point at build python_package/<CONFIG>)" |
| 45 | + ) |
| 46 | + if not _SMOKE.is_file(): |
| 47 | + pytest.fail(f"missing smoke script: {_SMOKE}") |
| 48 | + |
| 49 | + if version_key == "1.23" and sys.version_info >= (3, 12): |
| 50 | + pytest.skip( |
| 51 | + "numpy==1.23.5 is not supported on Python 3.12+ (no wheels; matrix uses 3.12/3.13)" |
| 52 | + ) |
| 53 | + |
| 54 | + py = f"{sys.version_info.major}.{sys.version_info.minor}" |
| 55 | + cmd = [ |
| 56 | + "uv", |
| 57 | + "run", |
| 58 | + "--no-project", |
| 59 | + "--python", |
| 60 | + py, |
| 61 | + "--with", |
| 62 | + numpy_pin, |
| 63 | + "python", |
| 64 | + str(_SMOKE), |
| 65 | + version_key, |
| 66 | + ] |
| 67 | + subprocess.run(cmd, check=True, env=os.environ.copy()) |
0 commit comments