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

Added clearer error reporting when skipping pre-releases #655

Merged
merged 2 commits into from
Apr 26, 2018
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
34 changes: 28 additions & 6 deletions piptools/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,44 @@ class PipToolsError(Exception):


class NoCandidateFound(PipToolsError):
def __init__(self, ireq, candidates_tried, index_urls):
def __init__(self, ireq, candidates_tried, finder):
self.ireq = ireq
self.candidates_tried = candidates_tried
self.index_urls = index_urls
self.finder = finder

def __str__(self):
sorted_versions = sorted(c.version for c in self.candidates_tried)
versions = []
pre_versions = []

for candidate in sorted(self.candidates_tried):
version = str(candidate.version)
if candidate.version.is_prerelease:
pre_versions.append(version)
else:
versions.append(version)

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:

if versions:
lines.append('Tried: {}'.format(', '.join(versions)))

if pre_versions:
if self.finder.allow_all_prereleases:
line = 'Tried'
else:
line = 'Skipped'

line += ' pre-versions: {}'.format(', '.join(pre_versions))
lines.append(line)

if versions or pre_versions:
lines.append('There are incompatible versions in the resolved dependencies.')
else:
lines.append('No versions found')
lines.append('{} {} reachable?'.format(
'Were' if len(self.index_urls) > 1 else 'Was', ' or '.join(self.index_urls))
'Were' if len(self.finder.index_urls) > 1 else 'Was', ' or '.join(self.finder.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 @@ -104,7 +104,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, self.finder.index_urls)
raise NoCandidateFound(ireq, all_candidates, self.finder)
best_candidate = max(matching_candidates, key=self.finder._candidate_sort_key)

# Turn the candidate into a pinned InstallRequirement
Expand Down
24 changes: 24 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,27 @@ def test_filter_pip_markes():
assert '--output-file requirements.txt' in out.output
assert 'six==1.10.0' in out.output
assert 'unknown_package' not in out.output


def test_no_candidates():
runner = CliRunner()
with runner.isolated_filesystem():
with open('requirements', 'w') as req_in:
req_in.write('six>1.0b0,<1.0b0')

out = runner.invoke(cli, ['-n', 'requirements'])

assert out.exit_code == 2
assert 'Skipped pre-versions:' in out.output


def test_no_candidates_pre():
runner = CliRunner()
with runner.isolated_filesystem():
with open('requirements', 'w') as req_in:
req_in.write('six>1.0b0,<1.0b0')

out = runner.invoke(cli, ['-n', 'requirements', '--pre'])

assert out.exit_code == 2
assert 'Tried pre-versions:' in out.output
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ envlist =
py{27,34,35,36,py}
flake8
readme
skip_missing_interpreters = True

[testenv]
deps =
Expand Down