Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
36 changes: 30 additions & 6 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -422,6 +422,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]
Expand Down
Loading