From 560365cc3b06adb9cfb77e941c324f2da184f000 Mon Sep 17 00:00:00 2001 From: Alexander Watson Date: Tue, 31 Mar 2026 08:58:08 -0700 Subject: [PATCH] fix(sdk): gracefully handle missing proto stubs in __init__.py Wrap the sandbox import in try/except so subpackages like openshell.prover can be imported without a full Rust build. Removes the conftest.py namespace hack that was working around this. Signed-off-by: Alexander Watson --- python/conftest.py | 20 -------------------- python/openshell/__init__.py | 29 +++++++++++++++++------------ 2 files changed, 17 insertions(+), 32 deletions(-) delete mode 100644 python/conftest.py diff --git a/python/conftest.py b/python/conftest.py deleted file mode 100644 index 776624b0d..000000000 --- a/python/conftest.py +++ /dev/null @@ -1,20 +0,0 @@ -# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 - -"""Root conftest for Python tests. - -Pre-register openshell as a namespace package so subpackage tests (e.g., -the prover) can run without the full Rust build that generates proto stubs. -""" - -from __future__ import annotations - -import sys -import types -from pathlib import Path - -if "openshell" not in sys.modules: - _pkg = types.ModuleType("openshell") - _pkg.__path__ = [str(Path(__file__).resolve().parent / "openshell")] - _pkg.__package__ = "openshell" - sys.modules["openshell"] = _pkg diff --git a/python/openshell/__init__.py b/python/openshell/__init__.py index 27f8aaae9..7dbcd97f3 100644 --- a/python/openshell/__init__.py +++ b/python/openshell/__init__.py @@ -5,18 +5,23 @@ from __future__ import annotations -from .sandbox import ( - ClusterInferenceConfig, - ExecChunk, - ExecResult, - InferenceRouteClient, - Sandbox, - SandboxClient, - SandboxError, - SandboxRef, - SandboxSession, - TlsConfig, -) +try: + from .sandbox import ( + ClusterInferenceConfig, + ExecChunk, + ExecResult, + InferenceRouteClient, + Sandbox, + SandboxClient, + SandboxError, + SandboxRef, + SandboxSession, + TlsConfig, + ) +except ImportError: + # Proto stubs not yet generated (requires Rust build). + # Subpackages like openshell.prover can still be imported. + pass try: from importlib.metadata import version