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..2f74de9 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,35 @@ +exclude: | + (?x)^( + tests/test_data/.*| + examples/.*| + py3gpp/codes/.* + )$ + +repos: +- repo: "https://github.com/psf/black" + rev: "23.3.0" + hooks: + - id: "black" + args: [--line-length=120] + +- 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" + args: [--max-line-length=120] + +- 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