From a5cbec27c0a6e0568c5a3542e228df2655acdf69 Mon Sep 17 00:00:00 2001 From: Javier Gonzalez Date: Thu, 17 Nov 2022 11:48:01 -0500 Subject: [PATCH] flake --- actions/build/files/build.py | 18 +++++++---- scripts/github-runner-service.py | 2 +- skare3_tools/dashboard/views/test_log.py | 4 +-- skare3_tools/dashboard/views/test_results.py | 2 +- skare3_tools/github/__init__.py | 4 +-- skare3_tools/github/scripts/add_secrets.py | 6 ++-- .../github/scripts/release_merge_info.py | 2 +- skare3_tools/packages.py | 14 ++++---- skare3_tools/scripts/build.py | 7 ++-- skare3_tools/scripts/bulk.py | 2 +- skare3_tools/scripts/skare3_promote.py | 32 ++++++++++++++++--- skare3_tools/scripts/skare3_release_check.py | 7 ++-- skare3_tools/scripts/skare3_update_summary.py | 4 +-- skare3_tools/scripts/test_results.py | 12 +++---- 14 files changed, 72 insertions(+), 44 deletions(-) diff --git a/actions/build/files/build.py b/actions/build/files/build.py index 8e4b73a..68d7fbf 100755 --- a/actions/build/files/build.py +++ b/actions/build/files/build.py @@ -72,6 +72,8 @@ def overwrite_skare3_version(current_version, new_version, pkg_path): To fix this, I can require that packages are specified as a non-positional argument, but that breaks all current workflows. """ + + def get_parser(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('package', @@ -116,8 +118,8 @@ def main(): condarc_in = condarc.with_suffix('.in') condarc.replace(condarc_in) with open(condarc_in) as condarc_in, open(condarc, 'w') as condarc: - for l in condarc_in.readlines(): - condarc.write(l.replace('${CONDA_PASSWORD}', os.environ['CONDA_PASSWORD'])) + for line in condarc_in.readlines(): + condarc.write(line.replace('${CONDA_PASSWORD}', os.environ['CONDA_PASSWORD'])) else: print('Conda password needs to be given as environmental variable CONDA_PASSWORD') sys.exit(100) @@ -168,10 +170,12 @@ def main(): f.unlink() # report result - files = (list(build_dir.glob('linux-64/*tar.bz2*')) + - list(build_dir.glob('osx-64/*tar.bz2*')) + - list(build_dir.glob('noarch/*tar.bz2*')) + - list(build_dir.glob('win-64/*tar.bz2*'))) + files = ( + list(build_dir.glob('linux-64/*tar.bz2*')) + + list(build_dir.glob('osx-64/*tar.bz2*')) + + list(build_dir.glob('noarch/*tar.bz2*')) + + list(build_dir.glob('win-64/*tar.bz2*')) + ) files = ' '.join([str(f) for f in files]) print(f'Built files: {files}') @@ -179,4 +183,4 @@ def main(): if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/scripts/github-runner-service.py b/scripts/github-runner-service.py index 7a9521c..a4fea60 100755 --- a/scripts/github-runner-service.py +++ b/scripts/github-runner-service.py @@ -20,7 +20,7 @@ def get_pid(runner): if pid is not None: a = subprocess.run(["ps", "-A"], capture_output=True) - ps = [l for l in a.stdout.decode().split("\n") if re.match(f"{pid}\s", l)] + ps = [line for line in a.stdout.decode().split("\n") if re.match(f"{pid}\\s", line)] if not ps: logging.debug(f"process {pid} (runner={runner}) is not running. Resetting.") pid = None diff --git a/skare3_tools/dashboard/views/test_log.py b/skare3_tools/dashboard/views/test_log.py index 8ea5f95..60e7bbb 100644 --- a/skare3_tools/dashboard/views/test_log.py +++ b/skare3_tools/dashboard/views/test_log.py @@ -20,7 +20,7 @@ def html(text): span = { "\x1b[1m": '', "\x1b[4m": '', - #'\x1b[7m': '', # reverse + # '\x1b[7m': '', # reverse "\x1b[30m": '', "\x1b[31m": '', "\x1b[32m": '', @@ -61,7 +61,7 @@ def html(text): result = "" depth = 0 i = 0 - matches = [m for m in re.finditer("\x1b\[[0-9;]+m", text)] + matches = [m for m in re.finditer(r"\x1b\[[0-9;]+m", text)] for m in matches: s, e = m.span() c = text[s:e] diff --git a/skare3_tools/dashboard/views/test_results.py b/skare3_tools/dashboard/views/test_results.py index 746ef27..65c35b6 100755 --- a/skare3_tools/dashboard/views/test_results.py +++ b/skare3_tools/dashboard/views/test_results.py @@ -124,7 +124,7 @@ def main(): if not args.b: file_out = os.path.abspath(args.file_out) - webbrowser.open("file://{file_out}".format(file_out=args.file_out), new=2) + webbrowser.open("file://{file_out}".format(file_out=file_out), new=2) if __name__ == "__main__": diff --git a/skare3_tools/github/__init__.py b/skare3_tools/github/__init__.py index d93eeee..97c01bb 100644 --- a/skare3_tools/github/__init__.py +++ b/skare3_tools/github/__init__.py @@ -8,10 +8,10 @@ >>> from skare3_tools import github >>> github.init(token='c7hvg6pqi3fhqwv0wvlgp4mk9agwbqk1gxc331iz') # this is optional -.. _`authentication token`: https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token +.. _`authentication token`: https://docs.github.com/en/authentication """ from . import github, graphql -from .github import Organization, Repository +from .github import Organization, Repository # noqa GITHUB_API_V3 = github.GITHUB_API GITHUB_API_V4 = graphql.GITHUB_API diff --git a/skare3_tools/github/scripts/add_secrets.py b/skare3_tools/github/scripts/add_secrets.py index 8d232b3..3820822 100755 --- a/skare3_tools/github/scripts/add_secrets.py +++ b/skare3_tools/github/scripts/add_secrets.py @@ -132,9 +132,9 @@ def _get_button(text): def _get_link(text=None, **attributes): links = _driver_.find_elements_by_tag_name("a") if text is not None: - links = [l for l in links if l.text == text] + links = [line for line in links if line.text == text] for att in attributes: - links = [l for l in links if l.get_attribute(att) == attributes[att]] + links = [line for line in links if line.get_attribute(att) == attributes[att]] msg = f"link with attributes={attributes}" if text is not None: msg += f" and text={text}" @@ -183,7 +183,7 @@ def main(): args = the_parser.parse_args() try: - import selenium + import selenium # noqa except ModuleNotFoundError: logging.error( f"The script requires the selenium module. Run `{sys.argv[0]} -h` for help." diff --git a/skare3_tools/github/scripts/release_merge_info.py b/skare3_tools/github/scripts/release_merge_info.py index c0e5e96..2320a73 100755 --- a/skare3_tools/github/scripts/release_merge_info.py +++ b/skare3_tools/github/scripts/release_merge_info.py @@ -64,7 +64,7 @@ def main(): for commit in commits: msg = commit["commit"]["message"] match = re.match( - "Merge pull request (?P.+) from (?P\S+)\n\n(?P.+)", + r"Merge pull request (?P.+) from (?P\S+)\n\n(?P.+)", msg, ) if match: diff --git a/skare3_tools/packages.py b/skare3_tools/packages.py index 022afe3..4727ecb 100755 --- a/skare3_tools/packages.py +++ b/skare3_tools/packages.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -""" +r""" A module to keep track of all package information (repository, conda package info, etc). Package List @@ -93,7 +93,7 @@ class NetworkException(Exception): def json_cache(name, directory="", ignore=None, expires=None, update_policy=None): - """ + r""" Decorator to cache function results in json format. This decorator adds an 'update' argument to decorated functions. update is False by default, @@ -231,9 +231,9 @@ def _conda_package_list(update=True): if "about" in info and "home" in info["about"]: home = info["about"]["home"].strip() matches = [ - re.match("git@github.com:(?P[^/]+)/(?P\S+)\.git$", home), - re.match("git@github.com:(?P[^/]+)/(?P\S+)$", home), - re.match("https?://github.com/(?P[^/]+)/(?P[^/]+)/?", home), + re.match(r"git@github.com:(?P[^/]+)/(?P\S+)\.git$", home), + re.match(r"git@github.com:(?P[^/]+)/(?P\S+)$", home), + re.match(r"https?://github.com/(?P[^/]+)/(?P[^/]+)/?", home), ] m = {} for m in matches: @@ -479,7 +479,7 @@ def _get_repository_info_v4( ) release_info[-1]["commits"].append(commit) match = re.match( - "Merge pull request #(?P.+) from (?P\S+)\n\n(?P.+)", + r"Merge pull request #(?P<pr_number>.+) from (?P<branch>\S+)\n\n(?P<title>.+)", commit["message"], ) if match: @@ -799,7 +799,7 @@ def _get_repository_info_v3( } ) match = re.match( - "Merge pull request #(?P<pr_number>.+) from (?P<branch>\S+)\n\n(?P<title>.+)", + r"Merge pull request #(?P<pr_number>.+) from (?P<branch>\S+)\n\n(?P<title>.+)", commit["commit"]["message"], ) if match: diff --git a/skare3_tools/scripts/build.py b/skare3_tools/scripts/build.py index 8468706..7464040 100755 --- a/skare3_tools/scripts/build.py +++ b/skare3_tools/scripts/build.py @@ -133,7 +133,8 @@ def main(): version_info["label"] = ( f'+{version_info["label"]}' if version_info["label"] else "" ) - args.ska3_overwrite_version = f'{version_info["release"]}{version_info["label"]}:{version_info["version"]}' + args.ska3_overwrite_version = \ + f'{version_info["release"]}{version_info["label"]}:{version_info["version"]}' print("skare3 build args:", args) print("skare3 build unknown args:", unknown_args) @@ -159,9 +160,9 @@ def main(): condarc_in = condarc.with_suffix(".in") condarc.replace(condarc_in) with open(condarc_in) as condarc_in, open(condarc, "w") as condarc: - for l in condarc_in.readlines(): + for line in condarc_in.readlines(): condarc.write( - l.replace("${CONDA_PASSWORD}", os.environ["CONDA_PASSWORD"]) + line.replace("${CONDA_PASSWORD}", os.environ["CONDA_PASSWORD"]) ) else: print( diff --git a/skare3_tools/scripts/bulk.py b/skare3_tools/scripts/bulk.py index 32dd7f2..e89c20d 100755 --- a/skare3_tools/scripts/bulk.py +++ b/skare3_tools/scripts/bulk.py @@ -20,7 +20,7 @@ def parser(): def main(): args, extra = parser().parse_known_args() args.cmd += extra - packages = [l.strip() for l in open(args.repositories).readlines()] + packages = [line.strip() for line in open(args.repositories).readlines()] for package in packages: header = f"\n\n{package}\n{'-'*len(package)}" "" print(header) diff --git a/skare3_tools/scripts/skare3_promote.py b/skare3_tools/scripts/skare3_promote.py index 42539e0..9200398 100755 --- a/skare3_tools/scripts/skare3_promote.py +++ b/skare3_tools/scripts/skare3_promote.py @@ -115,7 +115,8 @@ def promote(package, args, platforms=None): # was not found. if pkgs == []: logging.warning( - f'package {package["name"]}=={package["version"]} not found for platform {platform}.' + f'package {package["name"]}=={package["version"]}' + f' not found for platform {platform}.' ) continue @@ -148,7 +149,8 @@ def promote(package, args, platforms=None): pkg_files += pkgs if not pkgs: logging.warning( - f"package {requirement['name']}=={requirement['version']} was not found" + f"package {requirement['name']}=={requirement['version']}" + " was not found" ) else: logging.error(f'Could not parse requirement: "{requirement}"') @@ -168,7 +170,13 @@ def promote(package, args, platforms=None): name: [p for p in pkg_files if p["name"] == name] for name in package_names } - row = "| {package:30s} | {noarch:24s} {noarch-src:7s} | {linux-64:24s} {linux-64-src:7s} | {osx-64:24s} {osx-64-src:7s} | {win-64:24s} {win-64-src:7s} |" + row = ( + "| {package:30s} " + "| {noarch:24s} {noarch-src:7s} " + "| {linux-64:24s} {linux-64-src:7s} " + "| {osx-64:24s} {osx-64-src:7s} " + "| {win-64:24s} {win-64-src:7s} |" + ) div = {"package": "", "noarch": "", "linux-64": "", "osx-64": "", "win-64": ""} div.update( {k: "" for k in ["noarch-src", "linux-64-src", "osx-64-src", "win-64-src"]} @@ -227,12 +235,26 @@ def promote(package, args, platforms=None): def parser(): - usage = "%(prog)s [-h] [--ska3-conda SKA3_CONDA] [--from FROM_CHANNEL [--from FROM_CHANNEL ...] ] [--to TO_CHANNEL] [--dry-run] [--move] [--skare3-local-copy SKARE3] [--log-level {error,warning,info,debug}] [-v] <package name>==<version> [<package name>==<version> ...]" + usage = ( + "%(prog)s [-h]" + " [--ska3-conda SKA3_CONDA]" + " [--from FROM_CHANNEL [--from FROM_CHANNEL ...] ]" + " [--to TO_CHANNEL]" + " [--dry-run]" + " [--move]" + " [--skare3-local-copy SKARE3]" + " [--log-level {error,warning,info,debug}]" + " [-v]" + " <package name>==<version> [<package name>==<version> ...]" + ) parse = argparse.ArgumentParser(description=__doc__, usage=usage) parse.add_argument("package", nargs="+", metavar="<package name>==<version>") parse.add_argument( "--ska3-conda", - help="ska3-conda directory containing source and target channels (defaults to the standard location)", + help=( + "ska3-conda directory containing source and target channels" + " (defaults to the standard location)" + ), default=SKA3_CONDA, ) parse.add_argument( diff --git a/skare3_tools/scripts/skare3_release_check.py b/skare3_tools/scripts/skare3_release_check.py index 03baa2b..8a69ca7 100644 --- a/skare3_tools/scripts/skare3_release_check.py +++ b/skare3_tools/scripts/skare3_release_check.py @@ -79,8 +79,8 @@ def main(): ] # versions can be git refs like refs/tags/V2 # regular expression (mostly) matching PEP-0440 version format fmt = ( - "(?P<final_version>((?P<epoch>[0-9]+)!)?(?P<release>[0-9]+(.[0-9]+(.[0-9]+)?)?))" - "((a|b|rc)(?P<rc>[0-9]+))?(\+(?P<label>[a-zA-Z]+))?$" + r"(?P<final_version>((?P<epoch>[0-9]+)!)?(?P<release>[0-9]+(.[0-9]+(.[0-9]+)?)?))" + r"((a|b|rc)(?P<rc>[0-9]+))?(\+(?P<label>[a-zA-Z]+))?$" ) version_info = re.match(fmt, tag_name) if not version_info: @@ -198,7 +198,8 @@ def main(): for pkg in possible_error: logging.warning(f" - {pkg}") logging.warning( - f'This can happen if YAML interprets version {version_info["final_version"]} as a float.' + 'This can happen if YAML interprets version' + f' {version_info["final_version"]} as a float.' ) logging.warning("They will not be built.") diff --git a/skare3_tools/scripts/skare3_update_summary.py b/skare3_tools/scripts/skare3_update_summary.py index a293524..9502650 100755 --- a/skare3_tools/scripts/skare3_update_summary.py +++ b/skare3_tools/scripts/skare3_update_summary.py @@ -111,10 +111,10 @@ def repository_change_summary(pkgs_repo_info, initial_versions={}, final_version if version_1 in releases and version_1: releases = releases[ - releases.index(version_2) : releases.index(version_1) + releases.index(version_2): releases.index(version_1) ] else: - releases = releases[releases.index(version_2) :] + releases = releases[releases.index(version_2):] release_info = { _clean_version(r["release_tag"]): r["merges"] for r in p["release_info"] diff --git a/skare3_tools/scripts/test_results.py b/skare3_tools/scripts/test_results.py index fd04ad3..37d03b4 100755 --- a/skare3_tools/scripts/test_results.py +++ b/skare3_tools/scripts/test_results.py @@ -13,19 +13,19 @@ def test_results(directory): filename = os.path.join(directory, "test.log") with open(filename) as f: - for l in f: - if re.match("\*\*\*\s+Package\s+Script\s+Status\s+\*\*\*", l): + for line in f: + if re.match(r"\*\*\*\s+Package\s+Script\s+Status\s+\*\*\*", line): break results = [] - for l in f: - if re.search("fail", l.lower()) or re.search("pass", l.lower()): - results.append(l.split()[1:-1]) + for line in f: + if re.search("fail", line.lower()) or re.search("pass", line.lower()): + results.append(line.split()[1:-1]) result_dict = {k[0]: {"tests": {}} for k in results} for k in results: try: module = importlib.import_module(k[0]) version = module.__version__ - except: + except Exception: version = "" result_dict[k[0]]["tests"][k[1]] = k[2].upper() res = result_dict[k[0]]["tests"].values()