Handle legacy version specifiers that would previously raise exceptions.

Related: rhbz#1950291
This commit is contained in:
Gordon Messmer 2021-12-19 14:09:06 -08:00 committed by Karolina Surma
parent 5513c410bf
commit 2abd0036ea
2 changed files with 22 additions and 8 deletions

View File

@ -12,7 +12,7 @@ License: MIT
# In other cases, such as backports, increment the point
# release.
Version: 0
Release: 51%{?dist}
Release: 52%{?dist}
# Macro files
Source001: macros.pyproject
@ -122,6 +122,9 @@ export HOSTNAME="rpmbuild" # to speedup tox in network-less mock, see rhbz#1856
%license LICENSE
%changelog
* Sun Dec 19 2021 Gordon Messmer <gordon.messmer@gmail.com> - 0-52
- Handle legacy version specifiers that would previously raise exceptions.
* Wed Dec 08 2021 Miro Hrončok <mhroncok@redhat.com> - 0-51
- Define provisional %%pyproject_build_lib

View File

@ -40,6 +40,9 @@ class RpmVersion():
# in public releases
# https://www.python.org/dev/peps/pep-0440/#local-version-identifiers
def is_legacy(self):
return isinstance(self.version, str)
def increment(self):
self.version[-1] += 1
self.pre = None
@ -48,7 +51,7 @@ class RpmVersion():
return self
def __str__(self):
if isinstance(self.version, str):
if self.is_legacy():
return self.version
if self.epoch:
rpm_epoch = str(self.epoch) + ':'
@ -71,6 +74,9 @@ def convert_compatible(name, operator, version_id):
if version_id.endswith('.*'):
return 'Invalid version'
version = RpmVersion(version_id)
if version.is_legacy():
# LegacyVersions are not supported in this context
return 'Invalid version'
if len(version.version) == 1:
return 'Invalid version'
upper_version = RpmVersion(version_id)
@ -96,6 +102,9 @@ def convert_not_equal(name, operator, version_id):
if version_id.endswith('.*'):
version_id = version_id[:-2]
version = RpmVersion(version_id)
if version.is_legacy():
# LegacyVersions are not supported in this context
return 'Invalid version'
version_gt = RpmVersion(version_id).increment()
version_gt_operator = '>='
# Prevent dev and pre-releases from satisfying a < requirement
@ -126,12 +135,14 @@ def convert_ordered(name, operator, version_id):
operator = '<'
else:
version = RpmVersion(version_id)
# Prevent dev and pre-releases from satisfying a < requirement
if operator == '<' and not version.pre and not version.dev and not version.post:
version = '{}~~'.format(version)
# Prevent post-releases from satisfying a > requirement
if operator == '>' and not version.pre and not version.dev and not version.post:
version = '{}.0'.format(version)
# For backwards compatibility, fallback to previous behavior with LegacyVersions
if not version.is_legacy():
# Prevent dev and pre-releases from satisfying a < requirement
if operator == '<' and not version.pre and not version.dev and not version.post:
version = '{}~~'.format(version)
# Prevent post-releases from satisfying a > requirement
if operator == '>' and not version.pre and not version.dev and not version.post:
version = '{}.0'.format(version)
return '{} {} {}'.format(name, operator, version)
OPERATORS = {'~=': convert_compatible,