Skip to content

Commit 83c45fa

Browse files
committed
Update compatibility tests for system CTK paths
Allow the real compatibility checks to pass when CTK artifacts come from a system install instead of site-packages, including cases where CUDA_PATH and CUDA_HOME are unset. Made-with: Cursor
1 parent cb54cf6 commit 83c45fa

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

cuda_pathfinder/tests/test_with_compatibility_checks.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,30 @@ def _located_bitcode_lib(name: str, abs_path: str) -> LocatedBitcodeLib:
6464
)
6565

6666

67+
def _assert_real_ctk_backed_path(path: str) -> None:
68+
norm_path = os.path.normpath(os.path.abspath(path))
69+
if "site-packages" in Path(norm_path).parts:
70+
return
71+
current = Path(norm_path)
72+
if current.is_file():
73+
current = current.parent
74+
for candidate in (current, *current.parents):
75+
version_json_path = candidate / "version.json"
76+
if version_json_path.is_file():
77+
return
78+
for env_var in ("CUDA_PATH", "CUDA_HOME"):
79+
ctk_root = os.environ.get(env_var)
80+
if not ctk_root:
81+
continue
82+
norm_ctk_root = os.path.normpath(os.path.abspath(ctk_root))
83+
if os.path.commonpath((norm_path, norm_ctk_root)) == norm_ctk_root:
84+
return
85+
raise AssertionError(
86+
"Expected a site-packages path, a path under a CTK root with version.json, "
87+
f"or a path under CUDA_PATH/CUDA_HOME, got {path!r}"
88+
)
89+
90+
6791
def test_load_dynamic_lib_then_find_headers_same_ctk_version(monkeypatch, tmp_path):
6892
ctk_root = tmp_path / "cuda-12.9"
6993
_write_version_json(ctk_root, "12.9.20250531")
@@ -272,7 +296,7 @@ def test_real_wheel_ctk_items_are_compatible(info_summary_append):
272296
) as exc:
273297
if STRICTNESS == "all_must_work":
274298
raise
275-
info_summary_append(f"real wheel check unavailable: {exc.__class__.__name__}: {exc}")
299+
info_summary_append(f"real CTK check unavailable: {exc.__class__.__name__}: {exc}")
276300
return
277301

278302
info_summary_append(f"nvrtc={loaded.abs_path!r}")
@@ -285,7 +309,7 @@ def test_real_wheel_ctk_items_are_compatible(info_summary_append):
285309
assert header_dir is not None
286310
assert nvcc is not None
287311
for path in (loaded.abs_path, header_dir, static_lib, bitcode_lib, nvcc):
288-
assert "site-packages" in path
312+
_assert_real_ctk_backed_path(path)
289313

290314

291315
def test_real_wheel_component_version_does_not_override_ctk_line(info_summary_append):
@@ -296,14 +320,14 @@ def test_real_wheel_component_version_does_not_override_ctk_line(info_summary_ap
296320
except (CompatibilityCheckError, CompatibilityInsufficientMetadataError) as exc:
297321
if STRICTNESS == "all_must_work":
298322
raise
299-
info_summary_append(f"real cufft wheel check unavailable: {exc.__class__.__name__}: {exc}")
323+
info_summary_append(f"real cufft CTK check unavailable: {exc.__class__.__name__}: {exc}")
300324
return
301325

302326
if header_dir is None:
303327
if STRICTNESS == "all_must_work":
304-
raise AssertionError("Expected wheel-backed cufft headers to be discoverable.")
305-
info_summary_append("real cufft wheel check unavailable: cufft headers not found")
328+
raise AssertionError("Expected CTK-backed cufft headers to be discoverable.")
329+
info_summary_append("real cufft CTK check unavailable: cufft headers not found")
306330
return
307331

308332
info_summary_append(f"cufft_headers={header_dir!r}")
309-
assert "site-packages" in header_dir
333+
_assert_real_ctk_backed_path(header_dir)

0 commit comments

Comments
 (0)