Skip to content

Commit dd4c2a4

Browse files
Merge pull request #31 from bespokelabsai/codex/shared-bespokelabs-namespace
Fix shared namespace packaging for Sandbox
2 parents 6a158ae + c0e6f78 commit dd4c2a4

4 files changed

Lines changed: 59 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@ The only required core dependency is Pydantic; provider SDKs are optional.
4444
pip install bespokelabs-sandbox
4545
```
4646

47+
Sandbox can share an environment with Curator:
48+
49+
```bash
50+
python -m pip install bespokelabs-curator bespokelabs-sandbox
51+
```
52+
53+
```python
54+
from bespokelabs import curator, sandbox
55+
```
56+
57+
Each distribution owns its own subpackage. Sandbox installs only
58+
`bespokelabs/sandbox`; it does not install `bespokelabs/__init__.py`.
59+
The separate `bespokelabs` distribution is not needed for these imports.
60+
The Nimble SDK uses the `bespokelabs-nimble` distribution.
61+
62+
For upgrades from older releases that shared the root file, use a fresh virtual
63+
environment with namespace-compatible versions of all installed Bespoke packages.
64+
Use `python -m pip` with the interpreter used by your app or notebook, and check
65+
for old editable checkouts or a local `bespokelabs.py` if imports fail.
66+
4767
With a specific backend:
4868

4969
```bash

‎pyproject.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ bespokelabs-sandbox-api = "bespokelabs.sandbox.control_plane.cli:main"
5555

5656
[tool.setuptools.packages.find]
5757
where = ["src"]
58+
include = ["bespokelabs.sandbox*"]
59+
namespaces = true
5860

5961
[tool.setuptools.package-data]
6062
"bespokelabs.sandbox" = ["pricing.json"]

‎src/bespokelabs/__init__.py‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

‎tests/test_namespace.py‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Check that a source install can share its namespace with another project."""
2+
3+
import subprocess
4+
import sys
5+
from pathlib import Path
6+
7+
import pytest
8+
9+
10+
@pytest.mark.parametrize("source_first", [True, False])
11+
def test_separate_namespace_portions(tmp_path: Path, source_first: bool):
12+
source = Path(__file__).resolve().parents[1] / "src"
13+
sibling = tmp_path / "other-project"
14+
package = sibling / "bespokelabs" / "namespace_probe"
15+
package.mkdir(parents=True)
16+
(package / "__init__.py").write_text("VALUE = 42\n")
17+
paths = [str(source), str(sibling)]
18+
if not source_first:
19+
paths.reverse()
20+
expected = str(source / "bespokelabs/sandbox/__init__.py")
21+
code = f"""
22+
import sys
23+
from importlib.util import find_spec
24+
sys.path[:0] = {paths!r}
25+
from bespokelabs import namespace_probe
26+
import bespokelabs
27+
assert namespace_probe.VALUE == 42
28+
assert bespokelabs.__file__ is None
29+
assert find_spec('bespokelabs.sandbox').origin == {expected!r}
30+
"""
31+
# Disable site-packages so installed siblings cannot mask the source layout.
32+
subprocess.run(
33+
[sys.executable, "-I", "-S", "-c", code],
34+
check=True,
35+
capture_output=True,
36+
text=True,
37+
)

0 commit comments

Comments
 (0)