diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000000..1c28f0b3d7 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,25 @@ +name: Lint + +on: + push: + branches: [main, 3.1.x] + pull_request: + branches: [main, 3.1.x] + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - name: Install uv + uses: astral-sh/setup-uv@v5 + - name: Install prek + run: uv tool install prek + - name: Run prek + run: prek run --all-files diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c4132530af..f85b500784 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,8 +1,9 @@ ci: autoupdate_commit_msg: "chore: update pre-commit hooks" autoupdate_schedule: "monthly" - autofix_commit_msg: "style: pre-commit fixes" autofix_prs: false + skip: [] # pre-commit.ci only checks for updates, prek runs hooks locally + default_stages: [pre-commit, pre-push] default_language_version: diff --git a/changes/3658.misc.md b/changes/3658.misc.md new file mode 100644 index 0000000000..f400d97473 --- /dev/null +++ b/changes/3658.misc.md @@ -0,0 +1 @@ +Switch from `pre-commit` to [`prek`](https://github.com/j178/prek) for pre-commit checks. \ No newline at end of file diff --git a/docs/contributing.md b/docs/contributing.md index e42ba0edf1..c330504536 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -109,26 +109,50 @@ All tests are automatically run via GitHub Actions for every pull request and mu > **Note:** Previous versions of Zarr-Python made extensive use of doctests. These tests were not maintained during the 3.0 refactor but may be brought back in the future. See issue #2614 for more details. -### Code standards - using pre-commit +### Code standards - using prek All code must conform to the PEP8 standard. Regarding line length, lines up to 100 characters are allowed, although please try to keep under 90 wherever possible. -`Zarr` uses a set of `pre-commit` hooks and the `pre-commit` bot to format, type-check, and prettify the codebase. `pre-commit` can be installed locally by running: +`Zarr` uses a set of git hooks managed by [`prek`](https://github.com/j178/prek), a fast, Rust-based pre-commit hook manager that is fully compatible with `.pre-commit-config.yaml` files. `prek` can be installed locally by running: ```bash -python -m pip install pre-commit +uv tool install prek +``` + +or: + +```bash +pip install prek ``` The hooks can be installed locally by running: ```bash -pre-commit install +prek install +``` + +This would run the checks every time a commit is created locally. The checks will by default only run on the files modified by a commit, but the checks can be triggered for all the files by running: + +```bash +prek run --all-files +``` + +You can also run hooks only for files in a specific directory: + +```bash +prek run --directory src/zarr +``` + +Or run hooks for files changed in the last commit: + +```bash +prek run --last-commit ``` -This would run the checks every time a commit is created locally. These checks will also run on every commit pushed to an open PR, resulting in some automatic styling fixes by the `pre-commit` bot. The checks will by default only run on the files modified by a commit, but the checks can be triggered for all the files by running: +To list all available hooks: ```bash -pre-commit run --all-files +prek list ``` If you would like to skip the failing checks and push the code for further discussion, use the `--no-verify` option with `git commit`. diff --git a/pyproject.toml b/pyproject.toml index e09bab4cb9..068caa1f0d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ maintainers = [ { name = "Deepak Cherian" } ] requires-python = ">=3.11" -# If you add a new dependency here, please also add it to .pre-commit-config.yml +# If you add a new dependency here, please also add it to .pre-commit-config.yaml dependencies = [ 'packaging>=22.0', 'numpy>=2.0', @@ -428,6 +428,7 @@ markers = [ ignore = [ "PC111", # fix Python code in documentation - enable later "PC180", # for JavaScript - not interested + "PC902", # pre-commit.ci custom autofix message - not using autofix ] [tool.numpydoc_validation]