mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-08 12:34:17 +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,25 +1,26 @@
|
|||
from __future__ import annotations
|
||||
try:
|
||||
from ._version import version as __version__
|
||||
except ImportError:
|
||||
# broken installation, we don't even try
|
||||
# unknown only works because we do poor mans version compare
|
||||
__version__ = "unknown"
|
||||
__version__ = 'unknown'
|
||||
|
||||
__all__ = [
|
||||
"__version__",
|
||||
"PluginManager",
|
||||
"PluginValidationError",
|
||||
"HookCaller",
|
||||
"HookCallError",
|
||||
"HookspecOpts",
|
||||
"HookimplOpts",
|
||||
"HookImpl",
|
||||
"HookRelay",
|
||||
"HookspecMarker",
|
||||
"HookimplMarker",
|
||||
"Result",
|
||||
"PluggyWarning",
|
||||
"PluggyTeardownRaisedWarning",
|
||||
'__version__',
|
||||
'PluginManager',
|
||||
'PluginValidationError',
|
||||
'HookCaller',
|
||||
'HookCallError',
|
||||
'HookspecOpts',
|
||||
'HookimplOpts',
|
||||
'HookImpl',
|
||||
'HookRelay',
|
||||
'HookspecMarker',
|
||||
'HookimplMarker',
|
||||
'Result',
|
||||
'PluggyWarning',
|
||||
'PluggyTeardownRaisedWarning',
|
||||
]
|
||||
|
||||
from ._manager import PluginManager, PluginValidationError
|
||||
|
|
|
|||
|
|
@ -34,18 +34,18 @@ def _raise_wrapfail(
|
|||
) -> NoReturn:
|
||||
co = wrap_controller.gi_code
|
||||
raise RuntimeError(
|
||||
"wrap_controller at %r %s:%d %s"
|
||||
% (co.co_name, co.co_filename, co.co_firstlineno, msg)
|
||||
'wrap_controller at %r %s:%d %s'
|
||||
% (co.co_name, co.co_filename, co.co_firstlineno, msg),
|
||||
)
|
||||
|
||||
|
||||
def _warn_teardown_exception(
|
||||
hook_name: str, hook_impl: HookImpl, e: BaseException
|
||||
hook_name: str, hook_impl: HookImpl, e: BaseException,
|
||||
) -> None:
|
||||
msg = "A plugin raised an exception during an old-style hookwrapper teardown.\n"
|
||||
msg += f"Plugin: {hook_impl.plugin_name}, Hook: {hook_name}\n"
|
||||
msg += f"{type(e).__name__}: {e}\n"
|
||||
msg += "For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning" # noqa: E501
|
||||
msg = 'A plugin raised an exception during an old-style hookwrapper teardown.\n'
|
||||
msg += f'Plugin: {hook_impl.plugin_name}, Hook: {hook_name}\n'
|
||||
msg += f'{type(e).__name__}: {e}\n'
|
||||
msg += 'For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning' # noqa: E501
|
||||
warnings.warn(PluggyTeardownRaisedWarning(msg), stacklevel=5)
|
||||
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ def _multicall(
|
|||
for argname in hook_impl.argnames:
|
||||
if argname not in caller_kwargs:
|
||||
raise HookCallError(
|
||||
f"hook call must provide argument {argname!r}"
|
||||
f'hook call must provide argument {argname!r}',
|
||||
)
|
||||
|
||||
if hook_impl.hookwrapper:
|
||||
|
|
@ -87,7 +87,7 @@ def _multicall(
|
|||
next(wrapper_gen) # first yield
|
||||
teardowns.append((wrapper_gen, hook_impl))
|
||||
except StopIteration:
|
||||
_raise_wrapfail(wrapper_gen, "did not yield")
|
||||
_raise_wrapfail(wrapper_gen, 'did not yield')
|
||||
elif hook_impl.wrapper:
|
||||
try:
|
||||
# If this cast is not valid, a type error is raised below,
|
||||
|
|
@ -97,7 +97,7 @@ def _multicall(
|
|||
next(function_gen) # first yield
|
||||
teardowns.append(function_gen)
|
||||
except StopIteration:
|
||||
_raise_wrapfail(function_gen, "did not yield")
|
||||
_raise_wrapfail(function_gen, 'did not yield')
|
||||
else:
|
||||
res = hook_impl.function(*args)
|
||||
if res is not None:
|
||||
|
|
@ -132,7 +132,7 @@ def _multicall(
|
|||
except BaseException as e:
|
||||
exception = e
|
||||
continue
|
||||
_raise_wrapfail(teardown, "has second yield") # type: ignore[arg-type]
|
||||
_raise_wrapfail(teardown, 'has second yield') # type: ignore[arg-type]
|
||||
|
||||
if exception is not None:
|
||||
raise exception.with_traceback(exception.__traceback__)
|
||||
|
|
@ -143,7 +143,7 @@ def _multicall(
|
|||
else:
|
||||
if firstresult: # first result hooks return a single value
|
||||
outcome: Result[object | list[object]] = Result(
|
||||
results[0] if results else None, exception
|
||||
results[0] if results else None, exception,
|
||||
)
|
||||
else:
|
||||
outcome = Result(results, exception)
|
||||
|
|
@ -159,7 +159,7 @@ def _multicall(
|
|||
_warn_teardown_exception(hook_name, teardown[1], e)
|
||||
raise
|
||||
else:
|
||||
_raise_wrapfail(teardown[0], "has second yield")
|
||||
_raise_wrapfail(teardown[0], 'has second yield')
|
||||
else:
|
||||
try:
|
||||
if outcome._exception is not None:
|
||||
|
|
@ -176,6 +176,6 @@ def _multicall(
|
|||
except BaseException as e:
|
||||
outcome.force_exception(e)
|
||||
continue
|
||||
_raise_wrapfail(teardown, "has second yield")
|
||||
_raise_wrapfail(teardown, 'has second yield')
|
||||
|
||||
return outcome.get_result()
|
||||
|
|
|
|||
|
|
@ -27,12 +27,12 @@ from typing import Union
|
|||
from ._result import Result
|
||||
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_F = TypeVar("_F", bound=Callable[..., object])
|
||||
_T = TypeVar('_T')
|
||||
_F = TypeVar('_F', bound=Callable[..., object])
|
||||
_Namespace = Union[ModuleType, type]
|
||||
_Plugin = object
|
||||
_HookExec = Callable[
|
||||
[str, Sequence["HookImpl"], Mapping[str, object], bool],
|
||||
[str, Sequence['HookImpl'], Mapping[str, object], bool],
|
||||
Union[object, List[object]],
|
||||
]
|
||||
_HookImplFunction = Callable[..., Union[_T, Generator[None, Result[_T], None]]]
|
||||
|
|
@ -79,7 +79,7 @@ class HookspecMarker:
|
|||
functions if the :class:`PluginManager` uses the same project name.
|
||||
"""
|
||||
|
||||
__slots__ = ("project_name",)
|
||||
__slots__ = ('project_name',)
|
||||
|
||||
def __init__(self, project_name: str) -> None:
|
||||
self.project_name: Final = project_name
|
||||
|
|
@ -133,13 +133,13 @@ class HookspecMarker:
|
|||
|
||||
def setattr_hookspec_opts(func: _F) -> _F:
|
||||
if historic and firstresult:
|
||||
raise ValueError("cannot have a historic firstresult hook")
|
||||
raise ValueError('cannot have a historic firstresult hook')
|
||||
opts: HookspecOpts = {
|
||||
"firstresult": firstresult,
|
||||
"historic": historic,
|
||||
"warn_on_impl": warn_on_impl,
|
||||
'firstresult': firstresult,
|
||||
'historic': historic,
|
||||
'warn_on_impl': warn_on_impl,
|
||||
}
|
||||
setattr(func, self.project_name + "_spec", opts)
|
||||
setattr(func, self.project_name + '_spec', opts)
|
||||
return func
|
||||
|
||||
if function is not None:
|
||||
|
|
@ -157,7 +157,7 @@ class HookimplMarker:
|
|||
functions if the :class:`PluginManager` uses the same project name.
|
||||
"""
|
||||
|
||||
__slots__ = ("project_name",)
|
||||
__slots__ = ('project_name',)
|
||||
|
||||
def __init__(self, project_name: str) -> None:
|
||||
self.project_name: Final = project_name
|
||||
|
|
@ -251,14 +251,14 @@ class HookimplMarker:
|
|||
|
||||
def setattr_hookimpl_opts(func: _F) -> _F:
|
||||
opts: HookimplOpts = {
|
||||
"wrapper": wrapper,
|
||||
"hookwrapper": hookwrapper,
|
||||
"optionalhook": optionalhook,
|
||||
"tryfirst": tryfirst,
|
||||
"trylast": trylast,
|
||||
"specname": specname,
|
||||
'wrapper': wrapper,
|
||||
'hookwrapper': hookwrapper,
|
||||
'optionalhook': optionalhook,
|
||||
'tryfirst': tryfirst,
|
||||
'trylast': trylast,
|
||||
'specname': specname,
|
||||
}
|
||||
setattr(func, self.project_name + "_impl", opts)
|
||||
setattr(func, self.project_name + '_impl', opts)
|
||||
return func
|
||||
|
||||
if function is None:
|
||||
|
|
@ -268,15 +268,15 @@ class HookimplMarker:
|
|||
|
||||
|
||||
def normalize_hookimpl_opts(opts: HookimplOpts) -> None:
|
||||
opts.setdefault("tryfirst", False)
|
||||
opts.setdefault("trylast", False)
|
||||
opts.setdefault("wrapper", False)
|
||||
opts.setdefault("hookwrapper", False)
|
||||
opts.setdefault("optionalhook", False)
|
||||
opts.setdefault("specname", None)
|
||||
opts.setdefault('tryfirst', False)
|
||||
opts.setdefault('trylast', False)
|
||||
opts.setdefault('wrapper', False)
|
||||
opts.setdefault('hookwrapper', False)
|
||||
opts.setdefault('optionalhook', False)
|
||||
opts.setdefault('specname', None)
|
||||
|
||||
|
||||
_PYPY = hasattr(sys, "pypy_version_info")
|
||||
_PYPY = hasattr(sys, 'pypy_version_info')
|
||||
|
||||
|
||||
def varnames(func: object) -> tuple[tuple[str, ...], tuple[str, ...]]:
|
||||
|
|
@ -293,14 +293,14 @@ def varnames(func: object) -> tuple[tuple[str, ...], tuple[str, ...]]:
|
|||
return (), ()
|
||||
elif not inspect.isroutine(func): # callable object?
|
||||
try:
|
||||
func = getattr(func, "__call__", func)
|
||||
func = getattr(func, '__call__', func)
|
||||
except Exception:
|
||||
return (), ()
|
||||
|
||||
try:
|
||||
# func MUST be a function or method here or we won't parse any args.
|
||||
sig = inspect.signature(
|
||||
func.__func__ if inspect.ismethod(func) else func # type:ignore[arg-type]
|
||||
func.__func__ if inspect.ismethod(func) else func, # type:ignore[arg-type]
|
||||
)
|
||||
except TypeError:
|
||||
return (), ()
|
||||
|
|
@ -320,8 +320,8 @@ def varnames(func: object) -> tuple[tuple[str, ...], tuple[str, ...]]:
|
|||
param.default
|
||||
for param in _valid_params.values()
|
||||
if param.default is not param.empty
|
||||
)
|
||||
or None
|
||||
) or
|
||||
None
|
||||
)
|
||||
|
||||
if defaults:
|
||||
|
|
@ -333,12 +333,12 @@ def varnames(func: object) -> tuple[tuple[str, ...], tuple[str, ...]]:
|
|||
# strip any implicit instance arg
|
||||
# pypy3 uses "obj" instead of "self" for default dunder methods
|
||||
if not _PYPY:
|
||||
implicit_names: tuple[str, ...] = ("self",)
|
||||
implicit_names: tuple[str, ...] = ('self',)
|
||||
else:
|
||||
implicit_names = ("self", "obj")
|
||||
implicit_names = ('self', 'obj')
|
||||
if args:
|
||||
qualname: str = getattr(func, "__qualname__", "")
|
||||
if inspect.ismethod(func) or ("." in qualname and args[0] in implicit_names):
|
||||
qualname: str = getattr(func, '__qualname__', '')
|
||||
if inspect.ismethod(func) or ('.' in qualname and args[0] in implicit_names):
|
||||
args = args[1:]
|
||||
|
||||
return args, kwargs
|
||||
|
|
@ -349,7 +349,7 @@ class HookRelay:
|
|||
"""Hook holder object for performing 1:N hook calls where N is the number
|
||||
of registered plugins."""
|
||||
|
||||
__slots__ = ("__dict__",)
|
||||
__slots__ = ('__dict__',)
|
||||
|
||||
def __init__(self) -> None:
|
||||
""":meta private:"""
|
||||
|
|
@ -371,11 +371,11 @@ class HookCaller:
|
|||
"""A caller of all registered implementations of a hook specification."""
|
||||
|
||||
__slots__ = (
|
||||
"name",
|
||||
"spec",
|
||||
"_hookexec",
|
||||
"_hookimpls",
|
||||
"_call_history",
|
||||
'name',
|
||||
'spec',
|
||||
'_hookexec',
|
||||
'_hookimpls',
|
||||
'_call_history',
|
||||
)
|
||||
|
||||
def __init__(
|
||||
|
|
@ -416,11 +416,11 @@ class HookCaller:
|
|||
) -> None:
|
||||
if self.spec is not None:
|
||||
raise ValueError(
|
||||
f"Hook {self.spec.name!r} is already registered "
|
||||
f"within namespace {self.spec.namespace}"
|
||||
f'Hook {self.spec.name!r} is already registered '
|
||||
f'within namespace {self.spec.namespace}',
|
||||
)
|
||||
self.spec = HookSpec(specmodule_or_class, self.name, spec_opts)
|
||||
if spec_opts.get("historic"):
|
||||
if spec_opts.get('historic'):
|
||||
self._call_history = []
|
||||
|
||||
def is_historic(self) -> bool:
|
||||
|
|
@ -432,7 +432,7 @@ class HookCaller:
|
|||
if method.plugin == plugin:
|
||||
del self._hookimpls[i]
|
||||
return
|
||||
raise ValueError(f"plugin {plugin!r} not found")
|
||||
raise ValueError(f'plugin {plugin!r} not found')
|
||||
|
||||
def get_hookimpls(self) -> list[HookImpl]:
|
||||
"""Get all registered hook implementations for this hook."""
|
||||
|
|
@ -463,22 +463,22 @@ class HookCaller:
|
|||
self._hookimpls.insert(i + 1, hookimpl)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<HookCaller {self.name!r}>"
|
||||
return f'<HookCaller {self.name!r}>'
|
||||
|
||||
def _verify_all_args_are_provided(self, kwargs: Mapping[str, object]) -> None:
|
||||
# This is written to avoid expensive operations when not needed.
|
||||
if self.spec:
|
||||
for argname in self.spec.argnames:
|
||||
if argname not in kwargs:
|
||||
notincall = ", ".join(
|
||||
notincall = ', '.join(
|
||||
repr(argname)
|
||||
for argname in self.spec.argnames
|
||||
# Avoid self.spec.argnames - kwargs.keys() - doesn't preserve order.
|
||||
if argname not in kwargs.keys()
|
||||
)
|
||||
warnings.warn(
|
||||
"Argument(s) {} which are declared in the hookspec "
|
||||
"cannot be found in this hook call".format(notincall),
|
||||
'Argument(s) {} which are declared in the hookspec '
|
||||
'cannot be found in this hook call'.format(notincall),
|
||||
stacklevel=2,
|
||||
)
|
||||
break
|
||||
|
|
@ -494,9 +494,9 @@ class HookCaller:
|
|||
"""
|
||||
assert (
|
||||
not self.is_historic()
|
||||
), "Cannot directly call a historic hook - use call_historic instead."
|
||||
), 'Cannot directly call a historic hook - use call_historic instead.'
|
||||
self._verify_all_args_are_provided(kwargs)
|
||||
firstresult = self.spec.opts.get("firstresult", False) if self.spec else False
|
||||
firstresult = self.spec.opts.get('firstresult', False) if self.spec else False
|
||||
# Copy because plugins may register other plugins during iteration (#438).
|
||||
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
|
||||
|
||||
|
|
@ -528,37 +528,37 @@ class HookCaller:
|
|||
result_callback(x)
|
||||
|
||||
def call_extra(
|
||||
self, methods: Sequence[Callable[..., object]], kwargs: Mapping[str, object]
|
||||
self, methods: Sequence[Callable[..., object]], kwargs: Mapping[str, object],
|
||||
) -> Any:
|
||||
"""Call the hook with some additional temporarily participating
|
||||
methods using the specified ``kwargs`` as call parameters, see
|
||||
:ref:`call_extra`."""
|
||||
assert (
|
||||
not self.is_historic()
|
||||
), "Cannot directly call a historic hook - use call_historic instead."
|
||||
), 'Cannot directly call a historic hook - use call_historic instead.'
|
||||
self._verify_all_args_are_provided(kwargs)
|
||||
opts: HookimplOpts = {
|
||||
"wrapper": False,
|
||||
"hookwrapper": False,
|
||||
"optionalhook": False,
|
||||
"trylast": False,
|
||||
"tryfirst": False,
|
||||
"specname": None,
|
||||
'wrapper': False,
|
||||
'hookwrapper': False,
|
||||
'optionalhook': False,
|
||||
'trylast': False,
|
||||
'tryfirst': False,
|
||||
'specname': None,
|
||||
}
|
||||
hookimpls = self._hookimpls.copy()
|
||||
for method in methods:
|
||||
hookimpl = HookImpl(None, "<temp>", method, opts)
|
||||
hookimpl = HookImpl(None, '<temp>', method, opts)
|
||||
# Find last non-tryfirst nonwrapper method.
|
||||
i = len(hookimpls) - 1
|
||||
while i >= 0 and (
|
||||
# Skip wrappers.
|
||||
(hookimpls[i].hookwrapper or hookimpls[i].wrapper)
|
||||
(hookimpls[i].hookwrapper or hookimpls[i].wrapper) or
|
||||
# Skip tryfirst nonwrappers.
|
||||
or hookimpls[i].tryfirst
|
||||
hookimpls[i].tryfirst
|
||||
):
|
||||
i -= 1
|
||||
hookimpls.insert(i + 1, hookimpl)
|
||||
firstresult = self.spec.opts.get("firstresult", False) if self.spec else False
|
||||
firstresult = self.spec.opts.get('firstresult', False) if self.spec else False
|
||||
return self._hookexec(self.name, hookimpls, kwargs, firstresult)
|
||||
|
||||
def _maybe_apply_history(self, method: HookImpl) -> None:
|
||||
|
|
@ -592,8 +592,8 @@ class _SubsetHookCaller(HookCaller):
|
|||
# proxy, however that adds more overhead and is more tricky to implement.
|
||||
|
||||
__slots__ = (
|
||||
"_orig",
|
||||
"_remove_plugins",
|
||||
'_orig',
|
||||
'_remove_plugins',
|
||||
)
|
||||
|
||||
def __init__(self, orig: HookCaller, remove_plugins: AbstractSet[_Plugin]) -> None:
|
||||
|
|
@ -619,7 +619,7 @@ class _SubsetHookCaller(HookCaller):
|
|||
return self._orig._call_history
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<_SubsetHookCaller {self.name!r}>"
|
||||
return f'<_SubsetHookCaller {self.name!r}>'
|
||||
|
||||
|
||||
@final
|
||||
|
|
@ -627,17 +627,17 @@ class HookImpl:
|
|||
"""A hook implementation in a :class:`HookCaller`."""
|
||||
|
||||
__slots__ = (
|
||||
"function",
|
||||
"argnames",
|
||||
"kwargnames",
|
||||
"plugin",
|
||||
"opts",
|
||||
"plugin_name",
|
||||
"wrapper",
|
||||
"hookwrapper",
|
||||
"optionalhook",
|
||||
"tryfirst",
|
||||
"trylast",
|
||||
'function',
|
||||
'argnames',
|
||||
'kwargnames',
|
||||
'plugin',
|
||||
'opts',
|
||||
'plugin_name',
|
||||
'wrapper',
|
||||
'hookwrapper',
|
||||
'optionalhook',
|
||||
'tryfirst',
|
||||
'trylast',
|
||||
)
|
||||
|
||||
def __init__(
|
||||
|
|
@ -662,34 +662,34 @@ class HookImpl:
|
|||
#: The name of the plugin which defined this hook implementation.
|
||||
self.plugin_name: Final = plugin_name
|
||||
#: Whether the hook implementation is a :ref:`wrapper <hookwrapper>`.
|
||||
self.wrapper: Final = hook_impl_opts["wrapper"]
|
||||
self.wrapper: Final = hook_impl_opts['wrapper']
|
||||
#: Whether the hook implementation is an :ref:`old-style wrapper
|
||||
#: <old_style_hookwrappers>`.
|
||||
self.hookwrapper: Final = hook_impl_opts["hookwrapper"]
|
||||
self.hookwrapper: Final = hook_impl_opts['hookwrapper']
|
||||
#: Whether validation against a hook specification is :ref:`optional
|
||||
#: <optionalhook>`.
|
||||
self.optionalhook: Final = hook_impl_opts["optionalhook"]
|
||||
self.optionalhook: Final = hook_impl_opts['optionalhook']
|
||||
#: Whether to try to order this hook implementation :ref:`first
|
||||
#: <callorder>`.
|
||||
self.tryfirst: Final = hook_impl_opts["tryfirst"]
|
||||
self.tryfirst: Final = hook_impl_opts['tryfirst']
|
||||
#: Whether to try to order this hook implementation :ref:`last
|
||||
#: <callorder>`.
|
||||
self.trylast: Final = hook_impl_opts["trylast"]
|
||||
self.trylast: Final = hook_impl_opts['trylast']
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<HookImpl plugin_name={self.plugin_name!r}, plugin={self.plugin!r}>"
|
||||
return f'<HookImpl plugin_name={self.plugin_name!r}, plugin={self.plugin!r}>'
|
||||
|
||||
|
||||
@final
|
||||
class HookSpec:
|
||||
__slots__ = (
|
||||
"namespace",
|
||||
"function",
|
||||
"name",
|
||||
"argnames",
|
||||
"kwargnames",
|
||||
"opts",
|
||||
"warn_on_impl",
|
||||
'namespace',
|
||||
'function',
|
||||
'name',
|
||||
'argnames',
|
||||
'kwargnames',
|
||||
'opts',
|
||||
'warn_on_impl',
|
||||
)
|
||||
|
||||
def __init__(self, namespace: _Namespace, name: str, opts: HookspecOpts) -> None:
|
||||
|
|
@ -698,4 +698,4 @@ class HookSpec:
|
|||
self.name = name
|
||||
self.argnames, self.kwargnames = varnames(self.function)
|
||||
self.opts = opts
|
||||
self.warn_on_impl = opts.get("warn_on_impl")
|
||||
self.warn_on_impl = opts.get('warn_on_impl')
|
||||
|
|
|
|||
|
|
@ -66,14 +66,14 @@ class DistFacade:
|
|||
|
||||
@property
|
||||
def project_name(self) -> str:
|
||||
name: str = self.metadata["name"]
|
||||
name: str = self.metadata['name']
|
||||
return name
|
||||
|
||||
def __getattr__(self, attr: str, default=None):
|
||||
return getattr(self._dist, attr, default)
|
||||
|
||||
def __dir__(self) -> list[str]:
|
||||
return sorted(dir(self._dist) + ["_dist", "project_name"])
|
||||
return sorted(dir(self._dist) + ['_dist', 'project_name'])
|
||||
|
||||
|
||||
class PluginManager:
|
||||
|
|
@ -103,7 +103,7 @@ class PluginManager:
|
|||
self.hook: Final = HookRelay()
|
||||
#: The tracing entry point. See :ref:`tracing`.
|
||||
self.trace: Final[_tracing.TagTracerSub] = _tracing.TagTracer().get(
|
||||
"pluginmanage"
|
||||
'pluginmanage',
|
||||
)
|
||||
self._inner_hookexec = _multicall
|
||||
|
||||
|
|
@ -137,14 +137,14 @@ class PluginManager:
|
|||
if self._name2plugin.get(plugin_name, -1) is None:
|
||||
return None # blocked plugin, return None to indicate no registration
|
||||
raise ValueError(
|
||||
"Plugin name already registered: %s=%s\n%s"
|
||||
% (plugin_name, plugin, self._name2plugin)
|
||||
'Plugin name already registered: %s=%s\n%s'
|
||||
% (plugin_name, plugin, self._name2plugin),
|
||||
)
|
||||
|
||||
if plugin in self._name2plugin.values():
|
||||
raise ValueError(
|
||||
"Plugin already registered under a different name: %s=%s\n%s"
|
||||
% (plugin_name, plugin, self._name2plugin)
|
||||
'Plugin already registered under a different name: %s=%s\n%s'
|
||||
% (plugin_name, plugin, self._name2plugin),
|
||||
)
|
||||
|
||||
# XXX if an error happens we should make sure no state has been
|
||||
|
|
@ -158,7 +158,7 @@ class PluginManager:
|
|||
normalize_hookimpl_opts(hookimpl_opts)
|
||||
method: _HookImplFunction[object] = getattr(plugin, name)
|
||||
hookimpl = HookImpl(plugin, plugin_name, method, hookimpl_opts)
|
||||
name = hookimpl_opts.get("specname") or name
|
||||
name = hookimpl_opts.get('specname') or name
|
||||
hook: HookCaller | None = getattr(self.hook, name, None)
|
||||
if hook is None:
|
||||
hook = HookCaller(name, self._hookexec)
|
||||
|
|
@ -185,7 +185,7 @@ class PluginManager:
|
|||
return None
|
||||
try:
|
||||
res: HookimplOpts | None = getattr(
|
||||
method, self.project_name + "_impl", None
|
||||
method, self.project_name + '_impl', None,
|
||||
)
|
||||
except Exception:
|
||||
res = {} # type: ignore[assignment]
|
||||
|
|
@ -195,7 +195,7 @@ class PluginManager:
|
|||
return res
|
||||
|
||||
def unregister(
|
||||
self, plugin: _Plugin | None = None, name: str | None = None
|
||||
self, plugin: _Plugin | None = None, name: str | None = None,
|
||||
) -> Any | None:
|
||||
"""Unregister a plugin and all of its hook implementations.
|
||||
|
||||
|
|
@ -205,9 +205,9 @@ class PluginManager:
|
|||
Returns the unregistered plugin, or ``None`` if not found.
|
||||
"""
|
||||
if name is None:
|
||||
assert plugin is not None, "one of name or plugin needs to be specified"
|
||||
assert plugin is not None, 'one of name or plugin needs to be specified'
|
||||
name = self.get_name(plugin)
|
||||
assert name is not None, "plugin is not registered"
|
||||
assert name is not None, 'plugin is not registered'
|
||||
|
||||
if plugin is None:
|
||||
plugin = self.get_plugin(name)
|
||||
|
|
@ -268,11 +268,11 @@ class PluginManager:
|
|||
|
||||
if not names:
|
||||
raise ValueError(
|
||||
f"did not find any {self.project_name!r} hooks in {module_or_class!r}"
|
||||
f'did not find any {self.project_name!r} hooks in {module_or_class!r}',
|
||||
)
|
||||
|
||||
def parse_hookspec_opts(
|
||||
self, module_or_class: _Namespace, name: str
|
||||
self, module_or_class: _Namespace, name: str,
|
||||
) -> HookspecOpts | None:
|
||||
"""Try to obtain a hook specification from an item with the given name
|
||||
in the given module or class which is being searched for hook specs.
|
||||
|
|
@ -286,7 +286,7 @@ class PluginManager:
|
|||
options for items decorated with :class:`HookspecMarker`.
|
||||
"""
|
||||
method = getattr(module_or_class, name)
|
||||
opts: HookspecOpts | None = getattr(method, self.project_name + "_spec", None)
|
||||
opts: HookspecOpts | None = getattr(method, self.project_name + '_spec', None)
|
||||
return opts
|
||||
|
||||
def get_plugins(self) -> set[Any]:
|
||||
|
|
@ -305,7 +305,7 @@ class PluginManager:
|
|||
To obtain the name of a registered plugin use :meth:`get_name(plugin)
|
||||
<get_name>` instead.
|
||||
"""
|
||||
name: str | None = getattr(plugin, "__name__", None)
|
||||
name: str | None = getattr(plugin, '__name__', None)
|
||||
return name or str(id(plugin))
|
||||
|
||||
def get_plugin(self, name: str) -> Any | None:
|
||||
|
|
@ -328,7 +328,7 @@ class PluginManager:
|
|||
if hook.is_historic() and (hookimpl.hookwrapper or hookimpl.wrapper):
|
||||
raise PluginValidationError(
|
||||
hookimpl.plugin,
|
||||
"Plugin %r\nhook %r\nhistoric incompatible with yield/wrapper/hookwrapper"
|
||||
'Plugin %r\nhook %r\nhistoric incompatible with yield/wrapper/hookwrapper'
|
||||
% (hookimpl.plugin_name, hook.name),
|
||||
)
|
||||
|
||||
|
|
@ -341,9 +341,9 @@ class PluginManager:
|
|||
if notinspec:
|
||||
raise PluginValidationError(
|
||||
hookimpl.plugin,
|
||||
"Plugin %r for hook %r\nhookimpl definition: %s\n"
|
||||
"Argument(s) %s are declared in the hookimpl but "
|
||||
"can not be found in the hookspec"
|
||||
'Plugin %r for hook %r\nhookimpl definition: %s\n'
|
||||
'Argument(s) %s are declared in the hookimpl but '
|
||||
'can not be found in the hookspec'
|
||||
% (
|
||||
hookimpl.plugin_name,
|
||||
hook.name,
|
||||
|
|
@ -357,17 +357,17 @@ class PluginManager:
|
|||
) and not inspect.isgeneratorfunction(hookimpl.function):
|
||||
raise PluginValidationError(
|
||||
hookimpl.plugin,
|
||||
"Plugin %r for hook %r\nhookimpl definition: %s\n"
|
||||
"Declared as wrapper=True or hookwrapper=True "
|
||||
"but function is not a generator function"
|
||||
'Plugin %r for hook %r\nhookimpl definition: %s\n'
|
||||
'Declared as wrapper=True or hookwrapper=True '
|
||||
'but function is not a generator function'
|
||||
% (hookimpl.plugin_name, hook.name, _formatdef(hookimpl.function)),
|
||||
)
|
||||
|
||||
if hookimpl.wrapper and hookimpl.hookwrapper:
|
||||
raise PluginValidationError(
|
||||
hookimpl.plugin,
|
||||
"Plugin %r for hook %r\nhookimpl definition: %s\n"
|
||||
"The wrapper=True and hookwrapper=True options are mutually exclusive"
|
||||
'Plugin %r for hook %r\nhookimpl definition: %s\n'
|
||||
'The wrapper=True and hookwrapper=True options are mutually exclusive'
|
||||
% (hookimpl.plugin_name, hook.name, _formatdef(hookimpl.function)),
|
||||
)
|
||||
|
||||
|
|
@ -376,14 +376,14 @@ class PluginManager:
|
|||
hook specification are optional, otherwise raise
|
||||
:exc:`PluginValidationError`."""
|
||||
for name in self.hook.__dict__:
|
||||
if name[0] != "_":
|
||||
if name[0] != '_':
|
||||
hook: HookCaller = getattr(self.hook, name)
|
||||
if not hook.has_spec():
|
||||
for hookimpl in hook.get_hookimpls():
|
||||
if not hookimpl.optionalhook:
|
||||
raise PluginValidationError(
|
||||
hookimpl.plugin,
|
||||
"unknown hook %r in plugin %r"
|
||||
'unknown hook %r in plugin %r'
|
||||
% (name, hookimpl.plugin),
|
||||
)
|
||||
|
||||
|
|
@ -404,11 +404,11 @@ class PluginManager:
|
|||
for dist in list(importlib.metadata.distributions()):
|
||||
for ep in dist.entry_points:
|
||||
if (
|
||||
ep.group != group
|
||||
or (name is not None and ep.name != name)
|
||||
ep.group != group or
|
||||
(name is not None and ep.name != name) or
|
||||
# already registered
|
||||
or self.get_plugin(ep.name)
|
||||
or self.is_blocked(ep.name)
|
||||
self.get_plugin(ep.name) or
|
||||
self.is_blocked(ep.name)
|
||||
):
|
||||
continue
|
||||
plugin = ep.load()
|
||||
|
|
@ -443,7 +443,7 @@ class PluginManager:
|
|||
return hookcallers
|
||||
|
||||
def add_hookcall_monitoring(
|
||||
self, before: _BeforeTrace, after: _AfterTrace
|
||||
self, before: _BeforeTrace, after: _AfterTrace,
|
||||
) -> Callable[[], None]:
|
||||
"""Add before/after tracing functions for all hooks.
|
||||
|
||||
|
|
@ -467,7 +467,7 @@ class PluginManager:
|
|||
) -> object | list[object]:
|
||||
before(hook_name, hook_impls, caller_kwargs)
|
||||
outcome = Result.from_call(
|
||||
lambda: oldcall(hook_name, hook_impls, caller_kwargs, firstresult)
|
||||
lambda: oldcall(hook_name, hook_impls, caller_kwargs, firstresult),
|
||||
)
|
||||
after(outcome, hook_name, hook_impls, caller_kwargs)
|
||||
return outcome.get_result()
|
||||
|
|
@ -484,10 +484,10 @@ class PluginManager:
|
|||
|
||||
Returns an undo function which, when called, removes the added tracing.
|
||||
"""
|
||||
hooktrace = self.trace.root.get("hook")
|
||||
hooktrace = self.trace.root.get('hook')
|
||||
|
||||
def before(
|
||||
hook_name: str, methods: Sequence[HookImpl], kwargs: Mapping[str, object]
|
||||
hook_name: str, methods: Sequence[HookImpl], kwargs: Mapping[str, object],
|
||||
) -> None:
|
||||
hooktrace.root.indent += 1
|
||||
hooktrace(hook_name, kwargs)
|
||||
|
|
@ -499,13 +499,13 @@ class PluginManager:
|
|||
kwargs: Mapping[str, object],
|
||||
) -> None:
|
||||
if outcome.exception is None:
|
||||
hooktrace("finish", hook_name, "-->", outcome.get_result())
|
||||
hooktrace('finish', hook_name, '-->', outcome.get_result())
|
||||
hooktrace.root.indent -= 1
|
||||
|
||||
return self.add_hookcall_monitoring(before, after)
|
||||
|
||||
def subset_hook_caller(
|
||||
self, name: str, remove_plugins: Iterable[_Plugin]
|
||||
self, name: str, remove_plugins: Iterable[_Plugin],
|
||||
) -> HookCaller:
|
||||
"""Return a proxy :class:`~pluggy.HookCaller` instance for the named
|
||||
method which manages calls to all registered plugins except the ones
|
||||
|
|
@ -518,4 +518,4 @@ class PluginManager:
|
|||
|
||||
|
||||
def _formatdef(func: Callable[..., object]) -> str:
|
||||
return f"{func.__name__}{inspect.signature(func)}"
|
||||
return f'{func.__name__}{inspect.signature(func)}'
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ from typing import TypeVar
|
|||
|
||||
|
||||
_ExcInfo = Tuple[Type[BaseException], BaseException, Optional[TracebackType]]
|
||||
ResultType = TypeVar("ResultType")
|
||||
ResultType = TypeVar('ResultType')
|
||||
|
||||
|
||||
class HookCallError(Exception):
|
||||
|
|
@ -27,7 +27,7 @@ class Result(Generic[ResultType]):
|
|||
"""An object used to inspect and set the result in a :ref:`hook wrapper
|
||||
<hookwrappers>`."""
|
||||
|
||||
__slots__ = ("_result", "_exception")
|
||||
__slots__ = ('_result', '_exception')
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
|
|
|||
|
|
@ -29,15 +29,15 @@ class TagTracer:
|
|||
else:
|
||||
extra = {}
|
||||
|
||||
content = " ".join(map(str, args))
|
||||
indent = " " * self.indent
|
||||
content = ' '.join(map(str, args))
|
||||
indent = ' ' * self.indent
|
||||
|
||||
lines = ["{}{} [{}]\n".format(indent, content, ":".join(tags))]
|
||||
lines = ['{}{} [{}]\n'.format(indent, content, ':'.join(tags))]
|
||||
|
||||
for name, value in extra.items():
|
||||
lines.append(f"{indent} {name}: {value}\n")
|
||||
lines.append(f'{indent} {name}: {value}\n')
|
||||
|
||||
return "".join(lines)
|
||||
return ''.join(lines)
|
||||
|
||||
def _processmessage(self, tags: tuple[str, ...], args: tuple[object, ...]) -> None:
|
||||
if self._writer is not None and args:
|
||||
|
|
@ -54,7 +54,7 @@ class TagTracer:
|
|||
|
||||
def setprocessor(self, tags: str | tuple[str, ...], processor: _Processor) -> None:
|
||||
if isinstance(tags, str):
|
||||
tags = tuple(tags.split(":"))
|
||||
tags = tuple(tags.split(':'))
|
||||
else:
|
||||
assert isinstance(tags, tuple)
|
||||
self._tags2proc[tags] = processor
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
# file generated by setuptools_scm
|
||||
# don't change, don't track in version control
|
||||
from __future__ import annotations
|
||||
TYPE_CHECKING = False
|
||||
if TYPE_CHECKING:
|
||||
from typing import Tuple, Union
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import final
|
||||
|
||||
|
||||
class PluggyWarning(UserWarning):
|
||||
"""Base class for all warnings emitted by pluggy."""
|
||||
|
||||
__module__ = "pluggy"
|
||||
__module__ = 'pluggy'
|
||||
|
||||
|
||||
@final
|
||||
|
|
@ -24,4 +26,4 @@ class PluggyTeardownRaisedWarning(PluggyWarning):
|
|||
<pluggy.Result.force_exception>` to set the exception instead of raising.
|
||||
"""
|
||||
|
||||
__module__ = "pluggy"
|
||||
__module__ = 'pluggy'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue