Skip to content

io

Input/Output operations.

Classes

Functions

make_sure_path_exists

make_sure_path_exists(path: os.PathLike[str]) -> None

Ensure that a directory exists, creating it if it does not.

PARAMETER DESCRIPTION
path

A directory tree path for creation.

TYPE: PathLike[str]

RAISES DESCRIPTION
ProjectForgeError

When there is an OSError

parse_file

parse_file(path: Union[str, Path]) -> Any

Read a file and parse its contents.

The file’s extension will be used to determine the file type, and the return type.

PARAMETER DESCRIPTION
path

The path to the file to read

TYPE: Union[str, Path]

RETURNS DESCRIPTION
Any

A data structure (from YAML, TOML, JSON) or a string.

parse_json

parse_json(contents: str) -> Any

Parse a JSON string into a data structure.

parse_toml

parse_toml(contents: str) -> Any

Parse a TOML string into a data structure.

parse_yaml

parse_yaml(contents: str) -> Any

Parse a YAML string into a data structure.

remove_paths

remove_paths(
    root: Path, paths_to_remove: Iterable[Path]
) -> None

Remove all paths in paths_to_remove from root.

Nabbed from Cruft: https://github.com/cruft/cruft/

PARAMETER DESCRIPTION
root

The absolute path of the directory requiring path removal

TYPE: Path

paths_to_remove

The set of relative paths to remove from root

TYPE: Iterable[Path]

remove_readonly_bit

remove_readonly_bit(
    func: Callable[[str], None], path: str, _: Any
) -> None

Clear the readonly bit and reattempt the removal.

remove_single_path

remove_single_path(path: Path) -> None

Remove a path with extra error handling for Windows.

PARAMETER DESCRIPTION
path

The path to remove

TYPE: Path

RAISES DESCRIPTION
IOError

If the file could not be removed