Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor version comparisons #166

Merged
merged 1 commit into from
Nov 24, 2023
Merged

Conversation

pederhan
Copy link
Member

@pederhan pederhan commented Nov 24, 2023

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.

@pederhan pederhan merged commit 299d8c6 into unioslo:master Nov 24, 2023
7 checks passed
@pederhan pederhan deleted the refactor-version branch November 24, 2023 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant