From 78b80cd475d0adf4204fc672aee2cf143983a810 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Mar 23 2024 18:11:07 +0000 Subject: Transfer to Gitlab --- diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 056b20e..0000000 --- a/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.vscode -go2rpm.egg-info/ -dist/ diff --git a/LICENSE b/LICENSE deleted file mode 100644 index ed7ba41..0000000 --- a/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -MIT License - -Copyright (c) 2017 Igor Gnatenko -Copyright (c) 2019 Robert-André Mauchin - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index ed7f464..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -include LICENSE -include go2rpm/templates/* diff --git a/README.md b/README.md index b57812f..70db889 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # go2rpm -Convert Go packages to RPM. +This project has been to transferred to Gitlab: +> https://gitlab.com/fedora/sigs/go/go2rpm diff --git a/go2rpm/__init__.py b/go2rpm/__init__.py deleted file mode 100644 index f84c53b..0000000 --- a/go2rpm/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__version__ = "1.11.0" diff --git a/go2rpm/__main__.py b/go2rpm/__main__.py deleted file mode 100644 index 9bbd7bf..0000000 --- a/go2rpm/__main__.py +++ /dev/null @@ -1,791 +0,0 @@ -import argparse -from datetime import datetime, timezone -import json -import os -import re -import shutil -import subprocess -import sys -import time -from pathlib import Path - -import aiohttp -import asyncio -import git -import jinja2 - -from . import __version__ - -DEFAULT_EDITOR = "vi" -XDG_CACHE_HOME = os.getenv("XDG_CACHE_HOME", os.path.expanduser("~/.cache")) -CACHEDIR = os.path.join(XDG_CACHE_HOME, "go2rpm") -GIT_CACHEDIR = os.path.join(XDG_CACHE_HOME, "go2rpm", "src") -JINJA_ENV = jinja2.Environment( - loader=jinja2.ChoiceLoader( - [ - jinja2.FileSystemLoader(["/"]), - jinja2.PackageLoader("go2rpm", "templates"), - ] - ), - extensions=["jinja2.ext.do"], - trim_blocks=True, - lstrip_blocks=True, -) - - -def detect_packager(): - rpmdev_packager = shutil.which("rpmdev-packager") - if rpmdev_packager is not None: - return subprocess.check_output(rpmdev_packager, universal_newlines=True).strip() - - gitbinary = shutil.which("git") - if gitbinary is not None: - name = subprocess.check_output( - [gitbinary, "config", "user.name"], universal_newlines=True - ).strip() - email = subprocess.check_output( - [gitbinary, "config", "user.email"], universal_newlines=True - ).strip() - return f"{name} <{email}>" - return None - - -def file_mtime(path): - return datetime.fromtimestamp(os.stat(path).st_mtime, timezone.utc).isoformat() - - -@jinja2.pass_environment -def do_customwordwrap( - environment, - s, - width=79, - break_long_words=True, - wrapstring=None, - break_on_hyphens=False, -): - """ - Return a copy of the string passed to the filter wrapped after - ``79`` characters. You can override this default using the first - parameter. If you set the second parameter to `false` Jinja will not - split words apart if they are longer than `width`. By default, the newlines - will be the default newlines for the environment, but this can be changed - using the wrapstring keyword argument. - """ - if not wrapstring: - wrapstring = environment.newline_sequence - import textwrap - - return wrapstring.join( - textwrap.wrap( - s, - width=width, - expand_tabs=False, - replace_whitespace=False, - break_long_words=break_long_words, - break_on_hyphens=break_on_hyphens, - ) - ) - - -# Sanitize a Go import path that can then serve as rpm package name -# Mandatory parameter: a Go import path -def rpmname(goipath, use_new_versioning=True): - # lowercase and end with '/' - goname = goipath.lower() + "/" - # remove eventual protocol prefix - goname = re.sub(r"^http(s?):\/\/", r"", goname) - # remove eventual .git suffix - goname = re.sub(r"\.git\/", r"", goname) - # remove eventual git. prefix - goname = re.sub(r"^git\.", r"", goname) - # remove FQDN root (.com, .org, etc) - # will also remove vanity FQDNs such as "tools" - goname = re.sub(r"^([^/]+)\.([^\./]+)/", r"\g<1>/", goname) - # add golang prefix - goname = "golang-" + goname - # special-case x.y.z number-strings as that’s an exception in our naming - # guidelines - while re.search(r"(\d)\.(\d)", goname): - goname = re.sub(r"(\d)\.(\d)", r"\g<1>:\g<2>", goname) - # replace various separators rpm does not like with - - goname = re.sub(r"[\._/\-\~]+", r"-", goname) - # because of the Azure sdk - goname = re.sub(r"\-for\-go\-", r"-", goname) - # Tokenize along - separators and remove duplicates to avoid - # golang-foo-foo-bar-foo names - result = "" - tokens = {} - tokens["go"] = True - for token in goname.split("-"): - if token not in tokens: - result = result + "-" + token - tokens[token] = True - # reassemble the string, restore x.y.z runs, convert the vx.y.z - # Go convention to x.y.z as prefered in rpm naming - result = re.sub(r"^-", r"", result) - result = re.sub(r"-$", r"", result) - 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[\.\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. - # 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 - - -def has_cmd(git_local_path): - cmd = os.path.isdir(os.path.join(git_local_path, "cmd")) - return cmd - - -def has_other_cmd(git_local_path): - other_cmd = set() - exclude = set( - [ - "cmd", - "vendor", - "example", - "examples", - "_example", - "_examples", - "internal", - "Godeps", - "testdata", - "_testdata", - "tests", - "test", - ] - ) - for root, dirs, files in os.walk(git_local_path, topdown=True): - dirs[:] = [d for d in dirs if d not in exclude] - for file in files: - if file.endswith(".go"): - with open(os.path.join(root, file), "r") as f: - for line in f: - if line.startswith("package main"): - other_cmd.add(os.path.relpath(root, git_local_path)) - break - return list(other_cmd) - - -def detect_license(git_local_path): - licenses = set() - raw_licenses = subprocess.check_output( - ["askalono", "--format", "json", "crawl", git_local_path], - universal_newlines=True, - ) - raw_licenses = to_list(raw_licenses) - for j in raw_licenses: - try: - if not "vendor" in json.loads(j)["path"]: - licenses.add(json.loads(j)["result"]["license"]["name"]) - except KeyError: - pass - return " AND ".join(list(licenses)) - - -def get_license_files(git_local_path): - license_files = [] - exclude = set( - [ - "vendor", - "example", - "examples", - "_example", - "_examples", - "internal", - "Godeps", - "testdata", - "_testdata", - ".github", - "tests", - "test", - ] - ) - matcher = re.compile( - r"(COPYING|COPYING[\.\-].*|COPYRIGHT|COPYRIGHT[\.\-].*|" - r"EULA|EULA[\.\-].*|licen[cs]e|licen[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].*)" - ) - for root, dirs, files in os.walk(git_local_path, topdown=True): - dirs[:] = [d for d in dirs if d not in exclude] - for f in files: - if matcher.match(f): - license_files.append( - os.path.relpath(os.path.join(root, f), git_local_path) - ) - return license_files - - -def get_doc_files(git_local_path): - doc_files = [] - include = set(["doc", "docs", "example", "examples", "_example", "_examples"]) - exclude = set( - [ - "vendor", - "doc", - "docs", - "example", - "examples", - "_example", - "_examples", - "internal", - "Godeps", - "testdata", - "_testdata", - ".github", - "tests", - "test", - ".circleci", - ] - ) - matcher = re.compile( - r"(.*\.md|.*\.markdown|.*\.mdown|.*\.mkdn|.*\.rst|.*\.txt|AUTHORS|" - r"AUTHORS[\.\-].*|CONTRIBUTORS|CONTRIBUTORS[\.\-].*|README|" - r"README[\.\-].*|CHANGELOG|CHANGELOG[\.\-].*|TODO|TODO[\.\-].*)", - re.IGNORECASE, - ) - licensesex = re.compile( - r"(COPYING|COPYING[\.\-].*|COPYRIGHT|COPYRIGHT[\.\-].*|EULA|" - r"EULA[\.\-].*|licen[cs]e|licen[cs]e.*|LICEN[CS]E|LICEN[CS]E[\.\-].*|" - r".*[\.\-]LICEN[CS]E.*|NOTICE|NOTICE[\.\-].*|PATENTS|PATENTS[\.\-].*|" - r"UNLICEN[CS]E|UNLICEN[CS]E[\.\-].*|agpl[\.\-].*|gpl[\.\-].*|" - r"lgpl[\.\-].*|AGPL-.*[0-9].*|APACHE-.*[0-9].*|BSD-.*[0-9].*|CC-BY-.*|" - r"GFDL-.*[0-9].*|GNU-.*[0-9].*|GPL-.*[0-9].*|LGPL-.*[0-9].*|" - r"MIT-.*[0-9].*|MPL-.*[0-9].*|OFL-.*[0-9].*|CMakeLists\.txt)" - ) - for root, dirs, files in os.walk(git_local_path, topdown=True): - doc_files = doc_files + [d for d in dirs if d in include] - dirs[:] = [d for d in dirs if d not in exclude] - for f in files: - if matcher.match(f) and not licensesex.match(f): - doc_files.append(os.path.relpath(os.path.join(root, f), git_local_path)) - return doc_files - - -async def get_description(forge): - owner = forge.split("/")[-2] - repo = forge.split("/")[-1] - if "github.com" in forge: - async with aiohttp.ClientSession() as session: - url = f"https://api.github.com/repos/{owner}/{repo}" - async with session.get(url) as resp: - jsonresp = await resp.json() - if "message" in jsonresp: - return None - else: - return normalize_description(jsonresp["description"]) - elif "gitlab.com" in forge: - async with aiohttp.ClientSession() as session: - url = f"https://gitlab.com/api/v4/projects/{owner}%2F{repo}" - async with session.get(url) as resp: - jsonresp = await resp.json() - if "message" in jsonresp: - return None - else: - return normalize_description(jsonresp["description"]) - elif "bitbucket.org" in forge: - async with aiohttp.ClientSession() as session: - url = f"https://api.bitbucket.org/2.0/repositories/{owner}/{repo}" - async with session.get(url) as resp: - jsonresp = await resp.json() - if "error" in jsonresp: - return None - else: - return normalize_description(jsonresp["description"]) - elif "pagure.io" in forge: - repo = "/".join(forge.split("/")[3:]) - async with aiohttp.ClientSession() as session: - url = f"https://pagure.io/api/0/{repo}" - async with session.get(url) as resp: - jsonresp = await resp.json() - if "error" in jsonresp: - return None - else: - return normalize_description(jsonresp["description"]) - elif "gitea.com" in forge: - async with aiohttp.ClientSession() as session: - url = f"https://gitea.com/api/v1/repos/{owner}/{repo}" - async with session.get(url) as resp: - jsonresp = await resp.json() - if "error" in jsonresp: - return None - else: - return normalize_description(jsonresp["description"]) - else: - return None - - -def normalize_description(description): - if description is not None: - description = description.strip() - else: - return description - if description != "": - description = description[:1].upper() + description[1:] - else: - return None - if not re.search(r"(\.|!)$", description): - description = description + "." - return description - - -def get_repo_name(forge): - url = forge.split("/") - return url[2:] - - -def get_subdirectory(subdir): - if subdir and not subdir.startswith("/"): - subdir = "/" + subdir - if subdir: - url = subdir.split("/") - else: - url = "" - return url - - -def get_repo_host(forge): - url = forge.split("/") - return url[0:3] - - -def download(forge): - # shutil.rmtree(os.path.join(GIT_CACHEDIR, *get_repo_name(forge)), ignore_errors=True) - git_local_path = os.path.join(GIT_CACHEDIR, *get_repo_name(forge)) - try: - repo = git.Repo.clone_from(forge, git_local_path) - repo.head.reference = repo.heads[0] - repo.head.reset(index=True, working_tree=True) - except git.GitCommandError as err: - if "is not an empty directory" in err.stderr: - try: - repo = git.Repo(git_local_path) - repo.remotes[0].fetch() - repo.git.checkout(repo.heads[0]) - repo.git.clean("-xdf") - repo.git.reset(repo.remotes[0].refs[0], "--hard") - except git.GitCommandError as err: - print(f"ERROR: Unable to 'git pull {forge}':") - print(err.stderr) - print(f"Try deleting the cache with the -C flag.") - sys.exit(1) - else: - print(f"ERROR: Unable to 'git clone {forge}':") - print(err.stderr) - sys.exit(1) - - -def get_version(git_local_path): - repo = git.Repo(git_local_path) - tags = sorted(repo.tags, key=lambda t: t.commit.committed_datetime) - if not len(tags): - commit = str(repo.heads[0].commit) - version = None - tag = None - else: - latest = str(tags[-1]) - if latest.startswith("v"): - version = latest[1:] - tag = None - else: - version = None - tag = latest - tag_date = datetime.now(timezone.utc) - tags[-1].commit.committed_datetime - if ( - tag_date.days > 365 - and repo.heads[0].commit.count() - tags[-1].commit.count() > 14 - ): - commit = str(repo.heads[0].commit) - else: - commit = None - return version, tag, commit - - -def check_if_version_exists(git_local_path, version, tag, commit): - repo = git.Repo(git_local_path) - repo.remotes[0].fetch() - repo.git.checkout(repo.heads[0]) - repo.git.clean("-xdf") - repo.git.reset(repo.remotes[0].refs[0], "--hard") - if commit: - try: - repo.git.checkout(commit) - except git.GitCommandError: - return False - elif version: - try: - repo.git.checkout("v" + version) - except git.GitCommandError: - return False - elif tag: - try: - repo.git.checkout(tag) - except git.GitCommandError: - return False - return True - - -def set_repo_version(git_local_path, version, tag, commit): - repo = git.Repo(git_local_path) - repo.remotes[0].fetch() - repo.git.checkout(repo.heads[0]) - repo.git.clean("-xdf") - repo.git.reset(repo.remotes[0].refs[0], "--hard") - if commit: - repo.git.checkout(commit) - elif version: - repo.git.checkout("v" + version) - elif tag: - repo.git.checkout(tag) - - -def get_buildrequires(forge, subdir): - os.environ["GOPATH"] = CACHEDIR - os.environ["GO111MODULE"] = "off" - buildrequires = subprocess.check_output( - [ - "golist", - "--imported", - "--skip-self", - "--package-path", - "/".join(get_repo_name(forge)) + subdir, - ], - universal_newlines=True, - ) - return buildrequires - - -def get_test_buildrequires(forge, subdir): - os.environ["GOPATH"] = CACHEDIR - os.environ["GO111MODULE"] = "off" - test_buildrequires = subprocess.check_output( - [ - "golist", - "--imported", - "--tests", - "--skip-self", - "--package-path", - "/".join(get_repo_name(forge)) + subdir, - ], - universal_newlines=True, - ) - return test_buildrequires - - -def to_list(s): - if not s: - return [] - return list(filter(None, (l.strip() for l in s.splitlines()))) - - -def main(): - parser = argparse.ArgumentParser( - "go2rpm", formatter_class=argparse.RawTextHelpFormatter - ) - changelog_group = parser.add_mutually_exclusive_group() - changelog_group.add_argument( - "-r", - "--rpmautospec", - action="store_true", - default=True, - help="Use autorelease and autochangelog features", - ) - changelog_group.add_argument( - "-n", - "--no-rpmautospec", - action="store_false", - dest="rpmautospec", - help="Use static release and changelog instead of rpmautospec.", - ) - parser.add_argument( - "--no-auto-changelog-entry", - 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" - ) - parser.add_argument( - "-p", - "--profile", - action="store", - nargs="?", - type=int, - choices=[1, 2], - default=2, - help="Profile of macros to use. \ - 1: legacy macros. 2: current macros. \ - default: 2", - ) - parser.add_argument( - "-q", - "--no-spec-warnings", - dest="spec_warnings", - action="store_false", - help="Exclude warning comments from generated specfile.\n" - "Currently, this only removes the %%gometa -f explanatory comment.", - ) - parser.add_argument("-f", "--forge", action="store", nargs="?", help="Forge URL") - parser.add_argument( - "-s", - "--subdir", - action="store", - nargs="?", - default=None, - help="Git subdirectory to specifically package", - ) - parser.add_argument( - "-a", - "--altipaths", - action="store", - nargs="+", - help="List of alternate import paths", - ) - parser.add_argument( - "-v", "--version", action="store", nargs="?", help="Package version" - ) - parser.add_argument("-t", "--tag", action="store", nargs="?", help="Package tag") - parser.add_argument( - "-c", "--commit", action="store", nargs="?", help="Package commit" - ) - dynamic_br_group = parser.add_mutually_exclusive_group() - dynamic_br_group.add_argument( - "--dynamic-buildrequires", - action="store_true", - help="Use dynamic BuildRequires feature", - ) - dynamic_br_group.add_argument( - "-R", - "--no-dynamic-buildrequires", - action="store_true", - help="Do not use dynamic BuildRequires feature", - ) - parser.add_argument( - "-C", - "--clean", - action="store_true", - default=True, - help="Clean cache for chosen Go import path", - ) - parser.add_argument( - "--clean-all", action="store_true", help="Clean all cached Go imports" - ) - parser.add_argument( - "-d", - "--create-directory", - action="store_true", - help="Save the final specfile output to NAME/NAME.spec", - ) - parser.add_argument( - "--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", - "gitlab.com", - "bitbucket.org", - "pagure.io", - "gitea.com", - ) - known_forge_re = r"^(" + r"|".join(re.escape(url) for url in known_forge) + r")" - if not re.search(known_forge_re, goipath) and args.forge is None: - print( - f"The forge provided is not known by go-rpm-macros. You will have to provide the source and archive parameters manually." - ) - - if args.forge is None: - forge = "https://" + goipath - else: - if not args.forge.startswith("http"): - args.forge = "https://" + args.forge - forge = args.forge.strip("/") - - git_local_path = os.path.join(GIT_CACHEDIR, *get_repo_name(forge)) - - # Clean any existing repos, if requested. - if args.clean_all: - shutil.rmtree(GIT_CACHEDIR, ignore_errors=True) - elif args.clean: - shutil.rmtree(git_local_path, ignore_errors=True) - - # Download the repo - download(forge) - - # Sort out the versions - if args.version is not None or args.tag is not None or args.commit is not None: - if not check_if_version_exists( - git_local_path, args.version, args.tag, args.commit - ): - version, tag, commit = get_version(git_local_path) - else: - version, tag, commit = args.version, args.tag, args.commit - else: - version, tag, commit = get_version(git_local_path) - - # Prepare the repo - set_repo_version(git_local_path, version, tag, commit) - - if args.no_dynamic_buildrequires: - # Get BuildRequires and filter them out of test BuildRequires - buildrequires = to_list(get_buildrequires(forge, subdir)) - buildrequires = [ipath for ipath in buildrequires if goipath not in ipath] - test_buildrequires = list( - set(to_list(get_test_buildrequires(forge, subdir))).difference( - set(buildrequires) - ) - ) - test_buildrequires = [ - ipath for ipath in test_buildrequires if goipath not in ipath - ] - else: - args.dynamic_buildrequires = True - buildrequires = [] - test_buildrequires = [] - - description = asyncio.run(get_description(forge)) - if description is not None: - summary = description[:-1] - else: - summary = None - - license_files = get_license_files(git_local_path) - doc_files = get_doc_files(git_local_path) - - cmd = has_cmd(git_local_path) - other_cmd = has_other_cmd(git_local_path) - if "." in other_cmd: - main_cmd = get_repo_name(forge)[-1] - other_cmd.remove(".") - else: - main_cmd = None - - JINJA_ENV.filters["customwordwrap"] = do_customwordwrap - if args.profile == 1: - template = JINJA_ENV.get_template("profile1.spec") - elif args.profile == 2: - template = JINJA_ENV.get_template("profile2.spec") - - kwargs = {} - kwargs["generator_version"] = __version__ - kwargs["goipath"] = goipath - kwargs["goname"] = args.name - kwargs["name"] = name - kwargs["forge"] = forge - kwargs["subdir"] = subdir - kwargs["altipaths"] = args.altipaths - - kwargs["version"] = version - kwargs["tag"] = tag - kwargs["commit"] = commit - - kwargs["description"] = description - kwargs["summary"] = summary - - kwargs["license_files"] = license_files - kwargs["doc_files"] = doc_files - - kwargs["buildrequires"] = buildrequires - kwargs["test_buildrequires"] = test_buildrequires - kwargs["generate_buildrequires"] = args.dynamic_buildrequires - - kwargs["has_cmd"] = cmd - kwargs["main_cmd"] = main_cmd - kwargs["other_cmd"] = other_cmd - - 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: - kwargs["auto_changelog_entry"] = True - - if version is None and tag is None: - kwargs["pkg_autorelease"] = "%autorelease -p" - kwargs["pkg_release"] = "0.1" - else: - kwargs["pkg_autorelease"] = "%autorelease" - kwargs["pkg_release"] = "1" - - kwargs["date"] = time.strftime("%a %b %d %Y") - kwargs["shortdate"] = time.strftime("%Y%m%d") - if commit is not None: - kwargs["shortcommit"] = commit[:7] - kwargs["packager"] = detect_packager() - - licenses = detect_license(git_local_path) - if licenses != "": - kwargs["licenses"] = licenses - - output_dir = Path(name) if args.create_directory else Path(".") - output_dir.mkdir(exist_ok=True) - spec_file = output_dir / f"{name}.spec" - spec_contents = template.render(**kwargs) - if args.stdout: - print(f"# {spec_file}") - print(spec_contents) - else: - with open(spec_file, "w") as fobj: - fobj.write(spec_contents) - print(spec_file) - - -if __name__ == "__main__": - main() diff --git a/go2rpm/templates/profile1.spec b/go2rpm/templates/profile1.spec deleted file mode 100644 index 7d6c615..0000000 --- a/go2rpm/templates/profile1.spec +++ /dev/null @@ -1,186 +0,0 @@ -# Generated by go2rpm {{ generator_version }} -%bcond_without check -{% if not has_cmd and main_cmd is none and other_cmd|length == 0 and generate_buildrequires %} -%global debug_package %{nil} -{% endif %} - -# {{ forge }} -%global goipath {{ goipath }} -{% if not 'github.com' in goipath %} -%global forgeurl {{ forge }} -{% endif %} -{% if altipaths is not none %} -{% for altipath in altipaths %} -%global altipath{{ loop.index }} {{ altipath }} -%global altname{{ loop.index }} %gorpmname %{altipath{{ loop.index }}} -{% endfor %} -{% endif %} -{% if version is not none %} -Version: {{ version }} -{% endif %} -{% if tag is not none %} -Version: {{ tag }} -%global tag {{ tag }} -{% endif %} -{% if commit is not none %} -%global commit {{ commit }} -{% endif %} - -%gometa - -%global common_description %{expand: -{{ description|default("# FIXME", true)|wordwrap(wrapstring="\\\n")|trim }}} - -Name: {{ name }} -{% if version is none and tag is none %} -Version: 0 -{% endif %} -{% if rpmautospec %} -Release: {{ pkg_autorelease }} -{% else %} -Release: {{ pkg_release }}%{?dist} -{% endif %} -Summary: {{ summary|default("# FIXME") }} - -License: {{ licenses|default("# FIXME", true) }} -URL: %{gourl} -Source0: %{gosource} - -{% if not generate_buildrequires %} -{% if buildrequires|length > 0 %} -{% set br = buildrequires|sort %} -{% for req in br %} -BuildRequires: golang({{ req }}) -{% endfor %} - -{% endif %} -{% if test_buildrequires|length > 0 %} -{% set test_br = test_buildrequires|sort %} -%if %{with check} -# Tests -{% for req in test_br %} -BuildRequires: golang({{ req }}) -{% endfor %} -%endif - -{% endif %} -{% endif %} -%description -%{common_description} - -%package devel -Summary: %{summary} -BuildArch: noarch - -%description devel -%{common_description} - -This package contains library source intended for -building other packages which use import path with -%{goipath} prefix. - -{% if altipaths is not none %} -{% for altipath in altipaths %} -%package -n compat-%{altname{{ loop.index }}}-devel -Summary: %{summary} -BuildArch: noarch - -%description -n compat-%{altname{{ loop.index }}}-devel -%{common_description} - -This package contains compatibility glue for code that still imports the -%{altipath{{ loop.index }}} Go namespace. - -{% endfor %} -{% endif %} -%prep -%forgeautosetup -p1 - -{% if generate_buildrequires %} -%generate_buildrequires -%go_generate_buildrequires - -{% endif -%} -{% if has_cmd or main_cmd is not none or other_cmd|length > 0 %} -%build -%gobuildroot -{% if has_cmd %} -for cmd in cmd/* ; do - %gobuild -o _bin/$(basename $cmd) %{goipath}/$cmd -done -{% endif %} -{% if main_cmd is not none %} -%gobuild -o _bin/{{ main_cmd }} %{goipath} -{% endif %} -{% if other_cmd|length > 0 %} -for cmd in {{ other_cmd|join(' ') }}; do - %gobuild -o _bin/$(basename $cmd) %{goipath}/$cmd -done -{% endif %} - -{% endif %} -%install -%goinstall -{% if has_cmd or main_cmd is not none or other_cmd|length > 0 %} -install -m 0755 -vd %{buildroot}%{_bindir} -install -m 0755 -vp _bin/* %{buildroot}%{_bindir}/ -{% endif %} - -{% if altipaths is not none %} -{% for altipath in altipaths %} -install -m 0755 -vd %{buildroot}%{gopath}/src/%(dirname %{altipath{{ loop.index }}}) -ln -s %{gopath}/src/%{goipath} %{buildroot}%{gopath}/src/%{altipath{{ loop.index }}} -{% endfor %} - -{% endif %} -%if %{with check} -%check -%gochecks -%endif - -{% if has_cmd or main_cmd is not none or other_cmd|length > 0 %} -%files -{% if license_files|length > 0 %} -%license {{ license_files|join(' ')|wordwrap(width=70, wrapstring="\n%license ")|trim }} -{% endif %} -{% if doc_files|length > 0 %} -%doc {{ doc_files|join(' ')|wordwrap(width=75, wrapstring="\n%doc ")|trim }} -{% endif %} -%{_bindir}/* - -{% endif %} -%files devel -f devel.file-list -{% if license_files|length > 0 %} -%license {{ license_files|join(' ')|customwordwrap(width=70, wrapstring="\n%license ", break_long_words=False, break_on_hyphens=False)|trim }} -{% endif %} -{% if doc_files|length > 0 %} -%doc {{ doc_files|join(' ')|customwordwrap(width=75, wrapstring="\n%doc ", break_long_words=False, break_on_hyphens=False)|trim }} -{% endif %} - -{% if altipaths is not none %} -{% for altipath in altipaths %} -%files -n compat-%{altname{{ loop.index }}}-devel -%dir %{gopath}/src/%(dirname %{altipath{{ loop.index }}}) -%{gopath}/src/%{altipath{{ loop.index }}} - -{% endfor %} -{% endif %} -%changelog -{% if rpmautospec %} -%autochangelog -{% else %} -{% if auto_changelog_entry %} -{% if version is none and tag is none and commit is not none %} -* {{ date }} {{ packager|default("go2rpm ") }} - 0-{{ pkg_release }}.{{ shortdate }}git{{ shortcommit }} -{% elif version is none and tag is not none and commit is none %} -* {{ date }} {{ packager|default("go2rpm ") }} - {{ tag }}-{{ pkg_release }} -{% elif version is none and tag is not none and commit is not none %} -* {{ date }} {{ packager|default("go2rpm ") }} - {{ tag }}-{{ pkg_release }}.{{ shortdate }}git{{ shortcommit }} -{% elif version is not none and tag is none and commit is none %} -* {{ date }} {{ packager|default("go2rpm ") }} - {{ version }}-{{ pkg_release }} -{% elif version is not none and tag is none and commit is not none %} -* {{ date }} {{ packager|default("go2rpm ") }} - {{ version }}-{{ pkg_release }}.{{ shortdate }}git{{ shortcommit }} -{% endif %} -- Initial package -{% endif %} -{% endif %} diff --git a/go2rpm/templates/profile2.spec b/go2rpm/templates/profile2.spec deleted file mode 100644 index e81102a..0000000 --- a/go2rpm/templates/profile2.spec +++ /dev/null @@ -1,162 +0,0 @@ -# Generated by go2rpm {{ generator_version }} -%bcond_without check -{% if not has_cmd and main_cmd is none and other_cmd|length == 0 and generate_buildrequires %} -%global debug_package %{nil} -{% endif %} - -# {{ forge }} -%global goipath {{ goipath }} -{% if not 'github.com' in goipath %} -%global forgeurl {{ forge }} -{% endif %} -{% if version is not none %} -Version: {{ version }} -{% endif %} -{% if tag is not none %} -Version: {{ tag }} -%global tag {{ tag }} -{% endif %} -{% if commit is not none %} -%global commit {{ commit }} -{% endif %} - -{% if spec_warnings %} -# REMOVE BEFORE SUBMITTING THIS FOR REVIEW -# --- -# New Fedora packages should use %%gometa -f, which makes the package -# ExclusiveArch to %%golang_arches_future and thus excludes the package from -# %%ix86. If the new package is needed as a dependency for another package, -# please consider removing that package from %%ix86 in the same way, instead of -# building more go packages for i686. If your package is not a leaf package, -# you'll need to coordinate the removal of the package's dependents first. -# --- -# REMOVE BEFORE SUBMITTING THIS FOR REVIEW -{% endif %} -{% if use_new_versioning %} -%gometa -L -f -{% else %} -%gometa -f -{% endif %} - -{% if altipaths is not none %} -%global goaltipaths {{ altipaths|join(' ') }} - -{% endif %} -%global common_description %{expand: -{{ description|default("# FIXME", true)|wordwrap(wrapstring="\n")|trim }}} - -{% if license_files|length > 0 %} -%global golicenses {{ license_files|join(' ')|wordwrap(width=53, wrapstring="\\\\\\\n ")|trim }} -{% endif %} -{% if doc_files|length > 0 %} -%global godocs {{ doc_files|join(' ')|wordwrap(width=53, wrapstring="\\\\\\\n ")|trim }} - -{% endif %} -Name: {{ name }} -{% if version is none and tag is none %} -Version: 0 -{% endif %} -{% if rpmautospec %} -Release: {{ pkg_autorelease }} -{% else %} -Release: {{ pkg_release }}%{?dist} -{% endif %} -Summary: {{ summary|default("# FIXME") }} - -License: {{ licenses|default("# FIXME", true) }} -URL: %{gourl} -Source: %{gosource} - -{% if not generate_buildrequires %} -{% if buildrequires|length > 0 %} -{% set br = buildrequires|sort %} -{% for req in br %} -BuildRequires: golang({{ req }}) -{% endfor %} - -{% endif %} -{% if test_buildrequires|length > 0 %} -{% set test_br = test_buildrequires|sort %} -%if %{with check} -# Tests -{% for req in test_br %} -BuildRequires: golang({{ req }}) -{% endfor %} -%endif - -{% endif %} -{% endif %} -%description %{common_description} - -%gopkg - -%prep -%goprep -A -%autopatch -p1 - -{% if generate_buildrequires %} -%generate_buildrequires -%go_generate_buildrequires - -{% endif -%} -{% if has_cmd or main_cmd is not none or other_cmd|length > 0 %} -%build -{% if has_cmd %} -for cmd in cmd/* ; do - %gobuild -o %{gobuilddir}/bin/$(basename $cmd) %{goipath}/$cmd -done -{% endif %} -{% if main_cmd is not none %} -%gobuild -o %{gobuilddir}/bin/{{ main_cmd }} %{goipath} -{% endif %} -{% if other_cmd|length > 0 %} -for cmd in {{ other_cmd|join(' ') }}; do - %gobuild -o %{gobuilddir}/bin/$(basename $cmd) %{goipath}/$cmd -done -{% endif %} - -{% endif %} -%install -%gopkginstall -{% if has_cmd or main_cmd is not none or other_cmd|length > 0 %} -install -m 0755 -vd %{buildroot}%{_bindir} -install -m 0755 -vp %{gobuilddir}/bin/* %{buildroot}%{_bindir}/ -{% endif %} - -%if %{with check} -%check -%gocheck -%endif - -{% if has_cmd or main_cmd is not none or other_cmd|length > 0 %} -%files -{% if license_files|length > 0 %} -%license {{ license_files|join(' ')|customwordwrap(width=70, wrapstring="\n%license ", break_long_words=False, break_on_hyphens=False)|trim }} -{% endif %} -{% if doc_files|length > 0 %} -%doc {{ doc_files|join(' ')|customwordwrap(width=75, wrapstring="\n%doc ", break_long_words=False, break_on_hyphens=False)|trim }} -{% endif %} -%{_bindir}/* - -{% endif %} -%gopkgfiles - -%changelog -{% if rpmautospec %} -%autochangelog -{% else %} -{% if auto_changelog_entry %} -{% if version is none and tag is none and commit is not none %} -* {{ date }} {{ packager|default("go2rpm ") }} - 0-{{ pkg_release }}.{{ shortdate }}git{{ shortcommit }} -{% elif version is none and tag is not none and commit is none %} -* {{ date }} {{ packager|default("go2rpm ") }} - {{ tag }}-{{ pkg_release }} -{% elif version is none and tag is not none and commit is not none %} -* {{ date }} {{ packager|default("go2rpm ") }} - {{ tag }}-{{ pkg_release }}.{{ shortdate }}git{{ shortcommit }} -{% elif version is not none and tag is none and commit is none %} -* {{ date }} {{ packager|default("go2rpm ") }} - {{ version }}-{{ pkg_release }} -{% elif version is not none and tag is none and commit is not none %} -* {{ date }} {{ packager|default("go2rpm ") }} - {{ version }}-{{ pkg_release }}.{{ shortdate }}git{{ shortcommit }} -{% endif %} -- Initial package -{% endif %} -{% endif %} diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index e846c40..0000000 --- a/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -aiohttp -asyncio -gitpython -jinja2 diff --git a/setup.py b/setup.py deleted file mode 100644 index 4880ef3..0000000 --- a/setup.py +++ /dev/null @@ -1,60 +0,0 @@ -# -*- coding: utf-8 -*- -from pathlib import Path - -from setuptools import setup - - -def read_version(path): - with open(path, "rt") as f: - for line in f: - if line.startswith("__version__"): - return line.split('"')[1] - raise IOError - - -version = read_version("go2rpm/__init__.py") - -ARGS = dict( - name="go2rpm", - version=version, - description="Convert Go packages to RPM", - long_description=Path("README.md").read_text(encoding="utf-8"), - long_description_content_type="text/markdown", - license="MIT", - keywords="go golang rpm", - packages=["go2rpm"], - package_data={ - "go2rpm": [ - "templates/*.spec", - "templates/*.spec.inc", - ], - }, - entry_points={ - "console_scripts": ["go2rpm = go2rpm.__main__:main"], - }, - install_requires=[ - # CLI tool - "aiohttp", - "gitpython", - "jinja2", - ], - author="Robert-André Mauchin", - author_email="zebob.m@gmail.com", - url="https://pagure.io/GoSIG/go2rpm", - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Developers", - "License :: OSI Approved :: MIT License", - "Operating System :: POSIX :: Linux", - "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Topic :: Software Development :: Build Tools", - "Topic :: System :: Software Distribution", - "Topic :: Utilities", - ], -) - -if __name__ == "__main__": - setup(**ARGS)