utilities#

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

append_safe(session: Session, /, 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, *, session: Session | None = None) → str[source]#
write(content: str, target: Path | TextIOBase | str, *, session: Session | None = None) → None[source]#
remove_configs(session: Session, /, paths: list[str]) → None[source]#
rename_file(session: Session, /, old: str, new: str) → None[source]#
remove_lines(session: Session, /, file: Path, pattern: str, flags: RegexFlag = re.IGNORECASE) → None[source]#
natural_sorting(text: str) → list[float | str][source]#
update_file(session: Session, /, 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}}}

Submodules and Subpackages