-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support document worker plugins
- Loading branch information
1 parent
40b940e
commit 9cd8b88
Showing
12 changed files
with
112 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/dsw-document-worker/dsw/document_worker/plugins/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .specs import hookspec, hookimpl | ||
|
||
__all__ = ['hookspec', 'hookimpl'] |
11 changes: 11 additions & 0 deletions
11
packages/dsw-document-worker/dsw/document_worker/plugins/manager.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import pluggy | ||
|
||
|
||
def create_manager(): | ||
import dsw.document_worker.plugins.specs as hookspecs | ||
from ..consts import PACKAGE_NAME, PLUGINS_ENTRYPOINT | ||
|
||
pm = pluggy.PluginManager(PACKAGE_NAME) | ||
pm.load_setuptools_entrypoints(PLUGINS_ENTRYPOINT) | ||
pm.add_hookspecs(hookspecs) | ||
return pm |
56 changes: 56 additions & 0 deletions
56
packages/dsw-document-worker/dsw/document_worker/plugins/specs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import pluggy | ||
import jinja2 | ||
|
||
from ..consts import PACKAGE_NAME | ||
from ..templates.steps import Step | ||
|
||
hookspec = pluggy.HookspecMarker(PACKAGE_NAME) | ||
hookimpl = pluggy.HookimplMarker(PACKAGE_NAME) | ||
|
||
|
||
@hookspec | ||
def provide_steps() -> dict[str, type[Step]]: | ||
""" | ||
Provide a list of steps that the plugin can execute. | ||
Steps are used to process the document generation in a specific way. Each step | ||
must comply with the interface of the provided `Step` class. The plugin must make | ||
sure to return a list of steps that it can execute and in compliance with the | ||
`Step` class in the current implementation (use correct dsw-document-worker as | ||
a dependency). | ||
:return: a list of steps | ||
""" | ||
pass | ||
|
||
|
||
@hookspec | ||
def enrich_document_context(context: dict) -> None: | ||
""" | ||
Enrich the document context with custom data. | ||
The plugin can enrich the provided document context with custom data that can be | ||
used in the document generation process. The context is a dictionary that is passed | ||
to each step during the document generation process. The plugin can manipulate the | ||
context in any way it sees fit. | ||
:param context: the document context to enrich | ||
""" | ||
|
||
|
||
@hookspec | ||
def enrich_jinja_env(jinja_env: jinja2.Environment, options: dict[str, str]) -> None: | ||
""" | ||
Enrich the Jinja environment with custom filters, tests, policies, etc. | ||
The plugin can enrich the provided Jinja environment with custom features like | ||
filters, tests, policies, global variables and other. It can manipulate the Jinja | ||
environment in any way it sees fit but should ensure that the environment is safe | ||
to use in the document generation process. This Jinja environment is used within | ||
all steps that are subclass of the `JinjaPoweredStep` (mainly the `jinja` step | ||
implemented in class `Jinja2Step`). | ||
:param jinja_env: the Jinja environment to enrich | ||
:param options: the options provided to the step | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters