]>
jfr.im git - dlqueue.git/blob - venv/lib/python3.11/site-packages/pip/_internal/utils/deprecation.py
2 A module that implements tooling to enable easy warnings about deprecations.
7 from typing
import Any
, Optional
, TextIO
, Type
, Union
9 from pip
._vendor
.packaging
.version
import parse
11 from pip
import __version__
as current_version
# NOTE: tests patch this name.
13 DEPRECATION_MSG_PREFIX
= "DEPRECATION: "
16 class PipDeprecationWarning(Warning):
20 _original_showwarning
: Any
= None
23 # Warnings <-> Logging Integration
25 message
: Union
[Warning, str],
26 category
: Type
[Warning],
29 file: Optional
[TextIO
] = None,
30 line
: Optional
[str] = None,
33 if _original_showwarning
is not None:
34 _original_showwarning(message
, category
, filename
, lineno
, file, line
)
35 elif issubclass(category
, PipDeprecationWarning
):
36 # We use a specially named logger which will handle all of the
37 # deprecation messages for pip.
38 logger
= logging
.getLogger("pip._internal.deprecations")
39 logger
.warning(message
)
41 _original_showwarning(message
, category
, filename
, lineno
, file, line
)
44 def install_warning_logger() -> None:
45 # Enable our Deprecation Warnings
46 warnings
.simplefilter("default", PipDeprecationWarning
, append
=True)
48 global _original_showwarning
50 if _original_showwarning
is None:
51 _original_showwarning
= warnings
.showwarning
52 warnings
.showwarning
= _showwarning
58 replacement
: Optional
[str],
59 gone_in
: Optional
[str],
60 feature_flag
: Optional
[str] = None,
61 issue
: Optional
[int] = None,
63 """Helper to deprecate existing functionality.
66 Textual reason shown to the user about why this functionality has
67 been deprecated. Should be a complete sentence.
69 Textual suggestion shown to the user about what alternative
70 functionality they can use.
72 The version of pip does this functionality should get removed in.
73 Raises an error if pip's current version is greater than or equal to
76 Command-line flag of the form --use-feature={feature_flag} for testing
77 upcoming functionality.
79 Issue number on the tracker that would serve as a useful place for
80 users to find related discussion and provide feedback.
83 # Determine whether or not the feature is already gone in this version.
84 is_gone
= gone_in
is not None and parse(current_version
) >= parse(gone_in
)
87 (reason
, f
"{DEPRECATION_MSG_PREFIX}{{}}"),
90 "pip {} will enforce this behaviour change."
92 else "Since pip {}, this is no longer supported.",
96 "A possible replacement is {}.",
100 "You can use the flag --use-feature={} to test the upcoming behaviour."
106 "Discussion can be found at https://github.com/pypa/pip/issues/{}",
111 format_str
.format(value
)
112 for value
, format_str
in message_parts
113 if format_str
is not None and value
is not None
116 # Raise as an error if this behaviour is deprecated.
118 raise PipDeprecationWarning(message
)
120 warnings
.warn(message
, category
=PipDeprecationWarning
, stacklevel
=2)