Skip to content

Commit 2f3a1be

Browse files
authored
Merge pull request #8033 from pfmoore/messages
Make message more user friendly when unable to resolve
2 parents e40d267 + 8c118c8 commit 2f3a1be

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

src/pip/_internal/resolution/resolvelib/requirements.py

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def __init__(self, ireq, factory):
5050
self._factory = factory
5151
self.extras = ireq.req.extras
5252

53+
def __str__(self):
54+
# type: () -> str
55+
return str(self._ireq.req)
56+
5357
def __repr__(self):
5458
# type: () -> str
5559
return "{class_name}({requirement!r})".format(

src/pip/_internal/resolution/resolvelib/resolver.py

+22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import functools
2+
import logging
23

34
from pip._vendor import six
45
from pip._vendor.packaging.utils import canonicalize_name
@@ -25,6 +26,9 @@
2526
from pip._internal.resolution.base import InstallRequirementProvider
2627

2728

29+
logger = logging.getLogger(__name__)
30+
31+
2832
class Resolver(BaseResolver):
2933
def __init__(
3034
self,
@@ -74,9 +78,27 @@ def resolve(self, root_reqs, check_supported_wheels):
7478

7579
try:
7680
self._result = resolver.resolve(requirements)
81+
7782
except ResolutionImpossible as e:
7883
error = self.factory.get_installation_error(e)
7984
if not error:
85+
# TODO: This needs fixing, we need to look at the
86+
# factory.get_installation_error infrastructure, as that
87+
# doesn't really allow for the logger.critical calls I'm
88+
# using here.
89+
for req, parent in e.causes:
90+
logger.critical(
91+
"Could not find a version that satisfies " +
92+
"the requirement " +
93+
str(req) +
94+
("" if parent is None else " (from {})".format(
95+
parent.name
96+
))
97+
)
98+
raise InstallationError(
99+
"No matching distribution found for " +
100+
", ".join([r.name for r, _ in e.causes])
101+
)
80102
raise
81103
six.raise_from(error, e)
82104

tests/functional/test_new_resolver.py

+35
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,41 @@ def test_new_resolver_installs_extras(script):
156156
assert_installed(script, base="0.1.0", dep="0.1.0")
157157

158158

159+
def test_new_resolver_installed_message(script):
160+
create_basic_wheel_for_package(script, "A", "1.0")
161+
result = script.pip(
162+
"install", "--unstable-feature=resolver",
163+
"--no-cache-dir", "--no-index",
164+
"--find-links", script.scratch_path,
165+
"A",
166+
expect_stderr=False,
167+
)
168+
assert "Successfully installed A-1.0" in result.stdout, str(result)
169+
170+
171+
def test_new_resolver_no_dist_message(script):
172+
create_basic_wheel_for_package(script, "A", "1.0")
173+
result = script.pip(
174+
"install", "--unstable-feature=resolver",
175+
"--no-cache-dir", "--no-index",
176+
"--find-links", script.scratch_path,
177+
"B",
178+
expect_error=True,
179+
expect_stderr=True,
180+
)
181+
182+
# Full messages from old resolver:
183+
# ERROR: Could not find a version that satisfies the
184+
# requirement xxx (from versions: none)
185+
# ERROR: No matching distribution found for xxx
186+
187+
assert "Could not find a version that satisfies the requirement B" \
188+
in result.stderr, str(result)
189+
# TODO: This reports the canonical name of the project. But the current
190+
# resolver reports the originally specified name (i.e. uppercase B)
191+
assert "No matching distribution found for b" in result.stderr, str(result)
192+
193+
159194
def test_new_resolver_installs_editable(script):
160195
create_basic_wheel_for_package(
161196
script,

0 commit comments

Comments
 (0)