Version Module

Various helper functions for analyzing and manipulating PEP 440 version numbers, meant to augment the packaging.version module.

extract_version(version_str: str)Tuple[Optional[packaging.version.Version], int, int]

Extracts a PEP 440 version object from a string which may have other text

Parameters

version_str – The input string to extract from

Returns

A tuple of (version, start, end), where start and end are the span of the version in the original string

increment_version(version_str: str, rel_seg: Optional[int] = None, pre_seg: Optional[str] = None)str

Increment the PEP 440 version number in a string

Parameters
  • version_str – The input string to manipulate

  • rel_seg – Which segment of the “release” value to increment, if any

  • pre_seg – Which kind of prerelease to use, if any. An empty string clears the prerelease field.

Returns

The original string with the version number incremented

join_version(epoch, release, pre, post, dev, local)str

Join multiple segments of a PEP 440 version

is_release(version_str: str)bool

Check if a version string is a release version

Parameters

version_str – the input string to check

Returns

True if the input contains a released PEP 440 version, or False if a prerelease version or no version is found