in antlir/rpm/allowed_versions/envra.py [0:0]
def _compare(self, other: "SortableENVRA") -> int:
# It makes no sense to compare wildcard with non-wildcard because it
# amounts to comparing different data types. All elements of a
# `SortableENVRA` collections should have wildcards in this field,
# or the field should be concrete throughout.
if (self.name is None) ^ (other.name is None):
raise TypeError(
f"Cannot compare concrete name with wildcard: {self} {other}"
)
if (self.arch is None) ^ (other.arch is None):
raise TypeError(
f"Cannot compare concrete arch with wildcard: {self} {other}"
)
# Sort lexicographically by name, then architecture
self_key = (self.name, self.arch)
other_key = (other.name, other.arch)
if self_key > other_key:
return 1
elif self_key == other_key:
# Same rationale as for the `.name` test above.
if (self.epoch is None) ^ (other.epoch is None):
raise TypeError(
f"Cannot compare int epoch with wildcard: {self} {other}"
)
return compare_rpm_versions(
self._as_rpm_metadata(), other._as_rpm_metadata()
)
elif self_key < other_key:
return -1
raise AssertionError(f"Bad name/arch keys: {self_key} {other_key}")