in antlir/rpm/rpm_metadata.py [0:0]
def compare_rpm_versions(a: RpmMetadata, b: RpmMetadata) -> int:
"""
Returns:
1 if the version of a is newer than b
0 if the versions match
-1 if the version of a is older than b
"""
# This is not a rule, but it makes sense that our libs don't want to
# compare versions of different RPMs
if a.name != b.name:
raise ValueError("Cannot compare RPM versions when names do not match")
# First compare the epoch, if set. If the epoch's are not the same, then
# the higher one wins no matter what the rest of the EVR is.
if a.epoch != b.epoch:
if a.epoch > b.epoch:
return 1 # a > b
else:
return -1 # a < b
# Epoch is the same, if version + release are the same we have a match
if (a.version == b.version) and (a.release == b.release):
return 0 # a == b
# Compare version first, if version is equal then compare release
compare_res = _compare_values(a.version, b.version)
if compare_res != 0: # a > b || a < b
return compare_res
else:
return _compare_values(a.release, b.release)