Skip to content

Commit 1269989

Browse files
committed
Add pre-commit.
1 parent 540f204 commit 1269989

4 files changed

Lines changed: 47 additions & 1 deletion

File tree

.pre-commit-config.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
files: ^(src|tests)/
2+
exclude: ^tests/(input|output)/
3+
4+
repos:
5+
# General file quality checks
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
7+
rev: v5.0.0
8+
hooks:
9+
- id: trailing-whitespace
10+
- id: end-of-file-fixer
11+
- id: check-added-large-files
12+
args: [--maxkb=1000] # Prevent files larger than 1MB
13+
- id: check-merge-conflict
14+
15+
# Python formatting and linting
16+
- repo: https://github.com/astral-sh/ruff-pre-commit
17+
rev: v0.8.4
18+
hooks:
19+
# Run the formatter
20+
- id: ruff-format
21+
# Run the linter (optional - remove if too strict)
22+
- id: ruff
23+
args: [--fix, --exit-zero] # Auto-fix but don't block commits

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,24 @@ Then install `loch` into the environment:
7272
pip install -e .
7373
```
7474

75+
## Development
76+
77+
Pre-commit hooks are used to ensure consistent code formatting and linting.
78+
To set up pre-commit in your development environment:
79+
80+
```
81+
pixi shell -e dev
82+
pre-commit install
83+
```
84+
85+
This will run [ruff](https://docs.astral.sh/ruff/) formatting and linting
86+
checks automatically on each commit. To run the checks manually against all
87+
files:
88+
89+
```
90+
pre-commit run --all-files
91+
```
92+
7593
## How does it work?
7694

7795
Instead of computing the energy change for each trial insertion/deletion with

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ distance-dirty = "{base_version}+{distance}.{vcs}{rev}.dirty"
2929

3030
[tool.versioningit.write]
3131
file = "src/loch/_version.py"
32+
33+
[tool.ruff.lint]
34+
ignore = ["E402"]
35+
36+
[tool.ruff.lint.per-file-ignores]
37+
"tests/**" = ["F841"]

src/loch/_sampler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2394,7 +2394,6 @@ def _set_water_state(self, context, indices=None, states=None, force=False):
23942394

23952395
# Loop over the indices and states.
23962396
for idx, state in zip(indices, states):
2397-
23982397
# Skip if the state is unchanged.
23992398
if not force and self._water_state[idx] == state:
24002399
continue

0 commit comments

Comments
 (0)