#31 Fix goname generation to match versioning guildelines
Merged 2 years ago by eclipseo. Opened 2 years ago by eclipseo.
GoSIG/ eclipseo/go2rpm alt_fix_goname  into  master

file modified
+1 -1
@@ -1,1 +1,1 @@ 

- __version__ = "1.9.0"

+ __version__ = "1.10.0"

file modified
+36 -2
@@ -89,7 +89,7 @@ 

  

  # Sanitize a Go import path that can then serve as rpm package name

  # Mandatory parameter: a Go import path

- def rpmname(goipath):

+ def rpmname(goipath, use_new_versioning=True):

      # lowercase and end with '/'

      goname = goipath.lower() + "/"

      # remove eventual protocol prefix
@@ -129,6 +129,20 @@ 

      # numbers on top of it, keep a - prefix before version strings

      result = re.sub(r"\-v([\.\d])$", r"-\g<1>", result)

      result = re.sub(r"\-v([\.\d]\-)", r"-\g<1>", result)

+     # according to the guidelines, if the base package name does not end with

+     # a digit, the version MUST be directly appended to the package name with

+     # no intervening separator.

+     # If the base package name ends with a digit, a single underscore (_) MUST

+     # be appended to the name, and the version MUST be appended to that, in

+     # order to avoid confusion over where the name ends and the version begins.

+     if use_new_versioning:

+         result = re.sub(

+             r"([^-]*)(-?)([\.0-9]+)$",

+             lambda m: f"{m.group(1)}_{m.group(3)}"

+             if re.search(r"\d$", m.group(1))

+             else f"{m.group(1)}{m.group(3)}",

+             result,

+         )

      return result

  

  
@@ -507,6 +521,24 @@ 

          action="store_true",

          help="Do not generate a changelog entry",

      )

+     versioning_group = parser.add_mutually_exclusive_group()

+     versioning_group.add_argument(

+         "-L",

+         "--use-new-versioning",

+         action="store_true",

+         default=True,

+         help="Enable new naming scheme for versioned compat packages that\n"

+         "respect Fedora Packaging Guidelines.\n"

+         "All new go packages should use this option.",

+     )

+     versioning_group.add_argument(

+         "--no-use-new-versioning",

+         action="store_false",

+         dest="use_new_versioning",

+         help="Use older naming scheme for versioned compat packages.\n"

+         "This does not respect Fedora Packaging Guidelines and\n"

+         "should not be used for new packages.",

+     )

      parser.add_argument(

          "-", "--stdout", action="store_true", help="Print spec into stdout"

      )
@@ -667,7 +699,7 @@ 

      if args.name:

          name = args.name

      else:

-         name = rpmname(goipath + subdir)

+         name = rpmname(goipath + subdir, args.use_new_versioning)

      cmd = has_cmd(git_local_path)

      other_cmd = has_other_cmd(git_local_path)

      if "." in other_cmd:
@@ -686,6 +718,7 @@ 

      kwargs["generator_version"] = __version__

      kwargs["goipath"] = goipath

      kwargs["goname"] = args.name

+     kwargs["name"] = name

      kwargs["forge"] = forge

      kwargs["subdir"] = subdir

      kwargs["altipaths"] = args.altipaths
@@ -710,6 +743,7 @@ 

  

      kwargs["rpmautospec"] = args.rpmautospec

      kwargs["spec_warnings"] = args.spec_warnings

+     kwargs["use_new_versioning"] = args.use_new_versioning

      if args.no_auto_changelog_entry:

          kwargs["auto_changelog_entry"] = False

      else:

@@ -31,7 +31,7 @@ 

  %global common_description %{expand:

  {{ description|default("# FIXME", true)|wordwrap(wrapstring="\\\n")|trim }}}

  

- Name:           %{goname}

+ Name:           {{ name }}

  {% if version is none and tag is none %}

  Version:        0

  {% endif %}

@@ -32,7 +32,11 @@ 

  # ---

  # REMOVE BEFORE SUBMITTING THIS FOR REVIEW

  {% endif %}

+ {% if use_new_versioning %}

+ %gometa -L -f

+ {% else %}

  %gometa -f

+ {% endif %}

  

  {% if goname %}

  %global goname {{ goname }}
@@ -52,7 +56,7 @@ 

  %global godocs          {{ doc_files|join(' ')|wordwrap(width=53, wrapstring="\\\\\\\n                        ")|trim }}

  

  {% endif %}

- Name:           %{goname}

+ Name:           {{ name }}

  {% if version is none and tag is none %}

  Version:        0

  {% endif %}

file modified
+1 -1
@@ -6,7 +6,7 @@ 

      with open(path, "rt") as f:

          for line in f:

              if line.startswith("__version__"):

-                 return line.split("\"")[1]

+                 return line.split('"')[1]

          raise IOError

  

  

We add a flag to use new versioning for new packages, which is enabled by default.
We now hardcode the Name field to the value of goname,

rebased onto b489b1e

2 years ago

rebased onto 59ffa56

2 years ago

rebased onto a288fd3

2 years ago

rebased onto c2fd8c0

2 years ago

rebased onto 564bcf5

2 years ago

rebased onto 52c49b2

2 years ago

([%.0-9]+) should be ([\.0-9]+). It looks like there was a copy-paste error between here and the lua implementation.

I don't think this'll do what you want. As of now, there is no way to disable --use-new-versioning. If you change action="store_true to action=argparse.BooleanOptionalAction, you should get both a --use-new-versioning and a --no-use-new-versioning flag.

rebased onto 7fccc9e

2 years ago

rebased onto 6770c7c

2 years ago

rebased onto 8b6977d

2 years ago

Ok this is reworked with a group (add_mutually_exclusive_group) and I fixed the regex.

Pull-Request has been merged by eclipseo

2 years ago