diff --git a/stubs/pluggy/@tests/stubtest_allowlist.txt b/stubs/pluggy/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000000..5a73304647ef --- /dev/null +++ b/stubs/pluggy/@tests/stubtest_allowlist.txt @@ -0,0 +1 @@ +pluggy._hooks._HookRelay.__getattr__ # is not present at runtime diff --git a/stubs/pluggy/METADATA.toml b/stubs/pluggy/METADATA.toml new file mode 100644 index 000000000000..c203c5d89c32 --- /dev/null +++ b/stubs/pluggy/METADATA.toml @@ -0,0 +1 @@ +version = "1.2.0" diff --git a/stubs/pluggy/pluggy/__init__.pyi b/stubs/pluggy/pluggy/__init__.pyi new file mode 100644 index 000000000000..5a4d250a5596 --- /dev/null +++ b/stubs/pluggy/pluggy/__init__.pyi @@ -0,0 +1,5 @@ +from ._hooks import HookimplMarker as HookimplMarker, HookspecMarker as HookspecMarker +from ._manager import PluginManager as PluginManager, PluginValidationError as PluginValidationError +from ._result import HookCallError as HookCallError + +__version__: str diff --git a/stubs/pluggy/pluggy/_hooks.pyi b/stubs/pluggy/pluggy/_hooks.pyi new file mode 100644 index 000000000000..5d8596a06ee5 --- /dev/null +++ b/stubs/pluggy/pluggy/_hooks.pyi @@ -0,0 +1,116 @@ +from collections.abc import Callable, Generator, Mapping, Sequence +from types import ModuleType +from typing import Any, TypeVar, overload +from typing_extensions import TypeAlias, TypedDict + +from ._result import _Result + +_T = TypeVar("_T") +_F = TypeVar("_F", bound=Callable[..., object]) +_Namespace: TypeAlias = ModuleType | type +_Plugin: TypeAlias = object +_HookExec: TypeAlias = Callable[[str, Sequence[HookImpl], Mapping[str, object], bool], object | list[object]] +_HookImplFunction: TypeAlias = Callable[..., _T | Generator[None, _Result[_T], None]] + +class _HookSpecOpts(TypedDict): + firstresult: bool + historic: bool + warn_on_impl: Warning | None + +class _HookImplOpts(TypedDict): + wrapper: bool + hookwrapper: bool + optionalhook: bool + tryfirst: bool + trylast: bool + specname: str | None + +class HookspecMarker: + project_name: str + def __init__(self, project_name: str) -> None: ... + @overload + def __call__( + self, function: _F, firstresult: bool = False, historic: bool = False, warn_on_impl: Warning | None = None + ) -> _F: ... + @overload + def __call__( + self, function: None = None, firstresult: bool = False, historic: bool = False, warn_on_impl: Warning | None = None + ) -> Callable[[_F], _F]: ... + +class HookimplMarker: + project_name: str + def __init__(self, project_name: str) -> None: ... + @overload + def __call__( + self, + function: _F, + hookwrapper: bool = False, + optionalhook: bool = False, + tryfirst: bool = False, + trylast: bool = False, + specname: str | None = None, + wrapper: bool = False, + ) -> _F: ... + @overload + def __call__( + self, + function: None = None, + hookwrapper: bool = False, + optionalhook: bool = False, + tryfirst: bool = False, + trylast: bool = False, + specname: str | None = None, + wrapper: bool = False, + ) -> Callable[[_F], _F]: ... + +def normalize_hookimpl_opts(opts: _HookImplOpts) -> None: ... +def varnames(func: object) -> tuple[tuple[str, ...], tuple[str, ...]]: ... + +class _HookRelay: + def __getattr__(self, name: str) -> _HookCaller: ... + +class _HookCaller: + name: str + spec: HookSpec | None + def __init__( + self, + name: str, + hook_execute: _HookExec, + specmodule_or_class: _Namespace | None = None, + spec_opts: _HookSpecOpts | None = None, + ) -> None: ... + def has_spec(self) -> bool: ... + def set_specification(self, specmodule_or_class: _Namespace, spec_opts: _HookSpecOpts) -> None: ... + def is_historic(self) -> bool: ... + def get_hookimpls(self) -> list[HookImpl]: ... + def __call__(self, **kwargs: object) -> Any: ... + def call_historic( + self, result_callback: Callable[[Any], None] | None = None, kwargs: Mapping[str, object] | None = None + ) -> None: ... + def call_extra(self, methods: Sequence[Callable[..., object]], kwargs: Mapping[str, object]) -> Any: ... + +class HookImpl: + function: _HookImplFunction[object] + plugin: _Plugin + opts: _HookImplOpts + plugin_name: str + wrapper: bool + hookwrapper: bool + optionalhook: bool + tryfirst: bool + trylast: bool + argnames: tuple[str, ...] + kwargnames: tuple[str, ...] + def __init__( + self, plugin: _Plugin, plugin_name: str, function: _HookImplFunction[object], hook_impl_opts: _HookImplOpts + ) -> None: ... + +class HookSpec: + namespace: _Namespace + function: Callable[..., object] + name: str + opts: _HookSpecOpts + warn_on_impl: Warning | None + argnames: tuple[str, ...] + kwargnames: tuple[str, ...] + def __init__(self, namespace: _Namespace, name: str, opts: _HookSpecOpts) -> None: ... diff --git a/stubs/pluggy/pluggy/_manager.pyi b/stubs/pluggy/pluggy/_manager.pyi new file mode 100644 index 000000000000..7bb775202b1e --- /dev/null +++ b/stubs/pluggy/pluggy/_manager.pyi @@ -0,0 +1,65 @@ +import sys +from _typeshed import Incomplete +from collections.abc import Callable, Iterable, Mapping, Sequence +from typing import Any +from typing_extensions import TypeAlias + +from ._hooks import ( + HookImpl as HookImpl, + HookSpec as HookSpec, + _HookCaller, + _HookImplOpts, + _HookRelay, + _HookSpecOpts, + _Namespace, + _Plugin, + normalize_hookimpl_opts as normalize_hookimpl_opts, +) +from ._result import _Result as _Result +from ._tracing import TagTracerSub + +if sys.version_info >= (3, 8): + from importlib.metadata import Distribution +else: + Distribution: TypeAlias = Any + +_BeforeTrace: TypeAlias = Callable[[str, Sequence[HookImpl], Mapping[str, Any]], None] +_AfterTrace: TypeAlias = Callable[[_Result[Any], str, Sequence[HookImpl], Mapping[str, Any]], None] + +class PluginValidationError(Exception): + plugin: _Plugin + def __init__(self, plugin: _Plugin, message: str) -> None: ... + +class DistFacade: + def __init__(self, dist: Distribution) -> None: ... + @property + def project_name(self) -> str: ... + def __getattr__(self, attr: str, default: Incomplete | None = None) -> Any: ... + def __dir__(self) -> list[str]: ... + +class PluginManager: + project_name: str + trace: TagTracerSub + hook: _HookRelay + def __init__(self, project_name: str) -> None: ... + def register(self, plugin: _Plugin, name: str | None = None) -> str | None: ... + def parse_hookimpl_opts(self, plugin: _Plugin, name: str) -> _HookImplOpts | None: ... + def unregister(self, plugin: _Plugin | None = None, name: str | None = None) -> _Plugin: ... + def set_blocked(self, name: str) -> None: ... + def is_blocked(self, name: str) -> bool: ... + def add_hookspecs(self, module_or_class: _Namespace) -> None: ... + def parse_hookspec_opts(self, module_or_class: _Namespace, name: str) -> _HookSpecOpts | None: ... + def get_plugins(self) -> set[Any]: ... + def is_registered(self, plugin: _Plugin) -> bool: ... + def get_canonical_name(self, plugin: _Plugin) -> str: ... + def get_plugin(self, name: str) -> Any | None: ... + def has_plugin(self, name: str) -> bool: ... + def get_name(self, plugin: _Plugin) -> str | None: ... + def check_pending(self) -> None: ... + def load_setuptools_entrypoints(self, group: str, name: str | None = None) -> int: ... + def list_plugin_distinfo(self) -> list[tuple[_Plugin, DistFacade]]: ... + def list_name_plugin(self) -> list[tuple[str, _Plugin]]: ... + def get_hookcallers(self, plugin: _Plugin) -> list[_HookCaller] | None: ... + def add_hookcall_monitoring(self, before: _BeforeTrace, after: _AfterTrace) -> Callable[[], None]: ... + def enable_tracing(self) -> Callable[[], None]: ... + def subset_hook_caller(self, name: str, remove_plugins: Iterable[_Plugin]) -> _HookCaller: ... diff --git a/stubs/pluggy/pluggy/_result.pyi b/stubs/pluggy/pluggy/_result.pyi new file mode 100644 index 000000000000..d92990612c9a --- /dev/null +++ b/stubs/pluggy/pluggy/_result.pyi @@ -0,0 +1,19 @@ +from _typeshed import ExcInfo +from collections.abc import Callable +from typing import Generic, TypeVar + +_T = TypeVar("_T") + +class HookCallError(Exception): ... + +class _Result(Generic[_T]): + def __init__(self, result: _T | None, exception: BaseException | None) -> None: ... + @property + def excinfo(self) -> ExcInfo | None: ... + @property + def exception(self) -> BaseException | None: ... + @classmethod + def from_call(cls, func: Callable[[], _T]) -> _Result[_T]: ... + def force_result(self, result: _T) -> None: ... + def force_exception(self, exception: BaseException) -> None: ... + def get_result(self) -> _T: ... diff --git a/stubs/pluggy/pluggy/_tracing.pyi b/stubs/pluggy/pluggy/_tracing.pyi new file mode 100644 index 000000000000..8f441007b7aa --- /dev/null +++ b/stubs/pluggy/pluggy/_tracing.pyi @@ -0,0 +1,20 @@ +from collections.abc import Callable +from typing import Any +from typing_extensions import TypeAlias + +_Writer: TypeAlias = Callable[[str], object] +_Processor: TypeAlias = Callable[[tuple[str, ...], tuple[Any, ...]], None] + +class TagTracer: + indent: int + def __init__(self) -> None: ... + def get(self, name: str) -> TagTracerSub: ... + def setwriter(self, writer: _Writer | None) -> None: ... + def setprocessor(self, tags: str | tuple[str, ...], processor: _Processor) -> None: ... + +class TagTracerSub: + root: TagTracer + tags: tuple[str, ...] + def __init__(self, root: TagTracer, tags: tuple[str, ...]) -> None: ... + def __call__(self, *args: object) -> None: ... + def get(self, name: str) -> TagTracerSub: ...