Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/sdk-python. Official Python SDK for openstatus
Something went wrong. Try again.
3.7 kB · 86 lines
Shell
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687#!/usr/bin/env bashset -euo pipefail
# Recorded in $DEST/VERSION only — the archive itself is fetched by the `main`# label, since the archive URL uses a plugin-version coordinate that cannot be# reconstructed from the commit alone.SCHEMA_COMMIT="${1:?usage: regen.sh <schema-commit>}"
# Transitive deps. Buf does not expose pinned versions for these from the# openstatus/api module, so we track main. The PHP plan ships empty initOnce()# stubs for these; in Python we vendor the real generated modules — they are# pure annotation/descriptor protos with no runtime impact on JSON transport.readonly BUF_VALIDATE_REF="bufbuild/protovalidate"readonly GNOSTIC_REF="gnostic/gnostic"
ARCHIVE_BASE="https://buf.build/gen/archive"ROOT="$(cd "$(dirname "$0")/.." && pwd)"DEST="${ROOT}/src/openstatus/_gen"TMP="$(mktemp -d)"trap 'rm -rf "$TMP"' EXIT
rm -rf "$DEST"mkdir -p "$DEST"
fetch() { # fetch <buf-ref> <plugin> <pinned-or-main> <local-name> local ref="$1" plugin="$2" version="$3" name="$4" local url="${ARCHIVE_BASE}/${ref}/protocolbuffers/${plugin}/${version}.zip" echo "Fetching ${ref} ${plugin} ${version}..." curl -fsSL -L "$url" -o "${TMP}/${name}-${plugin}.zip" mkdir -p "${TMP}/${name}-${plugin}" unzip -q "${TMP}/${name}-${plugin}.zip" -d "${TMP}/${name}-${plugin}"}
fetch "openstatus/api" python main openstatusfetch "openstatus/api" pyi main openstatusfetch "${BUF_VALIDATE_REF}" python main bufvalidatefetch "${BUF_VALIDATE_REF}" pyi main bufvalidatefetch "${GNOSTIC_REF}" python main gnosticfetch "${GNOSTIC_REF}" pyi main gnostic
# Merge a top-level package from a buf archive into $DEST.# - archive layout: <archive>/<plugin-prefix>_<lang>/<pkg-root>/...# e.g. openstatus-python/api_python/openstatus, bufvalidate-python/protovalidate_python/bufmerge() { local archive_dir="$1" pkg_root="$2" local src src="$(find "${TMP}/${archive_dir}" -type d -name "${pkg_root}" -maxdepth 3 | head -1)" if [[ -z "$src" ]]; then echo "ERROR: could not locate '${pkg_root}' tree inside ${archive_dir}" >&2 find "${TMP}/${archive_dir}" -maxdepth 3 -type d >&2 exit 1 fi # tar pipe preserves dir merges (rsync-style) without depending on rsync. ( cd "$(dirname "$src")" && tar cf - "$(basename "$src")" ) | ( cd "$DEST" && tar xf - )}
merge openstatus-python openstatusmerge openstatus-pyi openstatusmerge bufvalidate-python bufmerge bufvalidate-pyi bufmerge gnostic-python gnosticmerge gnostic-pyi gnostic
# The generated *.py and *.pyi files use absolute imports# (`from openstatus...`, `from buf...`, `from gnostic...`). Rewrite them to# resolve under our private `openstatus._gen.*` namespace so the public# `openstatus` package is not polluted and so the buf/gnostic vendored copies# do not collide with any user-installed packages of the same name.find "$DEST" -type f \( -name '*.py' -o -name '*.pyi' \) -print0 \ | xargs -0 sed -i \ -e 's|^from openstatus\.|from openstatus._gen.openstatus.|g' \ -e 's|^from buf\.|from openstatus._gen.buf.|g' \ -e 's|^from gnostic\.|from openstatus._gen.gnostic.|g' \ -e 's|^import openstatus\.|import openstatus._gen.openstatus.|g' \ -e 's|^import buf\.|import openstatus._gen.buf.|g' \ -e 's|^import gnostic\.|import openstatus._gen.gnostic.|g'
# Generated trees ship no __init__.py — create empty shims so packages import.find "$DEST" -type d -exec sh -c 'touch "$0/__init__.py"' {} \;
echo "${SCHEMA_COMMIT}" > "$DEST/VERSION"
echoecho "Done. Generated tree at $DEST"echo "Schema commit recorded at $DEST/VERSION"