hbutils.testing.requires.version
Version information utilities with dynamic comparison support.
This module provides a lightweight wrapper around
packaging.version.Version to accept flexible input formats and enable
lazy, dynamic resolution via callables. The main entry point is
VersionInfo, which supports comparisons, boolean evaluation, and
representation in a consistent way.
The module contains the following main component:
VersionInfo- Flexible version wrapper with comparison operators
Example:
>>> from hbutils.testing.requires.version import VersionInfo
>>> v1 = VersionInfo('1.2.3')
>>> v2 = VersionInfo((1, 2, 4))
>>> v1 < v2
True
>>> v3 = VersionInfo(lambda: '1.3.0')
>>> v1 < v3
True
Note
Instances of VersionInfo are intentionally not immutable because
callables may resolve to different values over time.
VersionInfo
- class hbutils.testing.requires.version.VersionInfo(v: VersionInfo | Version | Callable[[], VersionInfo | Version | str | Tuple[int, ...] | int | None] | str | Tuple[int, ...] | int | None)[source]
Class for wrapping version information with dynamic comparison support.
This class provides a flexible wrapper around version information that supports multiple input formats and allows for dynamic version resolution through callables.
Warning
This class is not immutable for its designing for dynamic comparison and boolean check. Please pay attention when use it.
- Parameters:
v (Union[VersionInfo, Version, Callable, str, tuple, int, None]) – The version information, can be a
VersionInfo,Version, callable, string, tuple, int, orNone.- Raises:
TypeError – If the version type is not supported.
- Example::
>>> v1 = VersionInfo('1.2.3') >>> v2 = VersionInfo((1, 2, 4)) >>> v1 < v2 True >>> v3 = VersionInfo(lambda: '1.3.0') >>> v1 < v3 True
- __bool__() bool[source]
Check if the version is truthy (not None).
- Returns:
True if the version is not None, False otherwise.
- Return type:
bool
- __eq__(other: VersionInfo | Version | Callable[[], VersionInfo | Version | str | Tuple[int, ...] | int | None] | str | Tuple[int, ...] | int | None) bool[source]
Check if this version is equal to another version.
- Parameters:
other (Union[VersionInfo, Version, str, tuple, int, None]) – The other version to compare against.
- Returns:
True if this version equals the other, False otherwise.
- Return type:
bool
Note
Equality checks compare resolved versions directly, including
None.
- __ge__(other: VersionInfo | Version | Callable[[], VersionInfo | Version | str | Tuple[int, ...] | int | None] | str | Tuple[int, ...] | int | None) bool[source]
Check if this version is greater than or equal to another version.
- Parameters:
other (Union[VersionInfo, Version, str, tuple, int, None]) – The other version to compare against.
- Returns:
True if this version is greater than or equal to the other, False otherwise.
- Return type:
bool
- __gt__(other: VersionInfo | Version | Callable[[], VersionInfo | Version | str | Tuple[int, ...] | int | None] | str | Tuple[int, ...] | int | None) bool[source]
Check if this version is greater than another version.
- Parameters:
other (Union[VersionInfo, Version, str, tuple, int, None]) – The other version to compare against.
- Returns:
True if this version is greater than the other, False otherwise.
- Return type:
bool
- __init__(v: VersionInfo | Version | Callable[[], VersionInfo | Version | str | Tuple[int, ...] | int | None] | str | Tuple[int, ...] | int | None) None[source]
Initialize the VersionInfo instance.
- Parameters:
v (Union[VersionInfo, Version, Callable, str, tuple, int, None]) – The version information to wrap. Accepts
VersionInfo,Version, callables, strings, tuples, integers, orNone.- Raises:
TypeError – If the version type is unknown or unsupported.
- __le__(other: VersionInfo | Version | Callable[[], VersionInfo | Version | str | Tuple[int, ...] | int | None] | str | Tuple[int, ...] | int | None) bool[source]
Check if this version is less than or equal to another version.
- Parameters:
other (Union[VersionInfo, Version, str, tuple, int, None]) – The other version to compare against.
- Returns:
True if this version is less than or equal to the other, False otherwise.
- Return type:
bool
- __lt__(other: VersionInfo | Version | Callable[[], VersionInfo | Version | str | Tuple[int, ...] | int | None] | str | Tuple[int, ...] | int | None) bool[source]
Check if this version is less than another version.
- Parameters:
other (Union[VersionInfo, Version, str, tuple, int, None]) – The other version to compare against.
- Returns:
True if this version is less than the other, False otherwise.
- Return type:
bool
- __ne__(other: VersionInfo | Version | Callable[[], VersionInfo | Version | str | Tuple[int, ...] | int | None] | str | Tuple[int, ...] | int | None) bool[source]
Check if this version is not equal to another version.
- Parameters:
other (Union[VersionInfo, Version, str, tuple, int, None]) – The other version to compare against.
- Returns:
True if this version does not equal the other, False otherwise.
- Return type:
bool