Skip to content

Commit 7d0cd30

Browse files
committed
Make the plugin ready for the new data model
1 parent d076672 commit 7d0cd30

3 files changed

Lines changed: 43 additions & 19 deletions

File tree

hermes.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
sources = ["cff"]
88

99
[curate]
10-
method = "software_card"
10+
plugin = "software_card"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ classifiers = [
2828
]
2929
requires-python = ">=3.11"
3030
dependencies = [
31-
"hermes @ git+https://github.com/softwarepub/hermes.git@develop",
31+
"hermes @ git+https://github.com/softwarepub/hermes.git@refactor/data-model",
3232
"software-card-policies @ git+https://github.com/softwarepub/software-card-policies.git",
3333
]
3434

src/hermes_plugin_software_card/curate.py

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
"""Module containing the Software CaRD curation plugin for HERMES."""
77

88
import json
9-
from pathlib import Path
109

11-
from hermes.commands.curate.base import BaseCuratePlugin
10+
from hermes.commands.base import HermesCommand
11+
from hermes.commands.curate.base import HermesCuratePlugin
12+
from hermes.model import SoftwareMetadata
13+
from hermes.model.hermes_cache import HermesCacheManager
1214
from software_card_policies.config import Config
1315
from software_card_policies.data_model import (
1416
make_shacl_graph,
@@ -20,12 +22,12 @@
2022
from hermes_plugin_software_card import environment
2123

2224

23-
class SoftwareCaRDCuratePlugin(BaseCuratePlugin):
25+
class SoftwareCaRDCuratePlugin(HermesCuratePlugin):
2426
"""Software CaRD curation plugin."""
2527

26-
def __init__(self, command, ctx):
28+
def __init__(self):
2729
"""Initialize the plugin."""
28-
super().__init__(command, ctx)
30+
super().__init__()
2931
self._data_graph = None
3032
self._shacl_graph = None
3133
self._conforms = False
@@ -65,14 +67,34 @@ def __init__(self, command, ctx):
6567
}
6668
}
6769

68-
def prepare(self):
70+
def __call__(
71+
self, command: HermesCommand, metadata: SoftwareMetadata
72+
) -> SoftwareMetadata:
73+
"""Entry point of the callable.
74+
75+
This method runs the main logic of the plugin. It calls the other methods of the
76+
object in the correct order. Depending on the result of
77+
``is_publication_approved`` the corresponding ``process_decision_*()`` method is
78+
called, based on the curation decision.
79+
"""
80+
self.prepare(metadata)
81+
self.validate()
82+
self.create_report(metadata)
83+
84+
if not self.is_publication_approved():
85+
return SoftwareMetadata()
86+
87+
return metadata
88+
89+
def prepare(self, metadata: SoftwareMetadata):
6990
"""Prepare the validation.
7091
7192
The metadata given in the context is parsed as an RDF graph and then validated
7293
using the Software CaRD validation.
7394
"""
74-
text = json.dumps(self.ctx.get_data()["curate"])
75-
self._data_graph = read_rdf_resource(format="json-ld", data=text)
95+
self._data_graph = read_rdf_resource(
96+
format="json-ld", data=json.dumps(metadata.ld_value)
97+
)
7698
self._shacl_graph = make_shacl_graph(Config.from_dict(self._validation_config))
7799

78100
def validate(self):
@@ -81,8 +103,17 @@ def validate(self):
81103
self._conforms = conforms
82104
self._validation_graph = validation_graph
83105

84-
def create_report(self):
85-
"""Create basic text report."""
106+
def create_report(self, metadata: SoftwareMetadata):
107+
"""Create validation report.
108+
109+
This creates the report both as a machine-readble JSON-LD file, and prints the
110+
URL to the Software CaRD web app to the screen.
111+
"""
112+
ctx = HermesCacheManager()
113+
validation_file = ctx.cache_dir / "curate" / "validation.json"
114+
validation_file.parent.mkdir(exist_ok=True, parents=True)
115+
self._validation_graph.serialize(validation_file, format="json-ld")
116+
86117
self._report = create_report(self._validation_graph)
87118
if self._environment is None:
88119
print("Software CaRD plugin not running in CI environment.")
@@ -95,10 +126,3 @@ def create_report(self):
95126
def is_publication_approved(self) -> bool:
96127
"""Decide whether the publication of the software is approved."""
97128
return self._conforms
98-
99-
def process_decision_positive(self):
100-
"""Write the given metadata into the curate directory."""
101-
curate_output = Path(self.ctx.get_cache("curate", self.ctx.hermes_name))
102-
Path.mkdir(curate_output.parent)
103-
with open(curate_output, "w") as curate_output_fh:
104-
json.dump(self.ctx.get_data(), curate_output_fh)

0 commit comments

Comments
 (0)