|
5 | 5 |
|
6 | 6 | set -euxo pipefail |
7 | 7 |
|
8 | | -# Need protoc >= 3.15 for explicit optional |
9 | | -PROTOBUF_VERSION=25.3 # 4.25.3 |
10 | 8 | # Whenever you update TENSORFLOW_VERSION here, version should be updated |
11 | 9 | # in stubs/tensorflow/METADATA.toml and vice-versa. |
12 | 10 | TENSORFLOW_VERSION=2.12.1 |
13 | 11 | MYPY_PROTOBUF_VERSION=3.6.0 |
14 | 12 |
|
15 | | -if uname -a | grep Darwin; then |
16 | | - # brew install coreutils wget |
17 | | - PLAT=osx |
18 | | -else |
19 | | - PLAT=linux |
20 | | -fi |
| 13 | +# brew install coreutils wget |
| 14 | +# sudo apt install -y unzip |
21 | 15 | REPO_ROOT="$(realpath "$(dirname "${BASH_SOURCE[0]}")"/..)" |
22 | 16 | TMP_DIR="$(mktemp -d)" |
23 | 17 | TENSORFLOW_FILENAME="v$TENSORFLOW_VERSION.zip" |
24 | | -PROTOC_FILENAME="protoc-$PROTOBUF_VERSION-$PLAT-x86_64.zip" |
25 | | -PROTOC_URL="https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/$PROTOC_FILENAME" |
26 | 18 | TENSORFLOW_URL="https://github.com/tensorflow/tensorflow/archive/refs/tags/$TENSORFLOW_FILENAME" |
| 19 | +TENSORFLOW_DIR="tensorflow-$TENSORFLOW_VERSION" |
27 | 20 |
|
28 | 21 | cd "$TMP_DIR" |
29 | 22 | echo "Working in $TMP_DIR" |
30 | 23 |
|
31 | | -# Install protoc |
32 | | -wget "$PROTOC_URL" |
33 | | -mkdir protoc_install |
34 | | -unzip "$PROTOC_FILENAME" -d protoc_install |
35 | | -protoc_install/bin/protoc --version |
36 | | - |
37 | 24 | # Fetch tensorflow (which contains all the .proto files) |
38 | 25 | wget "$TENSORFLOW_URL" |
39 | 26 | unzip "$TENSORFLOW_FILENAME" |
40 | | -TENSORFLOW_DIR="tensorflow-$TENSORFLOW_VERSION" |
41 | 27 |
|
42 | 28 | # Prepare virtualenv |
43 | 29 | python3 -m venv .venv |
44 | 30 | source .venv/bin/activate |
45 | | -python3 -m pip install pre-commit mypy-protobuf=="$MYPY_PROTOBUF_VERSION" |
| 31 | +python3 -m pip install grpcio-tools pre-commit mypy-protobuf=="$MYPY_PROTOBUF_VERSION" |
46 | 32 |
|
47 | 33 | # Remove existing pyi |
48 | 34 | find "$REPO_ROOT/stubs/tensorflow/" -name "*_pb2.pyi" -delete |
49 | 35 |
|
50 | 36 | # Folders here cover the more commonly used protobufs externally and |
51 | 37 | # their dependencies. Tensorflow has more protobufs and can be added if requested. |
52 | | -protoc_install/bin/protoc \ |
| 38 | +PROTOC_VERSION=$(python3 -m grpc_tools.protoc --version) |
| 39 | +echo $PROTOC_VERSION |
| 40 | +python3 -m grpc_tools.protoc \ |
53 | 41 | --proto_path="$TENSORFLOW_DIR" \ |
54 | 42 | --mypy_out "relax_strict_optional_primitives:$REPO_ROOT/stubs/tensorflow" \ |
55 | 43 | $TENSORFLOW_DIR/tensorflow/compiler/xla/*.proto \ |
|
89 | 77 | stubs/tensorflow/tensorflow/core/util/example_proto_fast_parsing_test_pb2.pyi \ |
90 | 78 |
|
91 | 79 | sed --in-place="" \ |
92 | | - "s/extra_description = .*$/extra_description = \"Partially generated using [mypy-protobuf==$MYPY_PROTOBUF_VERSION](https:\/\/github.com\/nipunn1313\/mypy-protobuf\/tree\/v$MYPY_PROTOBUF_VERSION) on tensorflow==$TENSORFLOW_VERSION\"/" \ |
93 | | - stubs/tensorflow/METADATA.toml |
| 80 | + "s/extra_description = .*$/extra_description = \"\ |
| 81 | +Partially generated using [mypy-protobuf==$MYPY_PROTOBUF_VERSION](https:\/\/github.com\/nipunn1313\/mypy-protobuf\/tree\/v$MYPY_PROTOBUF_VERSION) \ |
| 82 | +and $PROTOC_VERSION \ |
| 83 | +on tensorflow==$TENSORFLOW_VERSION.\"/" \ |
| 84 | + stubs/tensorflow/METADATA.toml |
94 | 85 |
|
95 | 86 | # use `|| true` so the script still continues even if a pre-commit hook |
96 | 87 | # applies autofixes (which will result in a nonzero exit code) |
|
0 commit comments