helper module

Define utility functions to test out the TOML config file.

check_type(instance, name, *args)[source]

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

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

Parameters:
Return type:

None

dict_for_pretty_output(some_kw)[source]

Transform a dict in strings for nice output.

Parameters:

some_kw (dict)

Return type:

str

_find_according_to_nature(path, nature)[source]

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

Parameters:
Return type:

bool

find_path(toml_folder, path, nature=None)[source]

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 (Path | None) – Folder where the TOML configuration file is.

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

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

Return type:

Path

Returns:

Absolute path, whose existence has been checked.

Raises:

FileNotFoundError – Raised if the required path does not exists.

find_file(toml_folder, path, *, nature='file')

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 – Folder where the TOML configuration file is.

  • path – Path to look for.

  • nature (default: 'file') – The type of path to check: “file” or “folder”, or None to simply check existence.

Returns:

Absolute path, whose existence has been checked.

Raises:

FileNotFoundError – Raised if the required path does not exists.

Return type:

Path

find_folder(toml_folder, path, *, nature='folder')

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 – Folder where the TOML configuration file is.

  • path – Path to look for.

  • nature (default: 'folder') – The type of path to check: “file” or “folder”, or None to simply check existence.

Returns:

Absolute path, whose existence has been checked.

Raises:

FileNotFoundError – Raised if the required path does not exists.

Return type:

Path