Skip to content

Commit 7a8e8ae

Browse files
author
notactuallyfinn
committed
implemented suggestions and fixed bug
1 parent ad63e5a commit 7a8e8ae

3 files changed

Lines changed: 41 additions & 12 deletions

File tree

src/hermes/commands/deposit/file.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77
# SPDX-FileContributor: Stephan Druskat
88

99
import json
10+
import logging
11+
import os
1012

1113
from pydantic import BaseModel
1214

1315
from hermes.commands.deposit.base import BaseDepositPlugin
1416

1517

18+
_log = logging.getLogger("cli.deposit.file")
19+
20+
1621
class FileDepositSettings(BaseModel):
1722
filename: str = 'hermes.json'
1823

@@ -31,3 +36,4 @@ def publish(self) -> None:
3136

3237
with open(file_config.filename, 'w') as deposition_file:
3338
json.dump(self.metadata.compact(), deposition_file, indent=2)
39+
_log.info(f"The deposited metadata can be found in {os.path.abspath(file_config.filename)}.")

src/hermes/commands/deposit/invenio.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,23 @@ def prepare(self) -> None:
311311
- update ``self.metadata`` with metadata collected during the checks
312312
"""
313313

314-
rec_id = self.config.record_id
315-
doi = self.config.doi
316-
317-
codemeta_identifier = self.metadata.get("identifier", None)
318-
rec_id, rec_meta = self.resolver.resolve_latest_id(
319-
record_id=rec_id, doi=doi, codemeta_identifier=codemeta_identifier
320-
)
314+
conf_rec_id = self.config.record_id
315+
conf_doi = self.config.doi
316+
317+
codemeta_identifiers = self.metadata.get("identifier", [None])
318+
rec_id, rec_meta = None, {}
319+
for codemeta_identifier in codemeta_identifiers:
320+
if not isinstance(codemeta_identifier, str):
321+
# FIXME: Can also be PropertyValue (i.e. ld_dict), that case has to be handled.
322+
codemeta_identifier = None
323+
tmp_rec_id, tmp_rec_meta = self.resolver.resolve_latest_id(
324+
record_id=conf_rec_id, doi=conf_doi, codemeta_identifier=codemeta_identifier
325+
)
326+
if tmp_rec_id is not None or tmp_rec_meta != {}:
327+
if rec_id != tmp_rec_id or rec_meta != tmp_rec_meta:
328+
# FIXME: Maybe finding different record ids is not fatal?
329+
raise HermesValidationError("Found two different record ids or conflicting metadata.")
330+
rec_id, rec_meta = tmp_rec_id, tmp_rec_meta
321331

322332
if len(self.metadata.get("version", [])) > 1:
323333
raise HermesValidationError("Too many licenses for invenio deposit.")

src/hermes/commands/process/base.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from hermes.error import HermesPluginRunError, MisconfigurationError
1414
from hermes.model.api import SoftwareMetadata
1515
from hermes.model.context_manager import HermesContext
16-
from hermes.model.error import HermesValidationError
1716
from hermes.model.merge.action import MergeAction
1817
from hermes.model.merge.container import ld_merge_dict
1918

@@ -28,6 +27,7 @@ def __call__(self, command: HermesCommand) -> dict[Union[str, None], dict[Union[
2827
class ProcessSettings(BaseModel):
2928
"""Generic deposition settings."""
3029

30+
sources: list = []
3131
plugins: list = []
3232

3333

@@ -72,19 +72,32 @@ def __call__(self, args: argparse.Namespace) -> None:
7272

7373
self.log.info("## Merge the metadata of the harvesters")
7474
# Get all harvesters
75-
harvester_names = self.root_settings.harvest.sources
75+
harvester_names = self.settings.sources if self.settings.sources else self.root_settings.harvest.sources
76+
merged_any = False
7677
for harvester in harvester_names:
7778
self.log.info(f"## Load data from {harvester} plugin")
7879
# load data from harvester
7980
try:
8081
metadata = SoftwareMetadata.load_from_cache(ctx, harvester)
81-
except Exception as e:
82-
self.log.error(f"The data from the harvester {harvester} could not be loaded or is invalid.")
83-
raise HermesValidationError(f"The results of the harvest plugin {harvester} is invalid.") from e
82+
except Exception:
83+
# skip this harvester when the data is invalid
84+
self.log.warning(f"The data from the harvester {harvester} could not be loaded or is invalid.")
85+
self.log.info(f"## Aborting merge for {harvester}")
86+
continue
8487

8588
self.log.info(f"## Merge data from {harvester} plugin")
8689
# merge data into the merge dict
8790
merged_doc.update(metadata)
91+
merged_any = True
92+
93+
# error if nothing was merged
94+
if not merged_any:
95+
self.log.error(
96+
f"""No metadata has been merged. {
97+
"No harvesters to merge from were supplied" if not harvester_names else
98+
"The merging failed for all harvesters."
99+
}"""
100+
)
88101

89102
self.log.info("## Store processed metadata")
90103
# store processed data

0 commit comments

Comments
 (0)