mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-18 09:29:58 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
72ad6dc953
commit
f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions
|
|
@ -1,16 +1,20 @@
|
|||
"""
|
||||
A module that implements tooling to enable easy warnings about deprecations.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import warnings
|
||||
from typing import Any, Optional, TextIO, Type, Union
|
||||
|
||||
from pip._vendor.packaging.version import parse
|
||||
from typing import Any
|
||||
from typing import Optional
|
||||
from typing import TextIO
|
||||
from typing import Type
|
||||
from typing import Union
|
||||
|
||||
from pip import __version__ as current_version # NOTE: tests patch this name.
|
||||
from pip._vendor.packaging.version import parse
|
||||
|
||||
DEPRECATION_MSG_PREFIX = "DEPRECATION: "
|
||||
DEPRECATION_MSG_PREFIX = 'DEPRECATION: '
|
||||
|
||||
|
||||
class PipDeprecationWarning(Warning):
|
||||
|
|
@ -22,12 +26,12 @@ _original_showwarning: Any = None
|
|||
|
||||
# Warnings <-> Logging Integration
|
||||
def _showwarning(
|
||||
message: Union[Warning, str],
|
||||
category: Type[Warning],
|
||||
message: Warning | str,
|
||||
category: type[Warning],
|
||||
filename: str,
|
||||
lineno: int,
|
||||
file: Optional[TextIO] = None,
|
||||
line: Optional[str] = None,
|
||||
file: TextIO | None = None,
|
||||
line: str | None = None,
|
||||
) -> None:
|
||||
if file is not None:
|
||||
if _original_showwarning is not None:
|
||||
|
|
@ -35,7 +39,7 @@ def _showwarning(
|
|||
elif issubclass(category, PipDeprecationWarning):
|
||||
# We use a specially named logger which will handle all of the
|
||||
# deprecation messages for pip.
|
||||
logger = logging.getLogger("pip._internal.deprecations")
|
||||
logger = logging.getLogger('pip._internal.deprecations')
|
||||
logger.warning(message)
|
||||
else:
|
||||
_original_showwarning(message, category, filename, lineno, file, line)
|
||||
|
|
@ -43,7 +47,7 @@ def _showwarning(
|
|||
|
||||
def install_warning_logger() -> None:
|
||||
# Enable our Deprecation Warnings
|
||||
warnings.simplefilter("default", PipDeprecationWarning, append=True)
|
||||
warnings.simplefilter('default', PipDeprecationWarning, append=True)
|
||||
|
||||
global _original_showwarning
|
||||
|
||||
|
|
@ -55,10 +59,10 @@ def install_warning_logger() -> None:
|
|||
def deprecated(
|
||||
*,
|
||||
reason: str,
|
||||
replacement: Optional[str],
|
||||
gone_in: Optional[str],
|
||||
feature_flag: Optional[str] = None,
|
||||
issue: Optional[int] = None,
|
||||
replacement: str | None,
|
||||
gone_in: str | None,
|
||||
feature_flag: str | None = None,
|
||||
issue: int | None = None,
|
||||
) -> None:
|
||||
"""Helper to deprecate existing functionality.
|
||||
|
||||
|
|
@ -84,30 +88,30 @@ def deprecated(
|
|||
is_gone = gone_in is not None and parse(current_version) >= parse(gone_in)
|
||||
|
||||
message_parts = [
|
||||
(reason, f"{DEPRECATION_MSG_PREFIX}{{}}"),
|
||||
(reason, f'{DEPRECATION_MSG_PREFIX}{{}}'),
|
||||
(
|
||||
gone_in,
|
||||
"pip {} will enforce this behaviour change."
|
||||
'pip {} will enforce this behaviour change.'
|
||||
if not is_gone
|
||||
else "Since pip {}, this is no longer supported.",
|
||||
else 'Since pip {}, this is no longer supported.',
|
||||
),
|
||||
(
|
||||
replacement,
|
||||
"A possible replacement is {}.",
|
||||
'A possible replacement is {}.',
|
||||
),
|
||||
(
|
||||
feature_flag,
|
||||
"You can use the flag --use-feature={} to test the upcoming behaviour."
|
||||
'You can use the flag --use-feature={} to test the upcoming behaviour.'
|
||||
if not is_gone
|
||||
else None,
|
||||
),
|
||||
(
|
||||
issue,
|
||||
"Discussion can be found at https://github.com/pypa/pip/issues/{}",
|
||||
'Discussion can be found at https://github.com/pypa/pip/issues/{}',
|
||||
),
|
||||
]
|
||||
|
||||
message = " ".join(
|
||||
message = ' '.join(
|
||||
format_str.format(value)
|
||||
for value, format_str in message_parts
|
||||
if format_str is not None and value is not None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue