Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MyPy Plugins not supported #19

Open
ewianda opened this issue Apr 29, 2020 · 8 comments
Open

MyPy Plugins not supported #19

ewianda opened this issue Apr 29, 2020 · 8 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@ewianda
Copy link

ewianda commented Apr 29, 2020

Description.

Using mypy plugin doesn't seem possible.

cat mypy.ini
[mypy]
ignore_missing_imports = True
plugins = pydantic.mypy
external/mypy_integration_config/mypy.ini:4: error: Error importing plugin 'pydantic.mypy': No module named 'pydantic'                            
Found 1 error in 1 file (checked 1 source file)    

Solution.

Make _mypy_cli configurable so users can customise accordingly.

@thundergolfer
Copy link
Collaborator

Yeah plugins aren't supported at the moment. Can I edit the title of your issue to say "MyPy Plugins not supported" and leave this open until they are?

@ewianda ewianda changed the title Using plugins. MyPy Plugins not supported Apr 30, 2020
@cristianmatache
Copy link

+1
I am a sqlalchemy-stubs user. Would also love this feature.

@thundergolfer
Copy link
Collaborator

thundergolfer commented Jun 13, 2020

Any ideas about how'd you want this supported, ideally? At the moment the plugin's dependency on mypy is kept separate from the application code's dependencies (specified in a requirements.txt somewhere).

If you wanted to use the pydantic plugin, the plugin could add the ability specify plugin packages that it should install, but then you'd be specifying pydantic as a dependency in two places. Once for the plugin and once for your application code. The versions would need to be kept in sync too.

It might be possible to have the plugin accept labels directly, so that you could pass a package you've installed for your application code directly to mypy, like:

mypy_integration_deps(
    mypy_version="//:current_mypy_version.txt",
    plugins={
       "pydantic.mypy": requirement("pydantic"),
   }
)

Just spitballing here though... 🤔

@cristianmatache
Copy link

I quite like your suggestion. 👍

@atadau
Copy link

atadau commented Aug 18, 2020

Another +1 on this. I'm looking to add this to our code base, and we have a couple of in house plugin (the mypy config point directly to the .py file) so would be great if that can be supported as well

@thundergolfer
Copy link
Collaborator

we have a couple of in house plugin (the mypy config point directly to the .py file) so would be great if that can be supported as well

Oh interesting, never done that. I think plain .py path references could prove tricky in Bazel, but providing a py_library target and then referencing the import path myworkspace.path.to.internal.plugin in the config file would be an easy substitute if I could get that working.

@thundergolfer thundergolfer added enhancement New feature or request help wanted Extra attention is needed labels Nov 14, 2020
@kwestb
Copy link

kwestb commented Dec 3, 2021

In my own build, I hacked together a solution that works for us by patching this code in the following way:

diff --git a/mypy/BUILD b/mypy/BUILD
index c8f843d..ac34fc3 100644
--- a/mypy/BUILD
+++ b/mypy/BUILD
@@ -1,4 +1,4 @@
-load("@mypy_integration_pip_deps//:requirements.bzl", "requirement")
+load("@mypy_integration_pip_deps//:requirements.bzl", "all_requirements")

 py_binary(
     name = "mypy",
@@ -6,13 +6,7 @@ py_binary(
     main = "main.py",
     python_version = "PY3",
     visibility = ["//visibility:public"],
-    deps = [
-        requirement("mypy"),
-        # Transitive deps determined by looking at: https://github.com/python/mypy/blob/master/mypy-requirements.txt
-        requirement("typing_extensions"),
-        requirement("mypy_extensions"),
-        requirement("typed_ast"),
-    ],
+    deps = all_requirements,
 )

 filegroup(

And then adding all of my plugins to //tools/typing:mypy_version.txt (in addition to the MyPy version) so that they are available at runtime.

@jonasrauber
Copy link

Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants