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

dist_is_editable incorrectly reports True when a non-editable dist shadows the editable #7782

Open
uranusjr opened this issue Feb 25, 2020 · 6 comments
Labels
S: needs triage Issues/PRs that need to be triaged

Comments

@uranusjr
Copy link
Member

Environment

  • pip version: 20.0.2 (probably goes way-back)
  • Python version: Any
  • OS: Any

Description

I noticed this when working on #7670.

After a currently-installed editable package is force reinstalled as non-editable, the dist_is_editable would still report True due to the lingering .egg-link file, creating an inconsistency, since the editable version of the package is shadowed in both sys.path and pkg_resources.

Expected behavior

pip should correctly report the package as non-editable.

How to Reproduce

$ python -m pip list
Package    Version
---------- -------
pip        20.0.2 
setuptools 45.2.0 
wheel      0.34.2 

$ python -m pip install -e git+https://github.com/benjaminp/six.git#egg=six
Obtaining six from git+https://github.com/benjaminp/six.git#egg=six
  Updating ./pip-play/src/six clone
  Running command git fetch -q --tags
  Running command git reset --hard -q 3a3db7510b33eb22c63ad94bc735a9032949249f
Installing collected packages: six
  Running setup.py develop for six
Successfully installed six

$ python -m pip list
Package    Version Location                     
---------- ------- -----------------------------
pip        20.0.2  
setuptools 45.2.0  
six        1.14.0  /private/tmp/pip-play/src/six
wheel      0.34.2  

$ python -m pip install -I six
Collecting six
  Using cached six-1.14.0-py2.py3-none-any.whl (10 kB)
Installing collected packages: six
Successfully installed six-1.14.0

$ python -m pip list
Package    Version Location                                         
---------- ------- -------------------------------------------------
pip        20.0.2  
setuptools 45.2.0  
six        1.14.0  /private/tmp/pip-play/lib/python3.7/site-packages
wheel      0.34.2

$ python -c 'import six; print(six.__file__)'
/private/tmp/pip-play/lib/python3.7/site-packages/six.py

Notice how the last list results included the Location column (suggesting six is editable), but the reported location (generated by pkg_resources) points to the non-editable one. The interpreter also finds the non-editable one over the editable installation.

@triage-new-issues triage-new-issues bot added the S: needs triage Issues/PRs that need to be triaged label Feb 25, 2020
@uranusjr uranusjr changed the title Inconsistency when editable package force-reinstalled without -e dist_is_editable incorrectly reports True when a non-editable dist shadows the editable Feb 25, 2020
@sbidoul
Copy link
Member

sbidoul commented Feb 25, 2020

I'm not sure what a fix would look like for this. At first glance I'd consider it normal to risk confusing results when installing with '-I'.

@uranusjr
Copy link
Member Author

One possibility is to also look for dist-info and egg-info when looping through sys.path, and return False if either is found before egg-link.

@sbidoul
Copy link
Member

sbidoul commented Jul 31, 2021

#10249 appears to resolve this, by using egg_link_path to detect legacy editable installs, in place of a search in sys.path.

@sbidoul
Copy link
Member

sbidoul commented Jul 31, 2021

That said, the sequence of steps described in this issue effectively leads to six being installed twice: once with .dist-info metadata in site package, and once with .egg-info metadata in sys.path (extended via easy-install.pth). So 🤷

@uranusjr
Copy link
Member Author

Installing a package multiple times is (unfortunately) valid in Python, and having a legacy editable install alongside with non-editable is not different from having one in system site and one in user site, from the Python interpreter’s prespective.

@sbidoul
Copy link
Member

sbidoul commented Aug 1, 2021

Yes. The problem is that neither pkg_resources nor importlib.metadata know about these .egg-link files so we have to have some heuristic to find it. And I don't know how we could be sure to do it in the same order as the machinery that list installed distributions.

So for now I will not attempt to fix this nor #10243 it in #10249. After all noboy really complains and these minor problems should fade away when PEP 660 is adopted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S: needs triage Issues/PRs that need to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants