helper module

Define utility functions to test out the .toml config file.

check_type(instance: type | tuple[type], name: str, *args: Any) None

Raise a warning if args are not all of type instance.

Not matching the provided type does not stop the program from running.

dict_for_pretty_output(some_kw: dict) str

Transform a dict in strings for nice output.

_find_according_to_nature(path: Path, nature: Literal['file', 'folder'] | None) bool

Helper function to check if the path matches the desired nature.

find_path(toml_folder: Path | None, path: str | Path, nature: Literal['file', 'folder'] | None = None) Path

Look for the given path in all possible places, make it absolute.

We sequentially check and return the first valid path: 1. If path is a Path object, resolve and check its existence. 2. If path exists relative to toml_folder. 3. If path is absolute.

Parameters:
  • toml_folder (pathlib.Path | None) – Folder where the .toml configuration file is.

  • path (str | pathlib.Path) – Path to look for.

  • nature (Literal["file", "folder"] | None, optional) – The type of path to check: “file” or “folder”, or None to simply check existence.

Returns:

path – Absolute path, whose existence has been checked.

Return type:

pathlib.Path

Raises:

FileNotFoundError – Raised if the required path does not exists.

find_file(toml_folder: Path | None, path: str | Path, *, nature: Literal['file', 'folder'] | None = 'file') Path

Look for the given path in all possible places, make it absolute.

We sequentially check and return the first valid path: 1. If path is a Path object, resolve and check its existence. 2. If path exists relative to toml_folder. 3. If path is absolute.

Parameters:
  • toml_folder (pathlib.Path | None) – Folder where the .toml configuration file is.

  • path (str | pathlib.Path) – Path to look for.

  • nature (Literal["file", "folder"] | None, optional) – The type of path to check: “file” or “folder”, or None to simply check existence.

Returns:

path – Absolute path, whose existence has been checked.

Return type:

pathlib.Path

Raises:

FileNotFoundError – Raised if the required path does not exists.

find_folder(toml_folder: Path | None, path: str | Path, *, nature: Literal['file', 'folder'] | None = 'folder') Path

Look for the given path in all possible places, make it absolute.

We sequentially check and return the first valid path: 1. If path is a Path object, resolve and check its existence. 2. If path exists relative to toml_folder. 3. If path is absolute.

Parameters:
  • toml_folder (pathlib.Path | None) – Folder where the .toml configuration file is.

  • path (str | pathlib.Path) – Path to look for.

  • nature (Literal["file", "folder"] | None, optional) – The type of path to check: “file” or “folder”, or None to simply check existence.

Returns:

path – Absolute path, whose existence has been checked.

Return type:

pathlib.Path

Raises:

FileNotFoundError – Raised if the required path does not exists.