From 7726572917fe7a951718d73dcba052ed60fcf85c Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Feb 12 2024 19:14:10 +0000 Subject: [PATCH 1/2] add --print-name flag to debug rpmname() --- diff --git a/go2rpm/__main__.py b/go2rpm/__main__.py index 3878d53..debfd43 100644 --- a/go2rpm/__main__.py +++ b/go2rpm/__main__.py @@ -617,11 +617,25 @@ def main(): "--name", help="Use name for spec file, useful for binary apps", ) + parser.add_argument( + "--print-name", + action="store_true", + help="Print the generated package name and exit", + ) parser.add_argument("goipath", help="Import path") args = parser.parse_args() + subdir = "/".join(get_subdirectory(args.subdir)) goipath = re.sub(r"^http(s?)://", r"", args.goipath) goipath = goipath.strip("/") + if args.name: + name = args.name + else: + name = rpmname(goipath + subdir, args.use_new_versioning) + + if args.print_name: + print(name) + return known_forge = ( "github.com", @@ -645,8 +659,6 @@ def main(): git_local_path = os.path.join(GIT_CACHEDIR, *get_repo_name(forge)) - subdir = "/".join(get_subdirectory(args.subdir)) - # Clean any existing repos, if requested. if args.clean_all: shutil.rmtree(GIT_CACHEDIR, ignore_errors=True) @@ -696,10 +708,6 @@ def main(): license_files = get_license_files(git_local_path) doc_files = get_doc_files(git_local_path) - if args.name: - name = args.name - else: - 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: From e2e60589be2ecf51b6d72ef48ebaa531a4763866 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Feb 12 2024 19:14:33 +0000 Subject: [PATCH 2/2] rpmname: fix naming of goipaths with multi-character versions ``` $ go2rpm --print-name github.com/AdamSLevy/jsonrpc2/v14 golang-github-adamslevy-jsonrpc2_14 $ rpm -E '%gorpmname -L github.com/AdamSLevy/jsonrpc2/v14' golang-github-adamslevy-jsonrpc2_14 $ go2rpm --print-name --no-use-new-versioning github.com/AdamSLevy/jsonrpc2/v14 golang-github-adamslevy-jsonrpc2-14 $ rpm -E '%gorpmname github.com/AdamSLevy/jsonrpc2/v14' golang-github-adamslevy-jsonrpc2-14 $ go2rpm --print-name github.com/apparentlymart/go-textseg/v15 golang-github-apparentlymart-textseg15 ``` Fixes: https://pagure.io/GoSIG/go2rpm/issue/34 --- diff --git a/go2rpm/__main__.py b/go2rpm/__main__.py index debfd43..9bbd7bf 100644 --- a/go2rpm/__main__.py +++ b/go2rpm/__main__.py @@ -127,8 +127,8 @@ def rpmname(goipath, use_new_versioning=True): result = re.sub(r":", r".", result) # some projects have a name that end up in a number, and *also* add release # 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) + result = re.sub(r"\-v(\d[\.\d]*)$", r"-\g<1>", result) + result = re.sub(r"\-v(\d[\.\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.