Skip to content

Commit f6c9247

Browse files
timmensclaude
andcommitted
Switch from pre-commit to prek in docs and fix local hook
Update contributor guide and styleguide to recommend prek instead of pre-commit. Fix the update-algo-selection-code hook to use importlib + uv instead of pip, which is not available in prek environments. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d2c907e commit f6c9247

3 files changed

Lines changed: 14 additions & 17 deletions

File tree

.tools/update_algo_selection_hook.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
import importlib.util
23
import subprocess
34
import sys
45
from pathlib import Path
@@ -8,19 +9,15 @@
89

910
# sys.executable guarantees we stay inside the pre‑commit venv
1011
PYTHON = [sys.executable]
11-
# "-m" lets us call std‑lib modules (e.g. pip) the same way
12-
PYTHON_MINUS_M = [*PYTHON, "-m"]
1312

1413

1514
def run(cmd: list[str], **kwargs: Any) -> None:
1615
subprocess.check_call(cmd, cwd=ROOT, **kwargs)
1716

1817

1918
def ensure_optimagic_is_locally_installed() -> None:
20-
try:
21-
run(PYTHON_MINUS_M + ["pip", "show", "optimagic"], stdout=subprocess.DEVNULL)
22-
except subprocess.CalledProcessError:
23-
run(PYTHON_MINUS_M + ["pip", "install", "-e", "."])
19+
if importlib.util.find_spec("optimagic") is None:
20+
run(["uv", "pip", "install", "--python", sys.executable, "-e", "."])
2421

2522

2623
def main() -> int:

docs/source/development/how_to_contribute.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ For regular contributors: **Clone** the [repository](https://github.com/optimagi
4444
local optimagic repository:
4545

4646
```console
47-
$ pre-commit install
47+
$ prek install
4848
```
4949

5050
This activates pre-commit hooks for linting and style formatting.
5151

5252
```{note}
53-
`pre-commit` is not managed by pixi and must be installed globally. We recommend
54-
installing it globally using pixi or uv.
53+
`prek` is not managed by pixi and must be installed globally. You can find
54+
installation instructions at [github.com/janosg/prek](https://github.com/janosg/prek).
5555
```
5656

5757
You can then run the test suite with:
@@ -90,8 +90,8 @@ For regular contributors: **Clone** the [repository](https://github.com/optimagi
9090
You can also run the test suite locally for
9191
[debugging](https://effective-programming-practices.vercel.app/debugging/pdbp/objectives_materials.html).
9292

93-
With pre-commit installed, linters run before each commit. Commits are rejected if
94-
any checks fail. Note that some linters may automatically fix errors by modifying the
93+
With prek installed, linters run before each commit. Commits are rejected if any
94+
checks fail. Note that some linters may automatically fix errors by modifying the
9595
code in-place. Remember to re-stage the files after such modifications.
9696

9797
```{tip}
@@ -109,9 +109,9 @@ Skip the next paragraph if you haven't worked on the documentation.
109109
`docs/build/html/index.html` or any other file. Similar to the online documentation,
110110
you can navigate to different pages simply by clicking on the links.
111111

112-
1. Once all tests and pre-commit hooks pass locally, push your changes to your forked
113-
repository and create a pull request through GitHub: Go to the Github repository of
114-
your fork. A banner on your fork's GitHub repository will prompt you to open a PR.
112+
1. Once all tests and hooks pass locally, push your changes to your forked repository
113+
and create a pull request through GitHub: Go to the Github repository of your fork. A
114+
banner on your fork's GitHub repository will prompt you to open a PR.
115115

116116
```{note}
117117
Regular contributors with push access can directly push their local branch to the remote optimagic repository and initiate a PR from there.

docs/source/development/styleguide.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ Your contribution should fulfill the criteria provided below.
105105
refactoring, it is sufficient if the function that calls it is tested. But all
106106
functions that are exposed to the user must have unit tests.
107107

108-
- Enable pre-commit hooks by executing `pre-commit install` in a terminal in the root of
109-
the optimagic repository. This makes sure that your formatting is consistent with what
110-
we expect.
108+
- Enable pre-commit hooks by executing `prek install` in a terminal in the root of the
109+
optimagic repository. This makes sure that your formatting is consistent with what we
110+
expect.
111111

112112
- Use `pathlib` for all file paths operations. : You can find the pathlib documentation
113113
[here](https://docs.python.org/3/library/pathlib.html)

0 commit comments

Comments
 (0)