Version¶
Note
The documentation in this section is aimed at people wishing to contribute to
versionah, and can be skipped if you are simply using the tool from the
command line.
-
versionah.VALID_PACKAGE= '[A-Za-z][A-Za-z0-9]+(?:[_\\.-][A-Za-z0-9]+)*'¶ Regular expression to match a valid package name
-
versionah.VALID_VERSION= '\\d+\\.\\d+(?:\\.\\d+){,2}'¶ Regular expression to match a valid package version
-
versionah.VALID_DATE= '(?:\\d{4}-\\d{2}-\\d{2}|\\d{2}-(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-\\d{4})'¶ Regular expression to match a package date. ISO-8601, and %d-%b-%Y formatting for shtool compatibility
-
versionah.VERSION_COMPS= ('major', 'minor', 'micro', 'patch')¶ Supported version components
-
class
versionah.Version(components=(0, 1, 0), name='unknown', date=datetime.today())[source]¶ Initialise a new
Versionobject.Parameters: - components (
intortupleofint) – Version components - name (str) – Package name
- date (datetime.date) – Date associated with version
-
as_date()[source]¶ Generate a ISO-8601 date string for release.
Return type: strReturns: Version’s release date as ISO-8601 date stamp
-
as_dict()[source]¶ Generate a dictionary of version components.
Return type: dictReturns: Version as dictionary
-
as_dotted()[source]¶ Generate a dotted version string.
Return type: strReturns: Standard dotted version string
-
as_libtool()[source]¶ Generate a libtool version string.
Return type: strReturns: Version as libtool string
-
as_tuple()[source]¶ Generate a tuple of version components.
Return type: intReturns: Version components as tuple
-
as_web()[source]¶ Generate a web UA-style string for release.
Return type: strReturns: Version’s string in web UA-style
-
display(display_format)[source]¶ Display a version string.
Parameters: display_format (str) – Format to display version string in Return type: strReturns: Formatted version string
-
static
display_types()[source]¶ Supported representation types.
Return type: listofstrReturns: Method names for representation types
-
static
read(filename)[source]¶ Read a version file.
Parameters: filename (str) – Version file to read
Return type: Returns: New
Versionobject representing fileRaises: - exceptions.OSError – When
filenamedoesn’t exist - exceptions.ValueError – Unparsable version data
- exceptions.OSError – When
- components (
Examples¶
Reading version data from a file¶
>>> Version.read('tests/data/test_a')
Version((0, 1, 0), 'test', datetime.date(2011, 2, 19))
>>> Version.read('tests/data/test_b')
Version((1, 0, 0), 'test', datetime.date(2011, 2, 19))
>>> Version.read('tests/data/test_c')
Version((2, 1, 3), 'test', datetime.date(2011, 2, 19))
Writing version date to a file¶
>>> v = Version((0, 1, 0), 'test', datetime.date(2011, 2, 19))
>>> v.write('test_data.python', 'py')
>>> v.write('test_data.hh', 'h')
>>> v.write('test_data.m4', 'm4')
Bumping a version component¶
>>> v = Version((0, 1, 0), 'test', datetime.date(2011, 2, 19))
>>> v.bump('minor')
>>> v.components
(0, 2, 0)
>>> v.bump('major')
>>> v.components
(1, 0, 0)
>>> v.bump_major()
>>> v.components
(2, 0, 0)