setuptools: Editable installs are broken after `__editable__` and `__path_hook__` changes
Description
I am starting to observe broken editable installs since past week.
Specifically, editable install now creates a __editable__.<pkg>.pth
and __editable___<pkg>_finder.py
files. These paths are returned as part of namespace.__path__
, which has broken a lot of tooling.
pdoc3
went broke. Skipping__editable__
package seems to fix (hack) it.- We also noticed, namespace packages that installs a CLI are now also broken, because while the binary is under
.venv/bin
, it is unable to import the modules since it was installed using-e
.- Modifying
PYTHONPATH
is the only option.
- Modifying
- We also noticed, due to these changes even VSCode/Pylance is now broken, as it is unable to resolve paths to editable installed packages.
- Adding
"python.analysis.extraPaths"
to.vscode/settings.json
is the way out
- Adding
I was unable to find any search result on Google for __editable__
and __path_hook__
. So, I am unsure what I am up against here.
Expected behavior
- Installed CLI from namespace package must work fine without modification of
PYTHONPATH
namespace.__path__
must return actual path instead of__editable__.*
which seems to break a lot of existing tooling
pip version
22.2.2
Python version
3.10.5
OS
MacOS 12.5
How to Reproduce
- Create a namespace package that installs CLI (entry point)
- Install the package with
-e
- Installed CLI is broken due to missing
PYTHONPATH
Our projects are using pyproject.toml
and setup.cfg
.
Output
`ImportError: cannot import name 'entry_point' from 'namespace.cli' (unknown location)`
Code of Conduct
- I agree to follow the PSF Code of Conduct.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 17
- Comments: 29 (12 by maintainers)
Commits related to this issue
- Workaround setuptools editable packages path issue Setuptools 64.0.0 introduced change that broke paths of editable cli packages. This change makes CLIs installed via editable packages to miss paths ... — committed to potiuk/airflow by potiuk 2 years ago
- Workaround setuptools editable packages path issue (#25848) Setuptools 64.0.0 introduced change that broke paths of editable cli packages. This change makes CLIs installed via editable packages to ... — committed to apache/airflow by potiuk 2 years ago
- BLD: fix editable installs * this allows `pip install -e .` to produce a working editable install locally * the basis for the `setuptools` pin here is based on reading through https://github.com/pyp... — committed to tylerjereddy/darshan by tylerjereddy a year ago
- Workaround setuptools editable packages path issue (#25848) Setuptools 64.0.0 introduced change that broke paths of editable cli packages. This change makes CLIs installed via editable packages to mi... — committed to GoogleCloudPlatform/composer-airflow by potiuk 2 years ago
- Workaround for pypa/setuptools/issues/3548 — committed to clu-ling/odinson-ruleutils by myedibleenso a year ago
- Fixed a bug in over_approximation of RepeatSurface (#30) * Fixed a bug in over_approximation of RepeatSurface * Only generate docs for one python version * Workaround for pypa/setuptools/issues... — committed to clu-ling/odinson-ruleutils by enoriega a year ago
- Fixed a bug in over_approximation of RepeatSurface (#30) * Fixed a bug in over_approximation of RepeatSurface * Only generate docs for one python version * Workaround for pypa/setuptools/issues/354... — committed to clu-ling/odinson-ruleutils by github-actions[bot] a year ago
- Workaround for pypa/setuptools/issues/3548 — committed to clu-ling/clu-template by myedibleenso a year ago
- Workaround for pypa/setuptools/issues/3548 (#23) — committed to clu-ling/clu-template by myedibleenso a year ago
- Workaround for pypa/setuptools/issues/3548 (#23) 41cde7b65ef06c6a01c08eded03b1e45c0d5800b — committed to clu-ling/clu-template by github-actions[bot] a year ago
- Workaround for pypa/setuptools/issues/3548 (#23) 41cde7b65ef06c6a01c08eded03b1e45c0d5800b — committed to clu-ling/clu-template by github-actions[bot] a year ago
- BLD: fix editable installs * this allows `pip install -e .` to produce a working editable install locally * the basis for the `setuptools` pin here is based on reading through https://github.com/pyp... — committed to Snell1224/darshan by tylerjereddy a year ago
Hi @lonetwin,
pkgutil.iter_modules
does not cover the same spectrum as theimportlib
machinery: it is much more limited.Based on this comment I would say that (so far) the stdlib developers have no intention the increase the scope or add features to
pkgutil
. The phrase used was: pkgutil is on its way out as soon as people have the time to deprecate it.If you absolutely need to use
pkgutil
you can try to opt into a different editable installation mode (e.g.pip install -e . --config-settings editable_mode=strict
) – I haven’t tested it myself, so I am not sure it will work.This is likely because setuptools released a new mechanism for implementing editable installs, as part of their PEP600 support. The pdoc3 project is probably not yet aware of the new mechanism, and will need updating.
There isn’t really anything for pip to do here, so I’m closing this issue. If it turns out that there is a pip problem here, feel free to reopen it.
@pfmoore This is likely going to create a lot of havoc. Editable install is how people operate in Python community. And if all of a sudden, entire tooling around editable install is going to break, then likely we must be planning better around it.
My 2 cents. May be, instead of enforcing the new mechanism as default, this could have been an opt in to start with. Instead of fighting this out, we decided to simply pin setuptools
"setuptools <= 62.6.0"
. While this has put us out of misery, we are now stuck in the past. FWIW, new mechanism has decided to return aPath
which returns in__path_hook__
as part of namespace. While that file actually doesn’t exist on the disk.Have you tried Hatchling?
@ofek Airlfow is an ASF project and community makes decisions not me personally. If you want to make a POC and have some good arguments, you will have to start dicsussion at the airflow devlist https://airflow.apache.org/community/ . But you have to - in general - have a good reasoning and justification for such a change in build system. just fixing an error that we can fix without switching to another build mechanism is not good enough reason.
Thanks for the pointer @abravalheri . I will take a closer look and see if I can work it out. I was kinda suspecting that we could have been doing something that PEP 660 does not really like 😃. I will keep you posted.
Hi @abhinavsingh,
Could you provide a minimal reproducer explaining more in details the issues you are having? (Maybe it is worthy to split multiple issues in multiple reproducers).
I tried to investigate what you are describing with the following reproducer, but I was not able to find the problematic behaviour you are referring to… (Maybe I understood something wrong? Or maybe the reproducer is missing something? Or – best case scenario – the problem might have already gotten solved in the latest release?).
As you can see above, the reproducer show that whenever possible
setuptools
will add the corresponding path entry to__path__
. Cases when this does not occur are likely associated with configurations by which users explicitly opt out from certain packages or there is simply no directory in the file system for the package to be associated with…There are a few other remarks I would like to make:
In Python, path entries do not need to be existing locations in the file system, this is mentioned in Python docs:
We can also demonstrate this with the following snippet:
Most static analysis tools (including the ones used in code editors) have limitations in terms of aspects of the Python language they cannot handle. Import hooks (which have been part of the Python language specification for years, and are listed in PEP 660 as a perfectly viable implementation for editable installs), are notably one of these limitations. This is reported in https://github.com/pypa/setuptools/issues/3518. Setuptools understand this limitation, and I am personally happy to contribute to an effort of improving this. However we do need someone to champion a design/architecture/standard that is well received in both packaging and static analysis community. I recommend anyone interested in pushing this forward to engage in the mailing list discussion, or on the thread on discourse.
I would also recommend setuptools’ docs on editable installs. There might be some useful information there.