Skip to content

Commit

Permalink
Adapt signatures for creating new deposit versions
Browse files Browse the repository at this point in the history
  • Loading branch information
sdruskat committed Nov 15, 2023
1 parent ea33103 commit 1385d96
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
9 changes: 8 additions & 1 deletion src/hermes/commands/deposit/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ def dummy_noop(
pass


def map_metadata(ctx: CodeMetaContext):
def map_metadata(
path: pathlib.Path,
config_path: pathlib.Path,
initial: bool,
auth_token: str,
files: list[pathlib.Path],
ctx: CodeMetaContext,
):
ctx.update(ContextPath.parse("deposit.file"), ctx["codemeta"])


Expand Down
22 changes: 18 additions & 4 deletions src/hermes/commands/deposit/invenio.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ def prepare(
ctx.update(invenio_path["access_conditions"], access_conditions)


def map_metadata(ctx: CodeMetaContext):
def map_metadata(
path: pathlib.Path,
config_path: pathlib.Path,
initial: bool,
auth_token: str,
files: list[pathlib.Path],
ctx: CodeMetaContext,
):
"""Map the harvested metadata onto the Invenio schema."""

deposition_metadata = _codemeta_to_invenio_deposition(ctx)
Expand All @@ -102,7 +109,14 @@ def map_metadata(ctx: CodeMetaContext):
json.dump(deposition_metadata, invenio_json, indent=" ")


def create_initial_version(ctx: CodeMetaContext):
def create_initial_version(
path: pathlib.Path,
config_path: pathlib.Path,
initial: bool,
auth_token: str,
files: list[pathlib.Path],
ctx: CodeMetaContext,
):
"""Create an initial version of a publication.
If a previous publication exists, this function does nothing, leaving the work for
Expand All @@ -118,7 +132,7 @@ def create_initial_version(ctx: CodeMetaContext):
# the next step. Thus, there is nothing to do here.
return

if not click_ctx.params["initial"]:
if not initial:
raise RuntimeError("Please use `--initial` to make an initial deposition.")

_log = logging.getLogger("cli.deposit.invenio")
Expand All @@ -137,7 +151,7 @@ def create_initial_version(ctx: CodeMetaContext):
json={"metadata": deposition_metadata},
headers={
"User-Agent": hermes_user_agent,
"Authorization": f"Bearer {click_ctx.params['auth_token']}",
"Authorization": f"Bearer {auth_token}",
},
)

Expand Down
22 changes: 18 additions & 4 deletions src/hermes/commands/deposit/invenio_rdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ def prepare(
ctx.update(invenio_path["access_conditions"], access_conditions)


def map_metadata(click_ctx: click.Context, ctx: CodeMetaContext):
def map_metadata(
path: Path,
config_path: Path,
initial: bool,
auth_token: str,
files: list[Path],
ctx: CodeMetaContext,
):
"""Map the harvested metadata onto the Invenio schema."""

deposition_metadata = _codemeta_to_invenio_deposition(ctx)
Expand All @@ -103,7 +110,14 @@ def map_metadata(click_ctx: click.Context, ctx: CodeMetaContext):
json.dump(deposition_metadata, invenio_json, indent=" ")


def create_initial_version(click_ctx: click.Context, ctx: CodeMetaContext):
def create_initial_version(
path: Path,
config_path: Path,
initial: bool,
auth_token: str,
files: list[Path],
ctx: CodeMetaContext,
):
"""Create an initial version of a publication.
If a previous publication exists, this function does nothing, leaving the work for
Expand All @@ -119,7 +133,7 @@ def create_initial_version(click_ctx: click.Context, ctx: CodeMetaContext):
# the next step. Thus, there is nothing to do here.
return

if not click_ctx.params["initial"]:
if not initial:
raise RuntimeError("Please use `--initial` to make an initial deposition.")

_log = logging.getLogger("cli.deposit.invenio_rdm")
Expand All @@ -138,7 +152,7 @@ def create_initial_version(click_ctx: click.Context, ctx: CodeMetaContext):
json={"metadata": deposition_metadata},
headers={
"User-Agent": hermes_user_agent,
"Authorization": f"Bearer {click_ctx.params['auth_token']}",
"Authorization": f"Bearer {auth_token}",
},
)

Expand Down
2 changes: 1 addition & 1 deletion src/hermes/commands/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def deposit(

for entry_point in loaded_entry_points:
try:
entry_point(initial, auth_token, files, ctx)
entry_point(path, config_path, initial, auth_token, files, ctx)
except (RuntimeError, MisconfigurationError) as e:
_log.error(f"Error in {group!r} entry point {name!r}: {e}")
sys.exit(1)
Expand Down

0 comments on commit 1385d96

Please sign in to comment.