2
A module that implements tooling to enable easy warnings about deprecations.
4
from __future__ import absolute_import
10
class PipDeprecationWarning(Warning):
14
class Pending(object):
18
class RemovedInPip10Warning(PipDeprecationWarning):
22
class RemovedInPip11Warning(PipDeprecationWarning, Pending):
26
class Python26DeprecationWarning(PipDeprecationWarning):
30
# Warnings <-> Logging Integration
33
_warnings_showwarning = None
36
def _showwarning(message, category, filename, lineno, file=None, line=None):
38
if _warnings_showwarning is not None:
39
_warnings_showwarning(
40
message, category, filename, lineno, file, line,
43
if issubclass(category, PipDeprecationWarning):
44
# We use a specially named logger which will handle all of the
45
# deprecation messages for pip.
46
logger = logging.getLogger("pip.deprecations")
48
# This is purposely using the % formatter here instead of letting
49
# the logging module handle the interpolation. This is because we
50
# want it to appear as if someone typed this entire message out.
51
log_message = "DEPRECATION: %s" % message
53
# PipDeprecationWarnings that are Pending still have at least 2
54
# versions to go until they are removed so they can just be
55
# warnings. Otherwise, they will be removed in the very next
56
# version of pip. We want these to be more obvious so we use the
57
# ERROR logging level.
58
if issubclass(category, Pending):
59
logger.warning(log_message)
61
logger.error(log_message)
63
_warnings_showwarning(
64
message, category, filename, lineno, file, line,
68
def install_warning_logger():
69
# Enable our Deprecation Warnings
70
warnings.simplefilter("default", PipDeprecationWarning, append=True)
72
global _warnings_showwarning
74
if _warnings_showwarning is None:
75
_warnings_showwarning = warnings.showwarning
76
warnings.showwarning = _showwarning