Skip to content

Commit

Permalink
Convert PluginManager to a dataclass
Browse files Browse the repository at this point in the history
  • Loading branch information
object-Object committed May 22, 2024
1 parent 6d0d831 commit 1419658
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/hexdoc/plugin/manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import importlib
from dataclasses import dataclass
from dataclasses import InitVar, dataclass, field
from importlib.resources import Package
from pathlib import Path
from types import ModuleType
Expand Down Expand Up @@ -87,21 +87,20 @@ class _NoCallTypedHookCaller(TypedHookCaller[_P, None]):
def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> Never: ...


# TODO: convert to dataclass
@dataclass
class PluginManager(ValidationContext):
"""Custom hexdoc plugin manager with helpers and stronger typing."""

def __init__(self, branch: str, props: Properties, load: bool = True) -> None:
"""Initialize the hexdoc plugin manager.
branch: str
props: Properties
load: InitVar[bool] = True
"""If true (the default), calls `init_entrypoints` and `init_mod_plugins`."""

If `load` is true (the default), calls `init_entrypoints` and `init_mod_plugins`.
"""
self.branch = branch
self.props = props
self.inner = pluggy.PluginManager(HEXDOC_PROJECT_NAME)
self.mod_plugins: dict[str, ModPlugin] = {}
self.book_plugins: dict[str, BookPlugin[Any]] = {}
mod_plugins: dict[str, ModPlugin] = field(default_factory=dict)
book_plugins: dict[str, BookPlugin[Any]] = field(default_factory=dict)

def __post_init__(self, load: bool):
self.inner = pluggy.PluginManager(HEXDOC_PROJECT_NAME)
self.inner.add_hookspecs(PluginSpec)
if load:
self.init_entrypoints()
Expand Down

0 comments on commit 1419658

Please sign in to comment.