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
+16-14Lines changed: 16 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,16 +33,16 @@ And uses the [schmea.org](https://schema.org/) (with prefix "schema") and the [C
33
33
HERMES uses a plugin architecture. Therefore, users are invited to contribute own features.
34
34
35
35
The structure for every plugin follows the same schema.
36
-
Every plugin is a sub class of a sub class of the `HermesPlugin` class.
37
-
This class implements one abstract method, `__call__`, which needs to be overwritten by every plugin.
38
-
In between the `HermesPlugin` class and the class of a specific plugin there is another class which follows the naming scheme `Hermes{Step}Plugin` where `{Step}` is the step the plugin is for.
36
+
Every plugin is a sub class of a sub class of the {py:class}`~hermes.commands.base.HermesPlugin` class.
37
+
This class implements one abstract method, {py:meth}`~hermes.commands.base.HermesPlugin.__call__`, which needs to be overwritten by every plugin.
38
+
In between the {py:class}`~hermes.commands.base.HermesPlugin` class and the class of a specific plugin there is another class which follows the naming scheme `Hermes{Step}Plugin` where `{Step}` is the step the plugin is for.
39
39
These base classes may implement additional (abstract) methods that may have to be implemented by the plugins class.
40
40
41
-
The first positional attribute of the `__call__` method is an object of class `Hermes{Step}Command` (where `{Step}` is the step the plugin is for), which is a sub class of `HermesCommand`, which triggered this plugin to run.
41
+
The first positional attribute of the `__call__` method is an object of class `Hermes{Step}Command` (where `{Step}` is the step the plugin is for), which is a sub class of {py:class}`~hermes.commands.base.HermesCommand`, which triggered this plugin to run.
42
42
An exception to this are the deposit plugins. Those don't implement the `__call__` method and instead can implement (and have to implement some) other functions.
43
43
44
-
The plugin class also uses a derivative of `HermesSettings` to add parameters that can be adapted by the configuration file.
45
-
`HermesSettings` is the base class for command specific settings.
44
+
The plugin class also uses a derivative of {py:class}`~hermes.commands.base.HermesSettings` to add parameters that can be adapted by the configuration file.
45
+
{py:class}`~hermes.commands.base.HermesSettings` is the base class for command specific settings.
46
46
It uses [pydantic](https://docs.pydantic.dev/latest/)[settings](https://docs.pydantic.dev/latest/api/pydantic_settings/) to specify and validate the parameters.
47
47
The user can either set the parameters in the `hermes.toml` or overwrite them in the command line.
48
48
To overwrite a parameter from command line, use the `-O` command line option followed by the dotted parameter name and the value.
@@ -80,7 +80,7 @@ class YourHarvestPlugin(HermesHarvestPlugin):
80
80
return data
81
81
```
82
82
83
-
The `__call__` method of harest plugins needs to return a SoftwareMetadata object containing the harvested metadata.
83
+
The {py:meth}`~hermes.commands.harvest.base.HermesHarvestPlugin.__call__` method of harest plugins needs to return a {py:class}`~hermes.model.api.SoftwareMetadata` object containing the harvested metadata.
84
84
For more information on how to use this object see [here](../dev/data_model.md).
85
85
86
86
### Process plugin
@@ -110,8 +110,8 @@ class YourProcessPlugin(HermesProcessPlugin):
110
110
return strategies
111
111
```
112
112
113
-
The `__call__` method of process plugins needs to return a dictionary mappings strings and/ or `None` to dictionaries mapping strings or `None` to {py:class}`hermes.model.merge.action.MergeAction`.
114
-
If `strategies` looked like this (where `Reject` is imported from `hermes.model.merge.action`)
113
+
The {py:meth}`~hermes.commands.process.base.HermesProcessPlugin.__call__` method of process plugins needs to return a dictionary mappings strings and/ or `None` to dictionaries mapping strings or `None` to {py:class}`~hermes.model.merge.action.MergeAction`.
114
+
If `strategies` looked like this (where {py:class}`~hermes.model.merge.action.Reject` is imported from {py:mod}`hermes.model.merge.action`)
115
115
```{code-block} python
116
116
strategies = {
117
117
full_type_iri: {
@@ -122,7 +122,7 @@ strategies = {
122
122
}
123
123
```
124
124
125
-
HERMES would use the `Reject` strategy for merging values of the key `full_property_iri` in objects of type `full_type_iri`. (A key in strategies being `None` instead of a string indicates to HERMES that its value is to be used as a default [i.e. if no more specific entry exists].)
125
+
HERMES would use the {py:class}`~hermes.model.merge.action.Reject` strategy for merging values of the key `full_property_iri` in objects of type `full_type_iri`. (A key in strategies being `None` instead of a string indicates to HERMES that its value is to be used as a default [i.e. if no more specific entry exists].)
126
126
127
127
HERMES will prioritize strategies from other plugins depending on the order of the plugins in the `hermes.toml`. Generally the hierarchy is as follows (first most important):
128
128
1. strategies with `full_property_iri` and `full_type_iri` not `None`.
@@ -157,7 +157,7 @@ class YourCuratePlugin(HermesCuratePlugin):
157
157
return data
158
158
```
159
159
160
-
The `__call__` method of harest plugins needs to return a SoftwareMetadata object containing the curated metadata.
160
+
The {py:meth}`~hermes.commands.curate.base.HermesCuratePlugin.__call__` method of curate plugins needs to return a {py:class}`~hermes.model.api.SoftwareMetadata` object containing the curated metadata.
161
161
For more information on how to use this object see [here](../dev/data_model.md).
162
162
The returned object may be the object `metadata` passed to `__call__`.
163
163
@@ -225,7 +225,7 @@ class YourDepositPlugin(HermesDepositPlugin):
225
225
A deposit plugin doesn't implement a `__call__` method like plugins for other steps.
226
226
Instead it can (and in some cases has to) implement methods, which will be called in a predefined order.
227
227
228
-
The plugin still has access to the command (via self.command) and the metadata for the software (via self.metadata).
228
+
The plugin still has access to the command (via `self.command`) and the metadata for the software (via `self.metadata`).
229
229
230
230
### Postprocess plugin
231
231
The class structure of a postprocess plugin should look like this:
@@ -259,7 +259,7 @@ with ctx[deposit_plugin_name] as manager:
259
259
ctx.finalize_step("deposit")
260
260
```
261
261
262
-
where `deposit_plugin_name` is the name of the deposit plugin the data is loaded from and HermesContext is {py:class}`hermes.model.context_manager.HermesContext`.
262
+
where `deposit_plugin_name` is the name of the deposit plugin the data is loaded from and {py:class}`~hermes.model.context_manager.HermesContext` is imported from {py:mod}`hermes.model.context_manager`.
263
263
The loaded data is some valid JSON data and has no fixed format.
264
264
265
265
## Implement and use plugin specific settings
@@ -376,11 +376,13 @@ target = "{plugin_name}"
376
376
[postprocess]
377
377
run = [ ..., "{plugin_name}", ... ]
378
378
...
379
+
379
380
```
380
381
<br><br>
381
382
```{admonition} Congratulations!
382
383
You can now write plugins for HERMES.
383
-
Consider publishing it for others to use following this guide. TODO: add link
384
384
```
385
385
386
+
Consider publishing it to the [HERMES plugin marketplace](../index.md#plugins) for others to use following this guide. TODO: add link
387
+
386
388
If you have any questions, wishes or requests, feel free to contact us.
0 commit comments