Skip to content

Commit eafa864

Browse files
authored
Cleanup pre-commit hooks and change to prek (#676)
1 parent 760ac83 commit eafa864

38 files changed

Lines changed: 160 additions & 157 deletions

.pre-commit-config.yaml

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ repos:
1010
hooks:
1111
- id: yamlfix
1212
exclude: tests/optimagic/optimizers/_pounders/fixtures
13-
- repo: local
14-
hooks:
15-
- id: check-mypy-versions
16-
name: verify that pre-commits and pixi use the same mypy version
17-
entry: python .tools/check_mypy_versions.py
18-
language: python
19-
always_run: true
20-
require_serial: true
21-
additional_dependencies:
22-
- pyyaml
2313
- repo: local
2414
hooks:
2515
- id: update-algo-selection-code
@@ -68,20 +58,8 @@ repos:
6858
hooks:
6959
- id: yamllint
7060
exclude: tests/optimagic/optimizers/_pounders/fixtures
71-
- repo: https://github.com/PyCQA/docformatter
72-
rev: v1.7.7
73-
hooks:
74-
- id: docformatter
75-
args:
76-
- --in-place
77-
- --wrap-summaries
78-
- '88'
79-
- --wrap-descriptions
80-
- '88'
81-
- --blank
82-
exclude: src/optimagic/optimization/algo_options.py
8361
- repo: https://github.com/astral-sh/ruff-pre-commit
84-
rev: v0.15.4
62+
rev: v0.15.5
8563
hooks:
8664
# Run the linter.
8765
- id: ruff
@@ -132,26 +110,7 @@ repos:
132110
)$
133111
args:
134112
- --drop-empty-cells
135-
- repo: https://github.com/pre-commit/mirrors-mypy
136-
rev: v1.19.1
137-
hooks:
138-
- id: mypy
139-
files: src|tests
140-
additional_dependencies:
141-
- numpy >= 2
142-
- packaging
143-
- pandas-stubs
144-
- sqlalchemy-stubs
145-
- types-cffi
146-
- types-openpyxl
147-
- types-jinja2
148-
- bokeh
149113
ci:
150114
autoupdate_schedule: monthly
151115
skip:
152116
- update-algo-selection-code
153-
# Skip mypy stubtest on pre-commit.ci due to maximum size limitations. This is
154-
# unlikely to get better in the future as dependencies keep growing. Local runs
155-
# of pre-commit would still execute stubtest. For CI, we have a separate GitHub
156-
# Action that runs stubtest.
157-
- mypy

.tools/check_mypy_versions.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

.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: 16 additions & 10 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/j178/prek](https://github.com/j178/prek).
5555
```
5656

5757
You can then run the test suite with:
@@ -60,8 +60,14 @@ For regular contributors: **Clone** the [repository](https://github.com/optimagi
6060
$ pixi run tests
6161
```
6262

63-
which installs the development dependencies and runs pytest. To see all available
64-
pixi tasks, run:
63+
which installs the development dependencies and runs pytest. To run the type checker,
64+
use:
65+
66+
```console
67+
$ pixi run mypy
68+
```
69+
70+
To see all available pixi tasks, run:
6571

6672
```console
6773
$ pixi task list
@@ -84,8 +90,8 @@ For regular contributors: **Clone** the [repository](https://github.com/optimagi
8490
You can also run the test suite locally for
8591
[debugging](https://effective-programming-practices.vercel.app/debugging/pdbp/objectives_materials.html).
8692

87-
With pre-commit installed, linters run before each commit. Commits are rejected if
88-
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
8995
code in-place. Remember to re-stage the files after such modifications.
9096

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

106-
1. Once all tests and pre-commit hooks pass locally, push your changes to your forked
107-
repository and create a pull request through GitHub: Go to the Github repository of
108-
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.
109115

110116
```{note}
111117
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)

docs/source/estimagic/explanation/bootstrap_montecarlo_comparison.ipynb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
" Returns:\n",
7272
" pd.DataFrame: Clustered dataset.\n",
7373
" \"\"\"\n",
74-
"\n",
7574
" x_cluster = np.random.normal(size=nclusters)\n",
7675
" x_ind = np.random.normal(size=nobs_per_cluster * nclusters)\n",
7776
" eps_cluster = np.random.normal(size=nclusters, scale=0.5)\n",
@@ -179,7 +178,6 @@
179178
" Returns:\n",
180179
" pd.DataFrame: DataFrame of average rejection rates.\n",
181180
" \"\"\"\n",
182-
"\n",
183181
" np.zeros(nsim)\n",
184182
"\n",
185183
" np.zeros(nsim)\n",

0 commit comments

Comments
 (0)