From e027cd84494b27da6e404dd03cba1a61bb4a0b60 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Fri, 6 Jul 2018 04:47:33 +0530 Subject: [PATCH] Update deprecation utilities to specify versions Also: - Remove conditional warning/error level logging - Remove now-obsolete class - Update call sites as per new signature --- src/pip/_internal/index.py | 1 + src/pip/_internal/operations/freeze.py | 1 + src/pip/_internal/req/req_install.py | 2 +- src/pip/_internal/utils/deprecation.py | 34 ++++++++++---------------- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/pip/_internal/index.py b/src/pip/_internal/index.py index fae26eeff..8c0ec82c0 100644 --- a/src/pip/_internal/index.py +++ b/src/pip/_internal/index.py @@ -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) diff --git a/src/pip/_internal/operations/freeze.py b/src/pip/_internal/operations/freeze.py index 80fdd1044..4bbc27b0a 100644 --- a/src/pip/_internal/operations/freeze.py +++ b/src/pip/_internal/operations/freeze.py @@ -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( diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py index 6a33e4e42..efe96a774 100644 --- a/src/pip/_internal/req/req_install.py +++ b/src/pip/_internal/req/req_install.py @@ -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 diff --git a/src/pip/_internal/utils/deprecation.py b/src/pip/_internal/utils/deprecation.py index e8f59705c..73bf69cd8 100644 --- a/src/pip/_internal/utils/deprecation.py +++ b/src/pip/_internal/utils/deprecation.py @@ -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)