run black/isort on Python scripts

This commit is contained in:
Damien Elmes 2021-04-14 18:22:02 +10:00
parent 01049b1289
commit c49d6ce49f
19 changed files with 73 additions and 52 deletions

View file

@ -21,12 +21,12 @@ COMMITS_SHALLOW_SINCE = {
"96e1358555c49905de89170f2b1102a7d8b6c4c2": "1598411535 +1000", "96e1358555c49905de89170f2b1102a7d8b6c4c2": "1598411535 +1000",
} }
import os
import sys
import subprocess
import shutil
import re
import glob import glob
import os
import re
import shutil
import subprocess
import sys
if os.getcwd() != os.path.abspath(os.path.dirname(__file__)): if os.getcwd() != os.path.abspath(os.path.dirname(__file__)):
print("Run this from the cargo/ folder") print("Run this from the cargo/ folder")

View file

@ -2,14 +2,15 @@
# Copyright: Ankitects Pty Ltd and contributors # Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # 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 copy
import json
import os
import re
import shutil import shutil
import sys
from fluent.syntax import parse, serialize 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 # clone an existing ftl string as a new key
# eg: # eg:

View file

@ -6,12 +6,13 @@
Tool to extract core strings and keys from .ftl files. Tool to extract core strings and keys from .ftl files.
""" """
import os
import json
import glob import glob
import json
import os
from fluent.syntax import parse from fluent.syntax import parse
from fluent.syntax.serializer import serialize_element
from fluent.syntax.ast import Junk from fluent.syntax.ast import Junk
from fluent.syntax.serializer import serialize_element
root = os.environ["BUILD_WORKSPACE_DIRECTORY"] root = os.environ["BUILD_WORKSPACE_DIRECTORY"]
ftl_files = glob.glob(os.path.join(root, "ftl", "core", "*.ftl"), recursive=True) ftl_files = glob.glob(os.path.join(root, "ftl", "core", "*.ftl"), recursive=True)

View file

@ -6,17 +6,18 @@
Parse and re-serialize ftl files to get them in a consistent form. Parse and re-serialize ftl files to get them in a consistent form.
""" """
import os
import json
import glob
import sys
import difflib import difflib
import glob
import json
import os
import sys
from typing import List 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 import parser
from compare_locales.checks.fluent import ReferenceMessageVisitor 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: def check_missing_terms(path: str) -> bool:

View file

@ -1,10 +1,11 @@
# Copyright: Ankitects Pty Ltd and contributors # Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import os
import format
import sys
import glob import glob
import os
import sys
import format
template_root = os.path.dirname(sys.argv[1]) template_root = os.path.dirname(sys.argv[1])
template_files = glob.glob(os.path.join(template_root, "*", "*.ftl"), recursive=True) template_files = glob.glob(os.path.join(template_root, "*", "*.ftl"), recursive=True)

View file

@ -5,14 +5,15 @@
# and copy source files to the translation repos. Requires access to the # and copy source files to the translation repos. Requires access to the
# i18n repos to run. # i18n repos to run.
import subprocess
from dataclasses import dataclass
import re
import os import os
import re
import subprocess
import sys import sys
from typing import Optional, Tuple from dataclasses import dataclass
import requests
from hashlib import sha256 from hashlib import sha256
from typing import Optional, Tuple
import requests
root = os.environ["BUILD_WORKSPACE_DIRECTORY"] root = os.environ["BUILD_WORKSPACE_DIRECTORY"]
repos_bzl = os.path.join(root, "repos.bzl") repos_bzl = os.path.join(root, "repos.bzl")

View file

@ -6,9 +6,10 @@
Tool to apply transform to an ftl string and its translations. Tool to apply transform to an ftl string and its translations.
""" """
import os
import json
import glob import glob
import json
import os
from fluent.syntax import parse, serialize from fluent.syntax import parse, serialize
from fluent.syntax.ast import Junk from fluent.syntax.ast import Junk

View file

@ -6,16 +6,16 @@ import argparse
import glob import glob
import logging import logging
import os import os
import shutil
import sys
import re import re
import shutil
import subprocess import subprocess
import sys
import pkginfo
from pip._internal.commands import create_command from pip._internal.commands import create_command
from pip._vendor import pkg_resources from pip._vendor import pkg_resources
import pkginfo
def _create_nspkg_init(dirpath): def _create_nspkg_init(dirpath):
"""Creates an init file to enable namespacing""" """Creates an init file to enable namespacing"""

View file

@ -1,8 +1,9 @@
# Copyright: Ankitects Pty Ltd and contributors # Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import sys
import os import os
import sys
import click import click
from piptools.scripts import compile from piptools.scripts import compile

View file

@ -7,9 +7,7 @@ import re
import sys import sys
import google.protobuf.descriptor import google.protobuf.descriptor
import pylib.anki._backend.backend_pb2 as pb import pylib.anki._backend.backend_pb2 as pb
import stringcase import stringcase
TYPE_DOUBLE = 1 TYPE_DOUBLE = 1

View file

@ -18,6 +18,7 @@ def _build_info_path() -> str:
raise Exception("missing buildinfo.txt") raise Exception("missing buildinfo.txt")
def _get_build_info() -> Dict[str, str]: def _get_build_info() -> Dict[str, str]:
info = {} info = {}
with open(_build_info_path()) as file: with open(_build_info_path()) as file:
@ -29,6 +30,7 @@ def _get_build_info() -> Dict[str, str]:
return info return info
_buildinfo = _get_build_info() _buildinfo = _get_build_info()
buildhash=_buildinfo["STABLE_BUILDHASH"] buildhash = _buildinfo["STABLE_BUILDHASH"]
version=_buildinfo["STABLE_VERSION"] version = _buildinfo["STABLE_VERSION"]

View file

@ -1,5 +1,6 @@
# Copyright: Ankitects Pty Ltd and contributors # Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import platform import platform
import time import time

View file

@ -1,5 +1,6 @@
# Copyright: Ankitects Pty Ltd and contributors # Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from __future__ import annotations from __future__ import annotations
import aqt import aqt

View file

@ -38,4 +38,4 @@ from . import stats
from . import studydeck from . import studydeck
from . import synclog from . import synclog
from . import taglimit from . import taglimit
from . import template from . import template

View file

@ -18,7 +18,12 @@ outdata = re.sub(
outlines = [] outlines = []
qt_bad_types = [".connect(", "setStandardButtons", "setTextInteractionFlags", "setAlignment"] qt_bad_types = [
".connect(",
"setStandardButtons",
"setTextInteractionFlags",
"setAlignment",
]
for line in outdata.splitlines(): for line in outdata.splitlines():
for substr in qt_bad_types: for substr in qt_bad_types:
if substr in line: if substr in line:

View file

@ -32,10 +32,12 @@ for line in open(input_scss):
colors.setdefault(var, []).append(val) colors.setdefault(var, []).append(val)
with open(output_py, "w") as buf: with open(output_py, "w") as buf:
buf.write("""\ buf.write(
"""\
# Copyright: Ankitects Pty Ltd and contributors # Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # 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") buf.write("# this file is auto-generated from _vars.scss\n")
for color, (day, night) in colors.items(): for color, (day, night) in colors.items():
color = color.replace("-", "_").upper() color = color.replace("-", "_").upper()

View file

@ -1,7 +1,10 @@
# Copyright: Ankitects Pty Ltd and contributors # Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # 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] clang_format = sys.argv[1]
workspace = os.environ.get("BUILD_WORKSPACE_DIRECTORY", "") workspace = os.environ.get("BUILD_WORKSPACE_DIRECTORY", "")

View file

@ -1,7 +1,8 @@
# Copyright: Ankitects Pty Ltd and contributors # Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # 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 from pathlib import Path
nonstandard_header = { nonstandard_header = {
@ -53,4 +54,4 @@ for dirpath, dirnames, fnames in os.walk("."):
found = True found = True
if found: if found:
sys.exit(1) sys.exit(1)

View file

@ -3,7 +3,6 @@
import json import json
import sys import sys
from typing import List
from typing import List, Literal, TypedDict from typing import List, Literal, TypedDict
import stringcase import stringcase
@ -63,12 +62,13 @@ def arg_kind(arg: Variable) -> str:
def map_args_to_real_names(args: List[Variable]) -> str: def map_args_to_real_names(args: List[Variable]) -> str:
return ("{" + ", ".join( return (
[f'"{arg["name"]}": args.{typescript_arg_name(arg)}' for arg in args] "{"
+ ", ".join(
[f'"{arg["name"]}": args.{typescript_arg_name(arg)}' for arg in args]
)
+ "}"
) )
+ "}"
)
def get_args(args: List[Variable]) -> str: def get_args(args: List[Variable]) -> str:
@ -91,6 +91,7 @@ def typescript_arg_name(arg: Variable) -> str:
else: else:
return name return name
def module_names() -> str: def module_names() -> str:
buf = "export enum ModuleName {\n" buf = "export enum ModuleName {\n"
for module in modules: for module in modules: