Skip to content

Commit cf11834

Browse files
committed
Configure black & ruff with pre-commit
1 parent baa1d6e commit cf11834

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

.pre-commit-config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
repos:
2+
- repo: "https://github.com/charliermarsh/ruff-pre-commit"
3+
rev: "v0.0.269"
4+
hooks:
5+
- id: "ruff"
6+
args: ["--fix", "--exit-non-zero-on-fix"]
7+
8+
- repo: "https://github.com/psf/black"
9+
rev: "23.3.0"
10+
hooks:
11+
- id: "black"

doc/contributing.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,17 @@ rm -rf dist
2121
python -m build
2222
pip install dist/*.whl # or `dist/*.tar.gz`
2323
```
24+
25+
26+
## Code formatting and linting
27+
28+
This codebase uses [black](https://black.readthedocs.io/en/stable/) and
29+
[ruff](https://github.com/charliermarsh/ruff) to automatically format and lint the code.
30+
31+
[`pre-commit`](https://pre-commit.com/) is configured to run them automatically. You can
32+
trigger this manually with `pre-commit run --all-files`.
33+
34+
Thanks to pre-commit, all commits should be formatted. In cases where formatting needs
35+
to be fixed (e.g. changing config of a linter), a format-only commit should be created,
36+
and then another commit should immediately follow which updates
37+
`.git-blame-ignore-revs`.

environment.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ channels:
33
- "conda-forge"
44
- "nodefaults"
55
dependencies:
6+
# Runtime
67
- "python ~=3.11"
78
- "numpy ~=1.24"
89
- "matplotlib ~=3.7"
910
- "colorspacious ~=1.1"
1011
- "scipy ~=1.10"
12+
13+
# Development
14+
- "pre-commit"
15+
1116
- pip:
1217
- "build ~=0.10"

pyproject.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,12 @@ packages = {find = {}}
4545
package-data = {viscm = ["examples/*"]}
4646

4747

48-
# [tool.black]
48+
[tool.black]
49+
target-version = ["py37", "py38", "py39", "py310", "py311"]
50+
51+
[tool.ruff]
52+
target-version = "py37"
53+
select = ["F", "E", "W", "C90", "I", "UP", "YTT", "B", "A", "C4", "T10", "RUF"]
54+
55+
[tool.ruff.mccabe]
56+
max-complexity = 11

0 commit comments

Comments
 (0)