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 94598c5d834..02184a07cd4 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 be55b6ff9c3..ee2c5b0a752 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 d88e22b1959..a67ac32184d 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 540a0692752..ded571fdd50 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 f71ab102e06..4550d9fae2f 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 3cc3adc8f24..a0f3e6b287c 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 4cc524c49e8..629d70a95bf 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")