From c49d6ce49f412d6220ec214c160206b271527559 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 14 Apr 2021 18:22:02 +1000 Subject: [PATCH] run black/isort on Python scripts --- cargo/update.py | 10 +++++----- ftl/duplicate-string.py | 11 ++++++----- ftl/extract-strings.py | 7 ++++--- ftl/format.py | 15 ++++++++------- ftl/format_check.py | 7 ++++--- ftl/sync.py | 11 ++++++----- ftl/transform-string.py | 5 +++-- pip/pyqt5/install_pyqt5.py | 8 ++++---- pip/update.py | 3 ++- pylib/anki/_backend/genbackend.py | 2 -- pylib/anki/buildinfo.py | 6 ++++-- qt/aqt/about.py | 1 + qt/aqt/browser/sidebar/searchbar.py | 1 + qt/aqt/forms/__init__.py | 2 +- qt/aqt/forms/build_ui.py | 7 ++++++- qt/tools/extract_sass_colors.py | 6 ++++-- rslib/proto_format.py | 5 ++++- scripts/copyright_headers.py | 5 +++-- ts/lib/genfluent.py | 13 +++++++------ 19 files changed, 73 insertions(+), 52 deletions(-) diff --git a/cargo/update.py b/cargo/update.py index 970c5dc96..3fb6ceaa5 100755 --- a/cargo/update.py +++ b/cargo/update.py @@ -21,12 +21,12 @@ COMMITS_SHALLOW_SINCE = { "96e1358555c49905de89170f2b1102a7d8b6c4c2": "1598411535 +1000", } -import os -import sys -import subprocess -import shutil -import re import glob +import os +import re +import shutil +import subprocess +import sys if os.getcwd() != os.path.abspath(os.path.dirname(__file__)): print("Run this from the cargo/ folder") diff --git a/ftl/duplicate-string.py b/ftl/duplicate-string.py index fbe1e1882..7bdbd900e 100644 --- a/ftl/duplicate-string.py +++ b/ftl/duplicate-string.py @@ -2,14 +2,15 @@ # Copyright: Ankitects Pty Ltd and contributors # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -import os -import json -import re -import sys import copy +import json +import os +import re import shutil +import sys + from fluent.syntax import parse, serialize -from fluent.syntax.ast import Message, TextElement, Identifier, Pattern, Junk +from fluent.syntax.ast import Identifier, Junk, Message, Pattern, TextElement # clone an existing ftl string as a new key # eg: diff --git a/ftl/extract-strings.py b/ftl/extract-strings.py index bd8c108a6..eb31317a8 100644 --- a/ftl/extract-strings.py +++ b/ftl/extract-strings.py @@ -6,12 +6,13 @@ Tool to extract core strings and keys from .ftl files. """ -import os -import json import glob +import json +import os + from fluent.syntax import parse -from fluent.syntax.serializer import serialize_element from fluent.syntax.ast import Junk +from fluent.syntax.serializer import serialize_element root = os.environ["BUILD_WORKSPACE_DIRECTORY"] ftl_files = glob.glob(os.path.join(root, "ftl", "core", "*.ftl"), recursive=True) diff --git a/ftl/format.py b/ftl/format.py index e398616fd..2a1425be1 100644 --- a/ftl/format.py +++ b/ftl/format.py @@ -6,17 +6,18 @@ Parse and re-serialize ftl files to get them in a consistent form. """ -import os -import json -import glob -import sys import difflib +import glob +import json +import os +import sys from typing import List -from fluent.syntax import parse, serialize -from fluent.syntax.ast import Junk -from compare_locales.paths import File + from compare_locales import parser from compare_locales.checks.fluent import ReferenceMessageVisitor +from compare_locales.paths import File +from fluent.syntax import parse, serialize +from fluent.syntax.ast import Junk def check_missing_terms(path: str) -> bool: diff --git a/ftl/format_check.py b/ftl/format_check.py index 5abbcf32f..7faeacd2c 100644 --- a/ftl/format_check.py +++ b/ftl/format_check.py @@ -1,10 +1,11 @@ # Copyright: Ankitects Pty Ltd and contributors # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -import os -import format -import sys import glob +import os +import sys + +import format template_root = os.path.dirname(sys.argv[1]) template_files = glob.glob(os.path.join(template_root, "*", "*.ftl"), recursive=True) diff --git a/ftl/sync.py b/ftl/sync.py index daf286a17..9d05db201 100644 --- a/ftl/sync.py +++ b/ftl/sync.py @@ -5,14 +5,15 @@ # and copy source files to the translation repos. Requires access to the # i18n repos to run. -import subprocess -from dataclasses import dataclass -import re import os +import re +import subprocess import sys -from typing import Optional, Tuple -import requests +from dataclasses import dataclass from hashlib import sha256 +from typing import Optional, Tuple + +import requests root = os.environ["BUILD_WORKSPACE_DIRECTORY"] repos_bzl = os.path.join(root, "repos.bzl") diff --git a/ftl/transform-string.py b/ftl/transform-string.py index 4a92944e4..c8c7b8a71 100644 --- a/ftl/transform-string.py +++ b/ftl/transform-string.py @@ -6,9 +6,10 @@ Tool to apply transform to an ftl string and its translations. """ -import os -import json import glob +import json +import os + from fluent.syntax import parse, serialize from fluent.syntax.ast import Junk diff --git a/pip/pyqt5/install_pyqt5.py b/pip/pyqt5/install_pyqt5.py index 05186160f..4e8de7bd7 100644 --- a/pip/pyqt5/install_pyqt5.py +++ b/pip/pyqt5/install_pyqt5.py @@ -6,16 +6,16 @@ import argparse import glob import logging import os -import shutil -import sys import re +import shutil import subprocess +import sys + +import pkginfo from pip._internal.commands import create_command from pip._vendor import pkg_resources -import pkginfo - def _create_nspkg_init(dirpath): """Creates an init file to enable namespacing""" diff --git a/pip/update.py b/pip/update.py index 69f586a03..68d862faf 100644 --- a/pip/update.py +++ b/pip/update.py @@ -1,8 +1,9 @@ # Copyright: Ankitects Pty Ltd and contributors # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -import sys import os +import sys + import click from piptools.scripts import compile diff --git a/pylib/anki/_backend/genbackend.py b/pylib/anki/_backend/genbackend.py index 64fff6da6..02bceda48 100755 --- a/pylib/anki/_backend/genbackend.py +++ b/pylib/anki/_backend/genbackend.py @@ -7,9 +7,7 @@ import re import sys import google.protobuf.descriptor - import pylib.anki._backend.backend_pb2 as pb - import stringcase TYPE_DOUBLE = 1 diff --git a/pylib/anki/buildinfo.py b/pylib/anki/buildinfo.py index 33efa0c9d..d9c5a7a5f 100644 --- a/pylib/anki/buildinfo.py +++ b/pylib/anki/buildinfo.py @@ -18,6 +18,7 @@ def _build_info_path() -> str: raise Exception("missing buildinfo.txt") + def _get_build_info() -> Dict[str, str]: info = {} with open(_build_info_path()) as file: @@ -29,6 +30,7 @@ def _get_build_info() -> Dict[str, str]: return info + _buildinfo = _get_build_info() -buildhash=_buildinfo["STABLE_BUILDHASH"] -version=_buildinfo["STABLE_VERSION"] +buildhash = _buildinfo["STABLE_BUILDHASH"] +version = _buildinfo["STABLE_VERSION"] diff --git a/qt/aqt/about.py b/qt/aqt/about.py index 50042f193..24e971622 100644 --- a/qt/aqt/about.py +++ b/qt/aqt/about.py @@ -1,5 +1,6 @@ # Copyright: Ankitects Pty Ltd and contributors # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html + import platform import time diff --git a/qt/aqt/browser/sidebar/searchbar.py b/qt/aqt/browser/sidebar/searchbar.py index 56eaebb8d..b06ad7fcb 100644 --- a/qt/aqt/browser/sidebar/searchbar.py +++ b/qt/aqt/browser/sidebar/searchbar.py @@ -1,5 +1,6 @@ # Copyright: Ankitects Pty Ltd and contributors # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html + from __future__ import annotations import aqt diff --git a/qt/aqt/forms/__init__.py b/qt/aqt/forms/__init__.py index 4553ff248..008cd902b 100644 --- a/qt/aqt/forms/__init__.py +++ b/qt/aqt/forms/__init__.py @@ -38,4 +38,4 @@ from . import stats from . import studydeck from . import synclog from . import taglimit -from . import template \ No newline at end of file +from . import template diff --git a/qt/aqt/forms/build_ui.py b/qt/aqt/forms/build_ui.py index 9c13a379d..a36857ff0 100644 --- a/qt/aqt/forms/build_ui.py +++ b/qt/aqt/forms/build_ui.py @@ -18,7 +18,12 @@ outdata = re.sub( outlines = [] -qt_bad_types = [".connect(", "setStandardButtons", "setTextInteractionFlags", "setAlignment"] +qt_bad_types = [ + ".connect(", + "setStandardButtons", + "setTextInteractionFlags", + "setAlignment", +] for line in outdata.splitlines(): for substr in qt_bad_types: if substr in line: diff --git a/qt/tools/extract_sass_colors.py b/qt/tools/extract_sass_colors.py index 9ac50a7b7..c13a1d7d9 100644 --- a/qt/tools/extract_sass_colors.py +++ b/qt/tools/extract_sass_colors.py @@ -32,10 +32,12 @@ for line in open(input_scss): colors.setdefault(var, []).append(val) with open(output_py, "w") as buf: - buf.write("""\ + buf.write( + """\ # Copyright: Ankitects Pty Ltd and contributors # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -""") +""" + ) buf.write("# this file is auto-generated from _vars.scss\n") for color, (day, night) in colors.items(): color = color.replace("-", "_").upper() diff --git a/rslib/proto_format.py b/rslib/proto_format.py index 7cdf763a2..32d79114e 100755 --- a/rslib/proto_format.py +++ b/rslib/proto_format.py @@ -1,7 +1,10 @@ # Copyright: Ankitects Pty Ltd and contributors # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -import sys, subprocess, os, difflib +import difflib +import os +import subprocess +import sys clang_format = sys.argv[1] workspace = os.environ.get("BUILD_WORKSPACE_DIRECTORY", "") diff --git a/scripts/copyright_headers.py b/scripts/copyright_headers.py index e1f2087b6..c24fc773b 100644 --- a/scripts/copyright_headers.py +++ b/scripts/copyright_headers.py @@ -1,7 +1,8 @@ # Copyright: Ankitects Pty Ltd and contributors # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -import os, sys +import os +import sys from pathlib import Path nonstandard_header = { @@ -53,4 +54,4 @@ for dirpath, dirnames, fnames in os.walk("."): found = True if found: - sys.exit(1) \ No newline at end of file + sys.exit(1) diff --git a/ts/lib/genfluent.py b/ts/lib/genfluent.py index b30d1f606..c92ae8503 100644 --- a/ts/lib/genfluent.py +++ b/ts/lib/genfluent.py @@ -3,7 +3,6 @@ import json import sys -from typing import List from typing import List, Literal, TypedDict import stringcase @@ -63,12 +62,13 @@ def arg_kind(arg: Variable) -> str: def map_args_to_real_names(args: List[Variable]) -> str: - return ("{" + ", ".join( - [f'"{arg["name"]}": args.{typescript_arg_name(arg)}' for arg in args] + return ( + "{" + + ", ".join( + [f'"{arg["name"]}": args.{typescript_arg_name(arg)}' for arg in args] + ) + + "}" ) - + "}" - ) - def get_args(args: List[Variable]) -> str: @@ -91,6 +91,7 @@ def typescript_arg_name(arg: Variable) -> str: else: return name + def module_names() -> str: buf = "export enum ModuleName {\n" for module in modules: