Skip to content

Commit

Permalink
fix: edit python generated pb2 import statements in general (#222)
Browse files Browse the repository at this point in the history
In the previous version of `python/run-protoc.sh`, we selectively
edited import statements for `extensions_pb2`. With the prior addition
of `permissionmessages`, the package is broken. We need to edit those
as well.

In order to avoid this in the present and future, we generalize the
edits to all pb2 import statements in our generated code.
  • Loading branch information
malandis authored Oct 3, 2023
1 parent 505e371 commit 3ffe7c2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion python/run-protoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ do
# `import extensions_pb2 as extensions__pb2` -> `from . import extensions_pb2 as extensions__pb2`
for pb2_src in $src_path/*_pb2.py
do
sed -i.old "s/^\(import extensions_pb2 as \)/from . \1/g" $pb2_src
filename=$(basename "$pb2_src")

# cacheclient_pb2.py -> cacheclient_pb2
pb2_module_name=${filename%.py}

# Replace gRPC absolute imports with relative imports so the package
# will work when installed, eg:
# `import cacheclient_pb2` -> `from . import cacheclient_pb2`
sed -i.old "s/^\(import $pb2_module_name as \)/from . \1/g" $src_path/*_pb2.py
done

rm $src_path/*.old
Expand Down

0 comments on commit 3ffe7c2

Please sign in to comment.