Skip to content

Commit

Permalink
Updated documentation and small issues raised in review.
Browse files Browse the repository at this point in the history
  • Loading branch information
hiker committed Dec 9, 2024
1 parent bbdb380 commit 0e6e41c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
7 changes: 6 additions & 1 deletion Documentation/source/site-specific-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ contains all the tools that will be used during the build process, but
it can only store one tool per category. If a certain tool should not
be defined in the toolbox, the default from the `ToolRepository` will
be used. This is useful for many standard tools like `git`, `rsync`
etc that de-facto will never be changed.
etc that de-facto will never be changed. Fab will check if a tool
is actually available on the system before adding it to a ToolBox.
This is typically done by trying to run the tool with some testing
parameters, for example requesting its version number. If this fails,
the tool is considered not to be available and will not be used (unless
the user explicitly puts a tool into the ToolBox).

.. note:: If you need to use for example different compilers for
different files, you would implement this as a `meta-compiler`:
Expand Down
3 changes: 1 addition & 2 deletions source/fab/tools/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ def check_available(self) -> bool:
:returns: whether the tool is working (True) or not.
'''
try:
op = self._availability_option
self.run(op)
self.run(self._availability_option)
except (RuntimeError, FileNotFoundError):
return False
return True
Expand Down
4 changes: 3 additions & 1 deletion source/fab/tools/tool_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(self):
# Add the common shells. While Fab itself does not need this,
# it is a very convenient tool for user configuration (e.g. to
# query nc-config etc)
for shell_name in ["bash", "sh", "ksh", "dash"]:
for shell_name in ["sh", "bash", "ksh", "dash"]:
self.add_tool(Shell(shell_name))

# Now create the potential mpif90 and Cray ftn wrapper
Expand Down Expand Up @@ -174,6 +174,8 @@ def get_default(self, category: Category,
OpenMP.
:raises KeyError: if the category does not exist.
:raises RuntimeError: if no tool in the requested category is
available on the system.
:raises RuntimeError: if no compiler/linker is found with the
requested level of MPI support (yes or no).
'''
Expand Down
8 changes: 4 additions & 4 deletions tests/unit_tests/tools/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@ def test_shell_check_available():

def test_shell_exec_single_arg():
'''Test running a shell script without additional parameters.'''
bash = Shell("ksh")
ksh = Shell("ksh")
mock_result = mock.Mock(returncode=0)
with mock.patch('fab.tools.tool.subprocess.run',
return_value=mock_result) as tool_run:
bash.exec("echo")
ksh.exec("echo")
tool_run.assert_called_with(['ksh', '-c', 'echo'],
capture_output=True, env=None, cwd=None,
check=False)


def test_shell_exec_multiple_args():
'''Test running a shell script with parameters.'''
bash = Shell("ksh")
ksh = Shell("ksh")
mock_result = mock.Mock(returncode=0)
with mock.patch('fab.tools.tool.subprocess.run',
return_value=mock_result) as tool_run:
bash.exec(["some", "shell", "function"])
ksh.exec(["some", "shell", "function"])
tool_run.assert_called_with(['ksh', '-c', 'some', 'shell', 'function'],
capture_output=True, env=None, cwd=None,
check=False)

0 comments on commit 0e6e41c

Please # to comment.