Skip to content

Commit

Permalink
[WIP] warn when legacy versions are selected by the resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Jun 25, 2023
1 parent 09a6a68 commit 95f8f49
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 65 deletions.
18 changes: 18 additions & 0 deletions src/pip/_internal/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 (
Expand Down Expand Up @@ -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 == "-":
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_vendor/packaging/specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 6 additions & 14 deletions src/pip/_vendor/packaging/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 2 additions & 50 deletions tools/vendoring/patches/packaging.patch
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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

0 comments on commit 95f8f49

Please sign in to comment.