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.models.
VALID_PACKAGE
= '[A-Za-z][A-Za-z0-9]+(?:[_\\.-][A-Za-z0-9]+)*'¶ Regular expression to match a valid package name
-
versionah.models.
VALID_VERSION
= '\\d+\\.\\d+(?:\\.\\d+){,2}'¶ Regular expression to match a valid package version
-
versionah.models.
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.models.
VERSION_COMPS
= ('major', 'minor', 'micro', 'patch')¶ Supported version components
-
class
versionah.models.
Version
(components=(0, 1, 0), name='unknown', date=datetime.today())[source]¶ Main version identifier representation.
Initialise a new
Version
object.- Parameters
components (str) – Version components
name (str) – Package name
date (datetime.date) – Date associated with version
-
as_date
()[source]¶ Generate a ISO-8601 date string for release.
- Returns
Version’s release date as ISO-8601 date stamp
- Return type
-
as_dict
()[source]¶ Generate a dictionary of version components.
- Returns
Version as dictionary
- Return type
-
as_dotted
()[source]¶ Generate a dotted version string.
- Returns
Standard dotted version string
- Return type
-
as_libtool
()[source]¶ Generate a libtool version string.
- Returns
Version as libtool string
- Return type
-
as_tuple
()[source]¶ Generate a tuple of version components.
- Returns
Version components as tuple
- Return type
-
as_web
()[source]¶ Generate a web UA-style string for release.
- Returns
Version’s string in web UA-style
- Return type
-
bump
(bump_type)[source]¶ Bump a version string.
- Parameters
bump_type (str) – Component to bump
- Raises
ValueError
– Invalidbump_type
argument
-
components
¶ Generate component tuple to initial resolution.
- Returns
tuple[int]
-
components_full
¶ Generate full length component tuple for version.
- Returns
tuple[int]
-
versionah.models.
split_version
(version)[source]¶ Split version string to components.
- Parameters
version (str) – Version string
- Returns
Components of version string
- Return type
- Raises
ValueError
– Invalid version string
Examples¶
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)
Version string parsing¶
>>> split_version('4.3.0')
(4, 3, 0)
>>> split_version('4.3.0.1')
(4, 3, 0, 1)
>>> split_version('4.3.0.1.3')
Traceback (most recent call last):
...
ValueError: Invalid version string '4.3.0.1.3'