Skip to content

Commit 5e445bf

Browse files
committed
fix(build): don't import cuda.pathfinder in build_hooks.py
The build backends run in an isolated venv created by pyproject-build. Although cuda-pathfinder is listed in build-system.requires and gets installed, the cuda namespace package from backend-path=["."] shadows the installed cuda-pathfinder, making `from cuda.pathfinder import ...` fail with ModuleNotFoundError. This broke all CI wheel builds. Revert _get_cuda_path() to use os.environ.get() directly with CUDA_PATH > CUDA_HOME priority, and remove cuda-pathfinder from build-system.requires (it was not there on main; our PR added it). Made-with: Cursor
1 parent 8d3ed03 commit 5e445bf

File tree

5 files changed

+8
-13
lines changed

5 files changed

+8
-13
lines changed

cuda_bindings/build_hooks.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@
3535

3636
@functools.cache
3737
def _get_cuda_path() -> str:
38-
from cuda.pathfinder import get_cuda_path_or_home
39-
40-
cuda_path = get_cuda_path_or_home()
38+
# Not using cuda.pathfinder.get_cuda_path_or_home() here because this
39+
# build backend runs in an isolated venv where the cuda namespace package
40+
# from backend-path shadows the installed cuda-pathfinder.
41+
cuda_path = os.environ.get("CUDA_PATH", os.environ.get("CUDA_HOME"))
4142
if not cuda_path:
4243
raise RuntimeError("Environment variable CUDA_PATH or CUDA_HOME is not set")
4344
print("CUDA path:", cuda_path)

cuda_bindings/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ requires = [
66
"setuptools_scm[simple]>=8",
77
"cython>=3.2,<3.3",
88
"pyclibrary>=0.1.7",
9-
"cuda-pathfinder",
109
]
1110
build-backend = "build_hooks"
1211
backend-path = ["."]

cuda_core/build_hooks.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030

3131
@functools.cache
3232
def _get_cuda_path() -> str:
33-
from cuda.pathfinder import get_cuda_path_or_home
34-
35-
cuda_path = get_cuda_path_or_home()
33+
# Not using cuda.pathfinder.get_cuda_path_or_home() here because this
34+
# build backend runs in an isolated venv where the cuda namespace package
35+
# from backend-path shadows the installed cuda-pathfinder.
36+
cuda_path = os.environ.get("CUDA_PATH", os.environ.get("CUDA_HOME"))
3637
if not cuda_path:
3738
raise RuntimeError("Environment variable CUDA_PATH or CUDA_HOME is not set")
3839
print("CUDA path:", cuda_path)

cuda_core/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ requires = [
77
"setuptools>=80",
88
"setuptools-scm[simple]>=8",
99
"Cython>=3.2,<3.3",
10-
"cuda-pathfinder"
1110
]
1211
build-backend = "build_hooks"
1312
backend-path = ["."]

cuda_core/tests/test_build_hooks.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
import pytest
2626

27-
from cuda.pathfinder import get_cuda_path_or_home
28-
2927
# build_hooks.py imports Cython and setuptools at the top level, so skip if not available
3028
pytest.importorskip("Cython")
3129
pytest.importorskip("setuptools")
@@ -70,7 +68,6 @@ def _check_version_detection(
7068

7169
build_hooks._get_cuda_path.cache_clear()
7270
build_hooks._determine_cuda_major_version.cache_clear()
73-
get_cuda_path_or_home.cache_clear()
7471

7572
mock_env = {
7673
k: v
@@ -95,7 +92,6 @@ def test_env_var_override(self, version):
9592
"""CUDA_CORE_BUILD_MAJOR env var override works with various versions."""
9693
build_hooks._get_cuda_path.cache_clear()
9794
build_hooks._determine_cuda_major_version.cache_clear()
98-
get_cuda_path_or_home.cache_clear()
9995
with mock.patch.dict(os.environ, {"CUDA_CORE_BUILD_MAJOR": version}, clear=False):
10096
result = build_hooks._determine_cuda_major_version()
10197
assert result == version
@@ -129,7 +125,6 @@ def test_missing_cuda_path_raises_error(self):
129125
"""RuntimeError is raised when CUDA_PATH/CUDA_HOME not set and no env var override."""
130126
build_hooks._get_cuda_path.cache_clear()
131127
build_hooks._determine_cuda_major_version.cache_clear()
132-
get_cuda_path_or_home.cache_clear()
133128
with (
134129
mock.patch.dict(os.environ, {}, clear=True),
135130
pytest.raises(RuntimeError, match="CUDA_PATH or CUDA_HOME"),

0 commit comments

Comments
 (0)