fab.tools.tool#

This file contains the base class for all tools, i.e. compiler, preprocessor, linker, archiver, Psyclone, rsync, versioning tools.

Each tool belongs to one category (e.g. FORTRAN_COMPILER). This category is used when adding a tool to a ToolRepository or ToolBox. It provides basic support for running a binary, and keeping track if a tool is actually available.

Classes

Tool(name, exec_name, category[, ...])

This is the base class for all tools.

class fab.tools.tool.Tool(name, exec_name, category, availability_option=None)#

This is the base class for all tools. It stores the name of the tool, the name of the executable, and provides a run method.

Parameters:
  • name (str) – name of the tool.

  • exec_name (str | Path) – name or full path of the executable to start.

  • category (Category) – the Category to which this tool belongs.

  • availability_option (str | list[str] | None) – a command line option for the tool to test if the tool is available on the current system. Defaults to –version. (default: None)

check_available()#

Run a ‘test’ command to check if this tool is available in the system.

Return type:

bool

Returns:

whether the tool is working (True) or not.

set_full_path(full_path)#

This function adds the full path to a tool. This allows tools to be used that are not in the user’s PATH. The ToolRepository will automatically update the path for a tool if the user specified a full path.

Parameters:

full_path (Path) – the full path to the executable.

property is_available: bool#

Checks if the tool is available or not. It will call a tool-specific function check_available to determine this, but will cache the results to avoid testing a tool more than once.

Returns:

whether the tool is available (i.e. installed and working).

property is_compiler: bool#

Returns whether this tool is a (Fortran or C) compiler or not.

property exec_path: Path#
Returns:

the path of the executable.

property exec_name: str#
Returns:

the name of the executable.

property name: str#
Returns:

the name of the tool.

property availability_option: str | list[str]#
Returns:

the option to use to check if the tool is available.

property category: Category#
Returns:

the category of this tool.

property logger: Logger#
Returns:

a logger object for convenience.

run(additional_parameters=None, env=None, cwd=None, capture_output=True)#

Run the binary as a subprocess.

Parameters:
  • additional_parameters (str | Sequence[Path | str] | None) – List of strings or paths to be sent to subprocess.run() as additional parameters for the command. Any path will be converted to a normal string. (default: None)

  • env (dict[str, str] | None) – Optional env for the command. By default it will use the current session’s environment. (default: None)

  • cwd (Path | str | None) – Optional working directory for the command. By default it will use the current working directory. (default: None)

  • capture_output – If True, capture and return stdout. If False, the command will print its output directly to the console. (default: True)

Raises:
Return type:

str