The utils.py
module#
Summary#
Metaclass for version comparison. |
|
Class for semantic versioning. |
|
Custom class to hold strings for versioning. |
|
Custom class to hold integers for versioning. |
|
Class for version comparison. |
Sanitize a version string number by adding additional zeros. |
|
Sanitize a version number by adding additional zeros. |
|
Convert a semantic version string into a tuple. |
|
Convert a semantic version tuple into a string. |
|
Check if server meets the required version. |
|
Ensure the method called matches a certain version. |
|
Check if version string is valid. |
|
Check if a semantic version is valid. |
Description#
A module containing various utilities.
Module detail#
- utils.sanitize_version_string(version_string)#
Sanitize a version string number by adding additional zeros.
- Parameters:
- version_string
str
A string representing a semantic version.
- version_string
- Returns:
str
A string representing a semantic version.
Examples
>>> sanitize_version_string("0") '0.0.0' >>> sanitize_version_string("1.2") '1.2.0' >>> sanitize_version_string("0.3.4") '0.3.4'
- utils.sanitize_version_tuple(version_tuple)#
Sanitize a version number by adding additional zeros.
- Parameters:
- version_tuple
tuple
A tuple representing a semantic version.
- version_tuple
- Returns:
tuple
A tuple representing a semantic version.
Examples
>>> sanitize_version_tuple((0,)) (0, 0, 0) >>> sanitize_version_tuple((1, 2)) (1, 2, 0) >>> sanitize_version_tuple((0, 3, 4)) (0, 3, 4)
- utils.version_string_as_tuple(version_string)#
Convert a semantic version string into a tuple.
- Parameters:
- version_string
str
A string representing a semantic version.
- version_string
- Returns:
- version_tuple
tuple
A tuple representing a semantic version.
- version_tuple
Examples
>>> version_string_as_tuple("0.3.4") (0, 3, 4) >>> version_string_as_tuple("1.2") (1, 2, 0)
- utils.version_tuple_as_string(version_tuple)#
Convert a semantic version tuple into a string.
- Parameters:
- version_tuple
tuple
A tuple representing a semantic version.
- version_tuple
- Returns:
str
A string representing a semantic version.
Examples
>>> version_tuple_as_string((0, 3, 4)) '0.3.4' >>> version_tuple_as_string((1, 2)) '1.2.0'
- utils.server_meets_version(server_version, required_version)#
Check if server meets the required version.
- Parameters:
- Returns:
- bool
True
if server version meets required version,False
if not.
- Raises:
ValueError
If the ‘server_version’ object does not have ‘_server_version’ attribute.
Examples
>>> server_version, required_version = "1.2.0", "1.3.0" >>> server_meets_version(server_version, required_version) False >>> server_version, required_version = (1, 2, 0), (1, 3, 0) >>> server_meets_version(server_version, required_version) False >>> server_version, required_version = "2.3.0", "1.3.0" >>> server_meets_version(server_version, required_version) True >>> server_version, required_version = (2, 3, 0), (1, 3, 0) >>> server_meets_version(server_version, required_version) True >>> server_version, required_version = (0, 0, 0), (0, 0, 0) >>> server_meets_version(server_version, required_version) True >>> class MyServer: def __init__(self): self._server_version = "1.2.0" >>> server = MyServer() >>> server_version, required_version = server, "1.3.0" >>> server_meets_version(server, required_version)
- utils.requires_version(version, VERSION_MAP=None)#
Ensure the method called matches a certain version.
- Parameters:
- Raises:
AttributeError
Decorated class method requires
_server_version
attribute.VersionError
Decorated class method is not supported by server version.
- utils.valid_version_string(version)#
Check if version string is valid.
- utils.valid_semantic_version(iterable)#
Check if a semantic version is valid.