#110 Improve detection of %autorel/%autochangelog use
Merged 3 years ago by nphilipp. Opened 3 years ago by nphilipp.
fedora-infra/ nphilipp/rpmautospec master--auto-regexes  into  master

@@ -25,9 +25,9 @@ 

  ## END: Set by rpmautospec

  """  # noqa: E501

  

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

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

  changelog_re = re.compile(r"^%changelog(?:\s.*)?$", re.IGNORECASE)

- autochangelog_re = re.compile(r"^\s*%(?:autochangelog|\{autochangelog\})\s*$")

+ autochangelog_re = re.compile(r"\s*%(?:autochangelog|\{\??autochangelog\})\s*")

  

  

  def register_subcommand(subparsers):

@@ -18,7 +18,7 @@ 

  

      autorel_autochangelog_cases = [

          (autorel_case, autochangelog_case)

-         for autorel_case in ("unchanged", "with braces")

+         for autorel_case in ("unchanged", "with braces", "optional")

          for autochangelog_case in (

              "unchanged",

              "changelog case insensitive",
@@ -26,6 +26,7 @@ 

              "line in between",

              "trailing line",

              "with braces",

+             "optional",

          )

      ]

  
@@ -38,6 +39,8 @@ 

                  if line.startswith("Release:") and autorel_case != "unchanged":

                      if autorel_case == "with braces":

                          print("Release:        %{autorel}", file=new)

+                     elif autorel_case == "optional":

+                         print("Release:        %{?autorel}", file=new)

                      else:

                          raise ValueError(f"Unknown autorel_case: {autorel_case}")

                  elif line.strip() == "%changelog" and autochangelog_case != "unchanged":
@@ -54,6 +57,9 @@ 

                      elif autochangelog_case == "with braces":

                          print("%changelog\n%{autochangelog}", file=new)

                          break

+                     elif autochangelog_case == "optional":

+                         print("%changelog\n%{?autochangelog}", file=new)

+                         break

                      else:

                          raise ValueError(f"Unknown autochangelog_case: {autochangelog_case}")

                  else:
@@ -66,8 +72,8 @@ 

          assert process_distgit.is_autorel("Release: %autorel")

          assert process_distgit.is_autorel("release: %{autorel}")

          assert process_distgit.is_autorel(" release :  %{autorel}")

-         assert process_distgit.is_autorel("Release: %{autorel_special}")

  

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

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

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

  

Previously, it wouldn't detect the optional forms of the macros, i.e.
%{?autorel} or %{?autochangelog}, respectively.

This change relaxes the regular expressions involved that they can cope
with this and (optionally) the inverted macro, so that maintainers can
use this to specify fallbacks if the macros aren't installed.

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

Build succeeded.

Pull-Request has been merged by nphilipp

3 years ago