Skip to content

Commit

Permalink
Include both sources in inconsistency error
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Jan 18, 2021
1 parent 3af9093 commit a67fea4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
3 changes: 3 additions & 0 deletions news/9186.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
New resolver: Error message shown when a wheel contains inconsistent metadata
is made more helpful by including both values from the file name and internal
metadata.
13 changes: 8 additions & 5 deletions src/pip/_internal/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,20 @@ class MetadataInconsistent(InstallationError):
that do not match the information previously obtained from sdist filename
or user-supplied ``#egg=`` value.
"""
def __init__(self, ireq, field, built):
# type: (InstallRequirement, str, Any) -> None
def __init__(self, ireq, field, f_val, m_val):
# type: (InstallRequirement, str, str, str) -> None
self.ireq = ireq
self.field = field
self.built = built
self.f_val = f_val
self.m_val = m_val

def __str__(self):
# type: () -> str
return "Requested {} has different {} in metadata: {!r}".format(
self.ireq, self.field, self.built,
template = (
"Requested {} has inconsistent {}: "
"filename has {!r}, but metadata has {!r}"
)
return template.format(self.ireq, self.field, self.f_val, self.m_val)


class InstallationSubprocessError(InstallationError):
Expand Down
21 changes: 15 additions & 6 deletions src/pip/_internal/resolution/resolvelib/candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,21 @@ def _prepare_distribution(self):
def _check_metadata_consistency(self, dist):
# type: (Distribution) -> None
"""Check for consistency of project name and version of dist."""
name = canonicalize_name(dist.project_name)
if self._name is not None and self._name != name:
raise MetadataInconsistent(self._ireq, "name", dist.project_name)
version = dist.parsed_version
if self._version is not None and self._version != version:
raise MetadataInconsistent(self._ireq, "version", dist.version)
canonical_name = canonicalize_name(dist.project_name)
if self._name is not None and self._name != canonical_name:
raise MetadataInconsistent(
self._ireq,
"name",
self._name,
dist.project_name,
)
if self._version is not None and self._version != dist.parsed_version:
raise MetadataInconsistent(
self._ireq,
"version",
str(self._version),
dist.version,
)

def _prepare(self):
# type: () -> Distribution
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,7 @@ def test_install_editable_with_wrong_egg_name(script, resolver_variant):
"for project name pkga. Fix your #egg=pkgb "
"fragments.") in result.stderr
if resolver_variant == "2020-resolver":
assert "has different name in metadata" in result.stderr, str(result)
assert "has inconsistent" in result.stderr, str(result)
else:
assert "Successfully installed pkga" in str(result), str(result)

Expand Down

0 comments on commit a67fea4

Please sign in to comment.