diff options
author | Sebastian Dröge <slomo@coaxion.net> | 2020-11-20 18:10:40 +0000 |
---|---|---|
committer | Sebastian Dröge <slomo@coaxion.net> | 2020-11-20 18:10:40 +0000 |
commit | fa8a39c6c65b808a0e65e43227618ad4dafb818b (patch) | |
tree | 078e29d1bee3f13db2b2c121c67067bd83ebb81d /.gitlab-ci | |
parent | a7c0adbe1123b0121f6884172e5aa35ecfd8acd5 (diff) | |
parent | d270b6c3db5f74384c0ea1570cfea5a0ead3e20f (diff) | |
download | glib-fa8a39c6c65b808a0e65e43227618ad4dafb818b.tar.gz |
Merge branch 'py-fixes' into 'master'
Python formatting improvements
See merge request GNOME/glib!1757
Diffstat (limited to '.gitlab-ci')
-rwxr-xr-x | .gitlab-ci/check-todos.py | 62 | ||||
-rwxr-xr-x | .gitlab-ci/meson-junit-report.py | 130 | ||||
-rwxr-xr-x | .gitlab-ci/run-flake8.sh | 5 |
3 files changed, 109 insertions, 88 deletions
diff --git a/.gitlab-ci/check-todos.py b/.gitlab-ci/check-todos.py index 83b3eee7a..915ee2834 100755 --- a/.gitlab-ci/check-todos.py +++ b/.gitlab-ci/check-todos.py @@ -23,18 +23,18 @@ import sys # that’s conventionally used as a way of marking a workaround which needs to # be merged for now, but is to be grepped for and reverted or reworked later. BANNED_KEYWORDS = [ - 'TO' + 'DO', - 'X' + 'XX', - 'W' + 'IP', + "TO" + "DO", + "X" + "XX", + "W" + "IP", ] def main(): parser = argparse.ArgumentParser( - description='Check a range of commits to ensure they don’t contain ' - 'banned keywords.') - parser.add_argument('commits', - help='SHA to diff from, or range of commits to diff') + description="Check a range of commits to ensure they don’t contain " + "banned keywords." + ) + parser.add_argument("commits", help="SHA to diff from, or range of commits to diff") args = parser.parse_args() banned_words_seen = set() @@ -43,47 +43,55 @@ def main(): # Check the log messages for banned words. log_process = subprocess.run( - ['git', 'log', '--no-color', args.commits + '..HEAD'], - stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8', - check=True) - log_lines = log_process.stdout.strip().split('\n') + ["git", "log", "--no-color", args.commits + "..HEAD"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + encoding="utf-8", + check=True, + ) + log_lines = log_process.stdout.strip().split("\n") for line in log_lines: for keyword in BANNED_KEYWORDS: - if re.search('(^|\W+){}(\W+|$)'.format(keyword), line): + if re.search(r"(^|\W+){}(\W+|$)".format(keyword), line): banned_words_seen.add(keyword) seen_in_log = True # Check the diff for banned words. diff_process = subprocess.run( - ['git', 'diff', '-U0', '--no-color', args.commits], - stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8', - check=True) - diff_lines = diff_process.stdout.strip().split('\n') + ["git", "diff", "-U0", "--no-color", args.commits], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + encoding="utf-8", + check=True, + ) + diff_lines = diff_process.stdout.strip().split("\n") for line in diff_lines: - if not line.startswith('+ '): + if not line.startswith("+ "): continue for keyword in BANNED_KEYWORDS: - if re.search('(^|\W+){}(\W+|$)'.format(keyword), line): + if re.search(r"(^|\W+){}(\W+|$)".format(keyword), line): banned_words_seen.add(keyword) seen_in_diff = True if banned_words_seen: if seen_in_log and seen_in_diff: - where = 'commit message and diff' + where = "commit message and diff" elif seen_in_log: - where = 'commit message' + where = "commit message" elif seen_in_diff: - where = 'commit diff' - - print('Saw banned keywords in a {}: {}. ' - 'This indicates the branch is a work in progress and should not ' - 'be merged in its current ' - 'form.'.format(where, ', '.join(banned_words_seen))) + where = "commit diff" + + print( + "Saw banned keywords in a {}: {}. " + "This indicates the branch is a work in progress and should not " + "be merged in its current " + "form.".format(where, ", ".join(banned_words_seen)) + ) sys.exit(1) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/.gitlab-ci/meson-junit-report.py b/.gitlab-ci/meson-junit-report.py index 90939ff6c..1855b4907 100755 --- a/.gitlab-ci/meson-junit-report.py +++ b/.gitlab-ci/meson-junit-report.py @@ -11,105 +11,115 @@ import argparse import datetime import json -import os import sys import xml.etree.ElementTree as ET -aparser = argparse.ArgumentParser(description='Turns a Meson test log into a JUnit report') -aparser.add_argument('--project-name', metavar='NAME', - help='The project name', - default='unknown') -aparser.add_argument('--job-id', metavar='ID', - help='The job ID for the report', - default='Unknown') -aparser.add_argument('--branch', metavar='NAME', - help='Branch of the project being tested', - default='master') -aparser.add_argument('--output', metavar='FILE', - help='The output file, stdout by default', - type=argparse.FileType('w', encoding='UTF-8'), - default=sys.stdout) -aparser.add_argument('infile', metavar='FILE', - help='The input testlog.json, stdin by default', - type=argparse.FileType('r', encoding='UTF-8'), - default=sys.stdin) +aparser = argparse.ArgumentParser( + description="Turns a Meson test log into a JUnit report" +) +aparser.add_argument( + "--project-name", metavar="NAME", help="The project name", default="unknown" +) +aparser.add_argument( + "--job-id", metavar="ID", help="The job ID for the report", default="Unknown" +) +aparser.add_argument( + "--branch", + metavar="NAME", + help="Branch of the project being tested", + default="master", +) +aparser.add_argument( + "--output", + metavar="FILE", + help="The output file, stdout by default", + type=argparse.FileType("w", encoding="UTF-8"), + default=sys.stdout, +) +aparser.add_argument( + "infile", + metavar="FILE", + help="The input testlog.json, stdin by default", + type=argparse.FileType("r", encoding="UTF-8"), + default=sys.stdin, +) args = aparser.parse_args() outfile = args.output -testsuites = ET.Element('testsuites') -testsuites.set('id', '{}/{}'.format(args.job_id, args.branch)) -testsuites.set('package', args.project_name) -testsuites.set('timestamp', datetime.datetime.utcnow().isoformat()) +testsuites = ET.Element("testsuites") +testsuites.set("id", "{}/{}".format(args.job_id, args.branch)) +testsuites.set("package", args.project_name) +testsuites.set("timestamp", datetime.datetime.utcnow().isoformat()) suites = {} for line in args.infile: data = json.loads(line) - (full_suite, unit_name) = data['name'].split(' / ') + (full_suite, unit_name) = data["name"].split(" / ") try: - (project_name, suite_name) = full_suite.split(':') + (project_name, suite_name) = full_suite.split(":") except ValueError: project_name = full_suite suite_name = full_suite - duration = data['duration'] - return_code = data['returncode'] - log = data['stdout'] - log_stderr = data.get('stderr', '') + duration = data["duration"] + return_code = data["returncode"] + log = data["stdout"] + log_stderr = data.get("stderr", "") unit = { - 'suite': suite_name, - 'name': unit_name, - 'duration': duration, - 'returncode': return_code, - 'stdout': log, - 'stderr': log_stderr, + "suite": suite_name, + "name": unit_name, + "duration": duration, + "returncode": return_code, + "stdout": log, + "stderr": log_stderr, } units = suites.setdefault(suite_name, []) units.append(unit) for name, units in suites.items(): - print('Processing suite {} (units: {})'.format(name, len(units))) + print("Processing suite {} (units: {})".format(name, len(units))) def if_failed(unit): - if unit['returncode'] != 0: + if unit["returncode"] != 0: return True return False def if_succeded(unit): - if unit['returncode'] == 0: + if unit["returncode"] == 0: return True return False successes = list(filter(if_succeded, units)) failures = list(filter(if_failed, units)) - print(' - {}: {} pass, {} fail'.format(name, len(successes), len(failures))) + print(" - {}: {} pass, {} fail".format(name, len(successes), len(failures))) - testsuite = ET.SubElement(testsuites, 'testsuite') - testsuite.set('name', '{}/{}'.format(args.project_name, name)) - testsuite.set('tests', str(len(units))) - testsuite.set('errors', str(len(failures))) - testsuite.set('failures', str(len(failures))) + testsuite = ET.SubElement(testsuites, "testsuite") + testsuite.set("name", "{}/{}".format(args.project_name, name)) + testsuite.set("tests", str(len(units))) + testsuite.set("errors", str(len(failures))) + testsuite.set("failures", str(len(failures))) for unit in successes: - testcase = ET.SubElement(testsuite, 'testcase') - testcase.set('classname', '{}/{}'.format(args.project_name, unit['suite'])) - testcase.set('name', unit['name']) - testcase.set('time', str(unit['duration'])) + testcase = ET.SubElement(testsuite, "testcase") + testcase.set("classname", "{}/{}".format(args.project_name, unit["suite"])) + testcase.set("name", unit["name"]) + testcase.set("time", str(unit["duration"])) for unit in failures: - testcase = ET.SubElement(testsuite, 'testcase') - testcase.set('classname', '{}/{}'.format(args.project_name, unit['suite'])) - testcase.set('name', unit['name']) - testcase.set('time', str(unit['duration'])) - - failure = ET.SubElement(testcase, 'failure') - failure.set('classname', '{}/{}'.format(args.project_name, unit['suite'])) - failure.set('name', unit['name']) - failure.set('type', 'error') - failure.text = unit['stdout'] + '\n' + unit['stderr'] - -output = ET.tostring(testsuites, encoding='unicode') + testcase = ET.SubElement(testsuite, "testcase") + testcase.set("classname", "{}/{}".format(args.project_name, unit["suite"])) + testcase.set("name", unit["name"]) + testcase.set("time", str(unit["duration"])) + + failure = ET.SubElement(testcase, "failure") + failure.set("classname", "{}/{}".format(args.project_name, unit["suite"])) + failure.set("name", unit["name"]) + failure.set("type", "error") + failure.text = unit["stdout"] + "\n" + unit["stderr"] + +output = ET.tostring(testsuites, encoding="unicode") outfile.write(output) diff --git a/.gitlab-ci/run-flake8.sh b/.gitlab-ci/run-flake8.sh index 2a7628303..5675a01ef 100755 --- a/.gitlab-ci/run-flake8.sh +++ b/.gitlab-ci/run-flake8.sh @@ -2,5 +2,8 @@ set -e +# Disable formatting warnings in flake8, as we use `black` to handle that. +formatting_warnings=E101,E111,E114,E115,E116,E117,E12,E13,E2,E3,E401,E5,E70,W1,W2,W3,W5 + # shellcheck disable=SC2046 -flake8 --max-line-length=88 $(git ls-files '*.py') +flake8 --max-line-length=88 --ignore="$formatting_warnings" $(git ls-files '*.py') |