From 8b6977dbeca1a7e54921bfe08136520a039b279f Mon Sep 17 00:00:00 2001 From: Robert-André Mauchin Date: Oct 28 2023 06:53:48 +0000 Subject: Fix goname generation to match versioning guildelines 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, --- diff --git a/go2rpm/__init__.py b/go2rpm/__init__.py index 0a0a43a..fcfdf38 100644 --- a/go2rpm/__init__.py +++ b/go2rpm/__init__.py @@ -1 +1 @@ -__version__ = "1.9.0" +__version__ = "1.10.0" diff --git a/go2rpm/__main__.py b/go2rpm/__main__.py index 332db23..3878d53 100644 --- a/go2rpm/__main__.py +++ b/go2rpm/__main__.py @@ -89,7 +89,7 @@ def do_customwordwrap( # 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 @@ def rpmname(goipath): # 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 @@ def main(): 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 @@ def main(): 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 @@ def main(): 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 @@ def main(): 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: diff --git a/go2rpm/templates/profile1.spec b/go2rpm/templates/profile1.spec index 249fbca..7d6c615 100644 --- a/go2rpm/templates/profile1.spec +++ b/go2rpm/templates/profile1.spec @@ -31,7 +31,7 @@ Version: {{ tag }} %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 %} diff --git a/go2rpm/templates/profile2.spec b/go2rpm/templates/profile2.spec index ca0c1cc..1dce456 100644 --- a/go2rpm/templates/profile2.spec +++ b/go2rpm/templates/profile2.spec @@ -32,7 +32,11 @@ Version: {{ tag }} # --- # 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 @@ Version: {{ tag }} %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 %} diff --git a/setup.py b/setup.py index fff7854..355a290 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ def read_version(path): with open(path, "rt") as f: for line in f: if line.startswith("__version__"): - return line.split("\"")[1] + return line.split('"')[1] raise IOError