Skip to content
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

[BUG] Editable wheel match import paths that are not theirs #3561

Closed
proto3 opened this issue Aug 24, 2022 · 4 comments · Fixed by #3562
Closed

[BUG] Editable wheel match import paths that are not theirs #3561

proto3 opened this issue Aug 24, 2022 · 4 comments · Fixed by #3562
Labels

Comments

@proto3
Copy link

proto3 commented Aug 24, 2022

setuptools version

65.2.0

Python version

3.10.6

OS

Ubuntu 20.04

Additional environment information

No response

Description

I'm currently working with two packages having names beginning the same, let's call them foo and foobar for example.
I install both of them using pip install -e, and both can be imported normally:

#!/usr/bin/env python
import foo
import foobar

Now I add a module bar in the foo package, so I can import foo, foobar and foo.bar
But importing foobar now always result in importing foo.bar

#!/usr/bin/env python
import foobar # PROBLEM this actually import foo.bar

Expected behavior

Importing foobar should never result in importing foo.bar instead.

How to Reproduce

#├── project1
#│   ├── foo
#│   │   ├── bar
#│   │   │   └── __init__.py
#│   │   └── __init__.py
#│   ├── pyproject.toml
#│   └── setup.cfg
#
#├─ project2
#│   ├── foobar
#│   │   └── __init__.py
#│   ├── pyproject.toml
#│   └── setup.cfg

# Commands to reproduce the same layout
mkdir -p project1/foo/bar
mkdir -p project2/foobar
touch project1/pyproject.toml 
touch project1/pyproject.toml
touch project1/setup.cfg
touch project1/setup.cfg
echo print\(\"Hello from foo\"\) > project1/foo/__init__.py
echo print\(\"Hello from foo.bar\"\) > project1/foo/bar/__init__.py
echo print\(\"Hello from foobar\"\) > project2/foobar/__init__.py
# Commands to reproduce the error
pip install -e project1
pip install -e project2
python
>>> import foobar
Hello from foo.bar # ERROR it should be foobar, not foo.bar

Output

pip install -e project1
pip install -e project2
python
>>> import foobar
Hello from foobar # This is what we expect
@proto3 proto3 added bug Needs Triage Issues that need to be evaluated for severity and status. labels Aug 24, 2022
@proto3
Copy link
Author

proto3 commented Aug 24, 2022

With debugger I can see the moment when foo.bar is chosen in place of foobar:

if fullname.startswith(pkg):

When fullname is "foobar" and pkg is "foo", it enter the if while it should not.

Using if fullname.split(".")[0] == pkg: instead would fix the problem by only comparing pkg to the first path item.

@abravalheri
Copy link
Contributor

Thank you very much for reporting this @proto3, I am working on a PR.

@abravalheri abravalheri removed the Needs Triage Issues that need to be evaluated for severity and status. label Aug 24, 2022
@proto3
Copy link
Author

proto3 commented Aug 24, 2022

This was so fast 😃
I can already use the new release, thanks a lot !

@abravalheri
Copy link
Contributor

abravalheri commented Aug 24, 2022

This was so fast 😃

The reporting was excellent, it helped a lot! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants