diff options
Diffstat (limited to 'venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/deprecation.py')
| -rw-r--r-- | venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/deprecation.py | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/deprecation.py b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/deprecation.py new file mode 100644 index 0000000..c0e3884 --- /dev/null +++ b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/deprecation.py | |||
| @@ -0,0 +1,77 @@ | |||
| 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 | from pip._internal.utils.typing import MYPY_CHECK_RUNNING | ||
| 10 | |||
| 11 | if MYPY_CHECK_RUNNING: | ||
| 12 | from typing import Any | ||
| 13 | |||
| 14 | |||
| 15 | class PipDeprecationWarning(Warning): | ||
| 16 | pass | ||
| 17 | |||
| 18 | |||
| 19 | class Pending(object): | ||
| 20 | pass | ||
| 21 | |||
| 22 | |||
| 23 | class RemovedInPip11Warning(PipDeprecationWarning): | ||
| 24 | pass | ||
| 25 | |||
| 26 | |||
| 27 | class RemovedInPip12Warning(PipDeprecationWarning, Pending): | ||
| 28 | pass | ||
| 29 | |||
| 30 | |||
| 31 | # Warnings <-> Logging Integration | ||
| 32 | |||
| 33 | |||
| 34 | _warnings_showwarning = None # type: Any | ||
| 35 | |||
| 36 | |||
| 37 | def _showwarning(message, category, filename, lineno, file=None, line=None): | ||
| 38 | if file is not None: | ||
| 39 | if _warnings_showwarning is not None: | ||
| 40 | _warnings_showwarning( | ||
| 41 | message, category, filename, lineno, file, line, | ||
| 42 | ) | ||
| 43 | else: | ||
| 44 | if issubclass(category, PipDeprecationWarning): | ||
| 45 | # We use a specially named logger which will handle all of the | ||
| 46 | # deprecation messages for pip. | ||
| 47 | logger = logging.getLogger("pip._internal.deprecations") | ||
| 48 | |||
| 49 | # This is purposely using the % formatter here instead of letting | ||
| 50 | # the logging module handle the interpolation. This is because we | ||
| 51 | # want it to appear as if someone typed this entire message out. | ||
| 52 | log_message = "DEPRECATION: %s" % message | ||
| 53 | |||
| 54 | # PipDeprecationWarnings that are Pending still have at least 2 | ||
| 55 | # versions to go until they are removed so they can just be | ||
| 56 | # warnings. Otherwise, they will be removed in the very next | ||
| 57 | # version of pip. We want these to be more obvious so we use the | ||
| 58 | # ERROR logging level. | ||
| 59 | if issubclass(category, Pending): | ||
| 60 | logger.warning(log_message) | ||
| 61 | else: | ||
| 62 | logger.error(log_message) | ||
| 63 | else: | ||
| 64 | _warnings_showwarning( | ||
| 65 | message, category, filename, lineno, file, line, | ||
| 66 | ) | ||
| 67 | |||
| 68 | |||
| 69 | def install_warning_logger(): | ||
| 70 | # Enable our Deprecation Warnings | ||
| 71 | warnings.simplefilter("default", PipDeprecationWarning, append=True) | ||
| 72 | |||
| 73 | global _warnings_showwarning | ||
| 74 | |||
| 75 | if _warnings_showwarning is None: | ||
| 76 | _warnings_showwarning = warnings.showwarning | ||
| 77 | warnings.showwarning = _showwarning | ||
