#171 Add --no-rpmautospec and filter .in|.tpl from %doc file lists
Merged 2 years ago by ignatenkobrain. Opened 2 years ago by zbyszek.
fedora-rust/ zbyszek/rust2rpm no-rpmautospec-and-filter-templates  into  main

file modified
+22 -17
@@ -37,15 +37,14 @@ 

      extensions=["jinja2.ext.do"],

      trim_blocks=True,

      lstrip_blocks=True)

- LICENSES = re.compile(

-          r"(COPYING|COPYING[\.\-].*|COPYRIGHT|COPYRIGHT[\.\-].*|"

-          r"EULA|EULA[\.\-].*|[Ll]icen[cs]e|[Ll]icen[cs]e.*|LICEN[CS]E|"

-          r"LICEN[CS]E[\.\-].*|.*[\.\-]LICEN[CS]E.*|NOTICE|NOTICE[\.\-].*|"

-          r"PATENTS|PATENTS[\.\-].*|UNLICEN[CS]E|UNLICEN[CS]E[\.\-].*|"

-          r"agpl[\.\-].*|gpl[\.\-].*|lgpl[\.\-].*|AGPL-.*[0-9].*|"

-          r"APACHE-.*[0-9].*|BSD-.*[0-9].*|CC-BY-.*|GFDL-.*[0-9].*|"

-          r"GNU-.*[0-9].*|GPL-.*[0-9].*|LGPL-.*[0-9].*|MIT-.*[0-9].*|"

-          r"MPL-.*[0-9].*|OFL-.*[0-9].*)")

+ LICENSES = re.compile(r"""

+          COPYING(?:[.-].*)?|COPYRIGHT(?:[.-].*)?|

+          EULA(?:[.-].*)?|[Ll]icen[cs]e|[Ll]icen[cs]e.*|

+          (?:.*[.-])?(?:UN)?LICEN[CS]E(?:[.-].*)?|NOTICE(?:[.-].*)?|

+          PATENTS(?:[.-].*)?|

+          (?:agpl|l?gpl)[.-].*|CC-BY-.*|

+          (?:AGPL|APACHE|BSD|GFDL|GNU|L?GPL|MIT|MPL|OFL)-.*[0-9].*

+          """, re.VERBOSE)

  

  def sortify(func):

      """Return a sorted list from a generator"""
@@ -236,16 +235,18 @@ 

  

  @sortify

  def get_doc_files(path):

-     matcher = re.compile(

-         r"(.*\.md|.*\.markdown|.*\.mdown|.*\.mkdn|.*\.rst|.*\.txt|AUTHORS|"

-         r"AUTHORS[\.\-].*|CONTRIBUTORS|CONTRIBUTORS[\.\-].*|README|"

-         r"README[\.\-].*|CHANGELOG|CHANGELOG[\.\-].*|TODO|TODO[\.\-].*)",

-         re.IGNORECASE)

-     matcherex = re.compile(r"CMakeLists\.txt")

+     plus = re.compile(r"""

+         .*\.(?:md|markdown|mdown|mkdn|rst|txt)|AUTHORS|

+         AUTHORS[.-].*|CONTRIBUTORS|CONTRIBUTORS[.-].*|README|

+         README[.-].*|CHANGELOG|CHANGELOG[.-].*|TODO|TODO[.-].*

+         """,

+         re.IGNORECASE | re.VERBOSE)

+     minus = re.compile(r"CMakeLists\.txt|.*\.tpl|.*\.in")

+ 

      for root, dirs, files in os.walk(path, topdown=True):

          dirs[:] = []

          for f in files:

-             if matcher.match(f) and not LICENSES.match(f) and not matcherex.match(f):

+             if plus.fullmatch(f) and not LICENSES.fullmatch(f) and not minus.fullmatch(f):

                  yield os.path.relpath(os.path.join(root, f), path)

  

  def get_package_info(package):
@@ -357,6 +358,8 @@ 

                          help="Store crate in current directory")

      parser.add_argument("-a", "--rpmautospec", action="store_true",

                          help="Use autorelease and autochangelog features")

+     parser.add_argument("--no-rpmautospec", action="store_false",

+                         help="Do not use rpmautospec")

      parser.add_argument("--all-features", action="store_true",

                          help="Activate all available features")

      parser.add_argument("--dynamic-buildrequires", action="store_true",
@@ -436,7 +439,9 @@ 

  

      kwargs["auto_changelog_entry"] = not args.no_auto_changelog_entry

  

-     rpmautospec = args.rpmautospec or detect_rpmautospec(default_target, spec_file)

+     rpmautospec = args.rpmautospec

+     if args.rpmautospec is None:

+         rpmautospec = detect_rpmautospec(default_target, spec_file)

Does this actually take into account the new flag?
I think you need to either actually read the args.no_rpmautospec value somewhere, or make the flag use the same dest (if that works?)

      kwargs["rpmautospec"] = rpmautospec

  

      if args.target in {"fedora", "mageia", "opensuse"}:

no initial comment

assuming I understand your changes correctly:

  • use re.VERBOSE, multiline string, and simplified regex for detecting license files
  • use simplified regex for detecting doc files and exclude common non-doc files (CMakeLists.txt: good catch!)

those two look good to me (well, as good as regular expressions can look...)

for the --no-rpmautospec change, I'll leave an inline comment.

Does this actually take into account the new flag?
I think you need to either actually read the args.no_rpmautospec value somewhere, or make the flag use the same dest (if that works?)

It works. Actually I just copied this from the --no-dynamic-buildrequires option. Seems to be an "undocumented feature" of argparse.

Seems so. I scanned the whole documentation for argparse library but it does not mention this "feature". If it works, it's fine with me :)

Pull-Request has been merged by ignatenkobrain

2 years ago
Metadata