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 parseparse_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) -> listSort 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 sortspecs: A tuple of (key, reverse) pairs
Returns
- The sorted list
serialize
python
def serialize(version: Version, serialize_patterns: List[str], context: MutableMapping) -> strAttempts 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 serializeserialize_patterns: The serialization format to use, using Python's format string syntaxcontext: The context to use when serializing the version
Returns
- The serialized version as a string
Raises
FormattingError: if a serialization pattern