From 664758fa776405b9a2e2a6199e008f820341a621 Mon Sep 17 00:00:00 2001 From: Sing_chan <51314274+betterpig@users.noreply.github.com> Date: Wed, 1 Jun 2022 16:20:17 +0800 Subject: [PATCH] code format check upgrade step1: pre-commit, remove-ctrlf, pylint (#43103) --- .pre-commit-config.yaml | 2 +- paddle/scripts/paddle_build.sh | 4 ++++ tools/codestyle/pylint_pre_commit.hook | 8 +++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 39d9ae5e0dc..06b9dfeb725 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/Lucas-C/pre-commit-hooks.git - sha: v1.0.1 + rev: v1.1.14 hooks: - id: remove-crlf files: (?!.*third_party)^.*$ | (?!.*book)^.*$ diff --git a/paddle/scripts/paddle_build.sh b/paddle/scripts/paddle_build.sh index eac2f95d14b..6ac1f6eb6b5 100755 --- a/paddle/scripts/paddle_build.sh +++ b/paddle/scripts/paddle_build.sh @@ -360,6 +360,10 @@ function check_style() { # pre-commit use python3.8.0 OLD_PATH=$PATH export PATH=/usr/local/python3.8.0/bin:/usr/local/python3.8.0/include:/usr/local/bin:${PATH} + + if ! [[ $(pre-commit --version) == *"2.17.0"* ]]; then + pip install pre-commit==2.17.0 + fi pre-commit install clang-format --version diff --git a/tools/codestyle/pylint_pre_commit.hook b/tools/codestyle/pylint_pre_commit.hook index 150a3f5666b..f0d2f0a22d7 100755 --- a/tools/codestyle/pylint_pre_commit.hook +++ b/tools/codestyle/pylint_pre_commit.hook @@ -6,6 +6,13 @@ TOTAL_ERRORS=0 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" export PYTHONPATH=$DIR:$PYTHONPATH +readonly VERSION="2.12.0" +version=$(pylint --version | grep 'pylint') + +if ! [[ $version == *"$VERSION"* ]]; then + pip install pylint==2.12.0 1>nul +fi + # The trick to remove deleted files: https://stackoverflow.com/a/2413151 for file in $(git diff --name-status | awk '$1 != "D" {print $2}'); do pylint --disable=all --load-plugins=docstring_checker \ @@ -16,4 +23,3 @@ done exit $TOTAL_ERRORS #For now, just warning: #exit 0 - -- GitLab