Skip to content

Commit

Permalink
Merge pull request #8033 from pfmoore/messages
Browse files Browse the repository at this point in the history
Make message more user friendly when unable to resolve
  • Loading branch information
pfmoore authored Apr 15, 2020
2 parents e40d267 + 8c118c8 commit 2f3a1be
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/pip/_internal/resolution/resolvelib/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def __init__(self, ireq, factory):
self._factory = factory
self.extras = ireq.req.extras

def __str__(self):
# type: () -> str
return str(self._ireq.req)

def __repr__(self):
# type: () -> str
return "{class_name}({requirement!r})".format(
Expand Down
22 changes: 22 additions & 0 deletions src/pip/_internal/resolution/resolvelib/resolver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import functools
import logging

from pip._vendor import six
from pip._vendor.packaging.utils import canonicalize_name
Expand All @@ -25,6 +26,9 @@
from pip._internal.resolution.base import InstallRequirementProvider


logger = logging.getLogger(__name__)


class Resolver(BaseResolver):
def __init__(
self,
Expand Down Expand Up @@ -74,9 +78,27 @@ def resolve(self, root_reqs, check_supported_wheels):

try:
self._result = resolver.resolve(requirements)

except ResolutionImpossible as e:
error = self.factory.get_installation_error(e)
if not error:
# TODO: This needs fixing, we need to look at the
# factory.get_installation_error infrastructure, as that
# doesn't really allow for the logger.critical calls I'm
# using here.
for req, parent in e.causes:
logger.critical(
"Could not find a version that satisfies " +
"the requirement " +
str(req) +
("" if parent is None else " (from {})".format(
parent.name
))
)
raise InstallationError(
"No matching distribution found for " +
", ".join([r.name for r, _ in e.causes])
)
raise
six.raise_from(error, e)

Expand Down
35 changes: 35 additions & 0 deletions tests/functional/test_new_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,41 @@ def test_new_resolver_installs_extras(script):
assert_installed(script, base="0.1.0", dep="0.1.0")


def test_new_resolver_installed_message(script):
create_basic_wheel_for_package(script, "A", "1.0")
result = script.pip(
"install", "--unstable-feature=resolver",
"--no-cache-dir", "--no-index",
"--find-links", script.scratch_path,
"A",
expect_stderr=False,
)
assert "Successfully installed A-1.0" in result.stdout, str(result)


def test_new_resolver_no_dist_message(script):
create_basic_wheel_for_package(script, "A", "1.0")
result = script.pip(
"install", "--unstable-feature=resolver",
"--no-cache-dir", "--no-index",
"--find-links", script.scratch_path,
"B",
expect_error=True,
expect_stderr=True,
)

# Full messages from old resolver:
# ERROR: Could not find a version that satisfies the
# requirement xxx (from versions: none)
# ERROR: No matching distribution found for xxx

assert "Could not find a version that satisfies the requirement B" \
in result.stderr, str(result)
# TODO: This reports the canonical name of the project. But the current
# resolver reports the originally specified name (i.e. uppercase B)
assert "No matching distribution found for b" in result.stderr, str(result)


def test_new_resolver_installs_editable(script):
create_basic_wheel_for_package(
script,
Expand Down

0 comments on commit 2f3a1be

Please sign in to comment.