From 633189ecaf26639435c92116fa7a3a6addbfbc1a Mon Sep 17 00:00:00 2001 From: andrewwhitecdw Date: Wed, 12 Aug 2026 15:01:33 -0500 Subject: [PATCH] fix: tilecpp exported unconditionally despite conditional import Signed-off-by: andrewwhitecdw --- src/tilegym/ops/__init__.py | 16 +++++++++++++--- tests/test_ops_init.py | 11 +++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 tests/test_ops_init.py diff --git a/src/tilegym/ops/__init__.py b/src/tilegym/ops/__init__.py index 83df0a4a..3be26f73 100644 --- a/src/tilegym/ops/__init__.py +++ b/src/tilegym/ops/__init__.py @@ -35,8 +35,17 @@ triton = None # type: ignore # Import CUDA Tile C++ backend if available +tilecpp = None # type: ignore if is_backend_available("tilecpp"): - from . import tilecpp + try: + from . import tilecpp + except (ImportError, RuntimeError): + import warnings + + warnings.warn( + "tilecpp backend import failed, tilecpp operations will not be available" + ) + tilecpp = None # type: ignore # Re-export key interfaces from .attn_interface import attention_sink_interface @@ -54,7 +63,6 @@ __all__ = [ # Export all operations from ops module # Backend implementations - "tilecpp", # Interface modules "attn_interface", "moe_interface", @@ -70,6 +78,8 @@ "fused_moe", ] -# Add cutile to exports only if successfully imported +# Add backend submodules to exports only if successfully imported if cutile is not None: __all__.append("cutile") +if tilecpp is not None: + __all__.append("tilecpp") diff --git a/tests/test_ops_init.py b/tests/test_ops_init.py new file mode 100644 index 00000000..dfd3a9f4 --- /dev/null +++ b/tests/test_ops_init.py @@ -0,0 +1,11 @@ +"""Tests for the tilegym.ops package init.""" + + +def test_tilecpp_not_exported_when_unavailable(): + """If tilecpp is not imported, it must not appear in __all__.""" + import tilegym.ops as ops + + if not hasattr(ops, "tilecpp") or ops.tilecpp is None: + assert "tilecpp" not in ops.__all__ + +