#49 Handle legacy version specifiers that would previously raise exceptions.
Merged 2 years ago by churchyard. Opened 2 years ago by gordonmessmer.
rpms/ gordonmessmer/python-rpm-generators pyreq_sync  into  rawhide

file modified
+4 -1
@@ -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 @@ 

  %{_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.

  

file modified
+22 -7
@@ -138,6 +138,9 @@ 

              # 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 @@ 

          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 @@ 

          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 @@ 

      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 @@ 

              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)

  

  

no initial comment

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

Pull-Request has been merged by churchyard

2 years ago