unioslo / zabbix-cli

Command-line interface for Zabbix
https://unioslo.github.io/zabbix-cli/
GNU General Public License v3.0
206 stars 102 forks source link

Refactor version comparisons #166

Closed pederhan closed 11 months ago

pederhan commented 11 months ago

This PR refactors version comparisons in the application by utilizing packaging.version.Version more broadly.

The attribute zabbixcli.api_version has been removed, and zabbixcli.zabbix_version is now an instance of packaging.version.Version containing the full version number instead of a single integer denoting the major version.

All existing comparisons of zabbixcli.zabbix_version with integers have been rewritten to use zabbixcli.zabbix_version.major.

Similarly, all zabbixcli.api_version comparisons now use zabbixcli.zabbix_version.major and compare them with integers instead of comparing with other version objects.

On version comparisons

Comparing Version.release with version tuples ignores pre-release information, which is important to support users running pre-release (alpha/beta/rc) versions of Zabbix. Given the following Zabbix version:

version = Version("6.2.0alpha1")

We can't compare directly with a Version object (alpha < final):

>>> version >= Version("6.2.0")
False

Using release we can compare against a tuple of integers, thus alpha >= final:

>>> version.release >= (6,2,0)
True

In tuple comparisons, we can omit micro/patch version:

>>> version.release >= (6,2)
True

Comparing exact major and minor version is best done by constructing a tuple or comparing with major and minor:

>>> (version.major, version.minor) == (6,2)
True
>>> version.major == 6 and version.minor == 2
True

This lays the foundation for implementing specific minor version comparisons, such as the one required by #159.