mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-11 13:44: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
|
|
@ -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)}'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue