#548 Skip NVR check if the %autorelease macro is used
Merged 2 years ago by onosek. Opened 3 years ago by nphilipp.

file modified
+30 -9
@@ -67,6 +67,11 @@ 

      # The SafeConfigParser class has been renamed to ConfigParser in Python 3.2.

      ConfigParser = configparser.ConfigParser

  

+ try:

+     from rpmautospec import specfile_uses_rpmautospec

+ except ImportError:

+     specfile_uses_rpmautospec = None

+ 

  

  class NullHandler(logging.Handler):

      """Null logger to avoid spurious messages, add a handler in app code"""
@@ -156,6 +161,8 @@ 

          self._nvr = None

          # The rpm release of the cloned package

          self._rel = None

+         # Whether the spec file uses %autorelease

+         self._uses_autorelease = None

          # The cloned repo object

          self._repo = None

          # The rpm defines used when calling rpm
@@ -672,20 +679,36 @@ 

      @property

      def rel(self):

          """This property ensures the rel attribute"""

-         if not self._rel:

+         if self._rel is None:

              self.load_nameverrel()

          return(self._rel)

  

+     @property

+     def uses_autorelease(self):

+         if self._uses_autorelease is None:

+             self.load_nameverrel()

+         return self._uses_autorelease

+ 

      def load_nameverrel(self):

          """Set the release of a package."""

  

+         specfile_path = os.path.join(self.path, self.spec)

+ 

+         if specfile_uses_rpmautospec:

+             self._uses_autorelease = specfile_uses_rpmautospec(

+                 specfile_path, check_autorelease=True, check_autochangelog=False

+             )

+         else:

+             # Set to 0 so it evaluates false-ish but differs from (unset) None.

+             self._uses_autorelease = 0

+ 

          cmd = ['rpm']

          cmd.extend(self.rpmdefines)

          # We make sure there is a space at the end of our query so that

          # we can split it later.  When there are subpackages, we get a

          # listing for each subpackage.  We only care about the first.

          cmd.extend(['-q', '--qf', '"??%{NAME} %{EPOCH} %{VERSION} %{RELEASE}??"',

-                     '--specfile', '"%s"' % os.path.join(self.path, self.spec)])

+                     '--specfile', '"%s"' % specfile_path])

          joined_cmd = ' '.join(cmd)

          try:

              proc = subprocess.Popen(joined_cmd, shell=True,
@@ -694,10 +717,8 @@ 

                                      stderr=subprocess.PIPE)

              output, err = proc.communicate()

          except Exception as e:

-             if err:

-                 self.log.debug('Errors occoured while running following command to get N-V-R-E:')

-                 self.log.debug(joined_cmd)

-                 self.log.error(err)

+             self.log.debug('Errors occoured while running following command to get N-V-R-E:')

+             self.log.debug(joined_cmd)

              raise rpkgError('Could not query n-v-r of %s: %s'

                              % (self.repo_name, e))

          if err:
@@ -2275,9 +2296,9 @@ 

                                    ' in following messages.')

                      build_reference = self.repo_name

  

-         # see if this build has been done.  Does not check builds within

-         # a chain

-         if nvr_check and not scratch and not url.endswith('.src.rpm'):

+         # See if this build has been done.  Does not check builds within

+         # a chain, or if the %autorelease macro is used.

+         if (nvr_check or self.uses_autorelease) and not scratch and not url.endswith('.src.rpm'):

              build = self.kojisession.getBuild(self.nvr)

              if build:

                  if build['state'] == 1:

file modified
+4 -1
@@ -3617,9 +3617,12 @@ 

          commithash.return_value = '45678'

          nvr.return_value = 'docpkg-0.1-1.fc28'

  

-         Popen.return_value.communicate.side_effect = [

+         proc = Popen.return_value

+         proc.communicate.side_effect = [

              ('12345', ''),

+             ('??docpkg (none) 1.2 2.el7??', ''),

          ]

+         proc.returncode = 0

  

          self.assert_build(

              'chain-build',

If a spec file sets the release field to the %autorelease macro, don't
even attempt to check if the build exists already, as using the macro
ensures that a new release number is used.

Fixes: https://pagure.io/fedora-infra/rpmautospec/issue/109

Signed-off-by: Nils Philippsen nils@redhat.com

Which package provides rpmautospec module?

It's in the python3-rpmautospec package we work on as part of the corresponding F35 Change: https://fedoraproject.org/wiki/Changes/rpmautospec

Sorry I didn't provide that context up-front.

Note, we have an open PR in rpmautospec (fedora-infra/rpmautospec#155) to expose a function doing the checksto 3rd parties, and we'll rework this PR to use it. Don't merge yet, thanks!

rebased onto fee44150e64a2088fb1b1cecc583fc7ee2343403

2 years ago

rebased onto 0c9233876b0a076dc7616f7b5e4849011a5da1f1

2 years ago

2 new commits added

  • Skip NVR check if the %autorelease macro is used
  • Don't access unset variable
2 years ago

The latest push uses the exposed function and adapts one test to make it aware of the new calls to load_nameverrel() -> Popen() introduced by the change. Please review, thanks!

@lsedlar is there anything missing from this PR before you or some other fedpkg/rpkg maintainer can do a review?

I like the design of the change. I have checked the code without locating an issue.
It would work in RHEL where the new dependency (rpmautospec) is missing.

rebased onto 215d809

2 years ago

Pull-Request has been merged by onosek

2 years ago
Metadata