Supporting functions using GitPython¶
The codebase uses GitPython to fetch the files from the source branch containing profiling outputs.
This is necessary to avoid manually copying across files from the source branch every time we want to rebuild, avoid tracking the results files alongside the code that processes them, and to provide some buffer against the automatic workflow commit overwriting the main branch.
This has the added advantage that we can read files on the source branch one-at-a-time to minimise memory usage.
- git_tree.branch_contents(branch_name: str, match_pattern: str | None = None) List[Path]¶
List the contents of a given branch in the repository, optionally matching the pattern provided.
- Parameters:
branch_name (str) – Name of a branch in the repository tree.
match_pattern (str, optional) – Pattern to match in filenames.
- Returns:
List of Paths to the files on the branch that match the pattern.
- Return type:
List[Path]
- git_tree.file_contents(branch_name: str, path_to_file: Path, write_to: Path | None = None) str¶
Fetches the content of a file on another branch, returning it as a character string.
If the write_to parameter is specified, contents will be dumped to the file location provided.
- Parameters:
branch_name (str) – Name of a branch in the repository tree.
path_to_file (Path) – Path to the file on the target branch to fetch.
write_to (Path, optional) – If provided, write the contents of the file to this location.
- Returns:
The content (as a string) of the requested file.
- Return type:
str
- git_tree.list_paths(root_tree, path: Path = PosixPath('.')) List[Path]¶
Return a generator that iterates over all files (with absolute paths) recursively, starting in the directory provided on the given tree.
This method is recursive so should not be used on deep / tall tree structures.
- Parameters:
root_tree – Tree (branch/sub-branch/repository) to recurse through.
path (Path, optional.) – The folder in which to begin recursing. Default is the root of the tree.
- Returns:
A list of Paths to the files that were found.
- Return type:
List[Path]