From 2abd0036eabf448082dfa8a84222384bb2f7be8d Mon Sep 17 00:00:00 2001 From: Gordon Messmer Date: Sun, 19 Dec 2021 14:09:06 -0800 Subject: [PATCH] Handle legacy version specifiers that would previously raise exceptions. Related: rhbz#1950291 --- pyproject-rpm-macros.spec | 5 ++++- pyproject_convert.py | 25 ++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/pyproject-rpm-macros.spec b/pyproject-rpm-macros.spec index 7d7ef30..da32975 100644 --- a/pyproject-rpm-macros.spec +++ b/pyproject-rpm-macros.spec @@ -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 - 0-52 +- Handle legacy version specifiers that would previously raise exceptions. + * Wed Dec 08 2021 Miro HronĨok - 0-51 - Define provisional %%pyproject_build_lib diff --git a/pyproject_convert.py b/pyproject_convert.py index e6875fc..ea01bc3 100644 --- a/pyproject_convert.py +++ b/pyproject_convert.py @@ -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,