From 9d767a03c0ee60081fd8a2d2a200e530bebef8eb Mon Sep 17 00:00:00 2001 From: Vladimir Iglovikov <ternaus@users.noreply.github.com> Date: Tue, 15 Oct 2019 08:28:02 -0700 Subject: [PATCH] Added pre-commit hook (#1536) * Added pre-commit hook * Trigger CI --- .github/CONTRIBUTING.md | 20 +++++++++++++++++++- .isort.cfg | 4 ++-- .pre-commit-config.yaml | 21 +++++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index d183655..39c145a 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -29,7 +29,25 @@ We use the following tools for linting and formatting: Style configurations of yapf and isort can be found in [.style.yapf](../.style.yapf) and [.isort.cfg](../.isort.cfg). +We use [pre-commit hook](https://pre-commit.com/) that checks and formats for `flake8`, `yapf`, `isort`, `trailing whitespaces`, + fixes `end-of-files`, sorts `requirments.txt` automatically on every commit. +The config for a pre-commit hook is stored in [.pre-commit-config](../.pre-commit-config.yaml). + +After you clone the repository, you will need to install initialize pre-commit hook. + +``` +pip install -U pre-commit +``` + +From the repository folder +``` +pre-commit install +``` + +After this on every commit check code linters and formatter will be enforced. + + >Before you create a PR, make sure that your code lints and is formatted by yapf. ### C++ and CUDA -We follow the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html). \ No newline at end of file +We follow the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html). diff --git a/.isort.cfg b/.isort.cfg index c1684dd..5169bea 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -2,6 +2,6 @@ line_length = 79 multi_line_output = 0 known_first_party = mmdet -known_third_party = mmcv,numpy,matplotlib,pycocotools,six,seaborn,terminaltables,torch,torchvision +known_third_party = Cython,albumentations,cv2,imagecorruptions,matplotlib,mmcv,numpy,pycocotools,robustness_eval,roi_align,roi_pool,seaborn,setuptools,six,terminaltables,torch no_lines_before = STDLIB,LOCALFOLDER -default_section = THIRDPARTY \ No newline at end of file +default_section = THIRDPARTY diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..2fae06c --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,21 @@ +repos: +- repo: https://github.com/asottile/seed-isort-config + rev: v1.9.3 + hooks: + - id: seed-isort-config +- repo: https://github.com/pre-commit/mirrors-isort + rev: v4.3.21 + hooks: + - id: isort +- repo: https://github.com/pre-commit/mirrors-yapf + rev: 80b9cd2f0f3b1f3456a77eff3ddbaf08f18c08ae + hooks: + - id: yapf +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: flake8 + - id: trailing-whitespace + - id: check-yaml + - id: end-of-file-fixer + - id: requirements-txt-fixer -- GitLab