From e8129c5e8b87b7eaa6a846fb3eb1c8cd8d3383b6 Mon Sep 17 00:00:00 2001 From: Vincent Philippon Date: Thu, 23 Nov 2017 20:49:43 -0500 Subject: [PATCH] Slightly improved NoCandidateFound error message. --- piptools/exceptions.py | 9 ++++++++- piptools/repositories/pypi.py | 2 +- tests/conftest.py | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/piptools/exceptions.py b/piptools/exceptions.py index d2ced265d..66df316fa 100644 --- a/piptools/exceptions.py +++ b/piptools/exceptions.py @@ -3,9 +3,10 @@ class PipToolsError(Exception): class NoCandidateFound(PipToolsError): - def __init__(self, ireq, candidates_tried): + def __init__(self, ireq, candidates_tried, index_urls): self.ireq = ireq self.candidates_tried = candidates_tried + self.index_urls = index_urls def __str__(self): sorted_versions = sorted(c.version for c in self.candidates_tried) @@ -13,6 +14,12 @@ def __str__(self): 'Could not find a version that matches {}'.format(self.ireq), 'Tried: {}'.format(', '.join(str(version) for version in sorted_versions) or '(no version found at all)') ] + if sorted_versions: + lines.append('There are incompatible versions in the resolved dependencies.') + else: + lines.append('{} {} reachable?'.format( + 'Were' if len(self.index_urls) > 1 else 'Was', ' or '.join(self.index_urls)) + ) return '\n'.join(lines) diff --git a/piptools/repositories/pypi.py b/piptools/repositories/pypi.py index 603eca7f6..26b0d080c 100644 --- a/piptools/repositories/pypi.py +++ b/piptools/repositories/pypi.py @@ -115,7 +115,7 @@ def find_best_match(self, ireq, prereleases=None): # Reuses pip's internal candidate sort key to sort matching_candidates = [candidates_by_version[ver] for ver in matching_versions] if not matching_candidates: - raise NoCandidateFound(ireq, all_candidates) + raise NoCandidateFound(ireq, all_candidates, self.finder.index_urls) best_candidate = max(matching_candidates, key=self.finder._candidate_sort_key) # Turn the candidate into a pinned InstallRequirement diff --git a/tests/conftest.py b/tests/conftest.py index e8eda9394..d1d79b5a2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -36,7 +36,7 @@ def find_best_match(self, ireq, prereleases=False): versions = list(ireq.specifier.filter(self.index[key_from_req(ireq.req)], prereleases=prereleases)) if not versions: - raise NoCandidateFound(ireq, self.index[key_from_req(ireq.req)]) + raise NoCandidateFound(ireq, self.index[key_from_req(ireq.req)], ['https://fake.url.foo']) best_version = max(versions, key=Version) return make_install_requirement(key_from_req(ireq.req), best_version, ireq.extras, constraint=ireq.constraint)