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

InstalledCode: Allow relative path for filepath_executable #5879

Merged
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
9 changes: 5 additions & 4 deletions aiida/orm/nodes/data/code/installed.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,14 @@ def validate_filepath_executable(self):
is intentionally not called in ``_validate`` as to allow the creation of ``Code`` instances whose computers can
not yet be connected to and as to not require the overhead of opening transports in storing a new code.

.. note:: If the ``filepath_executable`` is not an absolute path, the check is skipped.

:raises `~aiida.common.exceptions.ValidationError`: if no transport could be opened or if the defined executable
does not exist on the remote computer.
"""
if not self.filepath_executable.is_absolute():
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just checking: what effect does this have in verdi computer test (or wherever this validation is used)?

will the check be shown as skipped or as passed?

Copy link
Contributor Author

@sphuber sphuber Jan 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is only run by verdi code test. It will show that all tests have passed. But this is also the case for codes that are not InstalledCode even though no test was run.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sphuber I would note that ideally what you want to do, if the path is not absolute, is load the same environment that you would have, then check that the executable is on the $PATH.
Perhaps there could be an option in the code test, to run the prepend text (from both computer and code) then look for the executable
this would be a more "complete" test of whether the code might have issues running


try:
with override_log_level(): # Temporarily suppress noisy logging
with self.computer.get_transport() as transport:
Expand Down Expand Up @@ -146,10 +151,6 @@ def filepath_executable(self, value: str) -> None:
:param value: The absolute filepath of the executable.
"""
type_check(value, str)

if not pathlib.PurePosixPath(value).is_absolute():
raise ValueError('the `filepath_executable` should be absolute.')

self.base.attributes.set(self._KEY_ATTRIBUTE_FILEPATH_EXECUTABLE, value)

@staticmethod
Expand Down
5 changes: 4 additions & 1 deletion docs/source/topics/data_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ InstalledCode

The :class:`~aiida.orm.nodes.data.code.installed.InstalledCode` class is an implementation of the :class:`~aiida.orm.nodes.data.code.abstract.AbstractCode` class that represents an executable code on a remote computer.
This plugin should be used if an executable is pre-installed on a computer.
The ``InstalledCode`` represents the code by storing the absolute filepath of the relevant executable and the computer on which it is installed.
The ``InstalledCode`` represents the code by storing the filepath of the relevant executable and the computer on which it is installed.
The computer is represented by an instance of :class:`~aiida.orm.computers.Computer`.
Each time a :class:`~aiida.engine.CalcJob` is run using an ``InstalledCode``, it will run its executable on the associated computer.
Example of creating an ``InstalledCode``:
Expand All @@ -470,6 +470,9 @@ Example of creating an ``InstalledCode``:
filepath_executable='/usr/bin/bash'
)

.. versionchanged:: 2.3
The ``filepath_executable`` is no longer required to be an absolute path but can be just the executable name.


.. _topics:data_types:core:code:portable:

Expand Down
6 changes: 6 additions & 0 deletions tests/orm/data/code/test_installed.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ def test_filepath_executable(aiida_localhost):
code = InstalledCode(computer=aiida_localhost, filepath_executable=filepath_executable)
assert code.filepath_executable == pathlib.PurePath(filepath_executable)

# Relative path
filepath_executable = 'bash'
code = InstalledCode(computer=aiida_localhost, filepath_executable=filepath_executable)
assert code.filepath_executable == pathlib.PurePath(filepath_executable)

# Change through the property
filepath_executable = '/usr/bin/cat'
code.filepath_executable = filepath_executable
assert code.filepath_executable == pathlib.PurePath(filepath_executable)
Expand Down