Hi, Perhaps something for the docs. I’m using nam...
# general
c
Hi, Perhaps something for the docs. I’m using namespace packages, and had to put in some custom config in order for mypy to correctly detect my package names. Configuration I’m hoping pants should be able to add, but as it works with just a few lines of configuration, adding it to the documentation might be good enough to save others the trouble of finding this out themselves.. In
pants.toml
:
Copy code
[mypy]
config = "mypy.ini"
args = "--namespace-packages --explicit-package-bases"
and in
mypy.ini
:
Copy code
[mypy]
mypy_path = src:plugins
Any paths under which you have sources, but that aren’t part of the package name. So in this case, there are sources in
src/<namespaceroot-pkgs>/…
and
plugins/<other-pkgs>/…
To aid in debugging this, the
-v
flag to mypy was really helpful, so you can inspect the output from mypy, on the form:
Copy code
LOG:  Found source:           BuildSource(path='plugins/xx/flask/rest/routes/generic.py', module='xx.flask.rest.routes.generic', has_text=False, base_dir='/private/var/folders/8j/c8jf_msj009947wyw82xvdkw0000gn/T/process-executionLIFk6M/plugins')
Here, the
BuildSource(…, module=)
will show which module mypy thinks the source is in. Relevant (and helpful) mypy docs: https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules
e
Yeah, jyggen actually asked about this but appears to have deleted his sample repo. The super-spammy "gitmemory" records some of this (https://www.gitmemory.com/jyggen). Note that you can move
namespace_packages = True
into mypy.ini, and in the next release of mypy,
explicit_package_bases = True
as well so that your mypy setup is self-contained and works outside of Pants too which is always useful for debugging.
👍 1