From 8140ee8f2ecdede99589976b7103296de4c705ae Mon Sep 17 00:00:00 2001 From: tangwei Date: Wed, 20 May 2020 13:44:52 +0800 Subject: [PATCH] add codestyle travis --- .pre-commit-config.yaml | 36 ++++++++++++++++++++++++++++++++++++ run.py | 5 ++--- tools/build_script.sh | 6 ------ 3 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..8c268c52 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,36 @@ +repos: +- repo: https://github.com/Lucas-C/pre-commit-hooks.git + sha: v1.0.1 + hooks: + - id: remove-crlf + files: (?!.*third_party)^.*$ | (?!.*book)^.*$ +- repo: https://github.com/PaddlePaddle/mirrors-yapf.git + sha: 0d79c0c469bab64f7229c9aca2b1186ef47f0e37 + hooks: + - id: yapf + files: (.*\.(py|bzl)|BUILD|.*\.BUILD|WORKSPACE)$ +- repo: https://github.com/pre-commit/pre-commit-hooks + sha: 5bf6c09bfa1297d3692cadd621ef95f1284e33c0 + hooks: + - id: check-added-large-files + - id: check-merge-conflict + - id: check-symlinks + - id: detect-private-key + files: (?!.*third_party)^.*$ | (?!.*book)^.*$ + - id: end-of-file-fixer +- repo: local + hooks: + - id: pylint-doc-string + name: pylint + description: Check python docstring style using docstring_checker. + entry: bash ./tools/codestyle/pylint_pre_commit.hook + language: system + files: \.(py)$ +- repo: local + hooks: + - id: copyright_checker + name: copyright_checker + entry: python ./tools/codestyle/copyright.hook + language: system + files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|proto|py)$ + exclude: (?!.*third_party)^.*$ | (?!.*book)^.*$ diff --git a/run.py b/run.py index 56999935..4588c88f 100755 --- a/run.py +++ b/run.py @@ -52,6 +52,7 @@ def get_inters_from_yaml(file, filter): flattens = envs.flatten_environs(_envs) inters = {} + for k, v in flattens.items(): if k.startswith(filter): inters[k] = v @@ -62,16 +63,14 @@ def get_engine(args): transpiler = get_transpiler() run_extras = get_inters_from_yaml(args.model, "train.") - engine = run_extras.get("train.engine", "single") + engine = run_extras.get("train.engine", "single") engine = engine.upper() if engine not in engine_choices: raise ValueError("train.engin can not be chosen in {}".format(engine_choices)) print("engines: \n{}".format(engines)) - run_engine = engines[transpiler].get(engine, None) - return run_engine diff --git a/tools/build_script.sh b/tools/build_script.sh index 9db7ea53..fa26cc7f 100755 --- a/tools/build_script.sh +++ b/tools/build_script.sh @@ -37,14 +37,8 @@ function check_style() { eval "$(GIMME_GO_VERSION=1.8.3 gimme)" fi - pip install cpplint - # set up go environment for running gometalinter - mkdir -p $GOPATH/src/github.com/SeiriosPlus/PaddleRec - ln -sf ${ROOT} $GOPATH/src/github.com/SeiriosPlus/PaddleRec - export PATH=/usr/bin:$PATH pre-commit install - clang-format --version if ! pre-commit run -a; then git diff -- GitLab