From c717c3b8a1b7a72e03e427c4cd0ec5d1b6de723a Mon Sep 17 00:00:00 2001 From: Jared Roesch Date: Wed, 9 Sep 2020 21:29:44 -0700 Subject: [PATCH 1/7] Add black to CI --- pyproject.toml | 1 + python/tvm/support.py | 1 + tests/lint/git-black.sh | 72 +++++++++++++++++++++++++++++++++++++ tests/lint/python_format.sh | 21 +++++++++++ tests/scripts/task_lint.sh | 17 +++++---- 5 files changed, 106 insertions(+), 6 deletions(-) create mode 100755 tests/lint/git-black.sh create mode 100644 tests/lint/python_format.sh diff --git a/pyproject.toml b/pyproject.toml index 6c8cfdc9d144..60effda74384 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,6 +41,7 @@ exclude = ''' | nnvm\/ | rust\/ | src\/ + | tests\/ | vta\/ | web\/ )/|tests/lint/add_asf_header.py|tests/lint/check_file_type.py|python/tvm/topi/testing/pool3d_python.py|python/topi/python/test_topi_pooling.py diff --git a/python/tvm/support.py b/python/tvm/support.py index e0d688abb9e8..36c66a9b5f9b 100644 --- a/python/tvm/support.py +++ b/python/tvm/support.py @@ -27,6 +27,7 @@ def libinfo(): The dictionary of compile-time info. """ return {k: v for k, v in GetLibInfo().items()} # pylint: disable=unnecessary-comprehension + } tvm._ffi._init_api("support", __name__) diff --git a/tests/lint/git-black.sh b/tests/lint/git-black.sh new file mode 100755 index 000000000000..fb97e2cfb5c6 --- /dev/null +++ b/tests/lint/git-black.sh @@ -0,0 +1,72 @@ +#!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +set -e +set -u +set -o pipefail + +if [[ "$1" == "-i" ]]; then + INPLACE_FORMAT=1 + shift 1 +else + INPLACE_FORMAT=0 +fi + +if [[ "$#" -lt 1 ]]; then + echo "Usage: tests/lint/git-black.sh [-i] " + echo "" + echo "Run black-format on files that changed since " + echo "Examples:" + echo "- Compare last one commit: tests/lint/git-black.sh HEAD~1" + echo "- Compare against upstream/master: tests/lint/git-black.sh upstream/master" + echo "You can also add -i option to do inplace format" + exit 1 +fi + +cleanup() +{ + rm -rf /tmp/$$.black-format.txt +} +trap cleanup 0 + + +if [ -x "$(command -v black)" ]; then + BLACK=black +else + echo "Cannot find black" + exit 1 +fi + +# Print out specific version + +echo "Version Information: $(${BLACK} --version)" + + +IFS=$'\n' read -a FILES -d'\n' < <(git diff --name-only HEAD $1 -- "*.py" "*.pyi") || true +echo "read returned $?" +echo "Files: $FILES" + +if [[ ${INPLACE_FORMAT} -eq 1 ]]; then + echo "Running black on Python files against revision" $1): + CMD=( "black" "${FILES[@]}" ) + echo "${CMD[@]}" + "${CMD[@]}" + exit 0 +fi + +echo "Running black in checking mode" +black --diff --check diff --git a/tests/lint/python_format.sh b/tests/lint/python_format.sh new file mode 100644 index 000000000000..752abfd701f6 --- /dev/null +++ b/tests/lint/python_format.sh @@ -0,0 +1,21 @@ +#!/bin/bash -e +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + + +./tests/lint/git-black.sh HEAD~1 +./tests/lint/git-black.sh origin/master diff --git a/tests/scripts/task_lint.sh b/tests/scripts/task_lint.sh index 7ac06119b6f9..f7f2427eb77e 100755 --- a/tests/scripts/task_lint.sh +++ b/tests/scripts/task_lint.sh @@ -27,22 +27,27 @@ cleanup() trap cleanup 0 -echo "Check file types..." +echo "Checking file types..." python3 tests/lint/check_file_type.py -echo "Check ASF license header..." +echo "Checking ASF license headers..." tests/lint/check_asf_header.sh -echo "Check codestyle of c++ code..." +echo "Linting the C++ code..." tests/lint/cpplint.sh echo "clang-format check..." tests/lint/clang_format.sh -echo "Check codestyle of python code..." +# TODO(@jroesch): enable black check +# echo "black check..." +# tests/lint/python_format.sh + +echo "Linting the Python code..." tests/lint/pylint.sh -echo "Check codestyle of jni code..." + +echo "Lintinf the JNI code..." tests/lint/jnilint.sh -echo "Check documentations of c++ code..." +echo "Checking C++ documentation..." tests/lint/cppdocs.sh From 2be9b9d39521b4d6147b167eec2b6f2da553bb13 Mon Sep 17 00:00:00 2001 From: Jared Roesch Date: Fri, 11 Sep 2020 16:39:14 -0700 Subject: [PATCH 2/7] Clean up --- pyproject.toml | 8 ++++++-- python/tvm/support.py | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 60effda74384..7e0da89be8c9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,9 +41,13 @@ exclude = ''' | nnvm\/ | rust\/ | src\/ - | tests\/ | vta\/ | web\/ - )/|tests/lint/add_asf_header.py|tests/lint/check_file_type.py|python/tvm/topi/testing/pool3d_python.py|python/topi/python/test_topi_pooling.py + )/|/( + python/topi/python/test_topi_pooling.py + | python/tvm/topi/testing/pool3d_python.py + | tests/lint/add_asf_header.py + | tests/lint/check_file_type.py + )/ ) ''' diff --git a/python/tvm/support.py b/python/tvm/support.py index 36c66a9b5f9b..e0d688abb9e8 100644 --- a/python/tvm/support.py +++ b/python/tvm/support.py @@ -27,7 +27,6 @@ def libinfo(): The dictionary of compile-time info. """ return {k: v for k, v in GetLibInfo().items()} # pylint: disable=unnecessary-comprehension - } tvm._ffi._init_api("support", __name__) From 16663897ddede05e5dc4b4c253341feca581ff1c Mon Sep 17 00:00:00 2001 From: Jared Roesch Date: Fri, 11 Sep 2020 16:42:26 -0700 Subject: [PATCH 3/7] Add --- tests/lint/git-black.sh | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/tests/lint/git-black.sh b/tests/lint/git-black.sh index fb97e2cfb5c6..944b58b7da2d 100755 --- a/tests/lint/git-black.sh +++ b/tests/lint/git-black.sh @@ -29,21 +29,14 @@ fi if [[ "$#" -lt 1 ]]; then echo "Usage: tests/lint/git-black.sh [-i] " echo "" - echo "Run black-format on files that changed since " + echo "Run black on Python files that changed since " echo "Examples:" echo "- Compare last one commit: tests/lint/git-black.sh HEAD~1" echo "- Compare against upstream/master: tests/lint/git-black.sh upstream/master" - echo "You can also add -i option to do inplace format" + echo "The -i will use black to format files in-place instead of checking them." exit 1 fi -cleanup() -{ - rm -rf /tmp/$$.black-format.txt -} -trap cleanup 0 - - if [ -x "$(command -v black)" ]; then BLACK=black else @@ -52,10 +45,9 @@ else fi # Print out specific version +echo "Version Information: $(black --version)" -echo "Version Information: $(${BLACK} --version)" - - +# Compute Python files which changed to compare. IFS=$'\n' read -a FILES -d'\n' < <(git diff --name-only HEAD $1 -- "*.py" "*.pyi") || true echo "read returned $?" echo "Files: $FILES" @@ -65,8 +57,7 @@ if [[ ${INPLACE_FORMAT} -eq 1 ]]; then CMD=( "black" "${FILES[@]}" ) echo "${CMD[@]}" "${CMD[@]}" - exit 0 +else + echo "Running black in checking mode" + black --diff --check fi - -echo "Running black in checking mode" -black --diff --check From 38644c85265bd525bfd2a925253faf61a52a80a6 Mon Sep 17 00:00:00 2001 From: Jared Roesch Date: Fri, 11 Sep 2020 16:44:39 -0700 Subject: [PATCH 4/7] Tweak script --- pyproject.toml | 9 ++++----- tests/lint/git-black.sh | 4 +--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7e0da89be8c9..1dc34c91950d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,11 +43,10 @@ exclude = ''' | src\/ | vta\/ | web\/ - )/|/( - python/topi/python/test_topi_pooling.py - | python/tvm/topi/testing/pool3d_python.py - | tests/lint/add_asf_header.py - | tests/lint/check_file_type.py + )/| /(python/topi/python/test_topi_pooling.py + |python/tvm/topi/testing/pool3d_python.py + |tests/lint/add_asf_header.py + |tests/lint/check_file_type.py )/ ) ''' diff --git a/tests/lint/git-black.sh b/tests/lint/git-black.sh index 944b58b7da2d..21bec693a698 100755 --- a/tests/lint/git-black.sh +++ b/tests/lint/git-black.sh @@ -37,9 +37,7 @@ if [[ "$#" -lt 1 ]]; then exit 1 fi -if [ -x "$(command -v black)" ]; then - BLACK=black -else +if [ ! -x "$(command -v black)" ]; then echo "Cannot find black" exit 1 fi From 8db2b619caa0a38b404f6ac4f6c7a01291972444 Mon Sep 17 00:00:00 2001 From: Jared Roesch Date: Fri, 11 Sep 2020 16:46:23 -0700 Subject: [PATCH 5/7] Update regexx --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 1dc34c91950d..e48aa4c10a88 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,7 +43,7 @@ exclude = ''' | src\/ | vta\/ | web\/ - )/| /(python/topi/python/test_topi_pooling.py + )/|/(python/topi/python/test_topi_pooling.py |python/tvm/topi/testing/pool3d_python.py |tests/lint/add_asf_header.py |tests/lint/check_file_type.py From e1c30f4fbe0f78b8374e6df2db8b490b496a7fef Mon Sep 17 00:00:00 2001 From: Jared Roesch Date: Fri, 11 Sep 2020 16:47:40 -0700 Subject: [PATCH 6/7] Tweak ignore list --- pyproject.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e48aa4c10a88..2ea63215baee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,10 +43,9 @@ exclude = ''' | src\/ | vta\/ | web\/ - )/|/(python/topi/python/test_topi_pooling.py + )/|python/topi/python/test_topi_pooling.py |python/tvm/topi/testing/pool3d_python.py |tests/lint/add_asf_header.py |tests/lint/check_file_type.py - )/ ) ''' From 2caeda1ff49dfc2c3bf1e5ab6b17292be8bb3754 Mon Sep 17 00:00:00 2001 From: Jared Roesch Date: Fri, 11 Sep 2020 18:42:28 -0700 Subject: [PATCH 7/7] Bump lint container --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3ce5b604b86a..f6faf2542209 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -44,7 +44,7 @@ // // NOTE: these lines are scanned by docker/dev_common.sh. Please update the regex as needed. --> -ci_lint = "tlcpack/ci-lint:v0.61" +ci_lint = "tlcpack/ci-lint:v0.62" ci_gpu = "tlcpack/ci-gpu:v0.64" ci_cpu = "tlcpack/ci-cpu:v0.65" ci_wasm = "tlcpack/ci-wasm:v0.60"