-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #218 from hermes-hmc/feature/class-based-plugins
Class-based architecture for deposition plugins
- Loading branch information
Showing
10 changed files
with
804 additions
and
1,450 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ docs/build/ | |
|
||
.idea/ | ||
.venv/ | ||
.vscode/ | ||
dist/ | ||
|
||
# HERMES workflow specifics | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# SPDX-FileCopyrightText: 2023 Helmholtz-Zentrum Dresden-Rossendorf (HZDR) | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# SPDX-FileContributor: David Pape | ||
# SPDX-FileContributor: Michael Meinel | ||
|
||
import abc | ||
|
||
import click | ||
|
||
from hermes.model.context import CodeMetaContext | ||
|
||
|
||
class BaseDepositPlugin(abc.ABC): | ||
def __init__(self, click_ctx: click.Context, ctx: CodeMetaContext) -> None: | ||
self.click_ctx = click_ctx | ||
self.ctx = ctx | ||
|
||
def __call__(self) -> None: | ||
"""Initiate the deposition process. | ||
This calls a list of additional methods on the class, none of which need to be implemented. | ||
""" | ||
self.prepare() | ||
self.map_metadata() | ||
|
||
if self.is_initial_publication(): | ||
self.create_initial_version() | ||
else: | ||
self.create_new_version() | ||
|
||
self.update_metadata() | ||
self.delete_artifacts() | ||
self.upload_artifacts() | ||
self.publish() | ||
|
||
def prepare(self) -> None: | ||
"""Prepare the deposition. | ||
This method may be implemented to check whether config and context match some initial conditions. | ||
If no exceptions are raised, execution continues. | ||
""" | ||
pass | ||
|
||
@abc.abstractmethod | ||
def map_metadata(self) -> None: | ||
"""Map the given metadata to the target schema of the deposition platform.""" | ||
pass | ||
|
||
def is_initial_publication(self) -> bool: | ||
"""Decide whether to do an initial publication or publish a new version. | ||
Returning ``True`` indicates that publication of an initial version will be executed, resulting in a call of | ||
:meth:`create_initial_version`. ``False`` indicates a new version of an existing publication, leading to a call | ||
of :meth:`create_new_version`. | ||
By default, this returns ``True``. | ||
""" | ||
return True | ||
|
||
@abc.abstractmethod | ||
def create_initial_version(self) -> None: | ||
"""Create an initial version of the publication on the target platform.""" | ||
pass | ||
|
||
@abc.abstractmethod | ||
def create_new_version(self) -> None: | ||
"""Create a new version of an existing publication on the target platform.""" | ||
pass | ||
|
||
@abc.abstractmethod | ||
def update_metadata(self) -> None: | ||
"""Update the metadata of the newly created version.""" | ||
pass | ||
|
||
def delete_artifacts(self) -> None: | ||
"""Delete any superfluous artifacts taken from the previous version of the publication.""" | ||
pass | ||
|
||
def upload_artifacts(self) -> None: | ||
"""Upload new artifacts to the target platform.""" | ||
pass | ||
|
||
@abc.abstractmethod | ||
def publish(self) -> None: | ||
"""Publish the newly created deposit on the target platform.""" | ||
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
Oops, something went wrong.