Skip to content

Commit 3417fac

Browse files
authored
Merge pull request #3898 from xavfernandez/check_if_exists_editable
Make pip install -e uninstall existing versions
2 parents da22abb + 65a82a2 commit 3417fac

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

CHANGES.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
**8.2.0 (unreleased)**
22

3+
* Uninstall existing packages when performing an editable installation of
4+
the same packages (:issue:`1548`).
5+
36
* Pip show is less verbose by default. `--verbose` prints multiline fields
47

58
* Added optional column formatting to ``pip list`` (:issue:`3651`).

pip/req/req_install.py

+6
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,12 @@ def check_if_exists(self):
10041004
no_marker = Requirement(str(self.req))
10051005
no_marker.marker = None
10061006
self.satisfied_by = pkg_resources.get_distribution(str(no_marker))
1007+
if self.editable and self.satisfied_by:
1008+
self.conflicts_with = self.satisfied_by
1009+
# when installing editables, nothing pre-existing should ever
1010+
# satisfy
1011+
self.satisfied_by = None
1012+
return True
10071013
except pkg_resources.DistributionNotFound:
10081014
return False
10091015
except pkg_resources.VersionConflict:

pip/req/req_set.py

+1
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ def _prepare_file(self,
489489
abstract_dist.prep_for_dist()
490490
if self.is_download:
491491
req_to_install.archive(self.download_dir)
492+
req_to_install.check_if_exists()
492493
elif req_to_install.satisfied_by:
493494
if require_hashes:
494495
logger.debug(

tests/functional/test_install.py

+50
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,56 @@ def test_install_editable_from_git_autobuild_wheel(script, tmpdir):
179179
_test_install_editable_from_git(script, tmpdir, True)
180180

181181

182+
def test_install_editable_uninstalls_existing(data, script, tmpdir):
183+
"""
184+
Test that installing an editable uninstalls a previously installed
185+
non-editable version.
186+
https://github.com/pypa/pip/issues/1548
187+
https://github.com/pypa/pip/pull/1552
188+
"""
189+
to_install = data.packages.join("pip-test-package-0.1.tar.gz")
190+
result = script.pip_install_local(to_install)
191+
assert 'Successfully installed pip-test-package' in result.stdout
192+
result.assert_installed('piptestpackage', editable=False)
193+
194+
result = script.pip(
195+
'install', '-e',
196+
'%s#egg=pip-test-package' %
197+
local_checkout(
198+
'git+http://github.com/pypa/pip-test-package.git',
199+
tmpdir.join("cache"),
200+
),
201+
)
202+
result.assert_installed('pip-test-package', with_files=['.git'])
203+
assert 'Found existing installation: pip-test-package 0.1' in result.stdout
204+
assert 'Uninstalling pip-test-package-' in result.stdout
205+
assert 'Successfully uninstalled pip-test-package' in result.stdout
206+
207+
208+
def test_install_editable_uninstalls_existing_from_path(script, data):
209+
"""
210+
Test that installing an editable uninstalls a previously installed
211+
non-editable version from path
212+
"""
213+
to_install = data.src.join('simplewheel-1.0')
214+
result = script.pip_install_local(to_install)
215+
assert 'Successfully installed simplewheel' in result.stdout
216+
simple_folder = script.site_packages / 'simple'
217+
result.assert_installed('simple', editable=False)
218+
assert simple_folder in result.files_created, str(result.stdout)
219+
220+
result = script.pip(
221+
'install', '-e',
222+
to_install,
223+
)
224+
install_path = script.site_packages / 'simplewheel.egg-link'
225+
assert install_path in result.files_created, str(result)
226+
assert 'Found existing installation: simplewheel 1.0' in result.stdout
227+
assert 'Uninstalling simplewheel-' in result.stdout
228+
assert 'Successfully uninstalled simplewheel' in result.stdout
229+
assert simple_folder in result.files_deleted, str(result.stdout)
230+
231+
182232
def test_install_editable_from_hg(script, tmpdir):
183233
"""Test cloning from Mercurial."""
184234
pkg_path = _create_test_package(script, name='testpackage', vcs='hg')

0 commit comments

Comments
 (0)