#!/usr/bin/env bash # Regenerate type stubs from the built extension. # # Must run where the OCCT shared libraries resolve (inside the builder image, # pre-auditwheel), since stubgen imports the module to introspect it. Shipping # these plus py.typed is what retires the backend's blanket # `unresolved-import = "ignore"` ty suppression. set -euo pipefail cd /io . scripts/_env.sh SO=$(find "$CACHE/skbuild" -name '_OCP*.so' 2>/dev/null | head -1) if [ -z "$SO" ]; then echo "no built extension found; run the wheel build first" >&2 exit 1 fi # Stage the package tree next to the freshly built extension so stubgen can # import it without touching the repo copy. STAGE=$(mktemp -d) trap 'rm -rf "$STAGE"' EXIT cp -r python/OCP python/n3xd_ocp "$STAGE/" cp "$SO" "$STAGE/OCP/" # -O keeps each package's stubs inside its own directory: recursive # stubgen names files after the submodule alone, so a shared output dir would # flatten OCP.gp and n3xd_ocp.bintools into the same namespace. (cd "$STAGE" && "$PY" -m nanobind.stubgen -m OCP -r -O OCP && \ "$PY" -m nanobind.stubgen -m n3xd_ocp -r -O n3xd_ocp) find "$STAGE" -name '*.pyi' | while read -r f; do rel="${f#"$STAGE"/}" mkdir -p "python/$(dirname "$rel")" cp "$f" "python/$rel" done echo "stubs written:" find python -name '*.pyi' | sort