Skip to content

DEV: replace pre-commit with lefthook+Pixi #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 1, 2025
Merged
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 .dprint.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"json": {
"lineWidth": 100,
"array.preferSingleLine": true,
},
"markdown": {
"lineWidth": 200,
"emphasisKind": "asterisks",
},
"toml": {
"lineWidth": 100,
},
"yaml": {
"printWidth": 100,
"formatComments": true,
"braceSpacing": false,
},
"excludes": ["**/*-lock.json", "**/*.lock", "**/node_modules/", "dist/"],
"plugins": [
"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.1.wasm",
"https://plugins.dprint.dev/json-0.20.0.wasm",
"https://plugins.dprint.dev/markdown-0.19.0.wasm",
"https://plugins.dprint.dev/toml-0.7.0.wasm",
],
}
17 changes: 5 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ env:
FORCE_COLOR: 3

jobs:
pre-commit-and-lint:
name: Format
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Expand All @@ -30,24 +30,17 @@ jobs:
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: "3.13.3"
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
with:
extra_args: --hook-stage manual --all-files
- uses: prefix-dev/setup-pixi@19eac09b398e3d0c747adc7921926a6d802df4da # v0.8.8
with:
pixi-version: v0.42.1
pixi-version: v0.49.0
cache: true
environments: lint
- name: Run Pylint, Mypy & Pyright
run: |
pixi run -e lint pylint
pixi run -e lint mypy
pixi run -e lint pyright
- name: Lint
run: pixi run -e lint lint

checks:
name: Test ${{ matrix.environment }}
runs-on: ${{ matrix.runs-on }}
needs: [pre-commit-and-lint]
strategy:
fail-fast: false
matrix:
Expand Down
84 changes: 0 additions & 84 deletions .pre-commit-config.yaml

This file was deleted.

23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@
<!-- SPHINX-START -->

<!-- prettier-ignore-start -->
[actions-badge]: https://github.com/data-apis/array-api-extra/workflows/CI/badge.svg
[actions-link]: https://github.com/data-apis/array-api-extra/actions
[conda-badge]: https://img.shields.io/conda/vn/conda-forge/array-api-extra
[conda-link]: https://github.com/conda-forge/array-api-extra-feedstock

[actions-badge]: https://github.com/data-apis/array-api-extra/workflows/CI/badge.svg
[actions-link]: https://github.com/data-apis/array-api-extra/actions
[conda-badge]: https://img.shields.io/conda/vn/conda-forge/array-api-extra
[conda-link]: https://github.com/conda-forge/array-api-extra-feedstock
[github-discussions-badge]: https://img.shields.io/static/v1?label=Discussions&message=Ask&color=blue&logo=github
[github-discussions-link]: https://github.com/data-apis/array-api-extra/discussions
[pypi-link]: https://pypi.org/project/array-api-extra/
[pypi-platforms]: https://img.shields.io/pypi/pyversions/array-api-extra
[pypi-version]: https://img.shields.io/pypi/v/array-api-extra
[docs-badge]: https://img.shields.io/badge/docs-here!-2ea44f
[docs-link]: https://data-apis.org/array-api-extra/index.html
[github-discussions-link]: https://github.com/data-apis/array-api-extra/discussions
[pypi-link]: https://pypi.org/project/array-api-extra/
[pypi-platforms]: https://img.shields.io/pypi/pyversions/array-api-extra
[pypi-version]: https://img.shields.io/pypi/v/array-api-extra
[docs-badge]: https://img.shields.io/badge/docs-here!-2ea44f
[docs-link]: https://data-apis.org/array-api-extra/index.html

<!-- prettier-ignore-end -->

Expand All @@ -38,7 +39,7 @@ Used by:
scientific computing.
- [scikit-learn](https://github.com/scikit-learn/scikit-learn) — Machine
Learning in Python.
- _your library? Let us know!_
- *your library? Let us know!*

## Installation

Expand Down
58 changes: 31 additions & 27 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ development of array-api-extra is made easy with
at <https://github.com/data-apis/array-api-extra>.
- `cd array-api-extra`.
- [Install Pixi](https://pixi.sh/latest/#installation).
- To enter a development environment:
- To enter a development environment (if you prefer this to the `pixi run` interface):

```
pixi shell -e dev
Expand All @@ -73,71 +73,75 @@ pixi shell -e dev
pixi run tests
```

- To generate the coverage report:
- To build the docs locally:

```
pixi run coverage
pixi run docs
```

- To generate and display the coverage report:
- To build and preview the docs locally:

```
pixi run open-coverage
pixi run open-docs
```

- To build the docs locally:
- To install pre-commit hooks:

```
pixi run docs
pixi run hooks
```

- To build and preview the docs locally:
- To run pre-commit checks on staged files:

```
pixi run open-docs
pixi run pre-commit
```

- To install a [pre-commit](https://pre-commit.com) hook:
- To run the full lint suite:

```
pixi run pre-commit-install
pixi run --environment=lint lint
```

- To run the lint suite:
- To enter an interactive Python prompt:

```
pixi run -e lint lint
pixi run ipython
```

- To enter an interactive Python prompt:
- To run individual parts of the lint suite separately (for example):

```
pixi run ipython
pixi run --environment=lint pyright
pixi run --environment=lint dprint
```

- To generate the coverage report:

```
pixi run coverage
```

- To run individual parts of the lint suite separately:
- To generate and display the coverage report:

```
pixi run -e lint pre-commit
pixi run -e lint pylint
pixi run -e lint mypy
pixi run -e lint pyright
pixi run open-coverage
```

Alternative environments are available with a subset of the dependencies and
tasks available in the `dev` environment:

```
pixi shell -e docs
pixi shell -e tests
pixi shell -e tests-backends
pixi shell -e lint
pixi shell --environment=docs
pixi shell --environment=tests
pixi shell --environment=tests-backends
pixi shell --environment=lint
```

If you run on a host with CUDA hardware, you can enable extra tests:

```
pixi shell -e dev-cuda
pixi shell -e tests-cuda
pixi run -e tests-cuda tests
pixi shell --environment=dev-cuda
pixi shell --environment=tests-cuda
pixi run --environment=tests-cuda tests
```
1 change: 0 additions & 1 deletion docs/contributors.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
```{include} ../CONTRIBUTORS.md

```
7 changes: 3 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ well as delegation to existing implementations for known array library backends.
The intended users of this library are "array-consuming" libraries which are
using [array-api-compat](https://data-apis.org/array-api-compat/) to make their
own library's functions array-agnostic. In this library, they will find a set of
tools which provide _extra_ functionality on top of the array API standard,
tools which provide *extra* functionality on top of the array API standard,
which other array-consuming libraries in a similar position have found useful
themselves.

Expand All @@ -27,7 +27,7 @@ It is currently used by:
scientific computing.
- [scikit-learn](https://github.com/scikit-learn/scikit-learn) — Machine
Learning in Python.
- _your library? Let us know!_
- *your library? Let us know!*

(installation)=

Expand Down Expand Up @@ -114,8 +114,7 @@ def array_namespace(*xs, **kwargs):
See [an example of this in SciPy][scipy-vendor-example].
```

[scipy-vendor-example]:
https://github.com/scipy/scipy/blob/main/scipy/_lib/_array_api_compat_vendor.py
[scipy-vendor-example]: https://github.com/scipy/scipy/blob/main/scipy/_lib/_array_api_compat_vendor.py

## Versioning

Expand Down
43 changes: 43 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
lefthook: pixi run --environment=lint lefthook

templates:
run: run --environment=lint

pre-commit:
parallel: true
jobs:
- name: dprint
glob: "*.{json,jsonc,md,toml,yaml,yml}"
stage_fixed: true
run: pixi {run} dprint
- name: ruff
glob: "*.{py,pyi}"
stage_fixed: true
group:
piped: true
jobs:
- name: ruff check
run: pixi {run} ruff-check {staged_files}
- name: ruff format
run: pixi {run} ruff-format {staged_files}
- name: pyright
glob: "*.{py,pyi}"
run: pixi {run} pyright
- name: mypy
glob: "*.{py,pyi}"
run: pixi {run} mypy
- name: typos
stage_fixed: true
run: pixi {run} typos
- name: actionlint
run: pixi {run} actionlint
- name: blacken-docs
glob: "*.md"
stage_fixed: true
run: pixi {run} blacken-docs {staged_files}
- name: validate-pyproject
glob: "pyproject.toml"
run: pixi {run} validate-pyproject
- name: numpydoc
glob: "*.py"
run: pixi {run} numpydoc {staged_files}
Loading