-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Support finding "editable" type annotated packages made editable through direct_url.json #12313
Comments
Discover paths to editable packages by looking at direct_url.json files -- installed by pip when the -e/--editable flag is used -- and add to the package search paths.
Discover paths to editable packages by looking at direct_url.json files -- installed by pip when the -e/--editable flag is used -- and add to the package search paths.
Find paths to editable packages by looking at direct_url.json files -- installed by pip when the -e/--editable flag is used -- and add to the package search paths.
Hi @hashstat, although this approach might work for some packages, it may not generalise well... For example, it is a wide spread practice in the community to organise a project in what is called
(Of course there might be all sorts of creative ways of organizing a project layout, but I think that at least it is important to consider the |
Hmm. @abravalheri makes a good point. We could add a search for modules/packages in the src directory. That addition would likely handle 90% of the cases out there. But now we are making assumptions about the layout of project source code that may or may not be correct. Unfortunately, there doesn't appear to be a simple and reliable method to determine the path of editable packages installed using import hooks. Looks like we might be stuck using MYPYPATH, unless someone has another idea? |
1. Temporarily avoid recent asyncssh version that breaks the tests 2. Workaround pylance issue with pyproject.toml related changes and pip editable modules install format (#768) See Also: - microsoft/pylance-release#3473 May also affect `mypy`: - python/mypy#16988 - python/mypy#12313
1. Temporarily avoid recent asyncssh version that breaks the tests 2. Workaround pylance issue with pyproject.toml related changes and pip editable modules install format (microsoft#768) See Also: - microsoft/pylance-release#3473 May also affect `mypy`: - python/mypy#16988 - python/mypy#12313
1. Temporarily avoid recent asyncssh version that breaks the tests 2. Workaround pylance issue with pyproject.toml related changes and pip editable modules install format (microsoft#768) See Also: - microsoft/pylance-release#3473 May also affect `mypy`: - python/mypy#16988 - python/mypy#12313
Feature
Add the ability for mypy to discover the path of "editable" packages installed with direct_url.json files, as described in PEP-610.
Pitch
As the Python ecosystem continues to move toward PEP-517-compliant build systems, the way editable packages are installed is also changing. PEP-660 uses the editables package as an example of how to install editable wheels using import hooks that act as a proxy for editable packages. Editables uses .pth files to load a module finder to proxy the loading of modules from outside of the packages directory without modifying the Python path. Because the path is left unmodified, the methods described in PEP-561, and currently employed by mypy, fail to find these packages. But pip leaves behind a hint about the package path in the direct_url.json file it installs in the .dist-info directory when the -e/--editable flag is used.
The hatchling build backend uses editables to install editable packages. The problem is that mypy cannot determine that such packages are type annotated because of the limitations imposed by its current PEP-561-based discovery methods. Packages that are not stubs cannot be discovered because they aren't named appropriately. And py.typed files cannot be found because the project is proxied by a single python module and is missed by the current mypy search algorithm because the package files are not found on the python path.
Here is an example editable installation that might be installed using
pip install -e path/to/package
:venv/lib/python3.9/site-packages/editable_pkg_typed.pth
venv/lib/python3.9/site-packages/_editable_pkg_typed.py
venv/lib/python3.9/site-packages/editable_pkg_typed-0.dist-info/
venv/lib/python3.9/site-packages/editable_pkg_typed-0.dist-info/direct_url.json
/path/to/package/
/path/to/package/pyproject.toml
/path/to/package/editable_pkg_typed/
Adding the path from direct_url.json to those discovered in .pth files should be sufficient for mypy to find these editable packages. I will submit a pull request soon with the suggested functionality.
The text was updated successfully, but these errors were encountered: