mirror of https://github.com/pypa/pip
Update deprecation utilities to specify versions
Also: - Remove conditional warning/error level logging - Remove now-obsolete class - Update call sites as per new signature
This commit is contained in:
parent
4c2b268d52
commit
e027cd8449
|
@ -215,6 +215,7 @@ class PackageFinder(object):
|
|||
"Dependency Links processing has been deprecated and will be "
|
||||
"removed in a future release.",
|
||||
replacement=None,
|
||||
gone_in="18.2",
|
||||
issue=4187,
|
||||
)
|
||||
self.dependency_links.extend(links)
|
||||
|
|
|
@ -219,6 +219,7 @@ class FrozenRequirement(object):
|
|||
"SVN editable detection based on dependency links "
|
||||
"will be dropped in the future.",
|
||||
replacement=None,
|
||||
gone_in="18.2",
|
||||
issue=4187,
|
||||
)
|
||||
comments.append(
|
||||
|
|
|
@ -586,8 +586,8 @@ class InstallRequirement(object):
|
|||
"pyproject.toml files that do not contain the [build-system]"
|
||||
"table and the requires key, as specified in PEP 518.",
|
||||
replacement=None,
|
||||
gone_in="18.2",
|
||||
issue=5416,
|
||||
imminent=True,
|
||||
)
|
||||
|
||||
# Currently, we're isolating the build based on the presence of the
|
||||
|
|
|
@ -6,6 +6,9 @@ from __future__ import absolute_import
|
|||
import logging
|
||||
import warnings
|
||||
|
||||
from pip._vendor.packaging.version import parse
|
||||
|
||||
from pip import __version__ as current_version
|
||||
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
||||
|
||||
if MYPY_CHECK_RUNNING:
|
||||
|
@ -16,10 +19,6 @@ class PipDeprecationWarning(Warning):
|
|||
pass
|
||||
|
||||
|
||||
class PipPendingDeprecationWarning(PipDeprecationWarning):
|
||||
pass
|
||||
|
||||
|
||||
_original_showwarning = None # type: Any
|
||||
|
||||
|
||||
|
@ -34,16 +33,7 @@ def _showwarning(message, category, filename, lineno, file=None, line=None):
|
|||
# We use a specially named logger which will handle all of the
|
||||
# deprecation messages for pip.
|
||||
logger = logging.getLogger("pip._internal.deprecations")
|
||||
|
||||
# PipPendingDeprecationWarnings still have at least 2
|
||||
# versions to go until they are removed so they can just be
|
||||
# warnings. Otherwise, they will be removed in the very next
|
||||
# version of pip. We want these to be more obvious so we use the
|
||||
# ERROR logging level.
|
||||
if issubclass(category, PipPendingDeprecationWarning):
|
||||
logger.warning(log_message)
|
||||
else:
|
||||
logger.error(log_message)
|
||||
logger.warning(message)
|
||||
else:
|
||||
_original_showwarning(
|
||||
message, category, filename, lineno, file, line,
|
||||
|
@ -61,12 +51,11 @@ def install_warning_logger():
|
|||
warnings.showwarning = _showwarning
|
||||
|
||||
|
||||
def deprecated(reason, replacement, issue=None, imminent=False):
|
||||
# type: (str, Optional[str], Optional[int], bool) -> None
|
||||
if imminent:
|
||||
category = PipDeprecationWarning
|
||||
else:
|
||||
category = PipPendingDeprecationWarning
|
||||
def deprecated(reason, replacement, gone_in, issue=None):
|
||||
# type: (str, Optional[str], Optional[str], Optional[int]) -> None
|
||||
"""Helper to deprecate existing functionality.
|
||||
"""
|
||||
# NOTE: treat replacement, gone_in, issue as keyword only arguments.
|
||||
|
||||
# Construct a nice message.
|
||||
# This is purposely eagerly formatted as we want it to appear as if someone
|
||||
|
@ -78,4 +67,7 @@ def deprecated(reason, replacement, issue=None, imminent=False):
|
|||
url = "https://github.com/pypa/pip/issues/" + str(issue)
|
||||
message += " You can find discussion regarding this at {}.".format(url)
|
||||
|
||||
warnings.warn(message, category=category, stacklevel=2)
|
||||
# Raise as an error if it has to be removed.
|
||||
if gone_in is not None and parse(current_version) >= parse(gone_in):
|
||||
raise PipDeprecationWarning(message)
|
||||
warnings.warn(message, category=PipDeprecationWarning, stacklevel=2)
|
||||
|
|
Loading…
Reference in New Issue