Skip to content

Commit bb17196

Browse files
committed
build: fetch the protos with buf export
proto:fetch exports openshell.proto and credential_driver.proto from core at OPENSHELL_CORE_REF, and buf adds their imports, the same way sdk-go reads the protos through a buf git input. The generator compiles whatever proto/ holds instead of keeping its own file list. grpcio-tools still generates the bindings, and they are unchanged. fetch-core.sh is now only for the vendored conformance fixtures. Signed-off-by: Piotr Mlocek <pmlocek@nvidia.com>
1 parent bd4a957 commit bb17196

4 files changed

Lines changed: 26 additions & 14 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ mise run core:version
3030

3131
The bindings are generated from `proto/` in NVIDIA/OpenShell at the ref in
3232
`OPENSHELL_CORE_REF` (`mise.toml`, currently `v0.1.7`) and committed under
33-
`src/openshell/_proto`:
33+
`src/openshell/_proto`. `buf export` fetches the protos, the same way sdk-go
34+
reads them, and `grpcio-tools` generates the bindings:
3435

3536
- Building a wheel or sdist needs neither a core checkout nor network access.
3637
- A change of the pin shows the effect on the generated API in its diff.

‎mise.toml‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ min_version = { soft = "2026.9.9" }
1010

1111
[tools]
1212
python = "3.14.5"
13+
buf = "1.72.0"
1314
uv = "0.10.12"
1415

1516
[env]
@@ -29,8 +30,16 @@ description = "Install the SDK and its development dependencies"
2930
run = "uv sync --frozen --group dev"
3031

3132
[tasks."proto:fetch"]
32-
description = "Fetch core's proto/ at the pinned ref into proto/"
33-
run = "scripts/fetch-core.sh $OPENSHELL_CORE_REF . proto"
33+
description = "Export the SDK's protos from core at the pinned ref into proto/"
34+
# buf follows the imports of the two root files, so proto/ holds exactly the
35+
# files the SDK compiles.
36+
run = """
37+
#!/usr/bin/env bash
38+
set -euo pipefail
39+
rm -rf proto
40+
buf export "https://github.com/NVIDIA/OpenShell.git#ref=${OPENSHELL_CORE_REF},depth=1,subdir=proto" \
41+
--path openshell.proto --path credential_driver.proto --output proto
42+
"""
3443
sources = ["mise.toml"]
3544
outputs = ["proto/openshell.proto"]
3645

‎scripts/fetch-core.sh‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
# fetch-core.sh: copy files from NVIDIA/OpenShell at a pinned ref.
66
#
7+
# The protos come from `buf export` (mise run proto:fetch); this script fetches
8+
# the other core files the repository checks against, such as the vendored
9+
# conformance fixtures.
10+
#
711
# Usage: fetch-core.sh <ref> <out-dir> <core-path>...
812
#
913
# Fetches only <ref> (a tag or a full commit SHA), without history or unneeded

‎scripts/generate_python_proto.py‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,9 @@
99
import sys
1010
from pathlib import Path
1111

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-
]
12+
# `mise run proto:fetch` exports exactly the SDK's protos (two roots and their
13+
# imports) into proto/, so every file there is compiled.
14+
PROTO_DIR = Path("proto")
2015

2116

2217
def main() -> None:
@@ -31,6 +26,9 @@ def main() -> None:
3126
)
3227
args = parser.parse_args()
3328
output_dir = Path("src/openshell/_proto")
29+
proto_files = sorted(str(path) for path in PROTO_DIR.glob("*.proto"))
30+
if not proto_files:
31+
sys.exit(f"no .proto files in {PROTO_DIR}/; run `mise run proto:fetch`")
3432

3533
subprocess.run(
3634
[
@@ -48,19 +46,19 @@ def main() -> None:
4846
]
4947
),
5048
"--grpc_python_out=src/openshell/_proto",
51-
*PROTO_FILES,
49+
*proto_files,
5250
],
5351
check=True,
5452
)
5553

5654
# Rewrite only imports of our generated modules, leaving google.protobuf
5755
# 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)
56+
modules = "|".join(re.escape(f"{Path(path).stem}_pb2") for path in proto_files)
5957
pattern = rf"^import ({modules})( as \w+)?$"
6058
suffixes = ["_pb2.py", "_pb2_grpc.py"]
6159
if not args.no_pyi:
6260
suffixes.extend(["_pb2.pyi", "_pb2_grpc.pyi"])
63-
for proto in PROTO_FILES:
61+
for proto in proto_files:
6462
for suffix in suffixes:
6563
file_path = output_dir / f"{Path(proto).stem}{suffix}"
6664
text = file_path.read_text()

0 commit comments

Comments
 (0)