123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- """Base class for all plugins."""
- from collections.abc import Callable, Sequence
- from pathlib import Path
- from typing import ParamSpec, Protocol, TypedDict, TypeVarTuple
- from typing_extensions import Unpack
- class CommonContext(TypedDict):
- """Common context for all plugins."""
- P = ParamSpec("P")
- class AddTaskProtcol(Protocol):
- """Protocol for adding a task to the pre-compile context."""
- def __call__(
- self, task: Callable[P, tuple[str, str]], /, *args: P.args, **kwargs: P.kwargs
- ) -> None:
- """Add a task to the pre-compile context.
- Args:
- task: The task to add.
- args: The arguments to pass to the task
- kwargs: The keyword arguments to pass to the task
- """
- class PreCompileContext(CommonContext):
- """Context for pre-compile hooks."""
- add_task: AddTaskProtcol
- Types = TypeVarTuple("Types")
- class Plugin:
- """Base class for all plugins."""
- def get_frontend_development_dependancies(
- self, **context: Unpack[CommonContext]
- ) -> list[str] | set[str] | tuple[str, ...]:
- """Get the NPM packages required by the plugin for development.
- Args:
- context: The context for the plugin.
- Returns:
- A list of packages required by the plugin for development.
- """
- return []
- def get_frontend_dependancies(
- self, **context: Unpack[CommonContext]
- ) -> list[str] | set[str] | tuple[str, ...]:
- """Get the NPM packages required by the plugin.
- Args:
- context: The context for the plugin.
- Returns:
- A list of packages required by the plugin.
- """
- return []
- def get_static_assets(
- self, **context: Unpack[CommonContext]
- ) -> Sequence[tuple[Path, str | bytes]]:
- """Get the static assets required by the plugin.
- Args:
- context: The context for the plugin.
- Returns:
- A list of static assets required by the plugin.
- """
- return []
- def get_stylesheet_paths(self, **context: Unpack[CommonContext]) -> Sequence[str]:
- """Get the paths to the stylesheets required by the plugin relative to the styles directory.
- Args:
- context: The context for the plugin.
- Returns:
- A list of paths to the stylesheets required by the plugin.
- """
- return []
- def pre_compile(self, **context: Unpack[PreCompileContext]) -> None:
- """Called before the compilation of the plugin.
- Args:
- context: The context for the plugin.
- """
|