Skip to content

Commit

Permalink
WIP: feat(docworker): Support plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekSuchanek committed Sep 23, 2024
1 parent c852790 commit e11e441
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/dsw-document-worker/dsw/document_worker/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,11 @@ def main(config: DocumentWorkerConfig, workdir: str):
SentryReporter.capture_exception(e)
click.echo(f'Ended with error: {e}')
exit(2)


@click.command(name='list-plugins')
def list_plugins():
from .plugins import get_plugin_manager
plugin_manager = get_plugin_manager()
for plugin in plugin_manager.list_name_plugin():
click.echo(plugin)
1 change: 1 addition & 0 deletions packages/dsw-document-worker/dsw/document_worker/consts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CMD_CHANNEL = 'doc_worker'
CMD_COMPONENT = 'doc_worker'
COMPONENT_NAME = 'Document Worker'
PACKAGE_NAME = 'dsw-document-worker'
CURRENT_METAMODEL = 14
DEFAULT_ENCODING = 'utf-8'
EXIT_SUCCESS = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .host import get_plugin_manager, hookimpl

__all__ = ['get_plugin_manager', 'hookimpl']
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pluggy

from ..consts import PACKAGE_NAME
from ..templates.steps import Step


hookspec = pluggy.HookspecMarker(PACKAGE_NAME)


class PluginInfo:

def __init__(self, name, version):
self.name = name
self.version = version


@hookspec
def document_worker_steps() -> list[Step]:
pass

@hookspec
def document_worker_jinja_tests() -> dict:
pass

@hookspec
def document_worker_jinja_filters() -> dict:
pass

@hookspec
def document_worker_plugin_info() -> PluginInfo:
pass
13 changes: 13 additions & 0 deletions packages/dsw-document-worker/dsw/document_worker/plugins/host.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pluggy

from ..consts import PACKAGE_NAME
from . import hookspecs

hookimpl = pluggy.HookimplMarker(PACKAGE_NAME)

def get_plugin_manager():
pm = pluggy.PluginManager(PACKAGE_NAME)
pm.add_hookspecs(hookspecs)
pm.load_setuptools_entrypoints(PACKAGE_NAME)
# TODO: load local plugins
return pm
1 change: 1 addition & 0 deletions packages/dsw-document-worker/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies = [
'Markdown',
'MarkupSafe',
'pathvalidate',
'pluggy',
'python-dateutil',
'python-slugify',
'rdflib',
Expand Down
1 change: 1 addition & 0 deletions packages/dsw-document-worker/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ minio==7.2.8
panflute==2.3.1
pathvalidate==3.2.1
Pillow==10.4.0
pluggy==1.5.0
psycopg==3.2.2
psycopg-binary==3.2.2
pycparser==2.22
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ multidict==6.1.0
pathspec==0.12.1
pathvalidate==3.2.1
Pillow==10.4.0
pluggy==1.5.0
psycopg==3.2.2
psycopg-binary==3.2.2
pycparser==2.22
Expand Down

0 comments on commit e11e441

Please sign in to comment.