From 4ede22a4b3edf3251ccbd68c3c9b6dd4ef5e0e30 Mon Sep 17 00:00:00 2001 From: jianyunchao Date: Tue, 26 Sep 2023 16:24:35 +0800 Subject: [PATCH] add pre-commit --- .flake8 | 9 +++++++++ .github/workflows/ci.yml | 14 ++++++++------ .pre-commit-config.yaml | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 .flake8 create mode 100644 .pre-commit-config.yaml diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..c90f937 --- /dev/null +++ b/.flake8 @@ -0,0 +1,9 @@ +[flake8] +max-line-length = 120 +extend-exclude = + docs/*, + setup.py +extend-ignore = E203 +per-file-ignores = + */__init__.py:F401,F403 + examples/*,tests/*:E402 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3dffbef..86c08d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,8 +4,6 @@ name: CI on: - push: - branches: [ "master" ] pull_request: branches: [ "master" ] @@ -21,6 +19,9 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 + with: + # requites to grab the history of the PR + fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v3 with: @@ -29,12 +30,13 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements/ci_requirements.txt - - name: Analysing the code with pylint - run: | - pylint mindpet --rcfile=.github/pylint.conf + - name: Lint with pre-commit + uses: pre-commit/action@v3.0.0 + with: + extra_args: --color=always --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }} - name: Test with unit test (UT) pytest run: | pytest test/unit_test - name: Test with system test (ST) pytest run: | - pytest test/developer_test \ No newline at end of file + pytest test/developer_test diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..ff897d2 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,34 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 + hooks: + # list of supported hooks: https://pre-commit.com/hooks.html + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + - id: mixed-line-ending + args: ["--fix=lf"] + - id: trailing-whitespace + + - repo: https://github.com/PyCQA/isort + rev: 5.11.5 + hooks: + - id: isort + args: ['--profile', 'black'] + + - repo: https://github.com/psf/black + rev: 23.1.0 + hooks: + - id: black + + - repo: https://github.com/PyCQA/flake8 + rev: 5.0.4 + hooks: + - id: flake8 + + - repo: https://github.com/pylint-dev/pylint + rev: v2.14.5 + hooks: + - id: pylint + args: [ "-rn", "-sn", "--rcfile=pylintrc", "--fail-on=I" ] + exclude: tests(/\w*)*/functional/|tests/input|tests(/\w*)*data/|doc/