salmon-planet-80683
08/19/2021, 8:22 PMprotobuf_library() , and in my pants.toml I have mypy_plugin = true set for the protobuf backend.
When I examine the chroot for pants typecheck :: (thanks to --no-process-execution-local-cleanup ) I see that:
⢠my protobuf_library has accurately generated .py and .pyi files.
⢠Importantly, I do not see any `__init__.py`s in the protobuf-codegen'd directory.
When I run pants typecheck, Mypy complains with: "Cannot find implementation or library stub for module named 'your_thing_that_you_imported_pb2'"
Interestingly, at runtime (i.e. during a test) this import is resolved correctly.
So, at this point, my suspicion is that the codegen is correct and mypy is just not able to find the .pyi files.
I was browsing through mypy documentation and I came across a seemingly perfect flag: --namespace-packages - that accounts for packages lacking init.py. Sure enough, running it with this flag makes it all work swimmingly.hundreds-father-404
08/19/2021, 8:27 PM__init__.py files. I'm glad you were able to figure this out!
FYI the other way you could have resolved this is adding empty __init__.py files to the locations where the files get generated to. Usually people don't want to add those to a src/protos folder, for example, hence the python_source_root option to allow you to have a file like src/protos/project/models.proto generate into src/py/project/models_pb2.py. Then you would have src/py/project/__init__.py and it should work. Does that make sense?
Using namespace packages is also totally valid. Although I don't think we want to be activating it by default: we generally try to keep the magic of setting MyPy options to a minimum because it can result in confusionsalmon-planet-80683
08/19/2021, 8:32 PMsrc/protos and are not using python_source_root.salmon-planet-80683
08/19/2021, 8:33 PMsrc/py - so I was a bit surprised that src/py doesn't, itself, have an init
https://github.com/danieljanes/pants-python-protobuf/tree/master/src/pyhundreds-father-404
08/19/2021, 8:34 PMsalmon-planet-80683
08/19/2021, 8:34 PMsalmon-planet-80683
08/19/2021, 8:35 PMsalmon-planet-80683
08/19/2021, 8:43 PMprotobuf_library(
name="protos",
python_source_root="src/python/protos-python"
)salmon-planet-80683
08/19/2021, 8:44 PMdependencies= declaration, would I specify src/protos:protos or src/python/protos-python ?salmon-planet-80683
08/19/2021, 8:45 PMhundreds-father-404
08/19/2021, 8:49 PMsrc/protos:protos. Or, use dependency inference which will infer a dep on my_module_pb2 šhundreds-father-404
08/19/2021, 8:50 PM