Skip to content

Commit 2878155

Browse files
Merge pull request #470 from softwarepub/feature/454-e2e-process
Merged features for process (new data model) back into the feature branches base branch.
2 parents 96861ec + 3291c4d commit 2878155

19 files changed

Lines changed: 1729 additions & 76 deletions

File tree

src/hermes/commands/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
# "unused import" errors.
99
# flake8: noqa
1010

11-
# from hermes.commands.base import HermesHelpCommand
12-
# from hermes.commands.base import HermesVersionCommand
13-
# from hermes.commands.clean.base import HermesCleanCommand
11+
from hermes.commands.base import HermesHelpCommand
12+
from hermes.commands.base import HermesVersionCommand
13+
from hermes.commands.clean.base import HermesCleanCommand
1414
# from hermes.commands.init.base import HermesInitCommand
1515
# from hermes.commands.curate.base import HermesCurateCommand
1616
from hermes.commands.harvest.base import HermesHarvestCommand
17-
# from hermes.commands.process.base import HermesProcessCommand
17+
from hermes.commands.process.base import HermesProcessCommand
1818
from hermes.commands.deposit.base import HermesDepositCommand
1919
# from hermes.commands.postprocess.base import HermesPostprocessCommand

src/hermes/commands/base.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def __call__(self, command: HermesCommand) -> None:
175175

176176

177177
class HermesHelpSettings(BaseModel):
178+
"""Intentionally empty settings class for the help command."""
178179
pass
179180

180181

@@ -200,3 +201,23 @@ def __call__(self, args: argparse.Namespace) -> None:
200201
# Otherwise, simply show the general help and exit (cleanly).
201202
self.parser.print_help()
202203
self.parser.exit()
204+
205+
206+
class HermesVersionSettings(BaseModel):
207+
"""Intentionally empty settings class for the version command."""
208+
pass
209+
210+
211+
class HermesVersionCommand(HermesCommand):
212+
"""Show HERMES version and exit."""
213+
214+
command_name = "version"
215+
settings_class = HermesVersionSettings
216+
217+
def load_settings(self, args: argparse.Namespace):
218+
"""Pass loading settings as not necessary for this command."""
219+
pass
220+
221+
def __call__(self, args: argparse.Namespace) -> None:
222+
self.log.info(metadata.version("hermes"))
223+
self.parser.exit()

src/hermes/commands/cli.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
# from hermes.commands import (HermesHelpCommand, HermesVersionCommand, HermesCleanCommand,
1717
# HermesHarvestCommand, HermesProcessCommand, HermesCurateCommand,
1818
# HermesDepositCommand, HermesPostprocessCommand, HermesInitCommand)
19-
from hermes.commands import HermesDepositCommand, HermesHarvestCommand
19+
from hermes.commands import (
20+
HermesDepositCommand, HermesHarvestCommand, HermesHelpCommand, HermesProcessCommand, HermesVersionCommand
21+
)
2022
from hermes.commands.base import HermesCommand
2123

2224

@@ -38,12 +40,12 @@ def main() -> None:
3840
setting_types = {}
3941

4042
for command in (
41-
# HermesHelpCommand(parser),
42-
# HermesVersionCommand(parser),
43+
HermesHelpCommand(parser),
44+
HermesVersionCommand(parser),
4345
# HermesInitCommand(parser),
4446
# HermesCleanCommand(parser),
4547
HermesHarvestCommand(parser),
46-
# HermesProcessCommand(parser),
48+
HermesProcessCommand(parser),
4749
# HermesCurateCommand(parser),
4850
HermesDepositCommand(parser),
4951
# HermesPostprocessCommand(parser),

src/hermes/commands/deposit/invenio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ def _codemeta_to_invenio_deposition(self) -> dict:
513513

514514
creators = []
515515
for author in metadata.get("author", []):
516-
if not "Person" in author.get("@type", []):
516+
if "Person" not in author.get("@type", []):
517517
continue
518518
creator = {}
519519
if len(
@@ -527,7 +527,7 @@ def _codemeta_to_invenio_deposition(self) -> dict:
527527
raise HermesValidationError(f"Author has too many family names: {author}")
528528
if len(author.get("familyName", [])) == 1:
529529
given_names_str = " ".join(author.get("givenName", []))
530-
name = f"{author["familyName"][0]}, {given_names_str}"
530+
name = f"{author['familyName'][0]}, {given_names_str}"
531531
elif len(author.get("name", [])) != 1:
532532
raise HermesValidationError(f"Author has too many or no names: {author}")
533533
else:

src/hermes/commands/process/base.py

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
# SPDX-FileContributor: Michael Meinel
66

77
import argparse
8-
import json
9-
import sys
108

119
from pydantic import BaseModel
1210

1311
from hermes.commands.base import HermesCommand, HermesPlugin
14-
from hermes.model.context import HermesHarvestContext, CodeMetaContext
12+
from hermes.model.api import SoftwareMetadata
13+
from hermes.model.context_manager import HermesContext
14+
from hermes.model.error import HermesContextError
15+
from hermes.model.merge.container import ld_merge_dict
1516

1617

1718
class HermesProcessPlugin(HermesPlugin):
@@ -33,42 +34,27 @@ class HermesProcessCommand(HermesCommand):
3334

3435
def __call__(self, args: argparse.Namespace) -> None:
3536
self.args = args
36-
ctx = CodeMetaContext()
37-
38-
if not (ctx.hermes_dir / "harvest").exists():
39-
self.log.error("You must run the harvest command before process")
40-
sys.exit(1)
37+
ctx = HermesContext()
38+
merged_doc = ld_merge_dict([{}])
4139

4240
# Get all harvesters
4341
harvester_names = self.root_settings.harvest.sources
44-
harvester_names.reverse() # Switch order for priority handling
4542

43+
ctx.prepare_step('harvest')
4644
for harvester in harvester_names:
4745
self.log.info("## Process data from %s", harvester)
48-
49-
harvest_context = HermesHarvestContext(ctx, harvester, {})
5046
try:
51-
harvest_context.load_cache()
52-
# when the harvest step ran, but there is no cache file, this is a serious flaw
53-
except FileNotFoundError:
54-
self.log.warning("No output data from harvester %s found, skipping", harvester)
47+
metadata = SoftwareMetadata.load_from_cache(ctx, harvester)
48+
except HermesContextError as e:
49+
self.log.error("Error while trying to load data from harvest plugin '%s': %s", harvester, e)
50+
self.errors.append(e)
5551
continue
56-
57-
ctx.merge_from(harvest_context)
58-
ctx.merge_contexts_from(harvest_context)
59-
60-
if ctx._errors:
61-
self.log.error('Errors during merge')
62-
self.errors.extend(ctx._errors)
63-
64-
for ep, error in ctx._errors:
65-
self.log.info(" - %s: %s", ep.name, error)
66-
67-
tags_path = ctx.get_cache('process', 'tags', create=True)
68-
with tags_path.open('w') as tags_file:
69-
json.dump(ctx.tags, tags_file, indent=2)
70-
71-
ctx.prepare_codemeta()
72-
73-
with open(ctx.get_cache("process", ctx.hermes_name, create=True), 'w') as codemeta_file:
74-
json.dump(ctx._data, codemeta_file, indent=2)
52+
merged_doc.update(metadata)
53+
ctx.finalize_step("harvest")
54+
55+
ctx.prepare_step("process")
56+
with ctx["result"] as result_ctx:
57+
result_ctx["codemeta"] = merged_doc.compact()
58+
result_ctx["context"] = {"@context": merged_doc.full_context}
59+
result_ctx["expanded"] = merged_doc.ld_value
60+
ctx.finalize_step("process")

src/hermes/model/api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# SPDX-FileCopyrightText: 2026 German Aerospace Center (DLR)
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# SPDX-FileContributor: Michael Fritzsche
6+
# SPDX-FileContributor: Stephan Druskat
7+
18
from hermes.model.context_manager import HermesContext, HermesContexError
29
from hermes.model.types import ld_dict
310
from hermes.model.types.ld_context import ALL_CONTEXTS

src/hermes/model/merge/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-FileCopyrightText: 2022 German Aerospace Center (DLR)
2+
#
3+
# SPDX-License-Identifier: Apache-2.0

0 commit comments

Comments
 (0)