dropbox / pyannotate

Auto-generate PEP-484 annotations
Apache License 2.0
1.42k stars 58 forks source link

Ship a pytest plugin? #97

Open blueyed opened 4 years ago

blueyed commented 4 years ago

There's an example conftest (https://github.com/dropbox/pyannotate/issues/11), but it would be possible to ship a pytest entrypoint plugin (via e.g. a pytest_pyannotate module), that could be used via pytest --pyannotate then automatically.

I'd be happy to add it, but wanted to ask for feedback first.

Just for reference: https://github.com/Instagram/MonkeyType/issues/25

JukkaL commented 4 years ago

I'm not familiar with pytest entrypoint plugins. Can you explain what this would mean in a bit more detail?

blueyed commented 4 years ago
diff --git i/setup.py w/setup.py
index 7cc0d2f..554486f 100644
--- i/setup.py
+++ w/setup.py
@@ -20,7 +20,15 @@ def get_long_description():
       platforms=['POSIX'],
       packages=['pyannotate_runtime', 'pyannotate_tools',
                 'pyannotate_tools.annotations', 'pyannotate_tools.fixes'],
-      entry_points={'console_scripts': ['pyannotate=pyannotate_tools.annotations.__main__:m>
+      modules=['pytest_pyannotate'],
+      entry_points={
+          "console_scripts": [
+              "pyannotate=pyannotate_tools.annotations.__main__:main",
+          ],
+          "pytest11": [
+              "pytest-pyannotate = pytest_pyannotate",
+          ],
+      },
       classifiers=[
           'Development Status :: 3 - Alpha',
           'Environment :: Console',

And then have the plugin in pytest_pyannotate.py, which would be similar to example/example_conftest.py (could be moved there).

The main benefit of course it that it easily allows to use pyannotate with pytest-based projects (although having the example conftest is very good already - this would just make the integration more seemingly etc)

gvanrossum commented 4 years ago

If you're willing to contribute the code that sounds like a good idea to me.

(Though I am no longer a Dropbox employee and I don't know if I can still merge PRs. I can definitely still review code though. :-)

tuukkamustonen commented 4 years ago

There's https://github.com/kensho-technologies/pytest-annotate at least.

terencehonles commented 3 years ago

I guess I didn't see this, but I basically did this with #107 I didn't add it as an entry point since I doubt you actually want to run it any time it's installed to the system and instead you'll probably want to opt in via pytest's plugin config/argument https://docs.pytest.org/en/latest/plugins.html#installing-and-using-plugins.

I updated the documentation to match.