From 6abd231fa3601fb4debf9d9cf5aec08029f4b3eb Mon Sep 17 00:00:00 2001 From: Vladislav Borshch Date: Sun, 8 Oct 2023 23:31:21 +0700 Subject: [PATCH 1/2] pre-commit flow for CI and standalone run --- .github/workflows/lint_and_test.yml | 20 ++++++++++++++++- .pre-commit-config.yaml | 33 +++++++++++++++++++++++++++++ README.md | 1 + requirements.txt | 3 ++- 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/lint_and_test.yml b/.github/workflows/lint_and_test.yml index 99e8a8d..2cf1807 100644 --- a/.github/workflows/lint_and_test.yml +++ b/.github/workflows/lint_and_test.yml @@ -7,7 +7,23 @@ on: types: [created] jobs: - lint: + lint-pre-commit: + runs-on: ubuntu-latest + name: pre-commit + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.10" + - name: pre-commit + run: | + pip install pre-commit + pre-commit run -a + + lint-quality: + needs: lint-pre-commit + if: github.ref == 'refs/heads/master' permissions: @@ -55,6 +71,8 @@ jobs: continue-on-error: true build: + needs: lint-pre-commit + runs-on: ubuntu-latest strategy: matrix: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..669124b --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,33 @@ +exclude: | + (?x)^( + tests/test_data/.*| + examples/.*| + py3gpp/codes/.* + )$ + +repos: +- repo: "https://github.com/psf/black" + rev: "23.3.0" + hooks: + - id: "black" + +- repo: "https://github.com/pycqa/isort" + rev: "5.12.0" + hooks: + - id: "isort" + args: + - "--profile=black" + +- repo: "https://github.com/pycqa/flake8" + rev: "6.0.0" + hooks: + - id: "flake8" + +- repo: "https://github.com/pre-commit/pre-commit-hooks" + rev: "v4.4.0" + hooks: + - id: "trailing-whitespace" + - id: "mixed-line-ending" + args: + - "--fix=lf" + - id: "end-of-file-fixer" diff --git a/README.md b/README.md index 6a3fbaa..247be17 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ See Matlab documentation of equivalent function ## Formatting * Screen width 120 * spaces on each side of math operators like +-*/ +* run `pre-commit run -a` before any push. Otherwise PR will be rejected ## Testing * Each function must have a hard-coded test that can run on CI * Each function should have a Matlab test that can run on a machine with Matlab license diff --git a/requirements.txt b/requirements.txt index 1d379ca..690f7ac 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ pylint anybadge pytest pytest-xdist -importlib_resources \ No newline at end of file +importlib_resources +pre-commit From 3a7e1aa5a49d2efdc2a9e9beba817eecd7bc7679 Mon Sep 17 00:00:00 2001 From: Vladislav Borshch Date: Mon, 9 Oct 2023 10:44:21 +0700 Subject: [PATCH 2/2] line-length = 120 setup --- .pre-commit-config.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 669124b..2f74de9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,6 +10,7 @@ repos: rev: "23.3.0" hooks: - id: "black" + args: [--line-length=120] - repo: "https://github.com/pycqa/isort" rev: "5.12.0" @@ -22,6 +23,7 @@ repos: rev: "6.0.0" hooks: - id: "flake8" + args: [--max-line-length=120] - repo: "https://github.com/pre-commit/pre-commit-hooks" rev: "v4.4.0"