Handle legacy version specifiers that would previously raise exceptions.
This commit is contained in:
parent
a3ad67b505
commit
2c2f8bd984
@ -1,7 +1,7 @@
|
||||
Name: python-rpm-generators
|
||||
Summary: Dependency generators for Python RPMs
|
||||
Version: 12
|
||||
Release: 10%{?dist}
|
||||
Release: 11%{?dist}
|
||||
|
||||
# Originally all those files were part of RPM, so license is kept here
|
||||
License: GPLv2+
|
||||
@ -47,6 +47,9 @@ install -Dpm0755 -t %{buildroot}%{_rpmconfigdir} *.py
|
||||
%{_rpmconfigdir}/pythonbundles.py
|
||||
|
||||
%changelog
|
||||
* Sun Dec 19 2021 Gordon Messmer <gordon.messmer@gmail.com> - 12-11
|
||||
- Handle legacy version specifiers that would previously raise exceptions.
|
||||
|
||||
* Fri Oct 29 2021 Gordon Messmer <gordon.messmer@gmail.com> - 12-10
|
||||
- Additional fix for dev releases.
|
||||
|
||||
|
@ -138,6 +138,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
|
||||
@ -146,7 +149,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) + ':'
|
||||
@ -172,6 +175,11 @@ def convert_compatible(name, operator, version_id):
|
||||
print('Invalid requirement: {} {} {}'.format(name, operator, version_id), file=stderr)
|
||||
exit(65) # os.EX_DATAERR
|
||||
version = RpmVersion(version_id)
|
||||
if version.is_legacy():
|
||||
# LegacyVersions are not supported in this context
|
||||
print("*** INVALID_REQUIREMENT_ERROR___SEE_STDERR ***")
|
||||
print('Invalid requirement: {} {} {}'.format(name, operator, version_id), file=stderr)
|
||||
exit(65) # os.EX_DATAERR
|
||||
if len(version.version) == 1:
|
||||
print("*** INVALID_REQUIREMENT_ERROR___SEE_STDERR ***")
|
||||
print('Invalid requirement: {} {} {}'.format(name, operator, version_id), file=stderr)
|
||||
@ -204,6 +212,11 @@ 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
|
||||
print("*** INVALID_REQUIREMENT_ERROR___SEE_STDERR ***")
|
||||
print('Invalid requirement: {} {} {}'.format(name, operator, version_id), file=stderr)
|
||||
exit(65) # os.EX_DATAERR
|
||||
version_gt = RpmVersion(version_id).increment()
|
||||
version_gt_operator = '>='
|
||||
# Prevent dev and pre-releases from satisfying a < requirement
|
||||
@ -235,12 +248,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)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user