Skip to content

Commit e795dfe

Browse files
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 <[email protected]> Change-Id: I1918421120ce2942f04b9110a2c0f1bd820d21c7
1 parent c596959 commit e795dfe

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

scripts/build-unit-test-docker

+2
Original file line numberDiff line numberDiff line change
@@ -846,10 +846,12 @@ RUN apt-get update && apt-get dist-upgrade -yy
846846

847847
dockerfile_base += """
848848
RUN pip3 install beautysh
849+
RUN pip3 install black
849850
RUN pip3 install codespell
850851
RUN pip3 install flake8
851852
RUN pip3 install gitlint
852853
RUN pip3 install inflection
854+
RUN pip3 install isort
853855
RUN pip3 install jsonschema
854856
RUN pip3 install meson==0.63.0
855857
RUN pip3 install protobuf

scripts/format-code.sh

+14
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ LINTERS_ALL=( \
2929
commit_spelling \
3030
beautysh \
3131
beautysh_sh \
32+
black \
3233
clang_format \
3334
eslint \
3435
flake8 \
36+
isort \
3537
prettier \
3638
shellcheck \
3739
)
@@ -176,6 +178,12 @@ function do_beautysh_sh() {
176178
beautysh --force-function-style paronly "$@"
177179
}
178180

181+
LINTER_REQUIRE+=([black]="black")
182+
LINTER_TYPES+=([black]="python")
183+
function do_black() {
184+
black -l 79 --preview "$@"
185+
}
186+
179187
LINTER_REQUIRE+=([eslint]="eslint;.eslintrc.json;${CONFIG_PATH}/eslint-global-config.json")
180188
LINTER_IGNORE+=([eslint]=".eslintignore")
181189
LINTER_TYPES+=([eslint]="json")
@@ -195,6 +203,12 @@ function do_flake8() {
195203
# disagree on best practices.
196204
}
197205

206+
LINTER_REQUIRE+=([isort]="isort")
207+
LINTER_TYPES+=([isort]="python")
208+
function do_isort() {
209+
isort --profile black "$@"
210+
}
211+
198212
LINTER_REQUIRE+=([prettier]="prettier;.prettierrc.yaml;${CONFIG_PATH}/prettierrc.yaml")
199213
LINTER_IGNORE+=([prettier]=".prettierignore")
200214
LINTER_TYPES+=([prettier]="json;markdown;yaml")

scripts/unit-test.py

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from urllib.parse import urljoin
2121

2222
from git import Repo
23+
2324
# interpreter is not used directly but this resolves dependency ordering
2425
# that would be broken if we didn't include it.
2526
from mesonbuild import interpreter # noqa: F401

0 commit comments

Comments
 (0)