Skip to content

Remove existing package before develop mode install #3875

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

Closed
wants to merge 1 commit into from
Closed
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
24 changes: 21 additions & 3 deletions pip/req/req_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ def install(self, install_options, global_options=(), *args, **kwargs):
the packages)
"""
to_install = self._to_install()
editable_reinstall = False

if to_install:
logger.info(
Expand All @@ -734,6 +735,23 @@ def install(self, install_options, global_options=(), *args, **kwargs):
)
with indent_log():
requirement.uninstall(auto_confirm=True)

if requirement.installed_version and requirement.editable:
# If we have an existing installation but are
# re-installing as editable, make sure we remove
# the existing version. Note that with
# setuptools<25 this is not strictly required, as
# there setuptools will modify easy-install.pth to
# put the "develop" mode install first in sys.path
# (see SETUPTOOLS_SYS_PATH_TECHNIQUE), effectively
# overwriting the prior installed version.
logger.info(
'Found prior install %s, reinstalling for develop mode'
% requirement.installed_version)
with indent_log():
requirement.uninstall(auto_confirm=True)
editable_reinstall = True

try:
requirement.install(
install_options,
Expand All @@ -743,12 +761,12 @@ def install(self, install_options, global_options=(), *args, **kwargs):
)
except:
# if install did not succeed, rollback previous uninstall
if (requirement.conflicts_with and not
requirement.install_succeeded):
if ((requirement.conflicts_with or editable_reinstall) and
not requirement.install_succeeded):
requirement.rollback_uninstall()
raise
else:
if (requirement.conflicts_with and
if ((requirement.conflicts_with or editable_reinstall) and
requirement.install_succeeded):
requirement.commit_uninstall()
requirement.remove_temporary_source()
Expand Down
24 changes: 23 additions & 1 deletion tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from tests.lib import (pyversion, pyversion_tuple,
_create_test_package, _create_svn_repo, path_to_url,
requirements_file)
from tests.lib.local_repos import local_checkout
from tests.lib.local_repos import local_checkout, local_repo
from tests.lib.path import Path


Expand Down Expand Up @@ -1026,3 +1026,25 @@ def test_double_install_fail(script, data):
msg = ("Double requirement given: pip==7.1.2 (already in pip==*, "
"name='pip')")
assert msg in result.stderr


@pytest.mark.network
def test_update_to_develop(script, tmpdir):
"""
Test updating from install to develop mode removes original package
"""
path = local_repo(
'git+http://github.com/pypa/pip-test-package.git',
tmpdir.join("cache"),
)
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather not have a network related test if we can avoid it.
You could use an existing module like https://github.com/pypa/pip/blob/6dc28c1/tests/data/src/singlemodule#L799-L805
Then:

  • install it via its path
  • install it via editable
  • check that pip freeze/list report it as editable
  • uninstall it
  • check that all installation disappeared


# regular install, then re-install with develop mode
result = script.pip(
'install', '%s' % path, expect_error=False)
result = script.pip(
'install', '-e', '%s' % path, expect_error=False)

# make sure we have overwritten the non-develop install with the
# git version.
result = script.pip('freeze', expect_stderr=True)
assert 'pip-test-package.git' in result.stdout