Skip to content

Commit bd6d708

Browse files
committed
Rewrite opamp_proto_codegen.sh to use uv
1 parent 434b0fd commit bd6d708

1 file changed

Lines changed: 8 additions & 15 deletions

File tree

scripts/opamp_proto_codegen.sh

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,17 @@ set -e
3232
OPAMP_SPEC_REPO_DIR=${OPAMP_SPEC_REPO_DIR:-"/tmp/opamp-spec"}
3333
# root of opentelemetry-python repo
3434
repo_root="$(git rev-parse --show-toplevel)"
35-
venv_dir="/tmp/opamp_proto_codegen_venv"
3635
proto_output_dir="$repo_root/opamp/opentelemetry-opamp-client/src/opentelemetry/_opamp/proto"
3736

38-
# run on exit even if crash
39-
cleanup() {
40-
echo "Deleting $venv_dir"
41-
rm -rf $venv_dir
37+
protoc() {
38+
uvx -c $repo_root/opamp-gen-requirements.txt \
39+
--python 3.12 \
40+
--from grpcio-tools \
41+
--with mypy-protobuf \
42+
python -m grpc_tools.protoc "$@"
4243
}
43-
trap cleanup EXIT
4444

45-
echo "Creating temporary virtualenv at $venv_dir using $(python3 --version)"
46-
python3 -m venv $venv_dir
47-
source $venv_dir/bin/activate
48-
python -m pip install \
49-
-c $repo_root/opamp-gen-requirements.txt \
50-
grpcio-tools mypy-protobuf
51-
echo 'python -m grpc_tools.protoc --version'
52-
python -m grpc_tools.protoc --version
45+
protoc --version
5346

5447
# Clone the proto repo if it doesn't exist
5548
if [ ! -d "$OPAMP_SPEC_REPO_DIR" ]; then
@@ -72,7 +65,7 @@ find . -regex ".*_pb2.*\.pyi?" -exec rm {} +
7265

7366
# generate proto code for all protos
7467
all_protos=$(find $OPAMP_SPEC_REPO_DIR/ -name "*.proto")
75-
python -m grpc_tools.protoc \
68+
protoc \
7669
-I $OPAMP_SPEC_REPO_DIR/proto \
7770
--python_out=. \
7871
--mypy_out=. \

0 commit comments

Comments
 (0)