Skip to content

Commit f44a308

Browse files
committed
Revert "fix(build): don't import cuda.pathfinder in build_hooks.py"
This reverts commit 5e445bf.
1 parent 5e445bf commit f44a308

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

cuda_bindings/build_hooks.py

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

3636
@functools.cache
3737
def _get_cuda_path() -> str:
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"))
38+
from cuda.pathfinder import get_cuda_path_or_home
39+
40+
cuda_path = get_cuda_path_or_home()
4241
if not cuda_path:
4342
raise RuntimeError("Environment variable CUDA_PATH or CUDA_HOME is not set")
4443
print("CUDA path:", cuda_path)

cuda_bindings/pyproject.toml

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

cuda_core/build_hooks.py

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

3131
@functools.cache
3232
def _get_cuda_path() -> str:
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"))
33+
from cuda.pathfinder import get_cuda_path_or_home
34+
35+
cuda_path = get_cuda_path_or_home()
3736
if not cuda_path:
3837
raise RuntimeError("Environment variable CUDA_PATH or CUDA_HOME is not set")
3938
print("CUDA path:", cuda_path)

cuda_core/pyproject.toml

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

cuda_core/tests/test_build_hooks.py

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

2525
import pytest
2626

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

6971
build_hooks._get_cuda_path.cache_clear()
7072
build_hooks._determine_cuda_major_version.cache_clear()
73+
get_cuda_path_or_home.cache_clear()
7174

7275
mock_env = {
7376
k: v
@@ -92,6 +95,7 @@ def test_env_var_override(self, version):
9295
"""CUDA_CORE_BUILD_MAJOR env var override works with various versions."""
9396
build_hooks._get_cuda_path.cache_clear()
9497
build_hooks._determine_cuda_major_version.cache_clear()
98+
get_cuda_path_or_home.cache_clear()
9599
with mock.patch.dict(os.environ, {"CUDA_CORE_BUILD_MAJOR": version}, clear=False):
96100
result = build_hooks._determine_cuda_major_version()
97101
assert result == version
@@ -125,6 +129,7 @@ def test_missing_cuda_path_raises_error(self):
125129
"""RuntimeError is raised when CUDA_PATH/CUDA_HOME not set and no env var override."""
126130
build_hooks._get_cuda_path.cache_clear()
127131
build_hooks._determine_cuda_major_version.cache_clear()
132+
get_cuda_path_or_home.cache_clear()
128133
with (
129134
mock.patch.dict(os.environ, {}, clear=True),
130135
pytest.raises(RuntimeError, match="CUDA_PATH or CUDA_HOME"),

0 commit comments

Comments
 (0)