noether.core.utils.common.path

Functions

validate_path(path[, exists, suffix, mkdir])

Converts a string to a Path, validates it, and optionally creates it.

select_with_path(obj, path)

Access values of an object, a list or a dictionary using a string path.

Module Contents

noether.core.utils.common.path.validate_path(path, exists='must', suffix=None, mkdir=False)

Converts a string to a Path, validates it, and optionally creates it.

Parameters:
  • path (str | pathlib.Path) – The path string to validate.

  • exists (Literal['must', 'must_not', 'any']) –

    • “must”: Raises FileNotFoundError if the path doesn’t exist.

    • ”must_not”: Raises FileExistsError if the path already exists.

    • ”any”: Performs no existence check.

  • suffix (str | None) – If provided, checks if the path ends with this suffix.

  • mkdir (bool) – If True, creates the directory path (like mkdir -p).

Returns:

The validated path.

Return type:

Path

noether.core.utils.common.path.select_with_path(obj, path)

Access values of an object, a list or a dictionary using a string path.

Parameters:
  • obj (dict[str, Any] | list[Any] | object) – The object to access.

  • path (str | None) – The path to the value, e.g. “a.b.c” or “a[0].b.c”.

Return type:

object