Skip to content

Commit

Permalink
Slightly improved NoCandidateFound error message.
Browse files Browse the repository at this point in the history
  • Loading branch information
vphilippon committed Nov 24, 2017
1 parent 79e81dc commit e8129c5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion piptools/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ 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)
lines = [
'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)


Expand Down
2 changes: 1 addition & 1 deletion piptools/repositories/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit e8129c5

Please sign in to comment.