Merge pull request #9469 from uranusjr/inconsistency-all

Include both sources in inconsistency error
This commit is contained in:
Pradyun Gedam 2021-01-18 20:25:38 +00:00 committed by GitHub
commit 90246ea835
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 14 deletions

3
news/9186.feature.rst Normal file
View File

@ -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.

View File

@ -7,7 +7,7 @@ from pip._internal.utils.typing import MYPY_CHECK_RUNNING
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
@ -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):

View File

@ -204,12 +204,21 @@ class _InstallRequirementBackedCandidate(Candidate):
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

View File

@ -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)

View File

@ -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")