Skip to content

Commit

Permalink
Fix uninstallation of user scripts
Browse files Browse the repository at this point in the history
User scripts are installed to ~/.local/bin. pip was looking for scripts
to uninstall in ~/.local/lib/python3.8/site-packages/bin. This commit
makes it look in ~/.local/bin instead.
  • Loading branch information
DaanDeMeyer committed Aug 8, 2020
1 parent 2e4d748 commit 6330493
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions news/8733.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Correctly uninstall scripts installed with --user
12 changes: 10 additions & 2 deletions src/pip/_internal/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,24 @@ def get_src_prefix():
except AttributeError:
user_site = site.USER_SITE

def _get_bin_user():
scheme = "{}_user".format(os.name)
if scheme not in sysconfig.get_scheme_names():
scheme = "posix_user" # Default to POSIX for unknown platforms.
path = sysconfig.get_path("scripts", scheme=scheme)
assert path is not None
return path

bin_user = _get_bin_user()

if WINDOWS:
bin_py = os.path.join(sys.prefix, 'Scripts')
bin_user = os.path.join(user_site, 'Scripts')
# buildout uses 'bin' on Windows too?
if not os.path.exists(bin_py):
bin_py = os.path.join(sys.prefix, 'bin')
bin_user = os.path.join(user_site, 'bin')
else:
bin_py = os.path.join(sys.prefix, 'bin')
bin_user = os.path.join(user_site, 'bin')

# Forcing to use /usr/local/bin for standard macOS framework installs
# Also log to ~/Library/Logs/ for use with the Console.app log viewer
Expand Down
2 changes: 2 additions & 0 deletions src/pip/_internal/req/req_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def _script_names(dist, script_name, is_gui):
bin_dir = bin_user
else:
bin_dir = bin_py
assert bin_dir is not None
exe_name = os.path.join(bin_dir, script_name)
paths_to_remove = [exe_name]
if WINDOWS:
Expand Down Expand Up @@ -562,6 +563,7 @@ def from_dist(cls, dist):
bin_dir = bin_user
else:
bin_dir = bin_py
assert bin_dir is not None
paths_to_remove.add(os.path.join(bin_dir, script))
if WINDOWS:
paths_to_remove.add(os.path.join(bin_dir, script) + '.bat')
Expand Down

0 comments on commit 6330493

Please sign in to comment.