utils
General utilities.
Attributes¶
Classes¶
Functions:¶
extract_regex_flags
¶
extract_regex_flags(regex_pattern: str) -> Tuple[str, str]
format_and_raise_error
¶
format_and_raise_error(exc: Union[BaseException, CalledProcessError]) -> None
Format the error message from an exception and re-raise it as a BumpVersionError.
get_nested_value
¶
get_nested_value(d: dict, path: str) -> Any
Retrieves the value of a nested key in a dictionary based on the given path.
| PARAMETER | DESCRIPTION |
|---|---|
d
|
The dictionary to search.
TYPE:
|
path
|
A string representing the path to the nested key, separated by periods.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
The value of the nested key. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If a key in the path does not exist. |
ValueError
|
If an element in the path is not a dictionary. |
get_overrides
¶
get_overrides(**kwargs) -> dict
Return a dictionary containing only the overridden key-values.
is_subpath
¶
is_subpath(parent: Pathlike, path: Pathlike) -> bool
Determines if a given path is a subpath of a specified parent path.
The function normalizes the inputs as Path objects and checks if the normalized path is within the normalized parent path. For relative paths, the function assumes the path could be within the parent and returns True.
| PARAMETER | DESCRIPTION |
|---|---|
parent
|
A Pathlike object representing the parent directory or path.
TYPE:
|
path
|
A Pathlike object representing the path to check.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the path is a subpath of the parent, or if it is a relative path; otherwise, False. |
key_val_string
¶
key_val_string(d: dict) -> str
Render the dictionary as a comma-delimited key=value string.
labels_for_format
¶
labels_for_format(serialize_format: str) -> List[str]
Return a list of labels for the given serialize_format.
run_command
¶
run_command(command: list, env: Optional[dict] = None) -> CompletedProcess
Run a shell command and return its output.
set_nested_value
¶
set_nested_value(d: dict, value: Any, path: str) -> None
Sets the value of a nested key in a dictionary based on the given path.
| PARAMETER | DESCRIPTION |
|---|---|
d
|
The dictionary to search.
TYPE:
|
value
|
The value to set.
TYPE:
|
path
|
A string representing the path to the nested key, separated by periods.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If an element in the path is not a dictionary. |
KeyError
|
If a key in the path does not exist. |