-
Notifications
You must be signed in to change notification settings - Fork 3.1k
pip-25.0.1 runs setup.py with broken import behaviour #13289
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
Comments
The same problem also occurs on Windows (needs some minor modifications to the script). |
Isn't this standard Python behavior? If you create a directory or Python file in the same directory, then it becomes importable, and has higher precedence than standard library modules. What else would you expect? What if someone was importing a local module with that name? |
I don't think it is standard Python behaviour - i think a local directory needs to have a Without a BTW i can't provide exact references to PEPs etc for this, import is pretty complicated and i don't pretend to understand all the details. But i do know that pip-25.0.1 has changed how setup's import statements behave. |
No, see PEP 420 - Implicit Namespace Packages. Plain directories have been importable since Python 3.3. |
could pypa/pyproject-hooks#199 be related i suspect it may start to identify the local platform directory as viable namespace package with that but i haven't verified that idea |
i suspect this may be a bug in behaviour of the meta path finder in pyproject hook i believe its expected to try if another path hook find this as a non-namespace package before designating it as such |
pypa/pyproject-hooks#207 looks like a very matching explanation i beleive the reproducer can be turned into a regression test for pyproject hooks |
Ah, apologies, i was completely unaware of this. [But presumably there's still a problem with pip-25.0.1 because the built-in |
About namespace packages: creating an empty |
Is there something going on beyond messing with the path? If I put
into
That is, unless python silently discards a circular import. |
It gets even more interesting. Even if
the |
pip 25/pyproject_hooks 1.2.0 inserts `_BackendPathFinder` into `sys.meta_path` at index 0, and that makes the import machinery find the directory `platform` as a namespace instead of importing the standrd platform module. Work around by removing this finder from `sys.meta_path` if it is present at index 0. Upstream bug: pypa/pip#13289
So it seems to be pyproject_hooks injecting its own Finder into |
In pip 25.0 pyproject-hooks was upgraded from 1.0.0 to 1.2.0, so if it was a consequence of a change from pyproject-hooks then it should be one of these PRs: https://github.com/pypa/pyproject-hooks/pulls?q=is%3Apr+is%3Amerged+merged%3A2022-11-22..2024-09-29 To me, the obvious candidates are pypa/pyproject-hooks#165 and the follow up PR pypa/pyproject-hooks#193 |
AFAICT it is commit 084b02e in pyprojetc-hooks which looks like a big squash of several commits. It is beyond me why people do that - it prevents isolated reverts, let alone bisecting. It's the last commit in a PR which - originally - consisted of 1 commit only but got rebased/rewritten meanwhile, it seems. So it clearly is the |
pip 25/pyproject_hooks 1.2.0 inserts `_BackendPathFinder` into `sys.meta_path` at index 0, and that makes the import machinery find the directory `platform` as a namespace instead of importing the standrd platform module. Work around by removing this finder from `sys.meta_path` if it is present at index 0. Upstream bug: pypa/pip#13289
Description
pip-25.0.1 appears to run setup.py in such a way that
import platform
picks up a localplatform/
directory if it exists, instead of the built-in module.This happens if
platform/
is empty, or if it contains other files and directories without a__init__.py
file.I include a Python script that shows the broken behaviour.
./pipbug.py
.pyproject.toml
file, a (non-working)setup.py
and an emptyplatform/
directory.Expected behavior
import platform
should get the built-in module regardless of whether there is a localplatform
directory.pip version
25.0.1
Python version
3.11 and 3.12.
OS
Linux, OpenBSD.
How to Reproduce
Run this Python script as file
pipbug.py
:Output
Example output on Linux is below.
AttributeError: module 'platform' has no attribute 'system'
, becauseimport platform
has picked up the local emptyplatform
directory instead of the built-in moduleplatform
.Code of Conduct
The text was updated successfully, but these errors were encountered: