fab.tools module

Known command line tools whose flags we wish to manage.

class fab.tools.Compiler(exe, compile_flag, module_folder_flag)

Bases: object

A command-line compiler whose flags we wish to manage.

fab.tools.remove_managed_flags(compiler, flags_in)

Remove flags which Fab manages.

Fab prefers to specify a few compiler flags itself. For example, Fab wants to place module files in the build_output folder. The flag to do this differs with compiler.

We don’t want duplicate, possibly conflicting flags in our tool invocation so this function is used to remove any flags which Fab wants to manage.

If the compiler is not known to Fab, we rely on the user to specify these flags in their config.

Note

This approach is due for discussion. It might not be desirable to modify user flags at all.

fab.tools.flags_checksum(flags)

Return a checksum of the flags.

fab.tools.run_command(command, env=None, cwd=None, capture_output=True)

Run a CLI command.

Parameters:
  • command (List[str]) – List of strings to be sent to subprocess.run() as the command.

  • env – (default: None) Optional env for the command. By default it will use the current session’s environment.

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

fab.tools.get_tool(tool_str=None)

Get the compiler, preprocessor, etc, from the given string.

Separate the tool and flags for the sort of value we see in environment variables, e.g. gfortran -c.

Returns the tool and a list of flags.

Parameters:

env_var – The environment variable from which to find the tool.

Return type:

Tuple[str, List[str]]

fab.tools.get_compiler_version(compiler)

Try to get the version of the given compiler.

Expects a version in a certain part of the –version output, which must adhere to the n.n.n format, with at least 2 parts.

Returns a version string, e.g ‘6.10.1’, or empty string.

Parameters:

compiler (str) – The command line tool for which we want a version.

Return type:

str