cool-easter-32542
09/02/2023, 10:50 PMpants check with mypy backend fails for files which import protoc-generated .py and .pyi sources.
> pants check src/test/python/loka/music/streaming/v1::
23:41:38.50 [INFO] Reading /Users/loka/Projects/loka-internal/python-monorepo-template/.python-version to determine desired version for [python-bootstrap].search_path.
23:41:38.54 [INFO] Reading /Users/loka/Projects/loka-internal/python-monorepo-template/.python-version to determine desired version for [python-bootstrap].search_path.
23:41:39.39 [INFO] Reading /Users/loka/Projects/loka-internal/python-monorepo-template/.python-version to determine desired version for [python-bootstrap].search_path.
23:41:41.83 [INFO] Canceled: Building 6 requirements for mypy.pex from the 3rdparty/python/mypy.lock resolve: grpc-stubs>=1.53.0.2, mypy-protobuf, mypy-typing-asserts, mypy==1.4.1, types-protobuf, types-protobuf>=4.23.0.2
23:41:43.64 [INFO] Completed: Building 3 requirements for requirements.pex from the 3rdparty/python/default.lock resolve: grpcio>=1.56.2, protobuf>=4.23.4, pytest==7.0.1
23:41:50.47 [INFO] Completed: Building 6 requirements for mypy.pex from the 3rdparty/python/mypy.lock resolve: grpc-stubs>=1.53.0.2, mypy-protobuf, mypy-typing-asserts, mypy==1.4.1, types-protobuf, types-protobuf>=4.23.0.2
23:41:50.70 [INFO] Canceled: Building mypy_protobuf.pex
23:41:52.92 [INFO] Completed: Building requirements_venv.pex
23:41:54.28 [INFO] Completed: Building mypy_protobuf.pex
23:42:19.78 [ERROR] Completed: Typecheck using MyPy - mypy - mypy failed (exit code 1).
src/test/python/loka/music/streaming/v1/test_streaming.py:1: note: In module imported here:
src/main/python/loka/music/streaming/v1/streaming_pb2.pyi:7:1: error: Library stubs not installed for "google.protobuf.descriptor" [import]
import google.protobuf.descriptor
^
src/main/python/loka/music/streaming/v1/streaming_pb2.pyi:7:1: error: Library stubs not installed for "google.protobuf" [import]
import google.protobuf.descriptor
^
src/main/python/loka/music/streaming/v1/streaming_pb2.pyi:8:1: error: Library stubs not installed for "google.protobuf.internal.containers" [import]
import google.protobuf.internal.containers
^
src/main/python/loka/music/streaming/v1/streaming_pb2.pyi:8:1: note: Hint: "python3 -m pip install types-protobuf"
src/main/python/loka/music/streaming/v1/streaming_pb2.pyi:8:1: note: (or run "mypy --install-types" to install all missing stub packages)
src/main/python/loka/music/streaming/v1/streaming_pb2.pyi:8:1: note: See <https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports>
src/main/python/loka/music/streaming/v1/streaming_pb2.pyi:8:1: error: Library stubs not installed for "google.protobuf.internal" [import]
import google.protobuf.internal.containers
^
src/main/python/loka/music/streaming/v1/streaming_pb2.pyi:9:1: error: Library stubs not installed for "google.protobuf.message" [import]
import google.protobuf.message
^
Found 5 errors in 1 file (checked 1 source file)
ā mypy failed.
# 3rdparty/python/mypy-requirements.txt
mypy==1.1.1
types-protobuf>=3.20.1,<3.21.0
mypy-protobuf
grpc-stubs>=1.53.0.2
Pants version
2.16.0
OS
MacOS + Linux GitHub action
Additional info
Forked `example-codegen` repo. MyPy patch commit.
Failed CI run.
When running from default virtual environment, seems like it works fine.
# activate python 3.8.16 venv
...
pip install -r 3rdparty/python/requirements.txt -r 3rdparty/python/mypy-requirements.txt
pants export-codegen src/protobuf/simple_example/v1
cp -r dist/codegen/src/python/simple_example src/python/simple_example
mypy src/python/protobuf_examples/simple_example_test.py
...
# no errors
Adding --install-types to mypy config shows that types-protobuf is not installed at the environment
# pants.toml
[mypy]
install_from_resolve = "mypy"
args = ["--install-types"]
> pants check src/python/protobuf_examples
00:17:15.37 [INFO] Canceled: Building mypy.pex
00:17:16.90 [INFO] Completed: Building 1 requirement for requirements.pex from the 3rdparty/python/default.lock resolve: protobuf==3.20.1
00:17:22.89 [INFO] Completed: Building mypy.pex
00:17:26.13 [INFO] Completed: Building mypy_protobuf.pex
00:17:30.98 [ERROR] Completed: Typecheck using MyPy - mypy - mypy failed (exit code 1).
Installing missing stub packages:
./requirements_venv.pex_bin_python_shim.sh -m pip install types-protobuf
Found 4 errors in 1 file (checked 1 source file)
/private/var/folders/5q/wc6nkqx94f1fcqj20939_8nh0000gp/T/pants-sandbox-Cwx6gt/.cache/pex_root/venvs/4fff6393c895988203b70cde0a39ab7a6bf464f0/ecdbb5b6b072942be4d04da33dc3820766a91e46/bin/python: No module named pip
src/python/simple_example/v1/person_pb2.pyi:6: error: Library stubs not installed for "google.protobuf.descriptor" [import]
src/python/simple_example/v1/person_pb2.pyi:6: note: Hint: "python3 -m pip install types-protobuf"
src/python/simple_example/v1/person_pb2.pyi:6: note: (or run "mypy --install-types" to install all missing stub packages)
src/python/simple_example/v1/person_pb2.pyi:6: note: See <https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports>
src/python/simple_example/v1/person_pb2.pyi:6: error: Library stubs not installed for "google.protobuf" [import]
src/python/simple_example/v1/person_pb2.pyi:6: error: Skipping analyzing "google": module is installed, but missing library stubs or py.typed marker [import]
src/python/simple_example/v1/person_pb2.pyi:7: error: Library stubs not installed for "google.protobuf.message" [import]
ā mypy failed.
pantsbuild/pantscool-easter-32542
09/06/2023, 10:06 PM