format-code: enable black/isort
* black is a widely used python formatting tool.
* isort is used to order python imports in a consistent way.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I1918421120ce2942f04b9110a2c0f1bd820d21c7
diff --git a/scripts/build-unit-test-docker b/scripts/build-unit-test-docker
index 2aa4c50..c7bb94a 100755
--- a/scripts/build-unit-test-docker
+++ b/scripts/build-unit-test-docker
@@ -846,10 +846,12 @@
dockerfile_base += """
RUN pip3 install beautysh
+RUN pip3 install black
RUN pip3 install codespell
RUN pip3 install flake8
RUN pip3 install gitlint
RUN pip3 install inflection
+RUN pip3 install isort
RUN pip3 install jsonschema
RUN pip3 install meson==0.63.0
RUN pip3 install protobuf
diff --git a/scripts/format-code.sh b/scripts/format-code.sh
index 17a6d1e..f6eaacc 100755
--- a/scripts/format-code.sh
+++ b/scripts/format-code.sh
@@ -29,9 +29,11 @@
commit_spelling \
beautysh \
beautysh_sh \
+ black \
clang_format \
eslint \
flake8 \
+ isort \
prettier \
shellcheck \
)
@@ -176,6 +178,12 @@
beautysh --force-function-style paronly "$@"
}
+LINTER_REQUIRE+=([black]="black")
+LINTER_TYPES+=([black]="python")
+function do_black() {
+ black -l 79 --preview "$@"
+}
+
LINTER_REQUIRE+=([eslint]="eslint;.eslintrc.json;${CONFIG_PATH}/eslint-global-config.json")
LINTER_IGNORE+=([eslint]=".eslintignore")
LINTER_TYPES+=([eslint]="json")
@@ -195,6 +203,12 @@
# disagree on best practices.
}
+LINTER_REQUIRE+=([isort]="isort")
+LINTER_TYPES+=([isort]="python")
+function do_isort() {
+ isort --profile black "$@"
+}
+
LINTER_REQUIRE+=([prettier]="prettier;.prettierrc.yaml;${CONFIG_PATH}/prettierrc.yaml")
LINTER_IGNORE+=([prettier]=".prettierignore")
LINTER_TYPES+=([prettier]="json;markdown;yaml")
diff --git a/scripts/unit-test.py b/scripts/unit-test.py
index 1660042..aaaf92b 100755
--- a/scripts/unit-test.py
+++ b/scripts/unit-test.py
@@ -20,6 +20,7 @@
from urllib.parse import urljoin
from git import Repo
+
# interpreter is not used directly but this resolves dependency ordering
# that would be broken if we didn't include it.
from mesonbuild import interpreter # noqa: F401