You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Software comparison does not work due to lexicographic order. Because of this, the Python statement assert 4.14.0 >= 10.14.0 is True, instead of False.
For example, let's test if the installed package dnf-4.14.0-5.el9_2.noarch is equal to or greater than the package version 10.14.0
The result will be True since version 4.14.0 is equal to version 4.14.0.
In Python, when you use the >= operator to compare strings, it performs lexicographic (dictionary-style) comparison based on the ASCII values of the characters. In lexicographic comparison, characters are compared one by one from left to right.
In our specific case, 4.14.0 is indeed greater than 10.14.0 according to lexicographic comparison because the first character 4 is greater than 1. The comparison stops as soon as a character difference is found, so the rest of the characters don't matter in this context.
Here's a step-by-step comparison:
Compare the first characters: '4' vs. '1'. '4' is greater than '1', so '4.14.0' is considered greater.
As a result, the assertion assert '4.14.0' >= '10.14.0' is true because, in lexicographic order, 4.14.0 comes after 10.14.0.
I propose adding function to convert 4.14.0 to 004.014.000 for comparison purposes for example:
def pad_version(version_string):
parts = version_string.split(".")
compare_version = ".".join([part.zfill(3) for part in parts])
return compare_version
# Example usage:
version_string = "4.14.0"
compare_version = pad_version(version_string)
print(compare_version)
# output
# 004.014.000
In this case, we will be able to execute a simple package comparison; however, we will have to write the version as 010.014.000 instead of 10.14.0
Maybe it doesn't look like the most beautiful solution; however, it will allow for easy-to-read package comparison code. And it will work with other distros and releases
I will appreciate your thought on this
The text was updated successfully, but these errors were encountered:
700grm
changed the title
Package comparison option in package module does not work as expected
The package comparison option in the package module is not working as expected.
Sep 2, 2023
I will be more than happy to take care of it; however, since I'm just starting my adventure with Python, I would appreciate more suggestions on how to implement the function into package module
Or split it into integers
# Split the strings into components
ver1 = '4.14.0'.split('.')
ver2 = '10.14.0'.split('.')
# Compare the first component as integers
print(int(ver1[0]) >= int(ver2[0])) # Output: False
Software comparison does not work due to lexicographic order. Because of this, the Python statement
assert 4.14.0 >= 10.14.0
isTrue
, instead ofFalse
.For example, let's test if the installed package
dnf-4.14.0-5.el9_2.noarch
is equal to or greater than the package version10.14.0
The result will be True since version
4.14.0
is equal to version4.14.0
.The result will be True since the version of package
5.14.0
is greater than the version of package4.14.0
.However, if we compare it with version
10.14.0
, the result will be True. The script will output that5.14.0
is bigger than10.14.0
.In Python, when you use the >= operator to compare strings, it performs lexicographic (dictionary-style) comparison based on the ASCII values of the characters. In lexicographic comparison, characters are compared one by one from left to right.
In our specific case,
4.14.0
is indeed greater than10.14.0
according to lexicographic comparison because the first character4
is greater than1
. The comparison stops as soon as a character difference is found, so the rest of the characters don't matter in this context.Here's a step-by-step comparison:
As a result, the assertion
assert '4.14.0' >= '10.14.0'
is true because, in lexicographic order,4.14.0
comes after10.14.0
.I propose adding function to convert
4.14.0
to004.014.000
for comparison purposes for example:In this case, we will be able to execute a simple package comparison; however, we will have to write the version as
010.014.000
instead of10.14.0
Maybe it doesn't look like the most beautiful solution; however, it will allow for easy-to-read package comparison code. And it will work with other distros and releases
I will appreciate your thought on this
The text was updated successfully, but these errors were encountered: