From bb15d79906629b3bd19cc9b8dab256ef972cbf5c Mon Sep 17 00:00:00 2001 From: Rob Parolin Date: Wed, 25 Nov 2026 12:37:24 -0700 Subject: [PATCH 1/2] refactor(pathfinder): move two test-only helpers out of the package - `quote_for_shell` is only used to print paths in test summaries. It moves to `tests/local_helpers.py`. - `_loadable_via_canary_subprocess` is only used by `tests/conftest.py`, which now calls the function it wrapped. No behavior change for the shipped package. 1645 passed, 6 skipped. Co-Authored-By: Claude Fable 5.2 Signed-off-by: Rob Parolin --- .../_dynamic_libs/load_nvidia_dynamic_lib.py | 5 ----- .../cuda/pathfinder/_utils/platform_aware.py | 12 ------------ cuda_pathfinder/tests/conftest.py | 5 ++++- cuda_pathfinder/tests/local_helpers.py | 13 +++++++++++++ cuda_pathfinder/tests/test_driver_lib_loading.py | 3 ++- cuda_pathfinder/tests/test_find_static_lib.py | 2 +- .../tests/test_load_nvidia_dynamic_lib.py | 4 ++-- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py b/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py index 94598c5d8340..02184a07cd46 100644 --- a/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py +++ b/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py @@ -129,11 +129,6 @@ def _resolve_system_loaded_abs_path_in_subprocess( return None -def _loadable_via_canary_subprocess(libname: str, *, timeout: float = _CANARY_PROBE_TIMEOUT_SECONDS) -> bool: - """Return True if the canary subprocess can resolve ``libname`` via system search.""" - return _resolve_system_loaded_abs_path_in_subprocess(libname, timeout=timeout) is not None - - def resolve_ctk_root_via_canary(canary_libname: str) -> str | None: """Resolve the CUDA Toolkit root from a system-loadable canary library. diff --git a/cuda_pathfinder/cuda/pathfinder/_utils/platform_aware.py b/cuda_pathfinder/cuda/pathfinder/_utils/platform_aware.py index be55b6ff9c3a..ee2c5b0a752c 100644 --- a/cuda_pathfinder/cuda/pathfinder/_utils/platform_aware.py +++ b/cuda_pathfinder/cuda/pathfinder/_utils/platform_aware.py @@ -16,15 +16,3 @@ # These describe the Python process ABI, not the Windows host architecture. IS_WINDOWS_X64 = _WINDOWS_PYTHON_ARCH == "x64" IS_WINDOWS_ARM64 = _WINDOWS_PYTHON_ARCH == "arm64" - - -def quote_for_shell(s: str) -> str: - if IS_WINDOWS: - # This is a relatively heavy import; keep pathfinder lean if possible. - from subprocess import list2cmdline - - return list2cmdline([s]) - else: - import shlex - - return shlex.quote(s) diff --git a/cuda_pathfinder/tests/conftest.py b/cuda_pathfinder/tests/conftest.py index d88e22b19595..a67ac32184d0 100644 --- a/cuda_pathfinder/tests/conftest.py +++ b/cuda_pathfinder/tests/conftest.py @@ -38,6 +38,9 @@ def skip_if_missing_libnvcudla_so(libname: str, *, timeout: float) -> None: # pytest collection for the whole test suite. from cuda.pathfinder._dynamic_libs import load_nvidia_dynamic_lib as load_nvidia_dynamic_lib_module - if load_nvidia_dynamic_lib_module._loadable_via_canary_subprocess("nvcudla", timeout=timeout): + canary_abs_path = load_nvidia_dynamic_lib_module._resolve_system_loaded_abs_path_in_subprocess( + "nvcudla", timeout=timeout + ) + if canary_abs_path is not None: return pytest.skip("libnvcudla.so is not loadable via canary subprocess on this host.") diff --git a/cuda_pathfinder/tests/local_helpers.py b/cuda_pathfinder/tests/local_helpers.py index 540a0692752d..ded571fdd50c 100644 --- a/cuda_pathfinder/tests/local_helpers.py +++ b/cuda_pathfinder/tests/local_helpers.py @@ -7,6 +7,8 @@ from packaging.version import Version +from cuda.pathfinder._utils.platform_aware import IS_WINDOWS + @functools.cache def have_distribution(name_pattern: str, *, minimum_version: str | None = None) -> bool: @@ -18,3 +20,14 @@ def have_distribution(name_pattern: str, *, minimum_version: str | None = None) for dist in importlib.metadata.distributions() if "Name" in dist.metadata ) + + +def quote_for_shell(s: str) -> str: + if IS_WINDOWS: + from subprocess import list2cmdline + + return list2cmdline([s]) + else: + import shlex + + return shlex.quote(s) diff --git a/cuda_pathfinder/tests/test_driver_lib_loading.py b/cuda_pathfinder/tests/test_driver_lib_loading.py index f71ab102e060..4550d9fae2fd 100644 --- a/cuda_pathfinder/tests/test_driver_lib_loading.py +++ b/cuda_pathfinder/tests/test_driver_lib_loading.py @@ -17,6 +17,7 @@ run_load_nvidia_dynamic_lib_in_subprocess, ) from conftest import skip_if_missing_libnvcudla_so +from local_helpers import quote_for_shell from cuda.pathfinder._dynamic_libs.lib_descriptor import LIB_DESCRIPTORS from cuda.pathfinder._dynamic_libs.load_dl_common import DynamicLibNotFoundError, LoadedDL @@ -27,7 +28,7 @@ ) from cuda.pathfinder._dynamic_libs.subprocess_protocol import STATUS_NOT_FOUND, parse_dynamic_lib_subprocess_payload from cuda.pathfinder._utils import driver_info -from cuda.pathfinder._utils.platform_aware import IS_WINDOWS, quote_for_shell +from cuda.pathfinder._utils.platform_aware import IS_WINDOWS STRICTNESS = os.environ.get("CUDA_PATHFINDER_TEST_LOAD_NVIDIA_DYNAMIC_LIB_STRICTNESS", "see_what_works") assert STRICTNESS in ("see_what_works", "all_must_work") diff --git a/cuda_pathfinder/tests/test_find_static_lib.py b/cuda_pathfinder/tests/test_find_static_lib.py index 3cc3adc8f241..a0f3e6b287ce 100644 --- a/cuda_pathfinder/tests/test_find_static_lib.py +++ b/cuda_pathfinder/tests/test_find_static_lib.py @@ -5,6 +5,7 @@ from pathlib import Path import pytest +from local_helpers import quote_for_shell import cuda.pathfinder._static_libs.find_static_lib as find_static_lib_module from cuda.pathfinder._static_libs.find_static_lib import ( @@ -14,7 +15,6 @@ locate_static_lib, ) from cuda.pathfinder._utils.env_vars import get_cuda_path_or_home -from cuda.pathfinder._utils.platform_aware import quote_for_shell STRICTNESS = os.environ.get("CUDA_PATHFINDER_TEST_FIND_NVIDIA_STATIC_LIB_STRICTNESS", "see_what_works") assert STRICTNESS in ("see_what_works", "all_must_work") diff --git a/cuda_pathfinder/tests/test_load_nvidia_dynamic_lib.py b/cuda_pathfinder/tests/test_load_nvidia_dynamic_lib.py index 4cc524c49e85..629d70a95bfd 100644 --- a/cuda_pathfinder/tests/test_load_nvidia_dynamic_lib.py +++ b/cuda_pathfinder/tests/test_load_nvidia_dynamic_lib.py @@ -12,7 +12,7 @@ run_load_nvidia_dynamic_lib_in_subprocess, ) from conftest import skip_if_missing_libnvcudla_so -from local_helpers import have_distribution +from local_helpers import have_distribution, quote_for_shell from cuda.pathfinder import DynamicLibNotAvailableError, DynamicLibUnknownError, load_nvidia_dynamic_lib from cuda.pathfinder._dynamic_libs import load_nvidia_dynamic_lib as load_nvidia_dynamic_lib_module @@ -21,7 +21,7 @@ STATUS_NOT_FOUND, parse_dynamic_lib_subprocess_payload, ) -from cuda.pathfinder._utils.platform_aware import IS_WINDOWS, quote_for_shell +from cuda.pathfinder._utils.platform_aware import IS_WINDOWS STRICTNESS = os.environ.get("CUDA_PATHFINDER_TEST_LOAD_NVIDIA_DYNAMIC_LIB_STRICTNESS", "see_what_works") assert STRICTNESS in ("see_what_works", "all_must_work") From 149fea4d798ef1980f96abb45cb1def65b1c7960 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 26 Nov 2026 11:17:25 -0800 Subject: [PATCH 2/2] ci: require manual copy-pr-bot approval Signed-off-by: Ralf W. Grosse-Kunstleve