Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slightly improved NoCandidateFound error message. #614

Merged
merged 1 commit into from
Nov 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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