pip-tools icon indicating copy to clipboard operation
pip-tools copied to clipboard

Disregard existing pins in the output which can't be found by pip, rather than failing to compile

Open AndydeCleyre opened this issue 4 years ago • 1 comments

Before running pip-compile, the output file may contain a pinned requirement which can't be found in PyPI or whichever repo (e.g. a revoked release). This change aims to disregard these un-find-able pins, rather than cause the compile operation to fail.

Fixes #1530

Contributor checklist
  • [x] Provided the tests for the changes.
  • [ ] Assure PR title is short, clear, and good to be included in the user-oriented changelog
Maintainer checklist
  • [ ] Assure one of these labels is present: backwards incompatible, feature, enhancement, deprecation, bug, dependency, docs or skip-changelog as they determine changelog listing.
  • [ ] Assign the PR to an existing or new milestone for the target version (following Semantic Versioning).

AndydeCleyre avatar Nov 09 '21 19:11 AndydeCleyre

The function could be restyled smaller, but it may be less obvious to read:

diff --git a/piptools/repositories/local.py b/piptools/repositories/local.py
index 07dd070..75a594e 100644
--- a/piptools/repositories/local.py
+++ b/piptools/repositories/local.py
@@ -1,5 +1,5 @@
 import optparse
-from contextlib import contextmanager
+from contextlib import contextmanager, suppress
 from typing import Iterator, Mapping, Optional, Set, cast
 
 from pip._internal.index.package_finder import PackageFinder
@@ -71,12 +71,9 @@ class LocalRequirementsRepository(BaseRepository):
         key = key_from_ireq(ireq)
         existing_pin = self.existing_pins.get(key)
         if existing_pin and ireq_satisfied_by_existing_pin(ireq, existing_pin):
-            try:
+            with suppress(NoCandidateFound):
                 return self.repository.find_best_match(existing_pin, prereleases)
-            except NoCandidateFound:
-                return self.repository.find_best_match(ireq, prereleases)
-        else:
-            return self.repository.find_best_match(ireq, prereleases)
+        return self.repository.find_best_match(ireq, prereleases)
 
     def get_dependencies(self, ireq: InstallRequirement) -> Set[InstallRequirement]:
         return self.repository.get_dependencies(ireq)

AndydeCleyre avatar Nov 10 '21 04:11 AndydeCleyre