Skip to content

bumpversion.versioning.serialization ​

Functions for serializing and deserializing version objects.

logger ​

python
logger = get_indented_logger(__name__)

parse_version ​

python
def parse_version(version_string: str, parse_pattern: str) -> Dict[str, str]

Parse a version string into a dictionary of the parts and values using a regular expression.

Parameters

  • version_string: Version string to parse
  • parse_pattern: The regular expression pattern to use for parsing

Returns

  • A dictionary of version part labels and their values, or an empty dictionary
  • if the version string doesn't match.

Raises

  • BumpVersionError: If the parse_pattern is not a valid regular expression

multisort ​

python
def multisort(xs: list, specs: tuple) -> list

Sort a list of dictionaries by multiple keys.

From https://docs.python.org/3/howto/sorting.html#sort-stability-and-complex-sorts

Parameters

  • xs: The list of dictionaries to sort
  • specs: A tuple of (key, reverse) pairs

Returns

  • The sorted list

serialize ​

python
def serialize(version: Version, serialize_patterns: List[str], context: MutableMapping) -> str

Attempts to serialize a version with the given serialization format.

  • valid serialization patterns are those that are renderable with the given context
  • formats that contain all required components are preferred
  • the shortest valid serialization pattern is used
  • if two patterns are equally short, the first one is used
  • if no valid serialization pattern is found, an error is raised

Parameters

  • version: The version to serialize
  • serialize_patterns: The serialization format to use, using Python's format string syntax
  • context: The context to use when serializing the version

Returns

  • The serialized version as a string

Raises

  • FormattingError: if a serialization pattern