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

Include both sources in inconsistency error #9469

Merged
merged 1 commit into from
Jan 18, 2021
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
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.
15 changes: 9 additions & 6 deletions src/pip/_internal/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
if MYPY_CHECK_RUNNING:
import configparser
from hashlib import _Hash
from typing import Any, Dict, List, Optional
from typing import Dict, List, Optional

from pip._vendor.pkg_resources import Distribution
from pip._vendor.requests.models import Request, Response
Expand Down 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
4 changes: 3 additions & 1 deletion tests/functional/test_new_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,9 @@ def test_new_resolver_skip_inconsistent_metadata(script):
allow_stderr_warning=True,
)

assert " different version in metadata: '2'" in result.stderr, str(result)
assert (
" inconsistent version: filename has '3', but metadata has '2'"
) in result.stderr, str(result)
assert_installed(script, a="1")


Expand Down