You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/tutorials/writing-a-plugin-for-hermes.md
+19-10Lines changed: 19 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,14 @@
1
1
<!--
2
-
SPDX-FileCopyrightText: 2024 German Aerospace Center (DLR)
2
+
SPDX-FileCopyrightText: 2025 German Aerospace Center (DLR), Forschungszentrum Jülich GmbH
3
3
4
4
SPDX-License-Identifier: CC-BY-SA-4.0
5
5
-->
6
6
7
7
<!--
8
8
SPDX-FileContributor: Michael Meinel
9
9
SPDX-FileContributor: Sophie Kernchen
10
+
SPDX-FileContributor: Nitai Heeb
11
+
SPDX-FileContributor: Oliver Bertuch
10
12
-->
11
13
12
14
# Write a plugin for HERMES
@@ -26,7 +28,7 @@ If you never used HERMES before, you might want to check the tutorial: [Automate
26
28
27
29
HERMES uses a plugin architecture. Therefore, users are invited to contribute own features.
28
30
The structure for every plugin follows the same schema.
29
-
There is a top-level base class for every plugin. In this `HermesPlugin` class there is one abstract method `__ call __` which needs to be overwritten.
31
+
There is a top-level base class for every plugin. In this `HermesPlugin` class there is one abstract method `__call__` which needs to be overwritten.
30
32
Furthermore, the `HermesCommand` class provides all needs for writing a plugin used in a HERMES command.
31
33
So the `HermesPlugin`s call method gets an instance of the `HermesCommand` that triggered this plugin to run.
32
34
In our case this will be the `HermesHarvestCommand` which calls all harvest plugins.
@@ -38,6 +40,7 @@ To overwrite a parameter from command line, use the `-O` command line option fol
38
40
E.g., you can set your authentication token for InvenioRDM by adding the following options to your call to `hermes deposit`:
To write a new plugin, it is important to follow the given structure.
@@ -64,15 +67,21 @@ class GitHarvestPlugin(HermesHarvestPlugin):
64
67
return {}, {}
65
68
```
66
69
67
-
The code uses the `HermesHarvestPlugin` as base class and pydantics Basemodel for the settings. In the `GitHarvestSettings` you
68
-
can see that an additional parameter is defined. The Parameter `from_branch` is specific for this plugin and can be accessed inside the plugin using `self.settings.harvest.git.git_branch` as long as our plugin will be named git.
70
+
The code uses the `HermesHarvestPlugin` as base class and pydantic's base model for the settings.
71
+
In the `GitHarvestSettings` you can see that an additional parameter is defined.
72
+
The Parameter `from_branch` is specific for this plugin and can be accessed inside the plugin using `self.settings.harvest.git.from_branch` as long as our plugin will be named `git`.
69
73
In the `hermes.toml` this would be achieved by [harvest.{plugin_name}].
70
-
The `GitHarvestSettings` are associated with the `GitHarvestPlugin`. In the plugin you need to overwrite the `__ call __` method.
71
-
For now a simple Hello World will do. The method returns two dictionaries. These will contain the harvested data in CodeMeta (JSON-LD) and additional information, e.g., to provide provenance information.
74
+
The `GitHarvestSettings` are associated with the `GitHarvestPlugin`.
75
+
In the plugin you need to overwrite the `__call__` method.
76
+
For now a simple "Hello World" will do. The method returns two dictionaries.
77
+
These will contain the harvested data in CodeMeta (JSON-LD) and additional information, e.g., to provide provenance information.
72
78
That is the basic structure for the plugins source code.
73
79
74
-
To integrate this code, you have to register it as a plugin in the `pyproject.toml`. To learn more about the `pyproject.toml` check https://python-poetry.org/docs/pyproject/ or refer to [PEP621](https://peps.python.org/pep-0621/).
75
-
We will just look at the important places for this plugin. There are two ways to integrate this plugin. First we will show how to use the plugin environment as the running base with HERMES as a dependency.
80
+
To integrate this code, you have to register it as a plugin in the `pyproject.toml`.
81
+
To learn more about the `pyproject.toml` check https://python-poetry.org/docs/pyproject/ or refer to [PEP621](https://peps.python.org/pep-0621/).
82
+
We will just look at the important places for this plugin.
83
+
There are two ways to integrate this plugin.
84
+
First we will show how to use the plugin environment as the running base with HERMES as a dependency.
76
85
Then we say how to integrate this plugin in HERMES itself.
77
86
78
87
### Include HERMES as Dependency
@@ -124,10 +133,10 @@ Note that this differs with the accessibility and your wishes, check [Explicit P
124
133
125
134
The second thing to adapt is to declare the access point for the plugin.
126
135
You can do that with `git = "hermes_plugin_git.harvest:GitHarvestPlugin"`.
127
-
This expression makes the GitHarvestPlugin from the hermes_plugin_git package, a hermes.harvest plugin named git.
136
+
This expression makes the `GitHarvestPlugin` from the `hermes_plugin_git` package, a `hermes.harvest` plugin named `git`.
128
137
So you need to configure this line with your plugin properties.
129
138
130
-
Now you just need to add the plugin to the hermes.toml and reinstall the adapted poetry package.
139
+
Now you just need to add the plugin to the `hermes.toml` and reinstall the adapted poetry package.
131
140
132
141
### Configure hermes.toml
133
142
To use the plugin, you have to activate it in the `hermes.toml`.
0 commit comments