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

when uninstalling, look for the case of paths containing symlinked directories #3154

Merged
merged 4 commits into from
Oct 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
* Implement a top-level ``pip download`` command and deprecate
``pip install --download``.

* Fixed :issue:`3141`, when uninstalling, look for the case of paths containing
symlinked directories (:pull:`3154`)

* When installing, if building a wheel fails, clear up the build directory
before falling back to a source install. :issue:`3047`.

Expand Down
7 changes: 6 additions & 1 deletion pip/req/req_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ def _can_uninstall(self):
return True

def add(self, path):
path = normalize_path(path, resolve_symlinks=False)
head, tail = os.path.split(path)

# we normalize the head to resolve parent directory symlinks, but not
# the tail, since we only want to uninstall symlinks, not their targets
path = os.path.join(normalize_path(head), os.path.normcase(tail))

if not os.path.exists(path):
return
if self._permitted(path):
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/test_req_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,31 @@ def test_add_symlink(self, tmpdir, monkeypatch):
ups = UninstallPathSet(dist=Mock())
ups.add(l)
assert ups.paths == set([l])

def test_compact_shorter_path(self, monkeypatch):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is secondary, I just added this, because we had no unit test for this

monkeypatch.setattr(pip.req.req_uninstall, 'is_local', lambda p: True)
monkeypatch.setattr('os.path.exists', lambda p: True)
ups = UninstallPathSet(dist=Mock())
ups.add('/path')
ups.add('/path/longer')
assert ups.compact(ups.paths) == set(['/path'])

@pytest.mark.skipif("sys.platform == 'win32'")
def test_detect_symlink_dirs(self, monkeypatch, tmpdir):
monkeypatch.setattr(pip.req.req_uninstall, 'is_local', lambda p: True)

# construct 2 paths:
# tmpdir/dir/file
# tmpdir/dirlink/file (where dirlink is a link to dir)
d = tmpdir.join('dir')
d.mkdir()
dlink = tmpdir.join('dirlink')
os.symlink(d, dlink)
d.join('file').touch()
path1 = str(d.join('file'))
path2 = str(dlink.join('file'))

ups = UninstallPathSet(dist=Mock())
ups.add(path1)
ups.add(path2)
assert ups.paths == set([path1])