oaknut.extension¶
The entry-point plug-in framework shared by every extensible axis of
the oaknut family. An axis is one extension point — a family of
interchangeable plug-ins that all answer the same question. The primary
axis is oaknut.filesystem (each plug-in detects and operates on one
disc format); oaknut.command (CLI subcommands) is another.
A concrete extension subclasses Extension,
declares a kind (a short identifier such as "filesystem"), and is
registered under the oaknut.<kind> entry-point namespace in its
package’s pyproject.toml:
[project.entry-points."oaknut.filesystem"]
acorn-dfs = "oaknut.dfs.filesystem:AcornDFS"
Consumers discover and load extensions with the functions below, which wrap stevedore. Discovery is by installed entry point, so a plug-in shipped by any package appears automatically — there is no central registry to edit.
This module is deliberately domain-agnostic: it knows nothing about discs, files, or formats. Per-axis packages build a thin convenience layer on top.
Every name documented here is importable directly from
oaknut.extension.
The extension base class¶
- class oaknut.extension.Extension(name, **kwargs)¶
Base class for every oaknut plug-in extension.
A concrete extension overrides
_kind()to name its axis and is instantiated with the entry-pointnameit was registered under. The class docstring doubles as its human-readable description (seedescribe()).- Parameters:
name (str)
- classmethod dirpath()¶
The directory path to the package providing this extension.
- Return type:
- classmethod version()¶
The extension version. Override to report something meaningful.
- Return type:
- classmethod describe(*, single_line=False)¶
A human-readable description of the extension.
By default this is the extension class’s docstring. Override it if you want something different.
- classmethod entry_point_name()¶
The entry-point name (key) this extension class is registered under.
Performs a reverse lookup from class to entry-point name by searching the axis’s namespace. Cached indefinitely since entry-point names are immutable for the life of the process.
- Raises:
ExtensionError – If this class is not a registered extension.
- Return type:
- exception oaknut.extension.ExtensionError(*args, exit_code=None)¶
Raised when an extension cannot be discovered or loaded.
A plug-in that is missing, mis-registered, or fails at import time is an environment/setup problem rather than bad input or a library bug — hence a
ConfigurationError.
Namespaces¶
Discovery and loading¶
- oaknut.extension.list_extensions(namespace)¶
List the names of the extensions registered in namespace.
- oaknut.extension.create_extension(kind, namespace, name, exception_type=None, **kwargs)¶
Instantiate an extension by name.
- Parameters:
kind (str) – The kind of extension (for error messages).
namespace (str) – The entry-point namespace to search.
name (str) – The name of the extension to load.
exception_type (type[BaseException] | None) – Exception raised if the extension cannot be loaded. Defaults to
ExtensionError.**kwargs – Forwarded to the extension constructor.
- Returns:
An
Extensioninstance.- Return type:
- oaknut.extension.extension(kind, namespace, name, exception_type=None)¶
Get an extension class (without instantiating it).
- Parameters:
kind (str) – The kind of extension (for error messages).
namespace (str) – The entry-point namespace to search.
name (str) – The name of the extension to load.
exception_type (type[BaseException] | None) – Exception raised if the extension cannot be loaded. Defaults to
ExtensionError.
- Returns:
The extension class.
- Return type:
- oaknut.extension.describe_extension(kind, namespace, name, exception_type=None, *, single_line=False)¶
Return the description of an extension by name.
- Parameters:
kind (str) – The kind of extension (for error messages).
namespace (str) – The entry-point namespace to search.
name (str) – The name of the extension.
exception_type (type[BaseException] | None) – Exception raised if the extension cannot be loaded.
single_line (bool) – If True, return only the first non-empty line.
- Returns:
The extension’s description string.
- Return type:
- oaknut.extension.extension_name_from_class(namespace, extension_class)¶
Reverse-lookup the entry-point name for an extension class.
Iterates the extensions in namespace until one whose plug-in is extension_class is found.
- Raises:
ExtensionError – If the class is not registered in namespace.
- Parameters:
- Return type:
- oaknut.extension.list_dirpaths(namespace)¶
Map each extension name in namespace to its package directory path.
- oaknut.extension.load_failure_callback(manager, entrypoint, exception)¶
Turn a stevedore load failure into an
ExtensionError.