From 69e88293bbc0c9915ded9eb0c2200455fb062d91 Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Wed, 24 Apr 2019 12:10:03 +0700 Subject: [PATCH] Fix pip>=19.1 compatibility --- piptools/repositories/pypi.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/piptools/repositories/pypi.py b/piptools/repositories/pypi.py index 08449d808..0f218443c 100644 --- a/piptools/repositories/pypi.py +++ b/piptools/repositories/pypi.py @@ -144,7 +144,16 @@ def find_best_match(self, ireq, prereleases=None): matching_candidates = [candidates_by_version[ver] for ver in matching_versions] if not matching_candidates: raise NoCandidateFound(ireq, all_candidates, self.finder) - best_candidate = max(matching_candidates, key=self.finder._candidate_sort_key) + + # pip <= 19.0.3 + if hasattr(self.finder, "_candidate_sort_key"): + best_candidate = max( + matching_candidates, key=self.finder._candidate_sort_key + ) + # pip >= 19.1 + else: + evaluator = self.finder.candidate_evaluator + best_candidate = evaluator.get_best_candidate(matching_candidates) # Turn the candidate into a pinned InstallRequirement return make_install_requirement(