From 5c031db2bcd227e9ab6031f51b453208e59f2132 Mon Sep 17 00:00:00 2001 From: Julien Cristau Date: Thu, 7 Sep 2023 13:38:12 +0200 Subject: [PATCH] Bug 1825116 - fix python formatting issues in firefox-android scripts. r=bhearsum,amejiamarmol,geckoview-reviewers,releng-reviewers Generated by `./mach lint -l black --fix taskcluster/android_taskgraph/ taskcluster/scripts/lint/ taskcluster/scripts/write-dummy-secret.py mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/experimentintegration/conftest.py mobile/android/fenix/automation/taskcluster/androidTest/parse-ui-test-fromfile.py mobile/android/focus-android/automation/taskcluster/androidTest/parse-ui-test*` Differential Revision: https://phabricator.services.mozilla.com/D201457 --- .../androidTest/parse-ui-test-fromfile.py | 36 +++++++--- .../androidTest/parse-ui-test-fromfile.py | 36 +++++++--- .../taskcluster/androidTest/parse-ui-test.py | 14 ++-- taskcluster/android_taskgraph/__init__.py | 4 +- .../android_taskgraph/release_promotion.py | 6 +- taskcluster/android_taskgraph/release_type.py | 1 + taskcluster/android_taskgraph/routes.py | 10 ++- taskcluster/android_taskgraph/target_tasks.py | 8 ++- .../transforms/beetmover_android_app.py | 2 +- .../external_gradle_dependencies.py | 72 +++++++++++++------ .../transforms/post_dummy.py | 3 +- .../transforms/push_android_app.py | 1 - .../transforms/signing_android_app.py | 2 +- .../android_taskgraph/util/group_by.py | 4 +- .../lint/is_buildconfig_yml_up_to_date.py | 9 ++- .../lint/update_buildconfig_from_gradle.py | 3 +- taskcluster/scripts/write-dummy-secret.py | 10 ++- 17 files changed, 151 insertions(+), 70 deletions(-) diff --git a/mobile/android/fenix/automation/taskcluster/androidTest/parse-ui-test-fromfile.py b/mobile/android/fenix/automation/taskcluster/androidTest/parse-ui-test-fromfile.py index 72880fc19efb..0c298744e5ae 100644 --- a/mobile/android/fenix/automation/taskcluster/androidTest/parse-ui-test-fromfile.py +++ b/mobile/android/fenix/automation/taskcluster/androidTest/parse-ui-test-fromfile.py @@ -10,10 +10,14 @@ from junitparser import Attr, Failure, JUnitXml, TestSuite def parse_args(cmdln_args): - parser = argparse.ArgumentParser(description="Parse and print UI test JUnit results") + parser = argparse.ArgumentParser( + description="Parse and print UI test JUnit results" + ) parser.add_argument( - "--results", type=Path, - help="Directory containing task artifact results", required=True + "--results", + type=Path, + help="Directory containing task artifact results", + required=True, ) return parser.parse_args(args=cmdln_args) @@ -24,25 +28,35 @@ class test_suite(TestSuite): def parse_print_failure_results(results): table = BeautifulTable(maxwidth=256) - table.columns.header = (['UI Test', 'Outcome', 'Details']) + table.columns.header = ["UI Test", "Outcome", "Details"] table.columns.alignment = BeautifulTable.ALIGN_LEFT table.set_style(BeautifulTable.STYLE_GRID) for suite in results: cur_suite = test_suite.fromelem(suite) - if cur_suite.flakes != '0': + if cur_suite.flakes != "0": for case in suite: for entry in case.result: if case.result: table.rows.append( - ["%s#%s" % (case.classname, case.name), "Flaky", entry.text.replace('\t', ' ')]) + [ + "%s#%s" % (case.classname, case.name), + "Flaky", + entry.text.replace("\t", " "), + ] + ) break else: for case in suite: for entry in case.result: if isinstance(entry, Failure): table.rows.append( - ["%s#%s" % (case.classname, case.name), "Failure", entry.text.replace('\t', ' ')]) + [ + "%s#%s" % (case.classname, case.name), + "Failure", + entry.text.replace("\t", " "), + ] + ) break print(table) @@ -50,11 +64,11 @@ def parse_print_failure_results(results): def load_results_file(filename): ret = None try: - f = open(filename, 'r') + f = open(filename, "r") try: ret = JUnitXml.fromfile(f) except xml.etree.ElementTree.ParseError as e: - print(f'Error parsing {filename} file: {e}') + print(f"Error parsing {filename} file: {e}") finally: f.close() except IOError as e: @@ -66,10 +80,10 @@ def load_results_file(filename): def main(): args = parse_args(sys.argv[1:]) - junitxml = load_results_file(args.results.joinpath('FullJUnitReport.xml')) + junitxml = load_results_file(args.results.joinpath("FullJUnitReport.xml")) if junitxml: parse_print_failure_results(junitxml) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/mobile/android/focus-android/automation/taskcluster/androidTest/parse-ui-test-fromfile.py b/mobile/android/focus-android/automation/taskcluster/androidTest/parse-ui-test-fromfile.py index 72880fc19efb..0c298744e5ae 100644 --- a/mobile/android/focus-android/automation/taskcluster/androidTest/parse-ui-test-fromfile.py +++ b/mobile/android/focus-android/automation/taskcluster/androidTest/parse-ui-test-fromfile.py @@ -10,10 +10,14 @@ from junitparser import Attr, Failure, JUnitXml, TestSuite def parse_args(cmdln_args): - parser = argparse.ArgumentParser(description="Parse and print UI test JUnit results") + parser = argparse.ArgumentParser( + description="Parse and print UI test JUnit results" + ) parser.add_argument( - "--results", type=Path, - help="Directory containing task artifact results", required=True + "--results", + type=Path, + help="Directory containing task artifact results", + required=True, ) return parser.parse_args(args=cmdln_args) @@ -24,25 +28,35 @@ class test_suite(TestSuite): def parse_print_failure_results(results): table = BeautifulTable(maxwidth=256) - table.columns.header = (['UI Test', 'Outcome', 'Details']) + table.columns.header = ["UI Test", "Outcome", "Details"] table.columns.alignment = BeautifulTable.ALIGN_LEFT table.set_style(BeautifulTable.STYLE_GRID) for suite in results: cur_suite = test_suite.fromelem(suite) - if cur_suite.flakes != '0': + if cur_suite.flakes != "0": for case in suite: for entry in case.result: if case.result: table.rows.append( - ["%s#%s" % (case.classname, case.name), "Flaky", entry.text.replace('\t', ' ')]) + [ + "%s#%s" % (case.classname, case.name), + "Flaky", + entry.text.replace("\t", " "), + ] + ) break else: for case in suite: for entry in case.result: if isinstance(entry, Failure): table.rows.append( - ["%s#%s" % (case.classname, case.name), "Failure", entry.text.replace('\t', ' ')]) + [ + "%s#%s" % (case.classname, case.name), + "Failure", + entry.text.replace("\t", " "), + ] + ) break print(table) @@ -50,11 +64,11 @@ def parse_print_failure_results(results): def load_results_file(filename): ret = None try: - f = open(filename, 'r') + f = open(filename, "r") try: ret = JUnitXml.fromfile(f) except xml.etree.ElementTree.ParseError as e: - print(f'Error parsing {filename} file: {e}') + print(f"Error parsing {filename} file: {e}") finally: f.close() except IOError as e: @@ -66,10 +80,10 @@ def load_results_file(filename): def main(): args = parse_args(sys.argv[1:]) - junitxml = load_results_file(args.results.joinpath('FullJUnitReport.xml')) + junitxml = load_results_file(args.results.joinpath("FullJUnitReport.xml")) if junitxml: parse_print_failure_results(junitxml) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/mobile/android/focus-android/automation/taskcluster/androidTest/parse-ui-test.py b/mobile/android/focus-android/automation/taskcluster/androidTest/parse-ui-test.py index fb12b24bfa9a..5ea932d7d6f8 100644 --- a/mobile/android/focus-android/automation/taskcluster/androidTest/parse-ui-test.py +++ b/mobile/android/focus-android/automation/taskcluster/androidTest/parse-ui-test.py @@ -56,12 +56,18 @@ def main(): print("| --- | --- | --- | --- |\n") for matrix, matrix_result in matrix_ids.items(): for axis in matrix_result["axes"]: - print(f"| {matrix_result['matrixId']} | {matrix_result['outcome']}" - f"| [Firebase Test Lab]({matrix_result['webLink']}) | {axis['details']}\n") + print( + f"| {matrix_result['matrixId']} | {matrix_result['outcome']}" + f"| [Firebase Test Lab]({matrix_result['webLink']}) | {axis['details']}\n" + ) print("---\n") print("# References & Documentation\n") - print("* [Automated UI Testing Documentation](https://github.com/mozilla-mobile/shared-docs/blob/main/android/ui-testing.md)\n") - print("* Mobile Test Engineering on [Confluence](https://mozilla-hub.atlassian.net/wiki/spaces/MTE/overview) | [Slack](https://mozilla.slack.com/archives/C02KDDS9QM9) | [Alerts](https://mozilla.slack.com/archives/C0134KJ4JHL)\n") + print( + "* [Automated UI Testing Documentation](https://github.com/mozilla-mobile/shared-docs/blob/main/android/ui-testing.md)\n" + ) + print( + "* Mobile Test Engineering on [Confluence](https://mozilla-hub.atlassian.net/wiki/spaces/MTE/overview) | [Slack](https://mozilla.slack.com/archives/C02KDDS9QM9) | [Alerts](https://mozilla.slack.com/archives/C0134KJ4JHL)\n" + ) if __name__ == "__main__": diff --git a/taskcluster/android_taskgraph/__init__.py b/taskcluster/android_taskgraph/__init__.py index 6b6fdeecee51..d4687bbe6ba3 100644 --- a/taskcluster/android_taskgraph/__init__.py +++ b/taskcluster/android_taskgraph/__init__.py @@ -7,7 +7,9 @@ import os from importlib import import_module CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) -PROJECT_DIR = os.path.realpath(os.path.join(CURRENT_DIR, "..", "..", "mobile", "android")) +PROJECT_DIR = os.path.realpath( + os.path.join(CURRENT_DIR, "..", "..", "mobile", "android") +) ANDROID_COMPONENTS_DIR = os.path.join(PROJECT_DIR, "android-components") FOCUS_DIR = os.path.join(PROJECT_DIR, "focus-android") FENIX_DIR = os.path.join(PROJECT_DIR, "fenix") diff --git a/taskcluster/android_taskgraph/release_promotion.py b/taskcluster/android_taskgraph/release_promotion.py index 590e52257e7a..d1442c6727f4 100644 --- a/taskcluster/android_taskgraph/release_promotion.py +++ b/taskcluster/android_taskgraph/release_promotion.py @@ -197,5 +197,9 @@ def release_promotion_action(parameters, graph_config, input, task_group_id, tas def read_version_file(): - with open(os.path.join(os.path.dirname(__file__), "..", "..", "mobile", "android", "version.txt")) as f: + with open( + os.path.join( + os.path.dirname(__file__), "..", "..", "mobile", "android", "version.txt" + ) + ) as f: return f.read().strip() diff --git a/taskcluster/android_taskgraph/release_type.py b/taskcluster/android_taskgraph/release_type.py index a837ef1ac201..4bc6e4d09030 100644 --- a/taskcluster/android_taskgraph/release_type.py +++ b/taskcluster/android_taskgraph/release_type.py @@ -2,6 +2,7 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. + def does_task_match_release_type(task, release_type): return ( # TODO: only use a single attribute to compare to `release_type` diff --git a/taskcluster/android_taskgraph/routes.py b/taskcluster/android_taskgraph/routes.py index cff1fc556530..6d5788abf06e 100644 --- a/taskcluster/android_taskgraph/routes.py +++ b/taskcluster/android_taskgraph/routes.py @@ -33,8 +33,7 @@ def add_signing_indexes(config, task): subs["artifact_type"] = "components" subs["artifact_name"] = task["attributes"]["component"] new_signing_routes = [ - template.format(**subs) - for template in SIGNING_ROUTE_TEMPLATES + template.format(**subs) for template in SIGNING_ROUTE_TEMPLATES ] elif task["attributes"].get("apks"): @@ -42,10 +41,9 @@ def add_signing_indexes(config, task): new_signing_routes = [] for abi in task["attributes"]["apks"].keys(): subs["artifact_name"] = abi - new_signing_routes.extend([ - template.format(**subs) - for template in SIGNING_ROUTE_TEMPLATES - ]) + new_signing_routes.extend( + [template.format(**subs) for template in SIGNING_ROUTE_TEMPLATES] + ) elif task["attributes"].get("aab"): # no indexes for AAB signing diff --git a/taskcluster/android_taskgraph/target_tasks.py b/taskcluster/android_taskgraph/target_tasks.py index 2cc08cbb0a8a..e3a7e5b034bb 100644 --- a/taskcluster/android_taskgraph/target_tasks.py +++ b/taskcluster/android_taskgraph/target_tasks.py @@ -25,7 +25,13 @@ def index_exists(index_path, reason=""): def target_tasks_nightly(full_task_graph, parameters, graph_config): def filter(task, parameters): build_type = task.attributes.get("build-type", "") - return build_type in ("nightly", "focus-nightly", "fenix-nightly", "fenix-nightly-firebase", "focus-nightly-firebase") + return build_type in ( + "nightly", + "focus-nightly", + "fenix-nightly", + "fenix-nightly-firebase", + "focus-nightly-firebase", + ) index_path = ( f"{graph_config['trust-domain']}.v2.{parameters['project']}.branch." diff --git a/taskcluster/android_taskgraph/transforms/beetmover_android_app.py b/taskcluster/android_taskgraph/transforms/beetmover_android_app.py index c4548395d5f3..bdf8da165810 100644 --- a/taskcluster/android_taskgraph/transforms/beetmover_android_app.py +++ b/taskcluster/android_taskgraph/transforms/beetmover_android_app.py @@ -26,7 +26,7 @@ beetmover_description_schema = Schema( Optional("dependencies"): task_description_schema["dependencies"], Optional("bucket-scope"): optionally_keyed_by("level", "build-type", str), }, - extra=ALLOW_EXTRA + extra=ALLOW_EXTRA, ) transforms = TransformSequence() diff --git a/taskcluster/android_taskgraph/transforms/external_gradle_dependencies.py b/taskcluster/android_taskgraph/transforms/external_gradle_dependencies.py index 1de90eb46442..93ff098ffb82 100644 --- a/taskcluster/android_taskgraph/transforms/external_gradle_dependencies.py +++ b/taskcluster/android_taskgraph/transforms/external_gradle_dependencies.py @@ -17,15 +17,14 @@ def set_treeherder_config(config, tasks): treeherder = task.setdefault("treeherder", {}) if not treeherder.get("symbol"): gradle_project = get_gradle_project(task) - treeherder_group = task.get("attributes", {}).get("treeherder-group", gradle_project) + treeherder_group = task.get("attributes", {}).get( + "treeherder-group", gradle_project + ) treeherder["symbol"] = f"{treeherder_group}(egd)" yield task - - - @transforms.add def extend_resources(config, tasks): deps_per_gradle_project = get_upstream_deps_for_all_gradle_projects() @@ -39,11 +38,13 @@ def extend_resources(config, tasks): dependencies = deps_per_gradle_project[gradle_project] gradle_project_and_deps = [gradle_project] + dependencies - resources.extend([ - path - for gradle_project in gradle_project_and_deps - for path in _get_build_gradle_paths(gradle_project) - ]) + resources.extend( + [ + path + for gradle_project in gradle_project_and_deps + for path in _get_build_gradle_paths(gradle_project) + ] + ) run["resources"] = sorted(list(set(resources))) @@ -68,9 +69,13 @@ def _get_build_gradle_paths(gradle_project): # Make sure we rebuild the cache when Fenix or Focus dependencies are changed if gradle_project == "fenix": - file_list.append(f"{project_dir}/plugins/fenixdependencies/src/main/java/FenixDependenciesPlugin.kt") + file_list.append( + f"{project_dir}/plugins/fenixdependencies/src/main/java/FenixDependenciesPlugin.kt" + ) elif gradle_project == "focus": - file_list.append(f"{project_dir}/plugins/focusdependencies/src/main/java/FocusDependenciesPlugin.kt") + file_list.append( + f"{project_dir}/plugins/focusdependencies/src/main/java/FocusDependenciesPlugin.kt" + ) return file_list @@ -95,14 +100,20 @@ def set_command_arguments(config, tasks): project_dir = _get_gradle_project_dir(gradle_project) arguments.append(project_dir) - gradle_task_template = "{gradle_task_name}" if gradle_project in ("focus", "fenix") else "{gradle_project}:{gradle_task_name}" - arguments.extend([ - gradle_task_template.format( - gradle_project=gradle_project, - gradle_task_name=gradle_task_name, - ) - for gradle_task_name in _get_gradle_task_names(gradle_project) - ]) + gradle_task_template = ( + "{gradle_task_name}" + if gradle_project in ("focus", "fenix") + else "{gradle_project}:{gradle_task_name}" + ) + arguments.extend( + [ + gradle_task_template.format( + gradle_project=gradle_project, + gradle_task_name=gradle_task_name, + ) + for gradle_task_name in _get_gradle_task_names(gradle_project) + ] + ) yield task @@ -110,10 +121,25 @@ def set_command_arguments(config, tasks): def _get_gradle_task_names(gradle_project): gradle_tasks_name = [] if gradle_project == "focus": - gradle_tasks_name.extend(["assembleFocusDebug", "assembleAndroidTest", "testFocusDebugUnitTest", "lint"]) + gradle_tasks_name.extend( + [ + "assembleFocusDebug", + "assembleAndroidTest", + "testFocusDebugUnitTest", + "lint", + ] + ) elif gradle_project == "fenix": - gradle_tasks_name.extend(["assemble", "assembleAndroidTest", "testClasses", "lint"]) + gradle_tasks_name.extend( + ["assemble", "assembleAndroidTest", "testClasses", "lint"] + ) else: - lint_task_name = "lint" if gradle_project in ("tooling-lint", "samples-browser") else "lintRelease" - gradle_tasks_name.extend(["assemble", "assembleAndroidTest", "test", lint_task_name]) + lint_task_name = ( + "lint" + if gradle_project in ("tooling-lint", "samples-browser") + else "lintRelease" + ) + gradle_tasks_name.extend( + ["assemble", "assembleAndroidTest", "test", lint_task_name] + ) return tuple(gradle_tasks_name) diff --git a/taskcluster/android_taskgraph/transforms/post_dummy.py b/taskcluster/android_taskgraph/transforms/post_dummy.py index 97f1d0dea48f..3a5e9c1f50d8 100644 --- a/taskcluster/android_taskgraph/transforms/post_dummy.py +++ b/taskcluster/android_taskgraph/transforms/post_dummy.py @@ -21,7 +21,8 @@ def set_name_and_clear_artifacts(config, tasks): def resolve_keys(config, tasks): for task in tasks: resolve_keyed_by( - task, "treeherder.symbol", + task, + "treeherder.symbol", item_name=task["name"], **{ "build-type": task["attributes"]["build-type"], diff --git a/taskcluster/android_taskgraph/transforms/push_android_app.py b/taskcluster/android_taskgraph/transforms/push_android_app.py index 8b12c5e3e07a..bca9b3c8dedc 100644 --- a/taskcluster/android_taskgraph/transforms/push_android_app.py +++ b/taskcluster/android_taskgraph/transforms/push_android_app.py @@ -38,7 +38,6 @@ def resolve_keys(config, tasks): @transforms.add def add_startup_test(config, tasks): - # TODO: change kind.yml to have the right dependency upfront for task in tasks: if "nightly" not in task["attributes"].get("build-type", ""): yield task diff --git a/taskcluster/android_taskgraph/transforms/signing_android_app.py b/taskcluster/android_taskgraph/transforms/signing_android_app.py index 0272a76e7e16..9fd4435f6ce4 100644 --- a/taskcluster/android_taskgraph/transforms/signing_android_app.py +++ b/taskcluster/android_taskgraph/transforms/signing_android_app.py @@ -41,7 +41,7 @@ def resolve_keys(config, tasks): "build-type": task["attributes"]["build-type"], "level": config.params["level"], "tasks-for": config.params["tasks_for"], - } + }, ) yield task diff --git a/taskcluster/android_taskgraph/util/group_by.py b/taskcluster/android_taskgraph/util/group_by.py index 09a5242da212..3c3b10980c2e 100644 --- a/taskcluster/android_taskgraph/util/group_by.py +++ b/taskcluster/android_taskgraph/util/group_by.py @@ -36,7 +36,7 @@ def component_grouping(config, tasks): return groups.values() -@group_by('build-type') +@group_by("build-type") def build_type_grouping(config, tasks): groups = {} for task in tasks: @@ -45,7 +45,7 @@ def build_type_grouping(config, tasks): if not task.attributes.get("is_final_chunked_task", True): continue - build_type = task.attributes.get('build-type') + build_type = task.attributes.get("build-type") groups.setdefault(build_type, []).append(task) return groups.values() diff --git a/taskcluster/scripts/lint/is_buildconfig_yml_up_to_date.py b/taskcluster/scripts/lint/is_buildconfig_yml_up_to_date.py index 9acac1bdd10e..2df9cc044fc8 100755 --- a/taskcluster/scripts/lint/is_buildconfig_yml_up_to_date.py +++ b/taskcluster/scripts/lint/is_buildconfig_yml_up_to_date.py @@ -23,7 +23,14 @@ logger = logging.getLogger(__name__) def _buildconfig_files_diff(): - cmd = ["hg", "diff", "--rev", "draft() and ancestors(.)", "-I", "**/.buildconfig.yml"] + cmd = [ + "hg", + "diff", + "--rev", + "draft() and ancestors(.)", + "-I", + "**/.buildconfig.yml", + ] p = subprocess.run(cmd, capture_output=True, universal_newlines=True) return p.stdout diff --git a/taskcluster/scripts/lint/update_buildconfig_from_gradle.py b/taskcluster/scripts/lint/update_buildconfig_from_gradle.py index d7b45b637aa1..148fa19aa45a 100755 --- a/taskcluster/scripts/lint/update_buildconfig_from_gradle.py +++ b/taskcluster/scripts/lint/update_buildconfig_from_gradle.py @@ -46,8 +46,7 @@ def _get_upstream_deps_per_gradle_project(gradle_root, existing_build_config): current_project_name = None print(f"Running command: {' '.join(cmd)}") try: - output = subprocess.check_output( - cmd, universal_newlines=True, cwd=gradle_root) + output = subprocess.check_output(cmd, universal_newlines=True, cwd=gradle_root) except subprocess.CalledProcessError as cpe: print(cpe.output) raise diff --git a/taskcluster/scripts/write-dummy-secret.py b/taskcluster/scripts/write-dummy-secret.py index 59d83f8eb94b..c96caad74978 100755 --- a/taskcluster/scripts/write-dummy-secret.py +++ b/taskcluster/scripts/write-dummy-secret.py @@ -20,15 +20,19 @@ def write_secret_to_file(path, secret): print(f"Outputting secret to: {path}") - with open(path, 'w') as f: + with open(path, "w") as f: f.write(secret) def main(): parser = argparse.ArgumentParser(description="Store a dummy secret to a file") - parser.add_argument("-c", dest="content", action="store", help="content of the secret") - parser.add_argument("-f", dest="path", action="store", help="file to save secret to") + parser.add_argument( + "-c", dest="content", action="store", help="content of the secret" + ) + parser.add_argument( + "-f", dest="path", action="store", help="file to save secret to" + ) result = parser.parse_args()