Are `mypy` types included with `pantsbuild.pants`?...
# plugins
w
Are
mypy
types included with
pantsbuild.pants
? In a custom plugin, I'm running into a bunch of these... Maybe it's a Monday morning thing, but I thought I had fixed these before, but can't recall anymore:
Copy code
pants-plugins/experimental/fooify/rules.py:4: error: Cannot find implementation or library stub for module named "experimental.fooify.subsystem"
pants-plugins/experimental/fooify/rules.py:5: error: Cannot find implementation or library stub for module named "experimental.fooify.target_types"
pants-plugins/experimental/fooify/rules.py:6: error: Cannot find implementation or library stub for module named "pants.core.goals.package"
pants-plugins/experimental/fooify/rules.py:7: error: Cannot find implementation or library stub for module named "pants.engine.fs"
pants-plugins/experimental/fooify/rules.py:8: error: Cannot find implementation or library stub for module named "pants.engine.rules"
pants-plugins/experimental/fooify/rules.py:9: error: Cannot find implementation or library stub for module named "pants.engine.target"
pants-plugins/experimental/fooify/rules.py:15: error: Cannot find implementation or library stub for module named "pants.engine.unions"
pants-plugins/experimental/fooify/rules.py:16: error: Cannot find implementation or library stub for module named "pants.util.logging"
1
oops, ignoring the
fooify
plugin as my path is incorrect
b
They aren't in a separate
pyi
so yes?
w
Hmm, I feel like I've misconfigured it, so it's not looking at my requirements correctly. It should pick up the imports. I now vaguely recall I dealt with these at some point while working on the
mypyc
plugin, but my memory is 🥔
Yeah, and there is a
py.typed
file... This must be a path issue
1
Hmm, maybe not - even outside of pants I can't get mypy to pick up the pants imports
b
You using
pants_requirements
?
It pairs well with 2.10.x multiple resolves
w
Like, when I'm not using Pants? I just mean that
mypy pants-plugins/experimental/fooify/target_types.py
fails, while other 3rd party deps in there succeed...
b
Is the environment you're running that in have
pants
?
w
Yep
b
Can you import the modules it's complaining about?
w
Yep
Runtime works perfectly, just mypy giving me a hassle
More like... lie-py
🤡 1
b
config issue perhaps?
Also I don't mean running the plugin with pants, I mean open a terminal and run
import pants....
w
I removed all config and everything, added inits everywhere, etc. ANd yeah, pants imports from a terminal python
b
Unless told otherwise,
mypy
assumes it's in the same environment as your code and dependencies
OK weird
w
Yeah, hence my confusion. EVERYTHING other than pants works perfectly
--namespace_packages
seems to have done the trick
I also upgraded to
2.10.0
, but I don't think that's related
h
hmm i think we fixed it in like 2.8 or something. why was namespace packages necessary?
🤷‍♂️ 1
w
I wasn't sure if
pantsbuild.pants
is confusing mypy? Not sure how the internals work
h
it was surprisingly rocky to do that if you follow the trails. i wouldnt be surprised if still broken. but we really do want to fix this if youre able to reproduce & file bug
w
https://github.com/sureshjoshi/pants-example-plugin/tree/0b8ebcd8618c932b133f00dede71440b16278e53 With this diff:
Copy code
diff --git a/pants-plugins/experimental/__init__.py b/pants-plugins/experimental/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/pants.toml b/pants.toml
index 3b204b6..4eede6b 100644
--- a/pants.toml
+++ b/pants.toml
@@ -7,12 +7,17 @@ backend_packages = [
     "pants.backend.plugin_development", # Adds the `pants_requirements` target type
     "pants.backend.python",
     "experimental.fooify",
+    "pants.backend.python.typecheck.mypy",
 ]
 
 [source]
 root_patterns = [
     "helloworld",
+    "pants-plugins",
 ]
 
+[python]
+interpreter_constraints = [">=3.9,<3.11"]
+
 [anonymous-telemetry]
 enabled = false
Copy code
sj@tinyrick pants-example-plugin % ./pants check ::
13:40:59.24 [INFO] Initializing scheduler...
13:40:59.42 [INFO] Scheduler initialized.
13:41:02.43 [ERROR] Completed: Typecheck using MyPy - MyPy failed (exit code 1).
pants-plugins/experimental/fooify/target_types.py:1: error: Cannot find implementation or library stub for module named "pants.engine.target"
pants-plugins/experimental/fooify/subsystem.py:1: error: Cannot find implementation or library stub for module named "pants.option.subsystem"
pants-plugins/experimental/fooify/subsystem.py:2: error: Cannot find implementation or library stub for module named "pants.engine.rules"
pants-plugins/experimental/fooify/rules.py:4: error: Cannot find implementation or library stub for module named "pants.core.goals.package"
pants-plugins/experimental/fooify/rules.py:4: note: See <https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports>
pants-plugins/experimental/fooify/rules.py:5: error: Cannot find implementation or library stub for module named "pants.engine.fs"
pants-plugins/experimental/fooify/rules.py:11: error: Cannot find implementation or library stub for module named "pants.engine.rules"
pants-plugins/experimental/fooify/rules.py:12: error: Cannot find implementation or library stub for module named "pants.engine.target"
pants-plugins/experimental/fooify/rules.py:18: error: Cannot find implementation or library stub for module named "pants.engine.unions"
pants-plugins/experimental/fooify/rules.py:19: error: Cannot find implementation or library stub for module named "pants.util.logging"
Found 9 errors in 3 files (checked 7 source files)
The "fixed" version, with a corresponding blog post about pants code quality plugins will be up soon - so I'll get the commit ref for the actual "broken" one
🙌 1
a
what did you do to resolve this issue? I'm seeing exactly the same thing.
b
IIRC you can't import modules, you have to import definitions from the modules. Or at least, that bit me
a
I think I 'solved' it by setting
Copy code
[tool.mypy]
namespace_packages = true
explicit_package_bases = true
in my pyproject.toml. It was weird. Everything was being type checked correctly. But it still errored about the stubs.
Still not sure how to make it not complain about
pytest
. Have added it as an ignore, but can't work out how the pants repo does it.
w
Sorry @ambitious-actor-36781 I didn't see this until now: https://sureshjoshi.com/development/pants-plugin-code-quality#typechecking In my case, I think it was specifically the
namespace_packages
in a
mypy.ini
h
hm this is really not ideal. anyone mind opening a ticket with a minimal reproduction?
a