8000 [BUG] PEP-660 editable installs import issue based on package name and CWD · Issue #3592 · pypa/setuptools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[BUG] PEP-660 editable installs import issue based on package name and CWD #3592

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

Closed
noah-weingarden opened this issue Sep 15, 2022 · 1 comment
Labels
bug Needs Triage Issues that need to be evaluated for severity and status.

Comments

@noah-weingarden
Copy link
noah-weingarden commented Sep 15, 2022

setuptools version

setuptools==65.3.0

Python version

Python 3.10 or Python 3.8

OS

Ubuntu 22.04

Additional environment information

pip==22.2.2

Description

If I install a package with a PEP 660 editable install using a pyproject.toml file and no setup.py file, and the package's parent directory has the same name as the package directory itself, Python fails to fully import the package specifically when my CWD is the grandparent of the package directory. That is, I can import the package, but I can't access its non-built-in attributes, and its __spec__ attribute includes loader=<_frozen_importlib_external._NamespaceLoader even though there are no namespace packages involved here. If my CWD is any other directory, I don't encounter this issue, and if I ensure that the package directory has a different name than its parent, I don't encounter this issue. This also isn't an issue when using setup.py instead of pyproject.toml.

Expected behavior

I expect to be able to import from an editable install with a venv activated regardless of my CWD and regardless of whether or not the package's name is the same as its parent directory.

How to Reproduce

I made a minimal reproducible example here: https://github.com/noah-weingarden/setuptools-mre

This is the directory structure:

.
├── bugexample
│   ├── bugexample
│   │   └── __init__.py
│   └── pyproject.toml
└── workingexample
    ├── pyproject.toml
    └── working
        └── __init__.py

Output

$ pwd
/home/noah/setuptools-bug-demo
$ python3 -m venv env
$ source env/bin/activate
$ pip install --upgrade pip setuptools wheel
$ pip install -e bugexample
$ pip install -e workingexample
$ python
>>> import bugexample
>>> import working
>>> bugexample.obj
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'bugexample' has no attribute 'obj'
>>> working.obj
'Yay! :D'
cd ~
python

(I think any other directory would also work.)

>>> import bugexample
>>> import working
>>> bugexample.obj
'Oh no!'
>>> working.obj
'Yay! :D'
@noah-weingarden noah-weingarden added bug Needs Triage Issues that need to be evaluated for severity and status. labels Sep 15, 2022
@noah-weingarden
Copy link
Author

Sorry, I think this is a duplicate of #3557.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Needs Triage Issues that need to be evaluated for severity and status.
Projects
None yet
Development

No branches or pull requests

1 participant
0