Skip to content

Commit

Permalink
Pass only user inputs to prepare_shell_job_inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
GeigerJ2 committed Nov 19, 2024
1 parent 627cc1d commit 26f7bab
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
22 changes: 20 additions & 2 deletions aiida_workgraph/engine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,26 @@ def prepare_for_shell_task(task: dict, inputs: dict) -> dict:

# Retrieve the signature of `prepare_shell_job_inputs` to determine expected input parameters.
signature = inspect.signature(prepare_shell_job_inputs)
kwargs = {key: inputs.pop(key, None) for key in signature.parameters.keys()}
inputs.update(prepare_shell_job_inputs(**kwargs))
aiida_shell_input_keys = signature.parameters.keys()

# Iterate over all WorkGraph `inputs`, and extract the ones which are expected by `prepare_shell_job_inputs`
inputs_aiida_shell_subset = {
key: inputs[key] for key in inputs.keys() if key in aiida_shell_input_keys
}

try:
aiida_shell_inputs = prepare_shell_job_inputs(**inputs_aiida_shell_subset)
except ValueError:
raise

# We need to remove the original input-keys, as they might be offending for the call to `launch_shell_job`
# E.g., `inputs` originally can contain `command`, which gets, however, transformed to #
# `code` by `prepare_shell_job_inputs`
for key in inputs_aiida_shell_subset.keys():
inputs.pop(key)

# Finally, we update the original `inputs` with the modified ones from the call to `prepare_shell_job_inputs`
inputs = {**inputs, **aiida_shell_inputs}

inputs.setdefault("metadata", {})
inputs["metadata"].update({"call_link_label": task["name"]})
Expand Down
10 changes: 10 additions & 0 deletions tests/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
from aiida.orm import SinglefileData, load_computer


def test_prepare_for_shell_task_nonexistent():
"""Check that the `ValueError` raised by `aiida-shell` for a non-extistent executable is captured by WorkGraph."""
from aiida_workgraph.engine.utils import prepare_for_shell_task

task = {"name": "test"}
inputs = {"command": "abc42"}
with pytest.raises(ValueError, match="failed to determine the absolute path"):
prepare_for_shell_task(task=task, inputs=inputs)


@pytest.mark.usefixtures("started_daemon_client")
def test_shell_command(fixture_localhost):
"""Test the ShellJob with command as a string."""
Expand Down

0 comments on commit 26f7bab

Please sign in to comment.