Skip to content

Commit 96c51fa

Browse files
committed
Remove dependency on grpcio-tools
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 96c51fa

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
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

Lines changed: 13 additions & 4 deletions
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

@@ -86,7 +89,6 @@ MYPY_PROTOBUF_VENV=venv_$PY_VER_MYPY_PROTOBUF
8689
exit 1
8790
fi
8891

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

@@ -102,16 +104,23 @@ MYPY_PROTOBUF_VENV=venv_$PY_VER_MYPY_PROTOBUF
102104
# Overwrite w/ run with mypy-protobuf without flags
103105
$PROTOC $PROTOC_ARGS --mypy_out=test/generated `find proto -name "*.proto"`
104106

105-
# Compile GRPC
106-
GRPC_PROTOS=$(find proto/testproto/grpc -name "*.proto")
107+
# Generate grpc protos
107108
$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
109109
)
110110

111111
for PY_VER in $PY_VER_UNIT_TESTS; do
112112
UNIT_TESTS_VENV=venv_$PY_VER
113113
PY_VER_MYPY_TARGET=$(echo $PY_VER | cut -d. -f1-2)
114114

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

setup.cfg

Lines changed: 0 additions & 1 deletion
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

Lines changed: 3 additions & 2 deletions
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)