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

CompilerSuiteTool(name, exec_name, suite, ...)

A tool that is part of a compiler suite (typically compiler and linker).

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

This is the base class for all tools.

class fab.tools.tool.Tool(name, exec_name, category=Category.MISC, 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 (Union[str, Path]) – name or full path of the executable to start.

  • category (Category) – the Category to which this tool belongs. (default: <Category.MISC: 13>)

  • availability_option (Union[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. :rtype: 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.

get_flags(profile=None)#
Returns:

the flags to be used with this tool.

add_flags(new_flags, profile=None)#

Adds the specified flags to the list of flags.

Parameters:

new_flags (Union[str, List[str]]) – A single string or list of strings which are the flags to be added.

define_profile(name, inherit_from=None)#

Defines a new profile name, and allows to specify if this new profile inherit settings from an existing profile.

Parameters:
  • name (str) – Name of the profile to define.

  • inherit_from (Optional[str]) – Optional name of a profile to inherit settings from. (default: None)

property logger: Logger#
Returns:

a logger object for convenience.

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

Run the binary as a subprocess.

Parameters:
  • additional_parameters (Union[str, Sequence[Union[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 (Optional[Dict[str, str]]) – Optional env for the command. By default it will use the current session’s environment. (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

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

A tool that is part of a compiler suite (typically compiler and linker).

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

  • exec_name (Union[str, Path]) – name of the executable to start.

  • suite (str) – name of the compiler suite.

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

  • availability_option (Union[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)

property suite: str#
Returns:

the compiler suite of this tool.