From ce46a5e36d0ed3499c38df3bedf4ac4eb1ed9bc2 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Thu, 19 Nov 2020 15:39:00 +0000 Subject: [PATCH] Re-install local candidates unconditionally Signed-off-by: Pradyun Gedam --- .../resolution/resolvelib/resolver.py | 8 +++- tests/functional/test_new_resolver.py | 40 +++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/pip/_internal/resolution/resolvelib/resolver.py b/src/pip/_internal/resolution/resolvelib/resolver.py index e2e164d12..6290d2fe3 100644 --- a/src/pip/_internal/resolution/resolvelib/resolver.py +++ b/src/pip/_internal/resolution/resolvelib/resolver.py @@ -132,15 +132,19 @@ class Resolver(BaseResolver): # Check if there is already an installation under the same name, # and set a flag for later stages to uninstall it, if needed. - # * There isn't, good -- no uninstalltion needed. + # + # * There is no existing installation. Nothing to uninstall. + # * The candidate is a local path/file. Always reinstall. # * The --force-reinstall flag is set. Always reinstall. # * The installation is different in version or editable-ness, so # we need to uninstall it to install the new distribution. # * The installed version is the same as the pending distribution. - # Skip this distrubiton altogether to save work. + # Skip this distribution altogether to save work. installed_dist = self.factory.get_dist_to_uninstall(candidate) if installed_dist is None: ireq.should_reinstall = False + elif candidate.source_link.is_file: + ireq.should_reinstall = True elif self.factory.force_reinstall: ireq.should_reinstall = True elif installed_dist.parsed_version != candidate.version: diff --git a/tests/functional/test_new_resolver.py b/tests/functional/test_new_resolver.py index 45e1a0347..2c28ff20a 100644 --- a/tests/functional/test_new_resolver.py +++ b/tests/functional/test_new_resolver.py @@ -1193,3 +1193,43 @@ def test_new_resolver_contraint_on_dep_with_extra(script): "simple", ) assert_installed(script, simple="1", dep="1", depx="1") + + +def test_new_resolver_does_reinstall_local_wheels(script): + archive_path = create_basic_wheel_for_package( + script, + "pkg", + "1.0", + ) + script.pip( + "install", "--no-cache-dir", "--no-index", + archive_path, + ) + assert_installed(script, pkg="1.0") + + result = script.pip( + "install", "--no-cache-dir", "--no-index", + archive_path, + ) + assert "Installing collected packages: pkg" in result.stdout, str(result) + assert_installed(script, pkg="1.0") + + +def test_new_resolver_does_reinstall_local_paths(script): + pkg = create_test_package_with_setup( + script, + name="pkg", + version="1.0" + ) + script.pip( + "install", "--no-cache-dir", "--no-index", + pkg, + ) + assert_installed(script, pkg="1.0") + + result = script.pip( + "install", "--no-cache-dir", "--no-index", + pkg, + ) + assert "Installing collected packages: pkg" in result.stdout, str(result) + assert_installed(script, pkg="1.0")