Skip to content

Commit 6927cfe

Browse files
committed
lazy import fix
1 parent 9da73e3 commit 6927cfe

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

cuda_bindings/tests/helpers.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222
import cuda_python_test_helpers
2323
except ImportError:
2424
# Import shared platform helpers for tests across repos
25-
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2] / "cuda_python_test_helpers"))
26-
import cuda_python_test_helpers
27-
28-
# If we imported the package instead of the module, get the actual module
29-
if hasattr(cuda_python_test_helpers, "__path__"):
30-
# We imported the package, need to get the actual module
31-
import cuda_python_test_helpers.cuda_python_test_helpers as cuda_python_test_helpers
25+
test_helpers_path = str(pathlib.Path(__file__).resolve().parents[2] / "cuda_python_test_helpers")
26+
try:
27+
sys.path.insert(0, test_helpers_path)
28+
import cuda_python_test_helpers
29+
finally:
30+
# Clean up sys.path modification
31+
if test_helpers_path in sys.path:
32+
sys.path.remove(test_helpers_path)
3233

3334

3435
IS_WSL = cuda_python_test_helpers.IS_WSL

cuda_core/tests/helpers.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@
2222
import cuda_python_test_helpers
2323
except ImportError:
2424
# Import shared platform helpers for tests across repos
25-
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2] / "cuda_python_test_helpers"))
26-
import cuda_python_test_helpers
25+
test_helpers_path = str(pathlib.Path(__file__).resolve().parents[2] / "cuda_python_test_helpers")
26+
try:
27+
sys.path.insert(0, test_helpers_path)
28+
import cuda_python_test_helpers
29+
finally:
30+
# Clean up sys.path modification
31+
if test_helpers_path in sys.path:
32+
sys.path.remove(test_helpers_path)
2733

2834

2935
IS_WSL = cuda_python_test_helpers.IS_WSL

cuda_python_test_helpers/cuda_python_test_helpers/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from contextlib import suppress
77
from typing import Union
88

9-
from cuda.core.experimental._utils.cuda_utils import handle_return
10-
119

1210
def _detect_wsl() -> bool:
1311
data = ""
@@ -39,6 +37,9 @@ def supports_ipc_mempool(device_id: Union[int, object]) -> bool:
3937
except Exception:
4038
from cuda import cuda as driver # type: ignore
4139

40+
# Lazy import handle_return to avoid hard dependency on cuda.core
41+
from cuda.core.experimental._utils.cuda_utils import handle_return
42+
4243
# Initialize CUDA
4344
handle_return(driver.cuInit(0))
4445

0 commit comments

Comments
 (0)