Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes from the first release #253

Merged
merged 21 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/hermes-zenodo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- run: pip install hermes
- run: pip install hermes hermes-plugin-python
- run: hermes harvest
- run: hermes process
- run: hermes curate
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ dist/

# HERMES workflow specifics
.hermes/
hermes.log
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ title: hermes
message: >-
If you use this software, please cite it using the
metadata from this file.
version: 0.8.1b1
version: 0.8.1
license: "Apache-2.0"
abstract: "Tool to automate software publication. Not stable yet."
type: software
Expand Down
5 changes: 1 addition & 4 deletions hermes.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
# SPDX-License-Identifier: CC0-1.0

[harvest]
sources = [ "cff" ] # ordered priority (first one is most important)

[harvest.cff]
enable_validation = false
sources = [ "cff", "toml" ] # ordered priority (first one is most important)

[deposit]
target = "invenio_rdm"
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[tool.poetry]
# Reference at https://python-poetry.org/docs/pyproject/
name = "hermes"
version = "0.1.0"
version = "0.8.1"
description = "Workflow to publish research software with rich metadata"
homepage = "https://software-metadata.pub"
license = "Apache-2.0"
Expand All @@ -20,6 +20,7 @@ authors = [
"Jeffrey Kelling <[email protected]>",
"Oliver Knodel <[email protected]>",
"David Pape <[email protected]>",
"Sophie Kernchen <[email protected]>",
]

readme = "README.md"
Expand Down
1 change: 1 addition & 0 deletions src/hermes/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, parser: argparse.ArgumentParser):
self.settings = None

self.log = logging.getLogger(f"hermes.{self.command_name}")
self.errors = []

def init_plugins(self):
"""Collect and initialize the plugins available for the HERMES command."""
Expand Down
30 changes: 27 additions & 3 deletions src/hermes/commands/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
This module provides the main entry point for the HERMES command line application.
"""
import argparse
import sys

from hermes import logger
from hermes.commands import HermesHelpCommand, HermesCleanCommand, HermesHarvestCommand, HermesProcessCommand, \
HermesCurateCommand, HermesDepositCommand, HermesPostprocessCommand
from hermes.commands.base import HermesCommand
Expand Down Expand Up @@ -56,6 +58,28 @@ def main() -> None:
# Actually parse the command line, configure it and execute the selected sub-command.
args = parser.parse_args()

args.command.load_settings(args)
args.command.patch_settings(args)
args.command(args)
logger.init_logging()
log = logger.getLogger("hermes.cli")
log.debug("Running hermes with the following command line arguments: %s", args)

try:
log.debug("Loading settings...")
args.command.load_settings(args)

log.debug("Update settings from command line...")
args.command.patch_settings(args)

log.info("Run subcommand %s", args.command.command_name)
args.command(args)
except Exception as e:
log.error("An error occurred during execution of %s", args.command.command_name)
log.debug("Original exception was: %s", e)

sys.exit(2)

if args.command.errors:
for e in args.command.errors:
log.error(e)
sys.exit(1)

sys.exit(0)
5 changes: 3 additions & 2 deletions src/hermes/commands/deposit/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ def init_command_parser(self, command_parser: argparse.ArgumentParser) -> None:
def __call__(self, args: argparse.Namespace) -> None:
self.args = args
plugin_name = self.settings.target
print(self.args)

ctx = CodeMetaContext()
codemeta_file = ctx.get_cache("curate", ctx.hermes_name)
Expand All @@ -135,11 +134,13 @@ def __call__(self, args: argparse.Namespace) -> None:
try:
plugin_func = self.plugins[plugin_name](self, ctx)

except KeyError:
except KeyError as e:
self.log.error("Plugin '%s' not found.", plugin_name)
self.errors.append(e)

try:
plugin_func(self)

except HermesValidationError as e:
self.log.error("Error while executing %s: %s", plugin_name, e)
self.errors.append(e)
2 changes: 1 addition & 1 deletion src/hermes/commands/deposit/invenio.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class InvenioResolver:
invenio_client_class = InvenioClient

def __init__(self, client=None):
self.client = client or self.invenio_client_class()
self.client = client or self.invenio_client_class(InvenioDepositSettings())

def resolve_latest_id(
self, record_id=None, doi=None, codemeta_identifier=None
Expand Down
10 changes: 5 additions & 5 deletions src/hermes/commands/harvest/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ def __call__(self, args: argparse.Namespace) -> None:
try:
plugin_func = self.plugins[plugin_name]()
harvested_data, tags = plugin_func(self)
print(harvested_data)
with HermesHarvestContext(
ctx, plugin_name
) as harvest_ctx:

with HermesHarvestContext(ctx, plugin_name) as harvest_ctx:
harvest_ctx.update_from(harvested_data,
plugin=plugin_name,
timestamp=datetime.now().isoformat(), **tags)
for _key, ((_value, _tag), *_trace) in harvest_ctx._data.items():
if any(v != _value and t == _tag for v, t in _trace):
raise MergeError(_key, None, _value)

except KeyError:
except KeyError as e:
self.log.error("Plugin '%s' not found.", plugin_name)
self.errors.append(e)

except HermesValidationError as e:
self.log.error("Error while executing %s: %s", plugin_name, e)
self.errors.append(e)
2 changes: 1 addition & 1 deletion src/hermes/commands/postprocess/invenio.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def config_record_id(ctx):
conf.deposit.invenio.record_id = deposition['record_id']
toml.dump(conf, open('hermes.toml', 'w'))
except KeyError:
raise RuntimeError("No deposit.invenio configuration available to store record id in") from None
raise RuntimeError("No deposit.invenio configuration available to store record id in")


def cff_doi(ctx):
Expand Down
2 changes: 1 addition & 1 deletion src/hermes/commands/postprocess/invenio_rdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ def config_record_id(ctx):
conf['deposit']['invenio_rdm']['record_id'] = deposition['record_id']
toml.dump(conf, open('hermes.toml', 'w'))
except KeyError:
raise RuntimeError("No deposit.invenio configuration available to store record id in") from None
raise RuntimeError("No deposit.invenio_rdm configuration available to store record id in")
3 changes: 2 additions & 1 deletion src/hermes/commands/process/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def __call__(self, args: argparse.Namespace) -> None:
ctx.merge_contexts_from(harvest_context)

if ctx._errors:
self.log.error('!!! warning "Errors during merge"')
self.log.error('Errors during merge')
self.errors.extend(ctx._errors)

for ep, error in ctx._errors:
self.log.info(" - %s: %s", ep.name, error)
Expand Down
16 changes: 5 additions & 11 deletions src/hermes/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
'class': "logging.FileHandler",
'formatter': "logfile",
'level': "DEBUG",
'filename': "./.hermes/hermes.log",
'filename': "./hermes.log",
led02 marked this conversation as resolved.
Show resolved Hide resolved
},

'auditfile': {
Expand All @@ -50,12 +50,6 @@
},
}

# This dict caches all the different configuration sections already loaded
_config = {
# We need some basic logging configuration to get logging up and running at all
'logging': _logging_config,
}

_loggers = {}


Expand All @@ -64,14 +58,14 @@ def init_logging():
return

# Make sure the directories to hold the log files exists (or else create)
pathlib.Path(_config['logging']['handlers']['logfile']['filename']).parent.mkdir(exist_ok=True, parents=True)
pathlib.Path(_config['logging']['handlers']['auditfile']['filename']).parent.mkdir(exist_ok=True, parents=True)
pathlib.Path(_logging_config['handlers']['logfile']['filename']).parent.mkdir(exist_ok=True, parents=True)
pathlib.Path(_logging_config['handlers']['auditfile']['filename']).parent.mkdir(exist_ok=True, parents=True)

# Inintialize logging system
import logging.config

logging.config.dictConfig(_config['logging'])
for log_name in _config['logging']['loggers']:
logging.config.dictConfig(_logging_config)
for log_name in _logging_config['loggers']:
_loggers[log_name] = logging.getLogger(log_name)


Expand Down
44 changes: 0 additions & 44 deletions src/hermes/settings.py

This file was deleted.

2 changes: 2 additions & 0 deletions test/hermes_test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ def __setitem__(self, path, data):

def __enter__(self):
self.test_path.mkdir(parents=True, exist_ok=True)

for file_name, data in self.test_files.items():
file_path = self.test_path / file_name
file_path.parent.mkdir(parents=True, exist_ok=True)
file_path.write_text(data)

os.chdir(self.test_path)
Expand Down
10 changes: 7 additions & 3 deletions test/hermes_test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,27 @@
from hermes.commands import cli


def test_hermes_full(capsys):
def test_hermes_full():
with pytest.raises(SystemExit) as se:
cli.main()
assert "choose from" in se


@pytest.mark.skip(reason="Needs update")
def test_hermes_harvest(hermes_env):
hermes_env['hermes.toml'] = ""

with hermes_env:
result = hermes_env.run("harvest")

assert result.returncode == 0


@pytest.mark.skip(reason="Needs update")
def test_hermes_process(hermes_env):
hermes_env['hermes.toml'] = ""
hermes_env['.hermes/harvest/test.json'] = ""

with hermes_env:
result = hermes_env.run("process")
print(result.stdout.read())

assert result.returncode == 0
Loading