~ibmcharmers/charms/xenial/ibm-cinder-storwize-svc/trunk

« back to all changes in this revision

Viewing changes to .tox/py35/lib/python3.5/site-packages/pip/utils/deprecation.py

  • Committer: Ankammarao
  • Date: 2017-03-06 05:11:42 UTC
  • Revision ID: achittet@in.ibm.com-20170306051142-dpg27z4es1k56hfn
Marked tests folder executable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
A module that implements 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 Pending(object):
 
15
    pass
 
16
 
 
17
 
 
18
class RemovedInPip10Warning(PipDeprecationWarning):
 
19
    pass
 
20
 
 
21
 
 
22
class RemovedInPip11Warning(PipDeprecationWarning, Pending):
 
23
    pass
 
24
 
 
25
 
 
26
class Python26DeprecationWarning(PipDeprecationWarning):
 
27
    pass
 
28
 
 
29
 
 
30
# Warnings <-> Logging Integration
 
31
 
 
32
 
 
33
_warnings_showwarning = None
 
34
 
 
35
 
 
36
def _showwarning(message, category, filename, lineno, file=None, line=None):
 
37
    if file is not None:
 
38
        if _warnings_showwarning is not None:
 
39
            _warnings_showwarning(
 
40
                message, category, filename, lineno, file, line,
 
41
            )
 
42
    else:
 
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")
 
47
 
 
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
 
52
 
 
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)
 
60
            else:
 
61
                logger.error(log_message)
 
62
        else:
 
63
            _warnings_showwarning(
 
64
                message, category, filename, lineno, file, line,
 
65
            )
 
66
 
 
67
 
 
68
def install_warning_logger():
 
69
    # Enable our Deprecation Warnings
 
70
    warnings.simplefilter("default", PipDeprecationWarning, append=True)
 
71
 
 
72
    global _warnings_showwarning
 
73
 
 
74
    if _warnings_showwarning is None:
 
75
        _warnings_showwarning = warnings.showwarning
 
76
        warnings.showwarning = _showwarning