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

uninstall doesn't remove scripts installed in 'editable' mode #5997

Open
bjmuld opened this issue Nov 8, 2018 · 11 comments
Open

uninstall doesn't remove scripts installed in 'editable' mode #5997

bjmuld opened this issue Nov 8, 2018 · 11 comments
Labels
project: setuptools Related to setuptools type: bug A confirmed bug or unintended behavior

Comments

@bjmuld
Copy link

bjmuld commented Nov 8, 2018

Environment

  • pip version: 18
  • Python version: 3.6
  • OS: ubuntu 18.04

Description
installed (setuputils) package with '-e' flag. uninstalled package. package scripts remain.

Expected behavior
uninstalling package should remove package scripts.

How to Reproduce

  1. install package with pip install -e which includes scripts=[] in the setup.py
  2. uninstall same package with pip uninstall
  3. observe that scripts are still on path
@uranusjr
Copy link
Member

uranusjr commented Nov 9, 2018

I can replicate this. Note that this only applies to editable requirements, and only to scripts (not entry_points.console_scripts).

(Also: You likely should use entry_points instead of scripts anyway.)


Edit: I di some digging and it seems the problem is that .egg-info does not record scripts installation at all. I am not sure whether this is intentional (to favour entry_points).

@xavfernandez xavfernandez added the type: bug A confirmed bug or unintended behavior label Nov 9, 2018
@xavfernandez
Copy link
Member

it seems the problem is that .egg-info does not record scripts installation at all.

This would mean the issue is on setuptools side ?

@uranusjr
Copy link
Member

uranusjr commented Nov 9, 2018

Kind of both, I guess? setuptools needs to record installed scripts, and pip needs to use that information during uninstallation to remove them.

@xavfernandez
Copy link
Member

Indeed, the uninstall should happen here

if dist.has_metadata('scripts') and dist.metadata_isdir('scripts'):
for script in dist.metadata_listdir('scripts'):
if dist_in_usersite(dist):
bin_dir = bin_user
else:
bin_dir = bin_py
paths_to_remove.add(os.path.join(bin_dir, script))
if WINDOWS:
paths_to_remove.add(os.path.join(bin_dir, script) + '.bat')
🤔

@bjmuld
Copy link
Author

bjmuld commented Nov 9, 2018

(Also: You likely should use entry_points instead of scripts anyway.)

I require bash scripts... was under the impression that entry_points will only offer entry to python?

Also, I might suggest that material installed into /bin be symlinked if the install is --editable ??

@uranusjr
Copy link
Member

uranusjr commented Nov 9, 2018

Also, I might suggest that material installed into /bin be symlinked if the install is --editable ??

This would need to be raised to setuptools instead. I don’t think it would be accepted, however, with the same reasons why the library itself is not symlinked, but using egg-link.

@cjerdonek cjerdonek added the project: setuptools Related to setuptools label Nov 10, 2018
dstein64 added a commit to dstein64/vimgolf that referenced this issue Feb 27, 2019
This avoids an issue where pip doesn't install the scripts.
pypa/pip#513
pypa/pip#5997
@DaanDeMeyer
Copy link
Contributor

This seems to be a problem when using console_scripts as well.

Reproduce:

git clone https://github.com/behrmann/mkosi --branch entrypoint
cd mkosi
pip install --user -e .
pip uninstall mkosi
ls ~/.local/bin/mkosi

@behrmann
Copy link

behrmann commented Aug 8, 2020

To further specify this, the problem does not appear, when installing with the consolce_scripts entrypoint in a virtual environment, only globally (with --user though).

@DaanDeMeyer
Copy link
Contributor

Strace shows us that pip tries to remove the file in the wrong location:

stat("/home/daan/.local/lib/python3.8/site-packages/bin/mkosi", 0x7ffc971ee2d0) = -1 ENOENT (No such file or directory)

It tries to go via site-packages while the script is actually in /home/daan/.local/bin

@behrmann
Copy link

behrmann commented Aug 8, 2020

The reason for this seems to be that _script_names in _internal/req/req_uninstall.py uses bin_user from _internal/locations.py, which is bin_user = os.path.join(user_site, 'bin') on Linux and user_site is set via

 try:
     # Use getusersitepackages if this is present, as it ensures that the
     # value is initialised properly.
     user_site = site.getusersitepackages()
 except AttributeError:
     user_site = site.USER_SITE

evaluating to

>>> import site
>>> site.getusersitepackages()
'/home/user/.local/lib/python3.8/site-packages'

@DaanDeMeyer
Copy link
Contributor

After systemd/mkosi@0e477de, the script gets uninstalled correctly on pip uninstall mkosi. @behrmann Can you verify this as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
project: setuptools Related to setuptools type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

No branches or pull requests

6 participants