#8 Making the callback triggers more lenient
Merged 4 years ago by nphilipp. Opened 4 years ago by asaleh.
fedora-infra/ asaleh/rpmautospec autospec_cb_cleanup  into  master

@@ -1,4 +1,6 @@ 

  import os

+ import re

+ 

  from glob import glob

  

  from koji.plugin import callback
@@ -7,14 +9,16 @@ 

  from rpmautospec.misc import koji_init

  from rpmautospec.release import holistic_heuristic_algo

  

- template = """%global function autorel() {{

+ autorel_template = """%global function autorel() {{

      return {autorel}

  }}

  """

  

+ autorel_re = re.compile(r"^\s*(?i:Release)\s*:\s+%(?:autorel(?:\s|$)|\{autorel[^\}]*\})")

+ 

  

- def is_autorel(l):

-     return "Release:" in l and "%{autorel}" in l

+ def is_autorel(line):

+     return autorel_re.match(line)

  

  

  def get_autorel(name, dist, session):
@@ -42,14 +46,16 @@ 

          return

  

      with open(specfiles[0], "r") as specfile:

-         lines = [l.rstrip("\n") for l in specfile]

+         content = specfile.read()

do we want to read all the content or go through it line by line so as to avoid loading the entire file in memory?

+         # we remove trailing lines

+         lines = content.rstrip().splitlines(keepends=False)

          autorel = any(is_autorel(l) for l in lines)

  

-         if lines[-1] == "%{autochangelog}" and lines[-2] == "%changelog":

+         if lines[-1] == "%{autochangelog}":

              autospec = True

  

      if autorel:

-         lines.insert(0, template.format(autorel=new_rel))

+         lines.insert(0, autorel_template.format(autorel=new_rel))

      if autospec:

          del lines[-1]

          lines += produce_changelog(srcdir)

file modified
+3 -2
@@ -66,7 +66,8 @@ 

  

  

  def holistic_heuristic_calculate_release(

-     dist, evr, lower_bound: dict, higher_bound: typing.Optional[dict],

+     dist: str, evr: typing.Tuple[int, str, str],

+     lower_bound: dict, higher_bound: typing.Optional[dict],

  ):

  

      # So what package EVR are we going for again? Default to "same as lower bound".
@@ -123,7 +124,7 @@ 

      return new_evr

  

  

- def holistic_heuristic_algo(package, dist, evr):

+ def holistic_heuristic_algo(package: str, dist: str, evr: typing.Tuple[int, str, str]):

      match = disttag_re.match(dist)

      if not match:

          print(

@@ -4,7 +4,7 @@ 

  import tempfile

  from unittest.mock import MagicMock

  

- from koji_plugin.rpmautospec_plugin import autospec_cb

+ from koji_plugin.rpmautospec_plugin import autospec_cb, is_autorel

  

  

  __here__ = os.path.dirname(__file__)
@@ -29,6 +29,16 @@ 

  class TestRpmautospecPlugin:

      """Test the koji_plugin.rpmautospec_plugin module"""

  

+     def test_is_autorel(self):

+         assert is_autorel("Release: %{autorel}")

+         assert is_autorel("Release: %autorel")

+         assert is_autorel("release: %{autorel}")

+         assert is_autorel(" release :  %{autorel}")

+         assert is_autorel("Release: %{autorel_special}")

+ 

+         assert not is_autorel("NotRelease: %{autorel}")

+         assert not is_autorel("release: 1%{?dist}")

+ 

      def test_autospec_cb(self):

          """Test the autospec_cb() function"""

          with tempfile.TemporaryDirectory() as workdir:

The autochangelog gets applied even if there is white-space/newlines
at the end of the file, it no longer requres %changelog to be present right
above %{autochangelog}.

The Release field is checked with regex.

Some additional typing updates.

Build succeeded.

do we want to read all the content or go through it line by line so as to avoid loading the entire file in memory?

rebased onto 9e70b6a6705b2b0b52d2ff81035ee8de52c53659

4 years ago

rebased onto dfebf3a

4 years ago

do we want to read all the content or go through it line by line so as to avoid loading the entire file in memory?

I discussed with @asaleh that we'll tackle this in separate PR.

Pull-Request has been merged by nphilipp

4 years ago

Build failed.