Skip to content

Commit

Permalink
Add pre-commit configuration and workflow
Browse files Browse the repository at this point in the history
Add a pre-commit [1] configuration in `.pre-commit-config.yaml` and a
corresponding GitHub workflow to run the checks on pull requests.

The pre-commit checks use ruff [2] for both linting and formatting.
Developers should integrate these checks into their local workflow by
installing pre-commit and running `pre-commit install` to enable the local
pre-commit hook.

Note that we have removed `tox -e pep8` from the existing test workflow, since
there's no reason to run the linting as part of the Python version matrix.

[1]: https://pre-commit.com/
[2]: https://docs.astral.sh/ruff/
  • Loading branch information
larsks committed Jul 13, 2024
1 parent 822016c commit 7dd7660
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/precommit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Run pre-commit checks

on:
pull_request:
push:

jobs:
run-linters:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Configure caching
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: precommit-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }}

- name: Install pre-commit
run: |
pip install pre-commit
- name: Run linters
run: |
pre-commit run --all-files
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install tox
- name: Lint
run: tox -epep8
- name: Unit Tests
run: tox -epy3
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
repos:
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.5
hooks:
- id: remove-tabs

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: check-merge-conflict
- id: end-of-file-fixer
- id: check-added-large-files
- id: check-case-conflict
- id: detect-private-key
- id: check-yaml
args: [--allow-multiple-documents]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.1
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format

0 comments on commit 7dd7660

Please sign in to comment.