Skip to content

Commit 0f6e0ec

Browse files
author
notactuallyfinn
committed
rename context_manager and its classes
1 parent 42045b5 commit 0f6e0ec

21 files changed

Lines changed: 80 additions & 80 deletions

File tree

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def read_version_from_pyproject():
194194
def autoapi_skip_member(app, obj_type, name, obj, skip, options):
195195
if obj_type == "attribute":
196196
if any(documented_type in obj.id for documented_type in [
197-
"Collect", "HermesCache", "HermesContext", "HermesMergeError", "ld_container", "ld_context", "ld_dict",
197+
"Collect", "HermesCache", "HermesCacheManager", "HermesMergeError", "ld_container", "ld_context", "ld_dict",
198198
"ld_list", "ld_merge_dict", "ld_merge_list", "MergeSet"
199199
]):
200200
return True

docs/source/tutorials/writing-a-plugin-for-hermes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,14 @@ class YourPostprocessPlugin(HermesPostprocessPlugin):
252252
The metadata from a deposit plugin can be loaded via
253253

254254
```python
255-
ctx = HermesContext()
255+
ctx = HermesCacheManager()
256256
ctx.prepare_step("deposit")
257257
with ctx[deposit_plugin_name] as manager:
258258
deposition = manager["result"]
259259
ctx.finalize_step("deposit")
260260
```
261261

262-
where `deposit_plugin_name` is the name of the deposit plugin the data is loaded from and {py:class}`~hermes.model.context_manager.HermesContext` is imported from {py:mod}`hermes.model.context_manager`.
262+
where `deposit_plugin_name` is the name of the deposit plugin the data is loaded from and {py:class}`~hermes.model.hermes_cache.HermesCacheManager` is imported from {py:mod}`hermes.model.hermes_cache`.
263263
The loaded data is some valid JSON data and has no fixed format.
264264

265265
## Implement and use plugin specific settings

src/hermes/commands/curate/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from hermes.commands.base import HermesCommand, HermesPlugin
1212
from hermes.error import HermesPluginRunError, MisconfigurationError
1313
from hermes.model import SoftwareMetadata
14-
from hermes.model.context_manager import HermesContext
14+
from hermes.model.hermes_cache import HermesCacheManager
1515
from hermes.model.error import HermesValidationError
1616

1717

@@ -38,7 +38,7 @@ def __call__(self, args: argparse.Namespace) -> None:
3838
self.log.info("# Metadata curation")
3939
plugin_name = self.settings.plugin
4040

41-
ctx = HermesContext()
41+
ctx = HermesCacheManager()
4242
ctx.prepare_step("curate")
4343

4444
self.log.info("## Load processed metadata")

src/hermes/commands/deposit/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from hermes.commands.base import HermesCommand, HermesPlugin
1414
from hermes.error import HermesPluginRunError, MisconfigurationError
15-
from hermes.model.context_manager import HermesContext
15+
from hermes.model.hermes_cache import HermesCacheManager
1616
from hermes.model import SoftwareMetadata
1717
from hermes.model.error import HermesValidationError
1818

@@ -29,7 +29,7 @@ def __call__(self, command: HermesCommand) -> None:
2929
This calls a list of additional methods on the class, none of which need to be implemented.
3030
"""
3131
self.command = command
32-
self.ctx = HermesContext()
32+
self.ctx = HermesCacheManager()
3333
self.ctx.prepare_step("deposit")
3434

3535
self.ctx.prepare_step("curate")

src/hermes/commands/harvest/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from hermes.commands.base import HermesCommand, HermesPlugin
1212
from hermes.error import HermesPluginRunError, MisconfigurationError
13-
from hermes.model.context_manager import HermesContext
13+
from hermes.model.hermes_cache import HermesCacheManager
1414
from hermes.model import SoftwareMetadata
1515

1616

@@ -45,7 +45,7 @@ def __call__(self, args: argparse.Namespace) -> None:
4545
raise MisconfigurationError("No harvest plugin was configured to be run and loaded.")
4646

4747
# Initialize the harvest cache directory here to indicate the step ran
48-
ctx = HermesContext()
48+
ctx = HermesCacheManager()
4949
ctx.prepare_step('harvest')
5050

5151
self.log.info("## Load and run the plugins")

src/hermes/commands/postprocess/invenio.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import tomlkit
1414

1515
from hermes.error import MisconfigurationError
16-
from hermes.model.context_manager import HermesContext
16+
from hermes.model.hermes_cache import HermesCacheManager
1717
from ..base import HermesCommand
1818
from .base import HermesPostprocessPlugin
1919

@@ -23,7 +23,7 @@
2323

2424
class config_record_id(HermesPostprocessPlugin):
2525
def __call__(self, command: HermesCommand):
26-
ctx = HermesContext()
26+
ctx = HermesCacheManager()
2727
ctx.prepare_step("deposit")
2828
with ctx["invenio"] as manager:
2929
deposition = manager["result"]
@@ -47,7 +47,7 @@ def __call__(self, command: HermesCommand):
4747

4848
class cff_doi(HermesPostprocessPlugin):
4949
def __call__(self, command: HermesCommand):
50-
ctx = HermesContext()
50+
ctx = HermesCacheManager()
5151
ctx.prepare_step("deposit")
5252
with ctx["invenio"] as manager:
5353
deposition = manager["result"]
@@ -78,7 +78,7 @@ def __call__(self, command: HermesCommand):
7878

7979
class codemeta_doi(HermesPostprocessPlugin):
8080
def __call__(self, command: HermesCommand):
81-
ctx = HermesContext()
81+
ctx = HermesCacheManager()
8282
ctx.prepare_step("deposit")
8383
with ctx["invenio"] as manager:
8484
deposition = manager["result"]

src/hermes/commands/postprocess/invenio_rdm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import tomlkit
1212

1313
from hermes.error import MisconfigurationError
14-
from hermes.model.context_manager import HermesContext
14+
from hermes.model.hermes_cache import HermesCacheManager
1515
from ..base import HermesCommand
1616
from .base import HermesPostprocessPlugin
1717

@@ -21,7 +21,7 @@
2121

2222
class config_record_id(HermesPostprocessPlugin):
2323
def __call__(self, command: HermesCommand):
24-
ctx = HermesContext()
24+
ctx = HermesCacheManager()
2525
ctx.prepare_step("deposit")
2626
with ctx["invenio_rdm"] as manager:
2727
deposition = manager["result"]

src/hermes/commands/process/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from hermes.commands.base import HermesCommand, HermesPlugin
1313
from hermes.error import HermesPluginRunError, MisconfigurationError
1414
from hermes.model.api import SoftwareMetadata
15-
from hermes.model.context_manager import HermesContext
15+
from hermes.model.hermes_cache import HermesCacheManager
1616
from hermes.model.merge.action import MergeAction
1717
from hermes.model.merge.container import ld_merge_dict
1818

@@ -83,7 +83,7 @@ def __call__(self, args: argparse.Namespace) -> None:
8383
self.log.critical("## No process plugin was ran successfully.")
8484
raise HermesPluginRunError("No process plugin was ran successfully.")
8585

86-
ctx = HermesContext()
86+
ctx = HermesCacheManager()
8787
ctx.prepare_step('harvest')
8888

8989
# merge data from harvesters

src/hermes/model/api.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from hermes.model.types.ld_context import ALL_CONTEXTS
1414
from hermes.model.types.pyld_util import bundled_loader
1515

16-
from .context_manager import HermesContext
17-
from .error import HermesContextError
16+
from .hermes_cache import HermesCacheManager
17+
from .error import HermesCacheError
1818

1919

2020
class SoftwareMetadata(ld_dict):
@@ -44,21 +44,21 @@ def __init__(
4444
super().__init__([ld_dict.from_dict(data, context=ctx).data_dict if data else {}], context=ctx)
4545

4646
@classmethod
47-
def load_from_cache(cls: type[Self], ctx: HermesContext, source: str) -> "SoftwareMetadata":
47+
def load_from_cache(cls: type[Self], ctx: HermesCacheManager, source: str) -> "SoftwareMetadata":
4848
"""
49-
Loads the JSON_LD data from the given HermesContext object at the given source.\n
49+
Loads the JSON_LD data from the given HermesCacheManager object at the given source.\n
5050
Note that only data from "codemeta.json" or ("context.json" and "expanded.json") is loaded where "codemeta.json"
5151
is preferred.
5252
5353
Args:
54-
ctx (HermesContext): The HERMES cache the data is loaded from.
54+
ctx (HermesCacheManager): The HERMES cache the data is loaded from.
5555
source (str): The directory the inside the cache the data is loaded from.
5656
5757
Returns:
5858
SoftwareMetadata: The SoftwareMetadata loaded from the cache.
5959
6060
Raises:
61-
HermesContextError: If neither of the listed files contains valid data for a SoftwareMetadata object.
61+
HermesCacheError: If neither of the listed files contains valid data for a SoftwareMetadata object.
6262
"""
6363
# open the directory in the context
6464
with ctx[source] as cache:
@@ -80,16 +80,16 @@ def load_from_cache(cls: type[Self], ctx: HermesContext, source: str) -> "Softwa
8080
return data
8181
except Exception as e:
8282
# No data could be loaded, raise an error instead.
83-
raise HermesContextError("There is no (valid) data stored in the cache.") from e
83+
raise HermesCacheError("There is no (valid) data stored in the cache.") from e
8484

85-
def write_to_cache(self: Self, ctx: HermesContext, target_dir: str) -> None:
85+
def write_to_cache(self: Self, ctx: HermesCacheManager, target_dir: str) -> None:
8686
"""
87-
Writes the JSON_LD data of `self` to the given HermesContext object at the given target.\n
87+
Writes the JSON_LD data of `self` to the given HermesCacheManager object at the given target.\n
8888
Note that data is written into "codemeta.json" (compacted value), "context.json" (context value) and
8989
"expanded.json" (expanded value).
9090
9191
Args:
92-
ctx (HermesContext): The HERMES cache the data is written to.
92+
ctx (HermesCacheManager): The HERMES cache the data is written to.
9393
target_dir (str): The directory the inside the cache the data is written to.
9494
9595
Returns:

src/hermes/model/error.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class HermesValidationError(Exception):
2424
pass
2525

2626

27-
class HermesContextError(Exception):
27+
class HermesCacheError(Exception):
2828
"""
2929
This exception should be raised when interacting with the model context.
3030
# TODO Change class name and docstring if we decide to call it differently
@@ -37,7 +37,7 @@ class HermesContextError(Exception):
3737
try:
3838
context[term]
3939
except ValueError as e:
40-
raise HermesContextError(term) from e
40+
raise HermesCacheError(term) from e
4141
"""
4242
pass
4343

0 commit comments

Comments
 (0)