Skip to content

Commit fd497c9

Browse files
committed
build: fix import style for ModuleNotFoundError compatibility
`from cuda import pathfinder` raises ImportError (not ModuleNotFoundError) when the cuda namespace exists but pathfinder is not a submodule. Switch to `import cuda.pathfinder` which raises ModuleNotFoundError when the submodule is missing. Made-with: Cursor
1 parent 1884c5e commit fd497c9

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

cuda_bindings/build_hooks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ def _import_get_cuda_path_or_home():
4343
site-packages ``cuda/`` directory.
4444
"""
4545
try:
46-
from cuda import pathfinder
46+
import cuda.pathfinder
4747
except ModuleNotFoundError:
4848
pass
4949
else:
5050
return getattr(
51-
pathfinder,
51+
cuda.pathfinder,
5252
"get_cuda_path_or_home",
5353
lambda: os.environ.get("CUDA_PATH", os.environ.get("CUDA_HOME")),
5454
)
@@ -61,10 +61,10 @@ def _import_get_cuda_path_or_home():
6161
cuda.__path__ = list(cuda.__path__) + [sp_cuda]
6262
break
6363

64-
from cuda import pathfinder
64+
import cuda.pathfinder
6565

6666
return getattr(
67-
pathfinder,
67+
cuda.pathfinder,
6868
"get_cuda_path_or_home",
6969
lambda: os.environ.get("CUDA_PATH", os.environ.get("CUDA_HOME")),
7070
)

cuda_core/build_hooks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ def _import_get_cuda_path_or_home():
3838
site-packages ``cuda/`` directory.
3939
"""
4040
try:
41-
from cuda import pathfinder
41+
import cuda.pathfinder
4242
except ModuleNotFoundError:
4343
pass
4444
else:
4545
return getattr(
46-
pathfinder,
46+
cuda.pathfinder,
4747
"get_cuda_path_or_home",
4848
lambda: os.environ.get("CUDA_PATH", os.environ.get("CUDA_HOME")),
4949
)
@@ -56,10 +56,10 @@ def _import_get_cuda_path_or_home():
5656
cuda.__path__ = list(cuda.__path__) + [sp_cuda]
5757
break
5858

59-
from cuda import pathfinder
59+
import cuda.pathfinder
6060

6161
return getattr(
62-
pathfinder,
62+
cuda.pathfinder,
6363
"get_cuda_path_or_home",
6464
lambda: os.environ.get("CUDA_PATH", os.environ.get("CUDA_HOME")),
6565
)

0 commit comments

Comments
 (0)