bumpversion.utils
General utilities.
logger
logger = get_indented_logger(__name__)Pathlike
Pathlike = Union[str, Path]A type alias for a path-like object.
extract_regex_flags
def extract_regex_flags(regex_pattern: str) -> Tuple[str, str]Extract the regex flags from the regex pattern.
Parameters
regex_pattern: The pattern that might start with regex flags
Returns
- A tuple of the regex pattern without the flag string and regex flag string
recursive_sort_dict
def recursive_sort_dict(input_value: Any) -> AnySort a dictionary recursively.
key_val_string
def key_val_string(d: dict) -> strRender the dictionary as a comma-delimited key=value string.
labels_for_format
def labels_for_format(serialize_format: str) -> List[str]Return a list of labels for the given serialize_format.
get_overrides
def get_overrides(kwargs = {}) -> dictReturn a dictionary containing only the overridden key-values.
get_nested_value
def get_nested_value(d: dict, path: str) -> AnyRetrieves the value of a nested key in a dictionary based on the given path.
Parameters
d: The dictionary to search.path: A string representing the path to the nested key, separated by periods.
Returns
- The value of the nested key.
Raises
KeyError: If a key in the path does not exist.ValueError: If an element in the path is not a dictionary.
set_nested_value
def set_nested_value(d: dict, value: Any, path: str) -> NoneSets the value of a nested key in a dictionary based on the given path.
Parameters
d: The dictionary to search.value: The value to set.path: A string representing the path to the nested key, separated by periods.
Raises
ValueError: If an element in the path is not a dictionary.KeyError: If a key in the path does not exist.
format_and_raise_error
def format_and_raise_error(exc: Union[BaseException, subprocess.CalledProcessError]) -> NoneFormat the error message from an exception and re-raise it as a BumpVersionError.
run_command
def run_command(command: list, env: Optional[dict] = None) -> CompletedProcessRun a shell command and return its output.
find_repo_root
def find_repo_root(start: Pathlike) -> Optional[Path]Return the nearest ancestor of start (inclusive) containing a .git or .hg entry.
Parameters
start: The directory to start searching from.
Returns
- The repository root, or
Noneifstartis not inside a repository.
is_subpath
def is_subpath(parent: Pathlike, path: Pathlike) -> boolDetermines 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.
Parameters
parent: A Pathlike object representing the parent directory or path.path: A Pathlike object representing the path to check.
Returns
- True if the path is a subpath of the parent, or if it is a relative path; otherwise, False.