Skip to content

Commit ed129dc

Browse files
authored
Commit the generated .pyi files (#272)
* Commit the generated .pyi files This should simplify some of our tests, as well as allow external tools to run mypy on our repo (such as mypy_primer) * Black test_negative as well
1 parent ca0d7d3 commit ed129dc

29 files changed

+71
-110
lines changed

.gitattributes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
*.expected linguist-language=Python
21
test_negative/output.expected.2.7 linguist-generated=true
32
test_negative/output.expected.3.8 linguist-generated=true

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595
- name: Run black
9696
run: |
9797
pip3 install black
98-
black --check mypy_protobuf/main.py test/
98+
black --check .
9999
100100
sanity_check_windows:
101101
name: Sanity Check Windows Executable

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ __pycache__/
88
/mypy_env/
99
*.pyc
1010
/test/generated/**/*.py
11-
/test/generated/**/*.pyi
1211
!/test/generated/**/__init__.py
1312
.pytest_cache
1413
/build/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ Contributions to the implementation are welcome. Please run tests using `./run_t
196196
Ensure code is formatted using black.
197197
```
198198
pip3 install black
199-
black mypy_protobuf/main.py test/
199+
black .
200200
```
201201

202202
## Contributors

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ requires = [
44
"wheel",
55
]
66
build-backend = "setuptools.build_meta"
7+
8+
[tool.black]
9+
extend-exclude = "(_pb2.pyi?$|_pb2_grpc.pyi?$)"

run_test.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ PY_VER_UNIT_TESTS="${PY_VER_UNIT_TESTS_3:=3.8.11} ${PY_VER_UNIT_TESTS_2:=2.7.18}
1212
PROTOC_ARGS="--proto_path=proto/ --experimental_allow_proto3_optional"
1313
GRPC_PROTOS=$(find proto/testproto/grpc -name "*.proto")
1414

15-
# Clean out generated/ directory - except for .generated / __init__.py
16-
find test/generated -type f -not \( -name "*.expected" -or -name "__init__.py" \) -delete
17-
1815
if [ -e $CUSTOM_TYPESHED_DIR ]; then
1916
export MYPYPATH=$CUSTOM_TYPESHED_DIR/stubs/protobuf
2017
fi
@@ -91,6 +88,11 @@ MYPY_PROTOBUF_VENV=venv_$PY_VER_MYPY_PROTOBUF
9188
exit 1
9289
fi
9390

91+
# CI Check to make sure generated files are committed
92+
SHA_BEFORE=$(find test/generated -name "*.pyi" | xargs sha1sum)
93+
# Clean out generated/ directory - except for __init__.py
94+
find test/generated -type f -not -name "__init__.py" -delete
95+
9496
# Compile protoc -> python
9597
$PROTOC $PROTOC_ARGS --python_out=test/generated `find proto -name "*.proto"`
9698

@@ -108,6 +110,11 @@ MYPY_PROTOBUF_VENV=venv_$PY_VER_MYPY_PROTOBUF
108110

109111
# Generate grpc protos
110112
$PROTOC $PROTOC_ARGS --mypy_grpc_out=test/generated $GRPC_PROTOS
113+
114+
if [[ -n $VALIDATE ]] && ! diff <(echo "$SHA_BEFORE") <(find test/generated -name "*.pyi" | xargs sha1sum); then
115+
echo -e "${RED}Some .pyi files did not match. Please commit those files${NC}"
116+
exit 1
117+
fi
111118
)
112119

113120
for PY_VER in $PY_VER_UNIT_TESTS; do
@@ -171,7 +178,7 @@ for PY_VER in $PY_VER_UNIT_TESTS; do
171178
)
172179

173180
(
174-
# Run unit tests. These tests generate .expected files
181+
# Run unit tests.
175182
source $UNIT_TESTS_VENV/bin/activate
176183
if [[ $PY_VER =~ ^2.* ]]; then IGNORE="--ignore=test/test_grpc_usage.py"; else IGNORE=""; fi
177184
PYTHONPATH=test/generated py.test --ignore=test/generated $IGNORE -v

test/generated/google/protobuf/empty_pb2.pyi.expected

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)