comparison venv/lib/python2.7/site-packages/pip/utils/deprecation.py @ 0:d67268158946 draft

planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author bcclaywell
date Mon, 12 Oct 2015 17:43:33 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d67268158946
1 """
2 A module that implments tooling to enable easy warnings about deprecations.
3 """
4 from __future__ import absolute_import
5
6 import logging
7 import warnings
8
9
10 class PipDeprecationWarning(Warning):
11 pass
12
13
14 class RemovedInPip7Warning(PipDeprecationWarning, DeprecationWarning):
15 pass
16
17
18 class RemovedInPip8Warning(PipDeprecationWarning, PendingDeprecationWarning):
19 pass
20
21
22 DEPRECATIONS = [RemovedInPip7Warning, RemovedInPip8Warning]
23
24
25 # Warnings <-> Logging Integration
26
27
28 _warnings_showwarning = None
29
30
31 def _showwarning(message, category, filename, lineno, file=None, line=None):
32 if file is not None:
33 if _warnings_showwarning is not None:
34 _warnings_showwarning(
35 message, category, filename, lineno, file, line,
36 )
37 else:
38 if issubclass(category, PipDeprecationWarning):
39 # We use a specially named logger which will handle all of the
40 # deprecation messages for pip.
41 logger = logging.getLogger("pip.deprecations")
42
43 # This is purposely using the % formatter here instead of letting
44 # the logging module handle the interpolation. This is because we
45 # want it to appear as if someone typed this entire message out.
46 log_message = "DEPRECATION: %s" % message
47
48 # Things that are DeprecationWarnings will be removed in the very
49 # next version of pip. We want these to be more obvious so we
50 # use the ERROR logging level while the PendingDeprecationWarnings
51 # are still have at least 2 versions to go until they are removed
52 # so they can just be warnings.
53 if issubclass(category, DeprecationWarning):
54 logger.error(log_message)
55 else:
56 logger.warning(log_message)
57 else:
58 _warnings_showwarning(
59 message, category, filename, lineno, file, line,
60 )
61
62
63 def install_warning_logger():
64 global _warnings_showwarning
65
66 if _warnings_showwarning is None:
67 _warnings_showwarning = warnings.showwarning
68 warnings.showwarning = _showwarning