Skip to content

Commit acc78e6

Browse files
authoredApr 8, 2021
python: Integrate linting (#15886)
- moves all tooling configs to repo root to allow using them directly and make explicit - moves the python linting job to format_pre only and includes a diff there Signed-off-by: Ryan Northey <ryan@synca.io>
1 parent 0abd955 commit acc78e6

File tree

9 files changed

+27
-18
lines changed

9 files changed

+27
-18
lines changed
 

‎.azure-pipelines/pipelines.yml

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ stages:
2626
BAZEL_REMOTE_INSTANCE: projects/envoy-ci/instances/default_instance
2727
GCP_SERVICE_ACCOUNT_KEY: $(GcpServiceAccountKey)
2828
displayName: "Run format pre-checks"
29+
- task: PublishBuildArtifacts@1
30+
inputs:
31+
pathtoPublish: "$(Build.StagingDirectory)/fix_format_pre.diff"
32+
artifactName: format
33+
# not all have fixes so improve condition/handling
34+
condition: failed()
2935

3036
- job: format
3137
dependsOn: ["format_pre"]

‎.devcontainer/devcontainer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"python.pythonPath": "/usr/bin/python3",
2323
"python.formatting.provider": "yapf",
2424
"python.formatting.yapfArgs": [
25-
"--style=${workspaceFolder}/tools/code_format/.style.yapf"
25+
"--style=${workspaceFolder}/.style.yapf"
2626
],
2727
"files.exclude": {
2828
"**/.clangd/**": true,

‎tools/code_format/flake8.conf ‎.flake8

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[flake8]
33

44
# TODO(phlax): make this an exclusive list and enable most tests
5-
select = N802,F401,E111,F821
5+
select = N802,F401,E111,F821,E9,F63,F72,F82
66

77
# TODO(phlax): exclude less
8-
exclude = build_docs,.git,generated,test,examples
8+
exclude = build_docs,.git,generated,test,examples,venv
File renamed without changes.

‎ci/do_ci.sh

-2
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ elif [[ "$CI_TARGET" == "fix_format" ]]; then
407407

408408
echo "fix_format..."
409409
"${ENVOY_SRCDIR}"/tools/code_format/check_format.py fix
410-
"${ENVOY_SRCDIR}"/tools/code_format/format_python_tools.sh fix
411410
BAZEL_BUILD_OPTIONS="${BAZEL_BUILD_OPTIONS[*]}" "${ENVOY_SRCDIR}"/tools/proto_format/proto_format.sh fix --test
412411
exit 0
413412
elif [[ "$CI_TARGET" == "check_format" ]]; then
@@ -418,7 +417,6 @@ elif [[ "$CI_TARGET" == "check_format" ]]; then
418417
"${ENVOY_SRCDIR}"/tools/code_format/check_format_test_helper.sh --log=WARN
419418
echo "check_format..."
420419
"${ENVOY_SRCDIR}"/tools/code_format/check_format.py check
421-
"${ENVOY_SRCDIR}"/tools/code_format/format_python_tools.sh check
422420
BAZEL_BUILD_OPTIONS="${BAZEL_BUILD_OPTIONS[*]}" "${ENVOY_SRCDIR}"/tools/proto_format/proto_format.sh check --test
423421
exit 0
424422
elif [[ "$CI_TARGET" == "check_repositories" ]]; then

‎ci/format_pre.sh

+16-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
FAILED=()
99
CURRENT=""
1010

11+
DIFF_OUTPUT="${DIFF_OUTPUT:-/build/fix_format_pre.diff}"
12+
1113
read -ra BAZEL_BUILD_OPTIONS <<< "${BAZEL_BUILD_OPTIONS:-}"
1214

1315

@@ -33,16 +35,26 @@ trap exit 1 INT
3335

3436
# TODO: move these to bazel
3537
CURRENT=glint
36-
./tools/code_format/glint.sh
38+
"${ENVOY_SRCDIR}"/tools/code_format/glint.sh
3739

3840
CURRENT=shellcheck
39-
./tools/code_format/check_shellcheck_format.sh check
41+
"${ENVOY_SRCDIR}"/tools/code_format/check_shellcheck_format.sh check
4042

4143
CURRENT=configs
4244
bazel run "${BAZEL_BUILD_OPTIONS[@]}" //configs:example_configs_validation
4345

44-
CURRENT=flake8
45-
bazel run "${BAZEL_BUILD_OPTIONS[@]}" //tools/code_format:python_flake8 "$(pwd)"
46+
# TODO(phlax): update to use bazel and python_flake8/python_check
47+
# this will simplify this code to a single line
48+
CURRENT=python
49+
"${ENVOY_SRCDIR}"/tools/code_format/format_python_tools.sh check || {
50+
"${ENVOY_SRCDIR}"/tools/code_format/format_python_tools.sh fix
51+
git diff HEAD | tee "${DIFF_OUTPUT}"
52+
raise () {
53+
# this throws an error without exiting
54+
return 1
55+
}
56+
raise
57+
}
4658

4759
if [[ "${#FAILED[@]}" -ne "0" ]]; then
4860
echo "TESTS FAILED:" >&2

‎tools/code_format/BUILD

-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ exports_files([
1010
"check_format.py",
1111
"header_order.py",
1212
"envoy_build_fixer.py",
13-
"flake8.conf",
1413
])
1514

1615
py_binary(
1716
name = "python_flake8",
1817
srcs = ["python_flake8.py"],
19-
data = [":flake8.conf"],
2018
visibility = ["//visibility:public"],
2119
deps = [
2220
requirement("flake8"),

‎tools/code_format/format_python_tools.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ def validate_format(fix=False):
3939
successful_update_files = set()
4040
for python_file in collect_files():
4141
reformatted_source, encoding, changed = FormatFile(
42-
python_file,
43-
style_config='tools/code_format/.style.yapf',
44-
in_place=fix,
45-
print_diff=not fix)
42+
python_file, style_config='.style.yapf', in_place=fix, print_diff=not fix)
4643
if not fix:
4744
fixes_required = True if changed else fixes_required
4845
if reformatted_source:

‎tools/code_format/python_flake8.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import subprocess
22
import sys
33

4-
FLAKE8_CONFIG = "tools/code_format/flake8.conf"
5-
64
# explicitly use python3 linter
7-
FLAKE8_COMMAND = ("python3", "-m", "flake8", "--config", FLAKE8_CONFIG, ".")
5+
FLAKE8_COMMAND = ("python3", "-m", "flake8", ".")
86

97

108
def main():

0 commit comments

Comments
 (0)