ksuit.utils.common.path¶
Functions¶
|
Converts a string to a Path and optionally performs file-system operations on it. |
|
Converts a string to a Path, validates it, and optionally creates it. |
|
Access values of an object, a list or a dictionary using a string path. |
Module Contents¶
- ksuit.utils.common.path.create_path_from_str(str_path, mkdir=False, should_exist=True, check_exists=True, suffix=None)¶
Converts a string to a Path and optionally performs file-system operations on it.
- Parameters:
str_path (str) – The path to convert.
mkdir (bool) – If True, creates the directory if it doesn’t exist.
should_exist (bool) – If True, checks if the path exists.
check_exists (bool) – If True, checks if the path exists or not.
suffix (str | None) – If not None, checks if the path ends with this suffix.
- Return type:
- ksuit.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