diff --git a/python/cudf_polars/cudf_polars/__init__.py b/python/cudf_polars/cudf_polars/__init__.py index 41d06f8631b..b6b7e59fc22 100644 --- a/python/cudf_polars/cudf_polars/__init__.py +++ b/python/cudf_polars/cudf_polars/__init__.py @@ -10,9 +10,31 @@ from __future__ import annotations -from cudf_polars._version import __git_commit__, __version__ -from cudf_polars.callback import execute_with_cudf -from cudf_polars.dsl.translate import translate_ir + +# We want to avoid initialising the GPU on import. Unfortunately, +# while we still depend on cudf, the default mode is to check things. +# This ugly hack patches away the import-time calls in cudf that +# require initialising the GPU. +# TODO: Remove this when we only depend on a pylibcudf package. +def _patch_away_import_gpu_init(): + import sys + import types + + fake_mod = types.ModuleType("_numba") + fake_mod.__dict__["_setup_numba"] = lambda: None + fake_mod.__dict__["_CUDFNumbaConfig"] = lambda: None + fake_mod.__dict__["_get_ptx_file"] = lambda: None + fake_mod.__dict__["validate_setup"] = lambda: None + sys.modules["cudf.utils._numba"] = fake_mod + sys.modules["cudf.utils.gpu_utils"] = fake_mod + + +_patch_away_import_gpu_init() +del _patch_away_import_gpu_init + +from cudf_polars._version import __git_commit__, __version__ # noqa: E402 +from cudf_polars.callback import execute_with_cudf # noqa: E402 +from cudf_polars.dsl.translate import translate_ir # noqa: E402 __all__: list[str] = [ "execute_with_cudf",