Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShellJob: Customize the _build_process_label method #17

Merged
merged 1 commit into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/aiida_shell/calculations/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ def validate_outputs(cls, value: List, _) -> str | None:

return None

def _build_process_label(self) -> str:
"""Construct the process label that should be set on ``ProcessNode`` instances for this process class.

Override the base implementation to include the full label of the ``Code`` which provides more useful info to
the user, for example when looking at an overview of submitted processes.

:returns: The process label to use for ``ProcessNode`` instances.
"""
if self.inputs:
return f'ShellJob<{self.inputs.code.full_label}>'
return super()._build_process_label()

def prepare_for_submission(self, folder: Folder) -> CalcInfo:
"""Prepare the calculation for submission.

Expand Down
9 changes: 9 additions & 0 deletions tests/calculations/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ def value_raises(self):
generate_calc_job('core.shell', {'code': generate_code(), 'nodes': nodes})


def test_build_process_label(generate_calc_job, generate_code):
"""Test the :meth:`~aiida_shell.calculations.shell_job.ShellJob.build_process_label` method."""
computer = 'localhost'
executable = '/bin/echo'
code = generate_code(executable, computer_label=computer, label='echo')
process = generate_calc_job('core.shell', {'code': code}, return_process=True)
assert process._build_process_label() == f'ShellJob<{code.full_label}>' # pylint: disable=protected-access


def test_submit_to_daemon(generate_code, submit_and_await):
"""Test submitting a ``ShellJob`` to the daemon."""
builder = generate_code('echo').get_builder()
Expand Down
6 changes: 5 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def generate_calc_job(tmp_path):
as well as the ``CalcInfo`` instance that it returned.
"""

def factory(entry_point_name, inputs=None):
def factory(entry_point_name, inputs=None, return_process=False):
"""Create a :class:`aiida.engine.CalcJob` instance with the given inputs."""
manager = get_manager()
runner = manager.get_runner()
Expand All @@ -59,6 +59,10 @@ def factory(entry_point_name, inputs=None):
process = instantiate_process(runner, process_class, **inputs or {})

calc_info = process.prepare_for_submission(Folder(tmp_path))

if return_process:
return process

return tmp_path, calc_info

return factory
Expand Down