diff --git a/cuda_core/cuda/core/__init__.py b/cuda_core/cuda/core/__init__.py index 69caf1c0de..7a3ce9ceb8 100644 --- a/cuda_core/cuda/core/__init__.py +++ b/cuda_core/cuda/core/__init__.py @@ -4,29 +4,29 @@ from cuda.core._version import __version__ -try: + +def _import_versioned_module(): + import importlib + from cuda import bindings -except ImportError: - raise ImportError("cuda.bindings 12.x or 13.x must be installed") from None -else: - cuda_major, cuda_minor = bindings.__version__.split(".")[:2] + + cuda_major = bindings.__version__.split(".")[0] if cuda_major not in ("12", "13"): raise ImportError("cuda.bindings 12.x or 13.x must be installed") -import importlib + subdir = f"cu{cuda_major}" + try: + versioned_mod = importlib.import_module(f".{subdir}", __package__) + # Import all symbols from the module + globals().update(versioned_mod.__dict__) + except ImportError: + # This is not a wheel build, but a conda or local build, do nothing + pass + + +_import_versioned_module() +del _import_versioned_module -subdir = f"cu{cuda_major}" -try: - versioned_mod = importlib.import_module(f".{subdir}", __package__) - # Import all symbols from the module - globals().update(versioned_mod.__dict__) -except ImportError: - # This is not a wheel build, but a conda or local build, do nothing - pass -else: - del versioned_mod -finally: - del bindings, importlib, subdir, cuda_major, cuda_minor from cuda.core import system, utils from cuda.core._device import Device