utilities#
import compwa_policy.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.
- write(content: str, target: Path | TextIOBase | str, *, session: Session | None = None) None[source]#
- remove_lines(session: Session, /, file: Path, pattern: str, flags: RegexFlag = re.IGNORECASE) None[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
- cfg
- check_hook
- match
- python
- readme
- resource
- session
- toml
- vscode
- yaml