Skip to content

Commit ca0d7d3

Browse files
authored
Remove dependency on grpcio-tools (#271)
mypy-protobuf doesn't require it to run. It's only required to run mypy on the generated stubs. This removes a dependency, especially nice for folks not actually using grpc. Fixes #270
1 parent d42fabc commit ca0d7d3

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Upcoming
22

33
- Switch from setup.py to pyproject.toml and setup.cfg per https://packaging.python.org/tutorials/packaging-projects/
4+
- Remove dependency on grpcio-tools. mypy-protobuf doesn't need it to run. It's only needed to run mypy afterward.
45

56
## 2.9
67

run_test.sh

+14-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ PY_VER_MYPY_PROTOBUF_SHORT=$(echo $PY_VER_MYPY_PROTOBUF | cut -d. -f1-2)
99
PY_VER_MYPY=${PY_VER_MYPY:=3.8.11}
1010
PY_VER_UNIT_TESTS="${PY_VER_UNIT_TESTS_3:=3.8.11} ${PY_VER_UNIT_TESTS_2:=2.7.18}"
1111

12+
PROTOC_ARGS="--proto_path=proto/ --experimental_allow_proto3_optional"
13+
GRPC_PROTOS=$(find proto/testproto/grpc -name "*.proto")
14+
1215
# Clean out generated/ directory - except for .generated / __init__.py
1316
find test/generated -type f -not \( -name "*.expected" -or -name "__init__.py" \) -delete
1417

@@ -72,6 +75,8 @@ MYPY_PROTOBUF_VENV=venv_$PY_VER_MYPY_PROTOBUF
7275
# Confirm version number
7376
test "$(protoc-gen-mypy -V)" = "mypy-protobuf 2.9"
7477
test "$(protoc-gen-mypy --version)" = "mypy-protobuf 2.9"
78+
test "$(protoc-gen-mypy_grpc -V)" = "mypy-protobuf 2.9"
79+
test "$(protoc-gen-mypy_grpc --version)" = "mypy-protobuf 2.9"
7580

7681
# Run mypy on mypy-protobuf internal code for developers to catch issues
7782
FILES="mypy_protobuf/main.py"
@@ -86,7 +91,6 @@ MYPY_PROTOBUF_VENV=venv_$PY_VER_MYPY_PROTOBUF
8691
exit 1
8792
fi
8893

89-
PROTOC_ARGS="--proto_path=proto/ --experimental_allow_proto3_optional"
9094
# Compile protoc -> python
9195
$PROTOC $PROTOC_ARGS --python_out=test/generated `find proto -name "*.proto"`
9296

@@ -102,16 +106,22 @@ MYPY_PROTOBUF_VENV=venv_$PY_VER_MYPY_PROTOBUF
102106
# Overwrite w/ run with mypy-protobuf without flags
103107
$PROTOC $PROTOC_ARGS --mypy_out=test/generated `find proto -name "*.proto"`
104108

105-
# Compile GRPC
106-
GRPC_PROTOS=$(find proto/testproto/grpc -name "*.proto")
109+
# Generate grpc protos
107110
$PROTOC $PROTOC_ARGS --mypy_grpc_out=test/generated $GRPC_PROTOS
108-
python -m grpc_tools.protoc $PROTOC_ARGS --grpc_python_out=test/generated $GRPC_PROTOS
109111
)
110112

111113
for PY_VER in $PY_VER_UNIT_TESTS; do
112114
UNIT_TESTS_VENV=venv_$PY_VER
113115
PY_VER_MYPY_TARGET=$(echo $PY_VER | cut -d. -f1-2)
114116

117+
# Generate GRPC protos for mypy / tests
118+
if [[ $PY_VER =~ ^3.* ]]; then
119+
(
120+
source $UNIT_TESTS_VENV/bin/activate
121+
python -m grpc_tools.protoc $PROTOC_ARGS --grpc_python_out=test/generated $GRPC_PROTOS
122+
)
123+
fi
124+
115125
# Run mypy on unit tests / generated output
116126
(
117127
source $MYPY_VENV/bin/activate

setup.cfg

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ py_modules =
1717
install_requires =
1818
protobuf>=3.17.3
1919
types-protobuf>=3.17.3
20-
grpcio-tools>=1.38.1
2120
python_requires = >=3.6
2221

2322
[options.entry_points]

test_requirements.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Requirements to run unit tests. Tests import from
22
# generated code.
3+
protobuf>=3.17.3
34
pytest ; python_version < "3.0"
45
pytest==6.2.4 ; python_version >= "3.0"
5-
protobuf>=3.17.3
6-
typing ; python_version<"3.5"
76
grpc-stubs>=1.24.6 ; python_version>="3.0"
7+
grpcio-tools>=1.38.1 ; python_version >= "3.5"
88
types-protobuf==3.17.3
9+
typing ; python_version<"3.5"

0 commit comments

Comments
 (0)