Skip to content

bumpversion.utils ​

General utilities.

logger ​

python
logger = get_indented_logger(__name__)

Pathlike ​

python
Pathlike = Union[str, Path]

A type alias for a path-like object.

extract_regex_flags ​

python
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 ​

python
def recursive_sort_dict(input_value: Any) -> Any

Sort a dictionary recursively.

key_val_string ​

python
def key_val_string(d: dict) -> str

Render the dictionary as a comma-delimited key=value string.

labels_for_format ​

python
def labels_for_format(serialize_format: str) -> List[str]

Return a list of labels for the given serialize_format.

get_overrides ​

python
def get_overrides(kwargs = {}) -> dict

Return a dictionary containing only the overridden key-values.

get_nested_value ​

python
def get_nested_value(d: dict, path: str) -> Any

Retrieves 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 ​

python
def 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.

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 ​

python
def format_and_raise_error(exc: Union[BaseException, subprocess.CalledProcessError]) -> None

Format the error message from an exception and re-raise it as a BumpVersionError.

run_command ​

python
def run_command(command: list, env: Optional[dict] = None) -> CompletedProcess

Run a shell command and return its output.

find_repo_root ​

python
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 None if start is not inside a repository.

is_subpath ​

python
def 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.

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.