fab.dep_tree module#

Classes and helper functions related to the dependency tree, as created by the analysis stage.

class fab.dep_tree.AnalysedDependent(fpath, file_hash=None, symbol_defs=None, symbol_deps=None, file_deps=None)#

Bases: AnalysedFile, ABC

An AnalysedFile which can depend on others, and be a dependency. Instances of this class are nodes in a source dependency tree.

During parsing, the symbol definitions and dependencies are filled in. During dependency analysis, symbol dependencies are turned into file dependencies.

Parameters:
  • fpath (Union[str, Path]) – The source file that was analysed.

  • file_hash (Optional[int]) – The hash of the source. If omitted, Fab will evaluate lazily. (default: None)

  • symbol_defs (Optional[Iterable[str]]) – Set of symbol names defined by this source file. (default: None)

  • symbol_deps (Optional[Iterable[str]]) – Set of symbol names used by this source file. Can include symbols in the same file. (default: None)

  • file_deps (Optional[Iterable[Path]]) – Other files on which this source depends. Must not include itself. This attribute is calculated during symbol analysis, after everything has been parsed. (default: None)

add_symbol_def(name)#
add_symbol_dep(name)#
add_file_dep(name)#
classmethod field_names()#

Defines the order in which we want fields to appear in str or repr strings.

Calling this helps to ensure any lazy attributes are evaluated before use, e.g when constructing a string representation of the instance, or generating a hash value.

to_dict()#

Create a dict representing the object.

The dict may be written to json, so can’t contain sets. Lists are sorted for reproducibility in testing.

Return type:

Dict[str, Any]

classmethod from_dict(d)#
fab.dep_tree.extract_sub_tree(source_tree, root, verbose=False)#

Extract the subtree required to build the target, from the full source tree of all analysed source files.

Parameters:
  • source_tree (Dict[Path, AnalysedDependent]) – The source tree of analysed files.

  • root (Path) – The root of the dependency tree, this is the filename containing the Fortran program.

  • verbose – Log missing dependencies. (default: False)

Return type:

Dict[Path, AnalysedDependent]

fab.dep_tree.filter_source_tree(source_tree, suffixes)#

Pull out files with the given extensions from a source tree.

Returns a list of AnalysedDependent.

Parameters:
Return type:

List[AnalysedDependent]

fab.dep_tree.validate_dependencies(source_tree)#

If any dep is missing from the tree, then it’s unknown code and we won’t be able to compile.

Parameters:

source_tree – The source tree of analysed files.