Skip to content

Commit

Permalink
Discard un-find-able existing pins in favor of a find-able match
Browse files Browse the repository at this point in the history
Fixes jazzband#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.
  • Loading branch information
AndydeCleyre committed Nov 22, 2022
1 parent 6e503bd commit 0b61399
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
12 changes: 6 additions & 6 deletions piptools/repositories/local.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 0b61399

Please sign in to comment.