From aa2bacbad6fae54a2aed36053e2fb44524ec6c88 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Jul 08 2022 07:32:17 +0000 Subject: Simplify handling of package suffix Instead of constructing the package name from "rust-" prefix, the name, and the suffix, let's just do it once. --- diff --git a/rust2rpm/__main__.py b/rust2rpm/__main__.py index d0e7661..3ad7b45 100644 --- a/rust2rpm/__main__.py +++ b/rust2rpm/__main__.py @@ -136,6 +136,10 @@ def remove_on_error(path): os.unlink(path) raise +def package_name_suffixed(name, suffix): + joiner = '_' if suffix and name[-1].isdigit() else '' + return 'rust-' + name + joiner + (suffix or '') + def local_toml(toml, version): if os.path.isdir(toml): doc_files = get_doc_files(toml) @@ -504,21 +508,14 @@ def main(): raise ValueError("No bins and no libs") kwargs["include_devel"] = is_lib - if args.suffix is not None: - if metadata.name[-1].isdigit(): - suffix = f'_{args.suffix}' - else: - suffix = args.suffix - else: - suffix = "" - kwargs["pkg_suffix"] = suffix - spec_file = pathlib.Path(f"rust-{metadata.name}{suffix}.spec") + kwargs["pkg_name"] = pkg_name = package_name_suffixed(metadata.name, args.suffix) + spec_file = pathlib.Path(f"{pkg_name}.spec") if args.target in {"fedora"} and args.existence_check and not os.path.exists(spec_file): # No specfile, so this is probably a new package - package_info = get_package_info(f"rust-{metadata.name}{suffix}") + package_info = get_package_info(pkg_name) if package_info: - print(f"Crate {metadata.name}{suffix} is already packaged in Fedora ({package_info['full_url']}).") + print(f"Crate {pkg_name} is already packaged in Fedora ({package_info['full_url']}).") print("Re-run with --no-existence-check if you still want to convert it.") sys.exit(1) diff --git a/rust2rpm/templates/main.spec b/rust2rpm/templates/main.spec index 897a1d3..ee69224 100644 --- a/rust2rpm/templates/main.spec +++ b/rust2rpm/templates/main.spec @@ -13,7 +13,7 @@ %global real_crate {{ crate }} {% endif %} -Name: rust-%{crate}{{ pkg_suffix }} +Name: {{ pkg_name }} Version: {{ md.version }} Release: {{ pkg_release }} {% if md.description is none %}