abx

Module Contents

Classes

HookSpecDecoratorThatReturnsFirstResult

Type of a plugin method decorated with @hookspec(firstresult=True), which returns a single result (from the first plugin that implements the hook)

HookSpecDecoratorThatReturnsListResults

Type of a plugin method decorated with @hookspec(firstresult=False), which returns a list of results (one for each plugin that implements the hook)

TypedHookspecMarker

Improved version of pluggy.HookspecMarker that supports type inference of hookspecs with firstresult=True|False correctly https://github.com/pytest-dev/pluggy/issues/191

PluginInfo

Full Metadata Dictionary containing all info about a plugin, returned by abx.get_plugin()

ABXPluginManager

Patch to fix pluggy’s PluginManager to work with pydantic models. See: https://github.com/pytest-dev/pluggy/pull/536

Functions

is_valid_attr_name

Check if a string is a valid attribute name (used to validate hook method names on a plugin)

is_valid_module_name

Check if a string e.g. “some_pkg.some_plugin_name” is a valid module name (used to validate plugin IDs)

get_plugin_order

Get the order a plugin should be loaded in by reading its ./.plugin_order file or .order attr

get_plugin

Get the full PluginInfo metadata for a plugin, given its plugin ID, module, or class

get_all_plugins

Get the PluginInfo metadata for all the loaded plugins

get_all_hook_names

Get the names of all hookspec/hookimpl methods available across all loaded plugins

get_all_hook_specs

Get a set of all hookspec methods defined in all plugins (useful for type checking if a pm.hook.call() is valid)

find_plugins_in_dir

Find all the plugins in a given directory. Just looks for an init.py file.

get_pip_installed_plugins

replaces pm.load_setuptools_entrypoints(“abx”), finds plugins that registered entrypoints via pip

load_plugins

Load all the plugins from a dictionary of module names and directory paths.

get_plugin_hooks

Get all the functions marked with @hookimpl on a plugin module or class.

as_list

Flatten a list of lists returned by a pm.hook.call() into a single list of [result1, result2, …]

as_dict

Flatten a list of dicts returned by a pm.hook.call() into a single dict of {plugin_id1: result1, plugin_id2: result2, …}

Data

__id__

__label__

__author__

__homepage__

__order__

ParamsT

ReturnT

AttrName

PluginId

PluginSpec

pm

API

abx.__id__[source]

‘abx’

abx.__label__[source]

‘ABX’

abx.__author__[source]

‘Nick Sweeting’

abx.__homepage__[source]

https://github.com/ArchiveBox/ArchiveBox

abx.__order__[source]

0

abx.ParamsT[source]

‘ParamSpec(…)’

abx.ReturnT[source]

‘TypeVar(…)’

class abx.HookSpecDecoratorThatReturnsFirstResult[source]

Bases: typing.Protocol

Type of a plugin method decorated with @hookspec(firstresult=True), which returns a single result (from the first plugin that implements the hook)

__call__(func: Callable[abx.ParamsT, abx.ReturnT]) Callable[abx.ParamsT, abx.ReturnT][source]
class abx.HookSpecDecoratorThatReturnsListResults[source]

Bases: typing.Protocol

Type of a plugin method decorated with @hookspec(firstresult=False), which returns a list of results (one for each plugin that implements the hook)

__call__(func: Callable[abx.ParamsT, abx.ReturnT]) Callable[abx.ParamsT, List[abx.ReturnT]][source]
class abx.TypedHookspecMarker(project_name: str)[source]

Improved version of pluggy.HookspecMarker that supports type inference of hookspecs with firstresult=True|False correctly https://github.com/pytest-dev/pluggy/issues/191

Initialization

__slots__[source]

(‘project_name’,)

__call__(function: Callable[abx.ParamsT, abx.ReturnT] | None = None, firstresult: bool = False, historic: bool = False, warn_on_impl: Warning | None = None, warn_on_impl_args: Mapping[str, Warning] | None = None) Callable[abx.ParamsT, List[abx.ReturnT]] | abx.HookSpecDecoratorThatReturnsListResults | abx.HookSpecDecoratorThatReturnsFirstResult[source]
abx.is_valid_attr_name(x: str) str[source]

Check if a string is a valid attribute name (used to validate hook method names on a plugin)

abx.is_valid_module_name(x: str) str[source]

Check if a string e.g. “some_pkg.some_plugin_name” is a valid module name (used to validate plugin IDs)

abx.AttrName[source]

None

abx.PluginId[source]

None

class abx.PluginInfo[source]

Bases: typing.TypedDict

Full Metadata Dictionary containing all info about a plugin, returned by abx.get_plugin()

Initialization

Initialize self. See help(type(self)) for accurate signature.

id: abx.PluginId[source]

None

package: abx.AttrName[source]

None

label: str[source]

None

version: str[source]

None

author: str[source]

None

homepage: str[source]

None

dependencies: List[str][source]

None

source_code: str[source]

None

hooks: Dict[abx.AttrName, Callable][source]

None

module: types.ModuleType[source]

None

abx.PluginSpec[source]

‘TypeVar(…)’

class abx.ABXPluginManager[source]

Bases: pluggy.PluginManager, typing.Generic[abx.PluginSpec]

Patch to fix pluggy’s PluginManager to work with pydantic models. See: https://github.com/pytest-dev/pluggy/pull/536

hook: abx.PluginSpec[source]

None

create_typed_hookcaller(name: str, module_or_class: Type[abx.PluginSpec], spec_opts: pluggy.HookspecOpts) pluggy.HookCaller[source]

create a new HookCaller subclass with a modified signature so that the return type is correct and args are converted to kwargs

add_hookspecs(module_or_class: Type[abx.PluginSpec]) None[source]

Add HookSpecs from the given class, (generic type allows us to enforce types of pm.hook.call() statically)

parse_hookimpl_opts(plugin, name: str) pluggy.HookimplOpts | None[source]
abx.pm[source]

‘ABXPluginManager(…)’

abx.get_plugin_order(plugin: abx.PluginId | pathlib.Path | types.ModuleType | Type) Tuple[int, pathlib.Path][source]

Get the order a plugin should be loaded in by reading its ./.plugin_order file or .order attr

abx.get_plugin(plugin: abx.PluginId | types.ModuleType | Type) abx.PluginInfo[source]

Get the full PluginInfo metadata for a plugin, given its plugin ID, module, or class

abx.get_all_plugins() Dict[abx.PluginId, abx.PluginInfo][source]

Get the PluginInfo metadata for all the loaded plugins

abx.get_all_hook_names() Set[str][source]

Get the names of all hookspec/hookimpl methods available across all loaded plugins

abx.get_all_hook_specs() Dict[str, Dict[str, Any]][source]

Get a set of all hookspec methods defined in all plugins (useful for type checking if a pm.hook.call() is valid)

abx.find_plugins_in_dir(plugins_dir: pathlib.Path) Dict[abx.PluginId, pathlib.Path][source]

Find all the plugins in a given directory. Just looks for an init.py file.

abx.get_pip_installed_plugins(group: abx.PluginId = 'abx') Dict[abx.PluginId, pathlib.Path][source]

replaces pm.load_setuptools_entrypoints(“abx”), finds plugins that registered entrypoints via pip

abx.load_plugins(plugins: Iterable[abx.PluginId | types.ModuleType | Type] | Dict[abx.PluginId, pathlib.Path])[source]

Load all the plugins from a dictionary of module names and directory paths.

abx.get_plugin_hooks(plugin: abx.PluginId | types.ModuleType | Type | None) Dict[abx.AttrName, Callable][source]

Get all the functions marked with @hookimpl on a plugin module or class.

abx.as_list(results: List[List[abx.ReturnT]]) List[abx.ReturnT][source]

Flatten a list of lists returned by a pm.hook.call() into a single list of [result1, result2, …]

abx.as_dict(results: List[Dict[abx.PluginId, abx.ReturnT]]) Dict[abx.PluginId, abx.ReturnT][source]

Flatten a list of dicts returned by a pm.hook.call() into a single dict of {plugin_id1: result1, plugin_id2: result2, …}