diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py index 3c15ed4158c..9ddd877bb97 100644 --- a/src/pip/_internal/commands/install.py +++ b/src/pip/_internal/commands/install.py @@ -7,6 +7,7 @@ from optparse import SUPPRESS_HELP, Values from typing import List, Optional +from pip._vendor.packaging.version import LegacyVersion from pip._vendor.rich import print_json from pip._internal.cache import WheelCache @@ -30,6 +31,7 @@ check_legacy_setup_py_options, ) from pip._internal.utils.compat import WINDOWS +from pip._internal.utils.deprecation import deprecated from pip._internal.utils.filesystem import test_writable_dir from pip._internal.utils.logging import getLogger from pip._internal.utils.misc import ( @@ -378,6 +380,22 @@ def run(self, options: Values, args: List[str]) -> int: reqs, check_supported_wheels=not options.target_dir ) + for requirement in requirement_set.requirements_to_install: + version = requirement.get_dist().version + if isinstance(version, LegacyVersion): + deprecated( + reason=( + f"pip has selected the non standard version {version} " + f"of {requirement}. In the future this version will be " + f"ignored as it isn't standard compliant." + ), + replacement=( + "update constraints to select another version " + "or contact the package author to fix the version number" + ), + gone_in="23.3", + ) + if options.json_report_file: report = InstallationReport(requirement_set.requirements_to_install) if options.json_report_file == "-": diff --git a/src/pip/_vendor/packaging/specifiers.py b/src/pip/_vendor/packaging/specifiers.py index 09ab9f21e49..e89026a9fd2 100644 --- a/src/pip/_vendor/packaging/specifiers.py +++ b/src/pip/_vendor/packaging/specifiers.py @@ -263,7 +263,7 @@ def __init__(self, spec: str = "", prereleases: Optional[bool] = None) -> None: def _coerce_version(self, version: UnparsedVersion) -> LegacyVersion: if not isinstance(version, LegacyVersion): - version = LegacyVersion(str(version), silence_deprecation_warning=True) + version = LegacyVersion(str(version)) return version def _compare_equal(self, prospective: LegacyVersion, spec: str) -> bool: diff --git a/src/pip/_vendor/packaging/version.py b/src/pip/_vendor/packaging/version.py index 05b2c2b8de6..de9a09a4ed3 100644 --- a/src/pip/_vendor/packaging/version.py +++ b/src/pip/_vendor/packaging/version.py @@ -104,23 +104,15 @@ def __ne__(self, other: object) -> bool: class LegacyVersion(_BaseVersion): - def __init__( - self, - version: str, - silence_deprecation_warning: bool = False, - ) -> None: + def __init__(self, version: str) -> None: self._version = str(version) self._key = _legacy_cmpkey(self._version) - if not silence_deprecation_warning: - from pip._internal.utils.deprecation import deprecated - - deprecated( - reason=(f"This form of version ({version}) has been deprecated."), - replacement="use PEP 440 compatible versions", - gone_in="23.3", - issue=12063, - ) + warnings.warn( + "Creating a LegacyVersion has been deprecated and will be " + "removed in the next major release", + DeprecationWarning, + ) def __str__(self) -> str: return self._version diff --git a/tools/vendoring/patches/packaging.patch b/tools/vendoring/patches/packaging.patch index 2f8d7091258..c30f0cbd978 100644 --- a/tools/vendoring/patches/packaging.patch +++ b/tools/vendoring/patches/packaging.patch @@ -1,16 +1,8 @@ -Surface LegacyVersion and LegacySpecifier deprecation warnings -as pip deprecation warnings. - ---- - src/pip/_vendor/packaging/specifiers.py | 12 +++++++----- - src/pip/_vendor/packaging/version.py | 19 +++++++++++++------ - 2 files changed, 20 insertions(+), 11 deletions(-) - diff --git a/src/pip/_vendor/packaging/specifiers.py b/src/pip/_vendor/packaging/specifiers.py -index 0e218a6f9f7..b0a1cee288b 100644 +index 0e218a6..e89026a 100644 --- a/src/pip/_vendor/packaging/specifiers.py +++ b/src/pip/_vendor/packaging/specifiers.py -@@ -252,15 +252,18 @@ class LegacySpecifier(_IndividualSpecifier): +@@ -252,10 +252,13 @@ class LegacySpecifier(_IndividualSpecifier): def __init__(self, spec: str = "", prereleases: Optional[bool] = None) -> None: super().__init__(spec, prereleases) @@ -28,43 +20,3 @@ index 0e218a6f9f7..b0a1cee288b 100644 ) def _coerce_version(self, version: UnparsedVersion) -> LegacyVersion: - if not isinstance(version, LegacyVersion): -- version = LegacyVersion(str(version)) -+ version = LegacyVersion(str(version), silence_deprecation_warning=True) - return version - - def _compare_equal(self, prospective: LegacyVersion, spec: str) -> bool: -diff --git a/src/pip/_vendor/packaging/version.py b/src/pip/_vendor/packaging/version.py -index de9a09a4ed3..cc68ed67424 100644 ---- a/src/pip/_vendor/packaging/version.py -+++ b/src/pip/_vendor/packaging/version.py -@@ -104,15 +104,23 @@ def __ne__(self, other: object) -> bool: - - - class LegacyVersion(_BaseVersion): -- def __init__(self, version: str) -> None: -+ def __init__( -+ self, -+ version: str, -+ silence_deprecation_warning: bool = False, -+ ) -> None: - self._version = str(version) - self._key = _legacy_cmpkey(self._version) - -- warnings.warn( -- "Creating a LegacyVersion has been deprecated and will be " -- "removed in the next major release", -- DeprecationWarning, -- ) -+ if not silence_deprecation_warning: -+ from pip._internal.utils.deprecation import deprecated -+ -+ deprecated( -+ reason=(f"This form of version ({version}) has been deprecated."), -+ replacement="use PEP 440 compatible versions", -+ gone_in="23.3", -+ issue=12063, -+ ) - - def __str__(self) -> str: - return self._version