semvermanager

semvermamager exports a single class Version which implements a restricted subset of the SEMVER standard.

Version defines a Semantic version using the following field structure:

# MAJOR.MINOR.PATCH-TAG

int MAJOR  # 0 to N
int MINOR  # 0 to N
int PATCH  # 0 to N
str TAG    # one of "alpha", "beta".
int TAG_VERSION # appended to the tag if the tag is alpha or beta.

Versions may be bumped by a single increment using any of the bump functions. Bumping a PATCH value simply increments it. Bumping a MINOR value zeros the PATCH value and bumping a MAJOR zeros the MINOR and the PATCH value.

semvermanager only supports Python 3.6 and greater.

class semvermanager.Version(major=0, minor=0, patch=0, tag='alpha', tag_version=0, lhs='VERSION', separator='=')[source]

Handle creation and storage of SEMVER version numbers. In this case SEMVERs must be of the form a.b.c-tag, Where a,b and c are integers in the range 0-n and tag is one of Version.TAGS.

Version numbers may be bumped by using the various bump functions. Bumping minor zeros patch, bumping major zeros minor.

bump_map()[source]

a mapping of field names to corresponding bump methods :return: a dict of field names to bump methods

field(field)[source]

Return the mapping from a field to its corresponding property. :param field: str in Version.FIELDS :return:

field_map()[source]

Mapping of field names to field values. :return: A dict of field names to their properties.

static find(filename, lhs='VERSION', separator='=')[source]

Look for the first instance of a VERSION definition in a file and try and parse it as a Version

read(filename, lhs=None, separator=None)[source]

Read a single line from filename and parse it as version string.

Parameters:filename – a file containing a single line VERSION string.

:param lhs : override the class field string :param separator: the character seperating the VERSION label from the value :return: a Version object

:raises VersionError if it fails to parse the file.

static update(filename, version, lhs='VERSION', separator='=')[source]

Find any line starting with “VERSION” and replace that line with the new version.

Parameters:
  • filename – A path to a file containing at least one VERSION line
  • version – The new version object
  • lhs – The label string
  • separator – label<seperator>value
Returns:

A tuple (number of lines updated, list(line_numbers))

write(filename)[source]

Write a single line containing the version object to filename. This will overwrite the existing file if it exists.

Parameters:filename – The file to create with the new version object
Returns:A tuple of the filename and the version object
exception semvermanager.VersionError[source]

Exception for handling errors in Version Class

Indices and tables