From 0b61399442bcda568462ad954572549fbb0ad20f Mon Sep 17 00:00:00 2001 From: Andy Kluger Date: Tue, 9 Nov 2021 14:32:13 -0500 Subject: [PATCH] Discard un-find-able existing pins in favor of a find-able match Fixes #1530, the following case: When a needed package is already pinned in the output file, but has an invalid or at least unavailable version there, the compilation will fail. The logic change also: - doesn't bother building an ireq when we've got one already, from finding a match. --- piptools/repositories/local.py | 12 ++++++------ tests/test_cli_compile.py | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/piptools/repositories/local.py b/piptools/repositories/local.py index 76cbea8fc..81beb191c 100644 --- a/piptools/repositories/local.py +++ b/piptools/repositories/local.py @@ -1,7 +1,7 @@ from __future__ import annotations import optparse -from contextlib import contextmanager +from contextlib import contextmanager, suppress from typing import Iterator, Mapping, cast from pip._internal.commands.install import InstallCommand @@ -11,8 +11,9 @@ from pip._internal.req import InstallRequirement from pip._internal.utils.hashes import FAVORITE_HASH -from piptools.utils import as_tuple, key_from_ireq, make_install_requirement +from piptools.utils import key_from_ireq +from ..exceptions import NoCandidateFound from .base import BaseRepository from .pypi import PyPIRepository @@ -78,10 +79,9 @@ def find_best_match( key = key_from_ireq(ireq) existing_pin = self.existing_pins.get(key) if existing_pin and ireq_satisfied_by_existing_pin(ireq, existing_pin): - project, version, _ = as_tuple(existing_pin) - return make_install_requirement(project, version, ireq) - else: - return self.repository.find_best_match(ireq, prereleases) + with suppress(NoCandidateFound): + return self.repository.find_best_match(existing_pin, prereleases) + return self.repository.find_best_match(ireq, prereleases) def get_dependencies(self, ireq: InstallRequirement) -> set[InstallRequirement]: return self.repository.get_dependencies(ireq) diff --git a/tests/test_cli_compile.py b/tests/test_cli_compile.py index 066013382..891cd2307 100644 --- a/tests/test_cli_compile.py +++ b/tests/test_cli_compile.py @@ -1958,7 +1958,6 @@ def test_preserve_compiled_prerelease_version(pip_conf, runner): assert "small-fake-a==0.3b1" in out.stderr.splitlines() -@pytest.mark.xfail def test_ignore_compiled_unavailable_version(pip_conf, runner): with open("requirements.in", "w") as req_in: req_in.write("small-fake-a")