Skip to content

Commit 36ee06f

Browse files
fix(rpm): build the Python SDK from older protoc and install every SDK module (#4439)
* fix(python): let proto stub generation skip .pyi for older protoc Add a --no-pyi option to generate_python_proto.py for toolchains whose protoc predates --pyi_out, such as Fedora's grpcio-tools 1.48, and list python3-googleapis-common-protos and python3-httpx in the spec's Recommends and dist-info Requires-Dist, which the SDK needs to import. Default behavior is unchanged. Contributes to #3510. Signed-off-by: politerealism <burdcat17@gmail.com> * fix(rpm): install every SDK module and record the license accounting The python3-openshell %install copied only __init__.py, sandbox.py and _proto/, but the package imports .errors, .mutations and .providers and ships a py.typed marker, so an installed RPM could not import openshell. Install the missing files and add a %check that fails if any relative import in the installed package has no matching installed module. Importing the package needs grpcio, which the build environment lacks, so the check is static. Set License to the minimal SPDX expression covering every crate linked into the shipped binaries, keep the pure-Python subpackage at Apache-2.0, and note how the non-crate content is covered. Signed-off-by: politerealism <burdcat17@gmail.com> --------- Signed-off-by: politerealism <burdcat17@gmail.com>
1 parent 4d9a1d2 commit 36ee06f

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

‎openshell.spec‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ Version: %{openshell_version}
1717
Release: 1.20260518180028805757.podman.toml.gateway.listener.11.g8c0cb7c8%{?dist}
1818
Summary: Safe, sandboxed runtimes for autonomous AI agents
1919

20-
License: Apache-2.0
20+
# OpenShell's own code is Apache-2.0. The binaries statically link third-party
21+
# crates; this is the minimal SPDX expression covering every crate linked into
22+
# openshell, openshell-gateway and openshell-prover (computed from `cargo tree`
23+
# license metadata, treating "X OR MIT" as satisfied by MIT or Apache-2.0).
24+
# The docs, man page sources, config templates and Python SDK sources carry
25+
# Apache-2.0 SPDX headers or fall under the repository LICENSE. The unit file is
26+
# generated from this spec. Re-check when Cargo.lock changes.
27+
License: Apache-2.0 AND BSD-3-Clause AND CC0-1.0 AND CDLA-Permissive-2.0 AND ISC AND MIT AND Unicode-3.0 AND Zlib
2128
URL: https://github.com/NVIDIA/OpenShell
2229
Source0: openshell-%{openshell_version}.tar.gz
2330
Source1: openshell-%{openshell_version}-vendor.tar.xz
@@ -69,11 +76,15 @@ within an operator-supplied maximum without connecting to a gateway.
6976
# --- Python SDK sub-package ---
7077
%package -n python3-%{name}
7178
Summary: OpenShell Python SDK for agent execution and management
79+
# Pure Python; links none of the crates covered by the main License tag.
80+
License: Apache-2.0
7281
# Use Recommends instead of Requires because Fedora 43+ ships older
7382
# versions of grpcio (1.48) and protobuf (3.19) than the SDK needs.
7483
# Users on distros with older packages can install these via pip/uv.
7584
Recommends: python3-cloudpickle >= 3.0
85+
Recommends: python3-googleapis-common-protos >= 1.63
7686
Recommends: python3-grpcio >= 1.60
87+
Recommends: python3-httpx >= 0.27
7788
Recommends: python3-protobuf >= 4.25
7889
Recommends: %{name}
7990

@@ -193,7 +204,11 @@ install -d %{buildroot}%{python3_sitelib}/%{name}
193204
install -d %{buildroot}%{python3_sitelib}/%{name}/_proto
194205

195206
install -pm 0644 python/%{name}/__init__.py %{buildroot}%{python3_sitelib}/%{name}/
207+
install -pm 0644 python/%{name}/errors.py %{buildroot}%{python3_sitelib}/%{name}/
208+
install -pm 0644 python/%{name}/mutations.py %{buildroot}%{python3_sitelib}/%{name}/
209+
install -pm 0644 python/%{name}/providers.py %{buildroot}%{python3_sitelib}/%{name}/
196210
install -pm 0644 python/%{name}/sandbox.py %{buildroot}%{python3_sitelib}/%{name}/
211+
install -pm 0644 python/%{name}/py.typed %{buildroot}%{python3_sitelib}/%{name}/
197212
install -pm 0644 python/%{name}/_proto/__init__.py %{buildroot}%{python3_sitelib}/%{name}/_proto/
198213
install -pm 0644 python/%{name}/_proto/*.py %{buildroot}%{python3_sitelib}/%{name}/_proto/
199214

@@ -207,7 +222,9 @@ Summary: OpenShell Python SDK for agent execution and management
207222
License: Apache-2.0
208223
Requires-Python: >=3.12
209224
Requires-Dist: cloudpickle>=3.0
225+
Requires-Dist: googleapis-common-protos>=1.63
210226
Requires-Dist: grpcio>=1.60
227+
Requires-Dist: httpx>=0.27
211228
Requires-Dist: protobuf>=4.25
212229
EOF
213230

@@ -233,6 +250,22 @@ touch %{buildroot}%{python3_sitelib}/%{name}-%{openshell_python_version}.dist-in
233250
# build environment.
234251
PYTHONPATH=%{buildroot}%{python3_sitelib} %{python3} -c "from importlib.metadata import version; v = version('openshell'); print(v); assert v == '%{openshell_python_version}', f'expected %{openshell_python_version}, got {v}'"
235252

253+
# Verify every module the installed SDK pulls in with a relative import was
254+
# installed. Importing the package needs grpcio, which the build environment
255+
# does not have, so check the imports statically.
256+
%{python3} - %{buildroot}%{python3_sitelib}/%{name} <<'PY'
257+
import ast, pathlib, sys
258+
pkg = pathlib.Path(sys.argv[1])
259+
missing = []
260+
for source in pkg.glob("*.py"):
261+
for node in ast.walk(ast.parse(source.read_text())):
262+
if isinstance(node, ast.ImportFrom) and node.level == 1 and node.module:
263+
base = pkg.joinpath(*node.module.split("."))
264+
if not (base.with_suffix(".py").exists() or (base / "__init__.py").exists()):
265+
missing.append(f"{source.name}: .{node.module}")
266+
assert not missing, f"installed SDK imports modules that were not installed: {missing}"
267+
PY
268+
236269
# Verify the RPM default TOML config template was installed.
237270
# A missing template means first-start seeding silently falls back to the
238271
# binary default of 127.0.0.1, which breaks Podman sandbox connectivity.

‎tasks/scripts/generate_python_proto.py‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
"""Generate Python protobuf stubs and make their imports package-relative."""
55

6+
import argparse
67
import re
78
import subprocess
89
import sys
@@ -72,14 +73,25 @@
7273

7374

7475
def main() -> None:
76+
parser = argparse.ArgumentParser(description=__doc__)
77+
parser.add_argument(
78+
"--no-pyi",
79+
action="store_true",
80+
help=(
81+
"Skip .pyi type stubs. Needed with protoc older than 3.20 "
82+
"(e.g. Fedora's grpcio-tools 1.48), which has no --pyi_out."
83+
),
84+
)
85+
args = parser.parse_args()
86+
7587
subprocess.run(
7688
[
7789
sys.executable,
7890
"-m",
7991
"grpc_tools.protoc",
8092
"-Iproto",
8193
"--python_out=python/openshell/_proto",
82-
"--pyi_out=python/openshell/_proto",
94+
*([] if args.no_pyi else ["--pyi_out=python/openshell/_proto"]),
8395
"--grpc_python_out=python/openshell/_proto",
8496
*PROTO_FILES,
8597
],

0 commit comments

Comments
 (0)