From 841a4afe0fa8fb1329f50b395bfd5dde719bc5f6 Mon Sep 17 00:00:00 2001 From: Robert-André Mauchin Date: Nov 09 2020 10:41:44 +0000 Subject: Rework source fetching Signed-off-by: Robert-André Mauchin --- diff --git a/go2rpm/__main__.py b/go2rpm/__main__.py index e6adefb..9ef4e4d 100644 --- a/go2rpm/__main__.py +++ b/go2rpm/__main__.py @@ -21,39 +21,49 @@ 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) +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() + 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() + 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() + return datetime.fromtimestamp(os.stat(path).st_mtime, timezone.utc).isoformat() @jinja2.environmentfilter -def do_customwordwrap(environment, s, width=79, break_long_words=True, - wrapstring=None, break_on_hyphens=False): +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 @@ -65,17 +75,24 @@ def do_customwordwrap(environment, s, width=79, break_long_words=True, 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)) + + 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): # lowercase and end with '/' - goname = goipath.lower() + '/' + goname = goipath.lower() + "/" # remove eventual protocol prefix goname = re.sub(r"^http(s?)://", r"", goname) # remove eventual .git suffix @@ -92,7 +109,7 @@ def rpmname(goipath): 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) + 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 @@ -100,7 +117,7 @@ def rpmname(goipath): result = "" tokens = {} tokens["go"] = True - for token in goname.split('-'): + for token in goname.split("-"): if token not in tokens: result = result + "-" + token tokens[token] = True @@ -115,54 +132,75 @@ def rpmname(goipath): return result -def has_cmd(goipath): - path = os.path.join(GIT_CACHEDIR, *get_repo_name(goipath)) - cmd = os.path.isdir(os.path.join(path, 'cmd')) +def has_cmd(git_local_path): + cmd = os.path.isdir(os.path.join(git_local_path, "cmd")) return cmd -def has_other_cmd(goipath): +def has_other_cmd(git_local_path): other_cmd = set() - path = os.path.join(GIT_CACHEDIR, *get_repo_name(goipath)) - exclude = set([ - 'cmd', 'vendor', 'example', 'examples', '_example', '_examples', - 'internal', 'Godeps', 'testdata', '_testdata', 'tests', 'test' - ]) - for root, dirs, files in os.walk(path, topdown=True): + 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, path)) + if line.startswith("package main"): + other_cmd.add(os.path.relpath(root, git_local_path)) break return list(other_cmd) -def detect_license(goipath): - path = os.path.join(GIT_CACHEDIR, *get_repo_name(goipath)) +def detect_license(git_local_path): licenses = set() raw_licenses = subprocess.check_output( - ['askalono', '--format', 'json', 'crawl', path], - universal_newlines=True) + ["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']) + if not "vendor" in json.loads(j)["path"]: + licenses.add(json.loads(j)["result"]["license"]["name"]) except KeyError: pass - return ' and '.join(list(licenses)) + return " and ".join(list(licenses)) -def get_license_files(goipath): +def get_license_files(git_local_path): license_files = [] - path = os.path.join(GIT_CACHEDIR, *get_repo_name(goipath)) - exclude = set([ - 'vendor', 'example', 'examples', '_example', '_examples', 'internal', - 'Godeps', 'testdata', '_testdata', '.github', 'tests', 'test' - ]) + 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|" @@ -171,31 +209,46 @@ def get_license_files(goipath): 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(path, topdown=True): + 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), path)) + os.path.relpath(os.path.join(root, f), git_local_path) + ) return license_files -def get_doc_files(goipath): +def get_doc_files(git_local_path): doc_files = [] - path = os.path.join(GIT_CACHEDIR, *get_repo_name(goipath)) - 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' - ]) + 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) + 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[\.\-].*|" @@ -203,56 +256,57 @@ def get_doc_files(goipath): 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(path, topdown=True): + 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), path)) + 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: + 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}' + url = f"https://api.github.com/repos/{owner}/{repo}" async with session.get(url) as resp: jsonresp = await resp.json() - if 'message' in jsonresp: + if "message" in jsonresp: return None else: - return normalize_description(jsonresp['description']) - elif 'gitlab.com' in forge: + 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}' + 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: + if "message" in jsonresp: return None else: - return normalize_description(jsonresp['description']) - elif 'bitbucket.org' in forge: + 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}' + 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: + if "error" in jsonresp: return None else: - return normalize_description(jsonresp['description']) - elif 'pagure.io' in forge: - repo = '/'.join(forge.split('/')[3:]) + 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}' + url = f"https://pagure.io/api/0/{repo}" async with session.get(url) as resp: jsonresp = await resp.json() - if 'error' in jsonresp: + if "error" in jsonresp: return None else: - return normalize_description(jsonresp['description']) + return normalize_description(jsonresp["description"]) else: return None @@ -262,7 +316,7 @@ def normalize_description(description): description = description.strip() else: return description - if description != '': + if description != "": description = description[:1].upper() + description[1:] else: return None @@ -271,44 +325,54 @@ def normalize_description(description): return description -def get_repo_name(goipath): - url = goipath.split('/') +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(goipath): - url = goipath.split('/') +def get_repo_host(forge): + url = forge.split("/") return url[0:3] -def download(goipath): - os.environ['GOPATH'] = CACHEDIR - os.environ['GO111MODULE'] = "off" +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: - subprocess.check_output(['go', 'get', '-d', goipath], - stderr=subprocess.STDOUT) - except subprocess.CalledProcessError as err: - if b'no Go files in' in err.stdout: + 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: - subprocess.check_output(['go', 'get', '-d', goipath + '/...'], - stderr=subprocess.STDOUT) - except subprocess.CalledProcessError as err: - print(f"ERROR: Unable to 'go get {goipath}':") - print(err.stdout.decode()) + 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 'go get {goipath}':") - print(err.stdout.decode()) + print(f"ERROR: Unable to 'git clone {forge}':") + print(err.stderr) sys.exit(1) - repo = git.Repo(os.path.join(GIT_CACHEDIR, *get_repo_host(goipath))) - repo.remotes[0].fetch() - repo.git.checkout(repo.heads[0]) - repo.git.clean('-xdf') - repo.git.reset(repo.remotes[0].refs[0], '--hard') -def get_version(goipath): - repo = git.Repo(os.path.join(GIT_CACHEDIR, *get_repo_host(goipath))) +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) @@ -316,30 +380,29 @@ def get_version(goipath): tag = None else: latest = str(tags[-1]) - if latest.startswith('v'): + 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): + 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(goipath, version, tag, commit): - path = os.path.join(GIT_CACHEDIR, *get_repo_host(goipath)) - repo = git.Repo(path) +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') + repo.git.clean("-xdf") + repo.git.reset(repo.remotes[0].refs[0], "--hard") if commit: try: repo.git.checkout(commit) @@ -347,7 +410,7 @@ def check_if_version_exists(goipath, version, tag, commit): return False elif version: try: - repo.git.checkout('v' + version) + repo.git.checkout("v" + version) except git.GitCommandError: return False elif tag: @@ -358,40 +421,50 @@ def check_if_version_exists(goipath, version, tag, commit): return True -def set_repo_version(goipath, version, tag, commit): - path = os.path.join(GIT_CACHEDIR, *get_repo_host(goipath)) - repo = git.Repo(path) +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') + 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) + repo.git.checkout("v" + version) elif tag: repo.git.checkout(tag) -def get_buildrequires(goipath): - os.environ['GOPATH'] = CACHEDIR - os.environ['GO111MODULE'] = "off" - buildrequires = subprocess.check_output([ - 'golist', '--imported', '--skip-self', '--package-path', '/'.join( - get_repo_host(goipath)) - ], - universal_newlines=True) +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(goipath): - os.environ['GOPATH'] = CACHEDIR - os.environ['GO111MODULE'] = "off" - test_buildrequires = subprocess.check_output([ - 'golist', '--imported', '--tests', '--skip-self', '--package-path', - '/'.join(get_repo_host(goipath)) - ], - universal_newlines=True) +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 @@ -403,59 +476,65 @@ def to_list(s): def main(): parser = argparse.ArgumentParser( - "go2rpm", formatter_class=argparse.RawTextHelpFormatter) - parser.add_argument("--show-license-map", - action="store_true", - help="Print license mappings and exit") - parser.add_argument("--no-auto-changelog-entry", - action="store_true", - help="Do not generate a changelog entry") - 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: old macros. 2: new macros. \ - default: 2") - parser.add_argument("-f", - "--forge", - action="store", - nargs="?", - help="Forge URL") - 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") - parser.add_argument("-C", - "--clean", - action="store_true", - help="Clean cache for chosen Go import path") - parser.add_argument("--clean-all", - action="store_true", - help="Clean all cached Go imports") + "go2rpm", formatter_class=argparse.RawTextHelpFormatter + ) + parser.add_argument( + "--show-license-map", + action="store_true", + help="Print license mappings and exit", + ) + parser.add_argument( + "--no-auto-changelog-entry", + action="store_true", + help="Do not generate a changelog entry", + ) + 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("-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" + ) + parser.add_argument( + "-C", + "--clean", + action="store_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("goipath", help="Import path") args = parser.parse_args() @@ -464,51 +543,56 @@ def main(): return goipath = re.sub(r"^http(s?)://", r"", args.goipath) - goipath = goipath.strip('/') + goipath = goipath.strip("/") - known_forge = ('github.com', 'gitlab.com', 'bitbucket.org', 'pagure.io') - known_forge_re = (r'^(' + - r'|'.join(re.escape(url) for url in known_forge) + - r')') + known_forge = ("github.com", "gitlab.com", "bitbucket.org", "pagure.io") + 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: - parser.error( - f"forge URL is required for import path other than {known_forge}" - ) + parser.error(f"forge URL is required for import path other than {known_forge}") if args.forge is None: - forge = 'https://' + goipath + forge = "https://" + goipath else: - if not args.forge.startswith('http'): - args.forge = 'https://' + args.forge - forge = args.forge.strip('/') + 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)) + + subdir = "/".join(get_subdirectory(args.subdir)) # Clean any existing repos, if requested. if args.clean_all: shutil.rmtree(GIT_CACHEDIR, ignore_errors=True) elif args.clean: - shutil.rmtree(os.path.join(GIT_CACHEDIR, *get_repo_host(goipath)), - ignore_errors=True) + shutil.rmtree(git_local_path, ignore_errors=True) # Download the repo - download(goipath) + 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(goipath, args.version, args.tag, - args.commit): - version, tag, commit = get_version(goipath) + 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(goipath) + version, tag, commit = get_version(git_local_path) # Prepare the repo - set_repo_version(goipath, version, tag, commit) + set_repo_version(git_local_path, version, tag, commit) - buildrequires = to_list(get_buildrequires(goipath)) + # 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(goipath))).difference( - set(buildrequires))) + set(to_list(get_test_buildrequires(forge, subdir))).difference( + set(buildrequires) + ) + ) + test_buildrequires = [ipath for ipath in test_buildrequires if goipath not in ipath] description = asyncio.run(get_description(forge)) if description is not None: @@ -516,29 +600,30 @@ def main(): else: summary = None - license_files = get_license_files(goipath) - doc_files = get_doc_files(goipath) + license_files = get_license_files(git_local_path) + doc_files = get_doc_files(git_local_path) - name = rpmname(goipath) - cmd = has_cmd(goipath) - other_cmd = has_other_cmd(goipath) - if '.' in other_cmd: + name = rpmname(goipath + subdir) + cmd = has_cmd(git_local_path) + other_cmd = has_other_cmd(git_local_path) + if "." in other_cmd: main_cmd = get_repo_name(goipath)[-1] - other_cmd.remove('.') + other_cmd.remove(".") else: main_cmd = None - JINJA_ENV.globals["to_list"] = to_list 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 = {} kwargs["generator_version"] = __version__ kwargs["goipath"] = goipath + kwargs["goname"] = name kwargs["forge"] = forge + kwargs["subdir"] = subdir kwargs["altipaths"] = args.altipaths kwargs["version"] = version @@ -574,8 +659,8 @@ def main(): kwargs["shortcommit"] = commit[:7] kwargs["packager"] = detect_packager() - licenses = detect_license(goipath) - if licenses != '': + licenses = detect_license(git_local_path) + if licenses != "": license, comments = licensing.translate_license_fedora(licenses) kwargs["licenses"] = licenses kwargs["license"] = license