compwa_policy.utilities package#

Subpackages#

Submodules#

Module contents#

Collection of helper functions that are shared by all sub-hooks.

append_safe(expected_line: str, path: Path) bool[source]#

Add a line to a file if it is not already present.

contains_line(input: Path | TextIOBase | str, expected_line: str) bool[source]#
hash_file(path: Path | str) str[source]#
read(input: Path | TextIOBase | str) str[source]#
write(content: str, target: Path | TextIOBase | str) None[source]#
remove_configs(paths: list[str]) None[source]#
remove_from_gitignore(pattern: str) None[source]#
rename_file(old: str, new: str) None[source]#

Rename a file and raise a PrecommitError.

natural_sorting(text: str) list[float | str][source]#
update_file(relative_path: Path, in_template_folder: bool = False) None[source]#
get_nested_dict(data: dict, keys: list[str]) dict[source]#

Get a nested dictionary from a list of keys, create it if it doesn’t exist.

>>> data = {}
>>> sub_dict = get_nested_dict(data, keys=["a", "b"])
>>> sub_dict["c"] = 1
>>> data
{'a': {'b': {'c': 1}}}