Skip to content

Commit

Permalink
Removed usage of logger module for config handling
Browse files Browse the repository at this point in the history
There is still one place... a hack that is required to introduce the
new interface while not having the front-end refactored yet.
  • Loading branch information
led02 committed Feb 9, 2024
1 parent 25a5bc7 commit ac6a33b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
3 changes: 1 addition & 2 deletions src/hermes/commands/deposit/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import json

import hermes.logger as logger
from hermes.commands.deposit.base import BaseDepositPlugin
from hermes.model.path import ContextPath

Expand All @@ -17,7 +16,7 @@ def map_metadata(self) -> None:
self.ctx.update(ContextPath.parse('deposit.file'), self.ctx['codemeta'])

def publish(self) -> None:
file_config = logger.config.deposit.file
file_config = self.ctx.config.deposit.file
output_data = self.ctx['deposit.file']

with open(file_config.get('filename', 'hermes.json'), 'w') as deposition_file:
Expand Down
4 changes: 2 additions & 2 deletions src/hermes/commands/deposit/invenio.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, auth_token=None, platform_name=None) -> None:
if platform_name is not None:
self.platform_name = platform_name

self.config = getattr(logger.config.deposit, self.platform_name)
self.config = getattr(self.ctx.config.deposit, self.platform_name)
self.headers.update({"User-Agent": hermes_user_agent})

self.auth_token = auth_token
Expand Down Expand Up @@ -251,7 +251,7 @@ def __init__(self, click_ctx: click.Context, ctx: CodeMetaContext, client=None,
self.client = client

self.resolver = resolver or self.invenio_resolver_class(self.client)
self.config = getattr(logger.config.deposit, self.platform_name)
self.config = getattr(self.ctx.config.deposit, self.platform_name)
self.links = {}

# TODO: Populate some data structure here? Or move more of this into __init__?
Expand Down
4 changes: 1 addition & 3 deletions src/hermes/commands/postprocess/invenio.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import toml
from ruamel import yaml

import hermes.logger as logger


_log = logging.getLogger('deposit.invenio')

Expand All @@ -21,7 +19,7 @@ def config_record_id(ctx):
deposition_path = ctx.get_cache('deposit', 'deposit')
with deposition_path.open("r") as deposition_file:
deposition = json.load(deposition_file)
conf = logger.config.hermes
conf = ctx.config.hermes
try:
conf.deposit.invenio.record_id = deposition['record_id']
toml.dump(conf, open('hermes.toml', 'w'))
Expand Down
3 changes: 1 addition & 2 deletions src/hermes/commands/postprocess/invenio_rdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import logging

import toml
import hermes.logger as logger


_log = logging.getLogger('deposit.invenio_rdm')
Expand All @@ -19,7 +18,7 @@ def config_record_id(ctx):
deposition_path = ctx.get_cache('deposit', 'deposit')
with deposition_path.open("r") as deposition_file:
deposition = json.load(deposition_file)
conf = logger.config.hermes
conf = ctx.config.hermes
try:
conf['deposit']['invenio_rdm']['record_id'] = deposition['record_id']
toml.dump(conf, open('hermes.toml', 'w'))
Expand Down
9 changes: 4 additions & 5 deletions src/hermes/commands/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import click

import hermes.logger as logger
from hermes.commands.deposit.base import BaseDepositPlugin
from hermes.error import MisconfigurationError
from hermes.model.context import HermesContext, HermesHarvestContext, CodeMetaContext
Expand All @@ -40,7 +39,7 @@ def harvest(click_ctx: click.Context):
ctx.init_cache("harvest")

# Get all harvesters
harvest_config = logger.config.harvest
harvest_config = ctx.config.harvest
harvester_names = harvest_config.sources if type(harvest_config.sources) else [ep.name for ep in
metadata.entry_points(
group='hermes.harvest')]
Expand Down Expand Up @@ -85,7 +84,7 @@ def process(click_ctx: click.Context):
click_ctx.exit(1)

# Get all harvesters
harvest_config = logger.config.harvest
harvest_config = ctx.config.harvest
harvester_names = harvest_config.sources if type(harvest_config.sources) else [ep.name for ep in
metadata.entry_points(
group='hermes.harvest')]
Expand Down Expand Up @@ -192,7 +191,7 @@ def deposit(click_ctx: click.Context, initial, auth_token, file):
with open(codemeta_file) as codemeta_fh:
ctx.update(codemeta_path, json.load(codemeta_fh))

deposit_config = logger.config.deposit
deposit_config = ctx.config.deposit

plugin_group = "hermes.deposit"
# TODO: Is having a default a good idea?
Expand Down Expand Up @@ -242,7 +241,7 @@ def postprocess(click_ctx: click.Context):
click_ctx.exit(1)

# Get all postprocessors
postprocess_config = logger.config.postprocess
postprocess_config = ctx.config.postprocess
postprocess_names = postprocess_config.execute

for postprocess_name in postprocess_names:
Expand Down
4 changes: 4 additions & 0 deletions src/hermes/model/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def __init__(self, project_dir: t.Optional[Path] = None):
self._errors = []
self.contexts = {self.hermes_lod_context}

# HACK this needs to be done differently
from hermes import logger
self.config = logger.config

def __getitem__(self, key: ContextPath | str) -> t.Any:
"""
Access a single entry from the context.
Expand Down

0 comments on commit ac6a33b

Please sign in to comment.