Skip to content

Commit dd0bf72

Browse files
committed
chore: import the Python SDK history from NVIDIA/OpenShell
Filtered from NVIDIA/OpenShell at v0.1.7 (5d25211b25a8fc887e8d5c606d57d6ab22f1d76c) with git filter-repo --paths-from-file. The tip tree 5619e0c equals the SDK paths at that commit mapped to src/, tests/, and scripts/. 76 commits from 24 authors, with bare #N references rewritten to NVIDIA/OpenShell#N. Signed-off-by: Piotr Mlocek <pmlocek@nvidia.com>
2 parents 7f2b1cb + b85ecc4 commit dd0bf72

20 files changed

Lines changed: 7754 additions & 0 deletions

‎pyproject.toml‎

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
[build-system]
5+
requires = ["setuptools>=84.1.0", "setuptools-scm[simple]>=8"]
6+
build-backend = "setuptools.build_meta"
7+
8+
[project]
9+
name = "openshell"
10+
dynamic = ["version"]
11+
description = "OpenShell is the safe, private runtime for autonomous AI agents. "
12+
license = "Apache-2.0"
13+
readme = "README.md"
14+
authors = [{ name = "NVIDIA Inc." }]
15+
requires-python = ">=3.11"
16+
dependencies = [
17+
"cloudpickle>=3.0",
18+
"grpcio>=1.60",
19+
"googleapis-common-protos>=1.63",
20+
"httpx>=0.27",
21+
"protobuf>=4.25",
22+
]
23+
classifiers = [
24+
"Development Status :: 3 - Alpha",
25+
"Intended Audience :: Developers",
26+
"Intended Audience :: Science/Research",
27+
"Intended Audience :: Information Technology",
28+
"Programming Language :: Python :: 3",
29+
"Programming Language :: Python :: 3.11",
30+
"Programming Language :: Python :: 3.12",
31+
"Programming Language :: Python :: 3.13",
32+
"Programming Language :: Python :: 3.14",
33+
"Topic :: Security",
34+
"Topic :: Scientific/Engineering",
35+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
36+
"Operating System :: POSIX :: Linux",
37+
"Operating System :: MacOS :: MacOS X",
38+
]
39+
keywords = ["agent", "sandbox", "nvidia"]
40+
41+
[project.urls]
42+
source = "https://github.com/NVIDIA/OpenShell"
43+
documentation = "https://docs.nvidia.com/openshell/latest/"
44+
45+
[dependency-groups]
46+
dev = [
47+
"pytest>=9.0.3",
48+
"pytest-asyncio>=0.23",
49+
"pytest-cov>=4.0",
50+
"pytest-xdist>=3.0",
51+
"ruff>=0.4",
52+
"ty>=0.0.94",
53+
"grpcio-tools>=1.60",
54+
"pyelftools>=0.30",
55+
"pyyaml==6.0.2",
56+
"types-pyyaml>=6.0.12.20260518",
57+
"mypy-protobuf>=5.1",
58+
"types-grpcio>=1.0.0.20251009",
59+
"types-protobuf>=6.32,<7",
60+
]
61+
62+
[tool.setuptools]
63+
package-dir = { "" = "python" }
64+
include-package-data = false
65+
66+
[tool.setuptools.packages.find]
67+
where = ["python"]
68+
include = ["openshell*"]
69+
namespaces = false
70+
71+
[tool.setuptools.package-data]
72+
openshell = ["py.typed", "_proto/*.py", "_proto/*.pyi"]
73+
74+
# Ignore non-release tags such as sdk/go/vX.Y.Z, which share the release commit.
75+
[tool.setuptools_scm]
76+
git_describe_command = ["git", "describe", "--dirty", "--tags", "--long", "--match", "v[0-9]*"]
77+
78+
[tool.ruff]
79+
target-version = "py311"
80+
line-length = 88
81+
exclude = ["python/openshell/_proto"]
82+
83+
[tool.ruff.lint]
84+
select = [
85+
"E", # pycodestyle errors
86+
"W", # pycodestyle warnings
87+
"F", # Pyflakes
88+
"I", # isort
89+
"B", # flake8-bugbear
90+
"C4", # flake8-comprehensions
91+
"UP", # pyupgrade
92+
"ARG", # flake8-unused-arguments
93+
"SIM", # flake8-simplify
94+
"TCH", # flake8-type-checking
95+
"PTH", # flake8-use-pathlib
96+
"RUF", # Ruff-specific rules
97+
]
98+
ignore = [
99+
"E501", # line too long (handled by formatter)
100+
]
101+
102+
[tool.ruff.lint.isort]
103+
known-first-party = ["openshell"]
104+
105+
[tool.ruff.format]
106+
quote-style = "double"
107+
indent-style = "space"
108+
skip-magic-trailing-comma = false
109+
line-ending = "auto"
110+
111+
[tool.pytest.ini_options]
112+
testpaths = ["python"]
113+
python_files = ["*_test.py"]
114+
python_functions = ["test_*"]
115+
addopts = "-v --tb=short"
116+
asyncio_mode = "auto"
117+
markers = [
118+
"gpu: requires a GPU-capable gateway and GPU-enabled sandbox image",
119+
]
120+
121+
[tool.coverage.run]
122+
source = ["python"]
123+
branch = true
124+
125+
[tool.coverage.report]
126+
exclude_lines = [
127+
"pragma: no cover",
128+
"def __repr__",
129+
"raise NotImplementedError",
130+
"if TYPE_CHECKING:",
131+
]

‎scripts/generate_python_proto.py‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""Generate Python protobuf stubs and make their imports package-relative."""
5+
6+
import argparse
7+
import re
8+
import subprocess
9+
import sys
10+
from pathlib import Path
11+
12+
PROTO_FILES = [
13+
"proto/openshell.proto",
14+
"proto/datamodel.proto",
15+
"proto/options.proto",
16+
"proto/sandbox.proto",
17+
"proto/extension.proto",
18+
"proto/credential_driver.proto",
19+
]
20+
21+
22+
def main() -> None:
23+
parser = argparse.ArgumentParser(description=__doc__)
24+
parser.add_argument(
25+
"--no-pyi",
26+
action="store_true",
27+
help=(
28+
"Skip .pyi type stubs. Needed with protoc older than 3.20 "
29+
"(e.g. Fedora's grpcio-tools 1.48), which has no --pyi_out."
30+
),
31+
)
32+
args = parser.parse_args()
33+
output_dir = Path("python/openshell/_proto")
34+
35+
subprocess.run(
36+
[
37+
sys.executable,
38+
"-m",
39+
"grpc_tools.protoc",
40+
"-Iproto",
41+
"--python_out=python/openshell/_proto",
42+
*(
43+
[]
44+
if args.no_pyi
45+
else [
46+
"--pyi_out=python/openshell/_proto",
47+
"--mypy_grpc_out=generate_concrete_servicer_stubs:python/openshell/_proto",
48+
]
49+
),
50+
"--grpc_python_out=python/openshell/_proto",
51+
*PROTO_FILES,
52+
],
53+
check=True,
54+
)
55+
56+
# Rewrite only imports of our generated modules, leaving google.protobuf
57+
# imports intact. The same rule covers runtime modules and type stubs.
58+
modules = "|".join(re.escape(f"{Path(path).stem}_pb2") for path in PROTO_FILES)
59+
pattern = rf"^import ({modules})( as \w+)?$"
60+
suffixes = ["_pb2.py", "_pb2_grpc.py"]
61+
if not args.no_pyi:
62+
suffixes.extend(["_pb2.pyi", "_pb2_grpc.pyi"])
63+
for proto in PROTO_FILES:
64+
for suffix in suffixes:
65+
file_path = output_dir / f"{Path(proto).stem}{suffix}"
66+
text = file_path.read_text()
67+
text = re.sub(pattern, r"from . import \1\2", text, flags=re.MULTILINE)
68+
file_path.write_text(text)
69+
70+
71+
if __name__ == "__main__":
72+
main()

‎scripts/verify-python-wheel.py‎

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#!/usr/bin/env python3
2+
3+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
from __future__ import annotations
7+
8+
import argparse
9+
import sys
10+
from configparser import ConfigParser
11+
from configparser import Error as ConfigParserError
12+
from email.parser import Parser
13+
from pathlib import Path
14+
from zipfile import BadZipFile, ZipFile
15+
16+
PROTO_STEMS = (
17+
"credential_driver",
18+
"datamodel",
19+
"extension",
20+
"openshell",
21+
"options",
22+
"sandbox",
23+
)
24+
BYTECODE_SUFFIXES = (".pyc", ".pyo")
25+
NATIVE_SUFFIXES = (".dll", ".dylib", ".exe", ".pyd", ".so")
26+
27+
28+
def _find_wheel(path: Path) -> Path:
29+
if path.is_file():
30+
return path
31+
32+
wheels = sorted(path.glob("*.whl"))
33+
if len(wheels) != 1:
34+
raise ValueError(f"expected exactly one wheel in {path}, found {len(wheels)}")
35+
return wheels[0]
36+
37+
38+
def _required_files() -> set[str]:
39+
files = {
40+
"openshell/__init__.py",
41+
"openshell/sandbox.py",
42+
"openshell/py.typed",
43+
"openshell/_proto/__init__.py",
44+
}
45+
for stem in PROTO_STEMS:
46+
files.add(f"openshell/_proto/{stem}_pb2.py")
47+
files.add(f"openshell/_proto/{stem}_pb2.pyi")
48+
files.add(f"openshell/_proto/{stem}_pb2_grpc.py")
49+
files.add(f"openshell/_proto/{stem}_pb2_grpc.pyi")
50+
return files
51+
52+
53+
def _single_member(names: set[str], suffix: str) -> str:
54+
matches = [name for name in names if name.endswith(suffix)]
55+
if len(matches) != 1:
56+
raise ValueError(f"expected exactly one {suffix} file, found {len(matches)}")
57+
return matches[0]
58+
59+
60+
def verify_wheel(path: Path, expected_version: str | None = None) -> Path:
61+
wheel = _find_wheel(path)
62+
if not wheel.name.endswith("-py3-none-any.whl"):
63+
raise ValueError(f"wheel is not platform-independent: {wheel.name}")
64+
65+
with ZipFile(wheel) as archive:
66+
names = set(archive.namelist())
67+
missing = sorted(_required_files() - names)
68+
if missing:
69+
raise ValueError(f"wheel is missing required files: {', '.join(missing)}")
70+
71+
scripts = sorted(
72+
name
73+
for name in names
74+
if not name.endswith("/")
75+
and Path(name).name in {"openshell", "openshell.exe"}
76+
)
77+
if scripts:
78+
raise ValueError(
79+
f"wheel contains an openshell executable: {', '.join(scripts)}"
80+
)
81+
82+
entry_points = [
83+
name for name in names if name.endswith(".dist-info/entry_points.txt")
84+
]
85+
if len(entry_points) > 1:
86+
raise ValueError(
87+
f"expected at most one entry_points.txt file, found {len(entry_points)}"
88+
)
89+
if entry_points:
90+
parser = ConfigParser(interpolation=None)
91+
try:
92+
parser.read_string(archive.read(entry_points[0]).decode())
93+
except (ConfigParserError, UnicodeDecodeError) as error:
94+
raise ValueError(
95+
"wheel contains invalid entry point metadata"
96+
) from error
97+
if parser.has_option("console_scripts", "openshell"):
98+
raise ValueError("wheel defines an openshell console script")
99+
100+
bytecode_files = sorted(
101+
name for name in names if name.endswith(BYTECODE_SUFFIXES)
102+
)
103+
if bytecode_files:
104+
raise ValueError(
105+
f"wheel contains Python bytecode: {', '.join(bytecode_files)}"
106+
)
107+
108+
native_files = sorted(name for name in names if name.endswith(NATIVE_SUFFIXES))
109+
if native_files:
110+
raise ValueError(f"wheel contains native files: {', '.join(native_files)}")
111+
112+
metadata_name = _single_member(names, ".dist-info/METADATA")
113+
metadata = Parser().parsestr(archive.read(metadata_name).decode())
114+
if metadata["Name"] != "openshell":
115+
raise ValueError(f"unexpected distribution name: {metadata['Name']}")
116+
117+
version = metadata["Version"]
118+
filename_version = wheel.name.removesuffix("-py3-none-any.whl").removeprefix(
119+
"openshell-"
120+
)
121+
if version != filename_version:
122+
raise ValueError(
123+
f"wheel filename version {filename_version} does not match metadata {version}"
124+
)
125+
if expected_version is not None and version != expected_version:
126+
raise ValueError(f"expected version {expected_version}, found {version}")
127+
128+
wheel_name = _single_member(names, ".dist-info/WHEEL")
129+
wheel_metadata = Parser().parsestr(archive.read(wheel_name).decode())
130+
if wheel_metadata.get_all("Tag", []) != ["py3-none-any"]:
131+
raise ValueError(
132+
f"unexpected wheel tags: {wheel_metadata.get_all('Tag', [])}"
133+
)
134+
if wheel_metadata["Root-Is-Purelib"] != "true":
135+
raise ValueError("wheel is not marked as pure Python")
136+
137+
return wheel
138+
139+
140+
def main() -> int:
141+
parser = argparse.ArgumentParser(description="Verify the OpenShell Python wheel")
142+
parser.add_argument(
143+
"path", type=Path, help="Wheel file or directory containing one wheel"
144+
)
145+
parser.add_argument("--expected-version")
146+
args = parser.parse_args()
147+
148+
try:
149+
wheel = verify_wheel(args.path, args.expected_version)
150+
except (BadZipFile, OSError, ValueError) as error:
151+
print(f"ERROR: {error}", file=sys.stderr)
152+
return 1
153+
154+
print(f"Verified {wheel}")
155+
return 0
156+
157+
158+
if __name__ == "__main__":
159+
raise SystemExit(main())

0 commit comments

Comments
 (0)