From 50286b8c4d0692209eedf1ce90202a10d737da1d Mon Sep 17 00:00:00 2001 From: Timo Reents Date: Thu, 16 Jul 2026 19:29:24 +0200 Subject: [PATCH 1/3] Fix `prepare_shell_job_inputs` to be compatible with `PortableCode` A ``PortableCode`` is not associated with a computer, so one needs to specify the computer in the metadata. However, in the previous version, the computer was popped from the metadata and therefore, `launch_shell_job` would fail because no computer is associated with the specified code. --- src/aiida_shell/launch.py | 3 ++- tests/test_launch.py | 34 ++++++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/aiida_shell/launch.py b/src/aiida_shell/launch.py index 7fe811e..45f6af9 100644 --- a/src/aiida_shell/launch.py +++ b/src/aiida_shell/launch.py @@ -132,8 +132,9 @@ def prepare_shell_job_inputs( # noqa: PLR0913 AiidaDeprecationWarning, stacklevel=2, ) + metadata['computer'] = computer else: - computer = metadata.pop('computer', None) + computer = metadata.get('computer', None) if isinstance(command, str): code = prepare_code(command, computer, resolve_command) diff --git a/tests/test_launch.py b/tests/test_launch.py index bad05ed..f7668bd 100644 --- a/tests/test_launch.py +++ b/tests/test_launch.py @@ -6,13 +6,17 @@ import pytest from aiida.engine import WorkChain, run_get_node, workfunction -from aiida.orm import AbstractCode, Computer, Float, Int, RemoteData, SinglefileData, Str +from aiida.orm import AbstractCode, Computer, Float, InstalledCode, Int, PortableCode, RemoteData, SinglefileData, Str +from aiida_shell import ShellCode from aiida_shell.calculations.shell import ShellJob from aiida_shell.launch import launch_shell_job, prepare_computer DATE_COMMAND = shutil.which('date') assert DATE_COMMAND is not None, 'The `date` command must be available in order to run the tests.' +ECHO_COMMAND = shutil.which('echo') +assert ECHO_COMMAND is not None, 'The `echo` command must be available in order to run the tests.' + class ShellWorkChain(WorkChain): """Implementation of :class:`aiida.engine.processes.workchains.workchain.WorkChain` that submits a ``ShellJob``.""" @@ -373,15 +377,29 @@ def test_preexisting_localhost_no_default_mpiprocs_per_machine( Computer.collection.delete(computer.pk) -def test_metadata_computer(generate_computer): - """Test the ``metadata.computer`` input.""" - label = 'custom-computer' - computer = generate_computer(label=label) - assert computer.label == label +@pytest.mark.parametrize('code_type', ('string', 'shell', 'installed', 'portable')) +def test_metadata_computer(code_type, generate_computer, tmp_path): + """Test that ``metadata.computer`` is respected for different code types.""" + computer = generate_computer(label=f'computer-{code_type}') + + if code_type == 'string': + command = 'echo' + elif code_type == 'shell': + command = ShellCode( + computer=computer, filepath_executable=ECHO_COMMAND, default_calc_job_plugin='core.shell' + ).store() + elif code_type == 'installed': + command = InstalledCode(computer=computer, filepath_executable=ECHO_COMMAND).store() + else: + filepath_executable = tmp_path / 'echo.sh' + filepath_executable.write_text('#!/bin/bash\necho "$@"\n') + filepath_executable.chmod(0o755) + command = PortableCode(filepath_executable='echo.sh', filepath_files=tmp_path).store() - _, node = launch_shell_job('date', metadata={'computer': computer}) + results, node = launch_shell_job(command, arguments=['hello'], metadata={'computer': computer}) assert node.is_finished_ok - assert node.inputs.code.computer.uuid == computer.uuid + assert results['stdout'].get_content().strip() == 'hello' + assert node.computer.uuid == computer.uuid def test_monitors(): From 353a5bb7f882ec4b26f100500b7bac550a1704bd Mon Sep 17 00:00:00 2001 From: Timo Reents Date: Thu, 23 Jul 2026 08:48:11 +0200 Subject: [PATCH 2/3] Fix pre-commit --- tests/test_launch.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_launch.py b/tests/test_launch.py index d3b7594..a89f999 100644 --- a/tests/test_launch.py +++ b/tests/test_launch.py @@ -8,6 +8,7 @@ import pytest from aiida.engine import WorkChain, run_get_node, workfunction from aiida.orm import AbstractCode, Computer, Float, InstalledCode, Int, PortableCode, RemoteData, SinglefileData, Str + from aiida_shell import ShellCode from aiida_shell.calculations.shell import ShellJob from aiida_shell.launch import launch_shell_job, prepare_computer From 121f1db3c1ad2a8ed27a337bb845ad98768c8c02 Mon Sep 17 00:00:00 2001 From: Timo Reents Date: Thu, 13 Aug 2026 13:39:54 +0200 Subject: [PATCH 3/3] Integrate review comments --- src/aiida_shell/launch.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/aiida_shell/launch.py b/src/aiida_shell/launch.py index 2fdc31e..edf5d68 100644 --- a/src/aiida_shell/launch.py +++ b/src/aiida_shell/launch.py @@ -124,18 +124,18 @@ def prepare_shell_job_inputs( # noqa: PLR0913 :returns: A dictionary containing prepared inputs for the ShellJob. """ metadata = metadata or {} - computer = metadata.get('options', {}).pop('computer', None) + options = metadata.get('options', {}) - if computer: + if 'computer' in options: warnings.warn( 'Specifying a computer through `metadata.options.computer` in `launch_shell_job` is deprecated. Please use ' '`metadata.computer` instead.', AiidaDeprecationWarning, stacklevel=2, ) - metadata['computer'] = computer - else: - computer = metadata.get('computer', None) + metadata['computer'] = options.pop('computer') + + computer = metadata.get('computer') if isinstance(command, str): code = prepare_code(command, computer, resolve_command) @@ -155,7 +155,7 @@ def prepare_shell_job_inputs( # noqa: PLR0913 'arguments': arguments, 'outputs': outputs, 'parser': parser, - 'metadata': metadata or {}, + 'metadata': metadata, } if monitors: inputs['monitors'] = monitors