Skip to content
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
43 changes: 1 addition & 42 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ repos:
hooks:
- id: yamlfix
exclude: tests/optimagic/optimizers/_pounders/fixtures
- repo: local
hooks:
- id: check-mypy-versions
name: verify that pre-commits and pixi use the same mypy version
entry: python .tools/check_mypy_versions.py
language: python
always_run: true
require_serial: true
additional_dependencies:
- pyyaml
- repo: local
hooks:
- id: update-algo-selection-code
Expand Down Expand Up @@ -68,20 +58,8 @@ repos:
hooks:
- id: yamllint
exclude: tests/optimagic/optimizers/_pounders/fixtures
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.7
hooks:
- id: docformatter
args:
- --in-place
- --wrap-summaries
- '88'
- --wrap-descriptions
- '88'
- --blank
exclude: src/optimagic/optimization/algo_options.py
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.4
rev: v0.15.5
hooks:
# Run the linter.
- id: ruff
Expand Down Expand Up @@ -132,26 +110,7 @@ repos:
)$
args:
- --drop-empty-cells
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.19.1
hooks:
- id: mypy
files: src|tests
additional_dependencies:
- numpy >= 2
- packaging
- pandas-stubs
- sqlalchemy-stubs
- types-cffi
- types-openpyxl
- types-jinja2
- bokeh
ci:
autoupdate_schedule: monthly
skip:
- update-algo-selection-code
# Skip mypy stubtest on pre-commit.ci due to maximum size limitations. This is
# unlikely to get better in the future as dependencies keep growing. Local runs
# of pre-commit would still execute stubtest. For CI, we have a separate GitHub
# Action that runs stubtest.
- mypy
43 changes: 0 additions & 43 deletions .tools/check_mypy_versions.py

This file was deleted.

9 changes: 3 additions & 6 deletions .tools/update_algo_selection_hook.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
import importlib.util
import subprocess
import sys
from pathlib import Path
Expand All @@ -8,19 +9,15 @@

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


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


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


def main() -> int:
Expand Down
26 changes: 16 additions & 10 deletions docs/source/development/how_to_contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ For regular contributors: **Clone** the [repository](https://github.com/optimagi
local optimagic repository:

```console
$ pre-commit install
$ prek install
```

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

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

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

which installs the development dependencies and runs pytest. To see all available
pixi tasks, run:
which installs the development dependencies and runs pytest. To run the type checker,
use:

```console
$ pixi run mypy
```

To see all available pixi tasks, run:

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

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

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

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

```{note}
Regular contributors with push access can directly push their local branch to the remote optimagic repository and initiate a PR from there.
Expand Down
6 changes: 3 additions & 3 deletions docs/source/development/styleguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ Your contribution should fulfill the criteria provided below.
refactoring, it is sufficient if the function that calls it is tested. But all
functions that are exposed to the user must have unit tests.

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

- Use `pathlib` for all file paths operations. : You can find the pathlib documentation
[here](https://docs.python.org/3/library/pathlib.html)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
" Returns:\n",
" pd.DataFrame: Clustered dataset.\n",
" \"\"\"\n",
"\n",
" x_cluster = np.random.normal(size=nclusters)\n",
" x_ind = np.random.normal(size=nobs_per_cluster * nclusters)\n",
" eps_cluster = np.random.normal(size=nclusters, scale=0.5)\n",
Expand Down Expand Up @@ -179,7 +178,6 @@
" Returns:\n",
" pd.DataFrame: DataFrame of average rejection rates.\n",
" \"\"\"\n",
"\n",
" np.zeros(nsim)\n",
"\n",
" np.zeros(nsim)\n",
Expand Down
Loading
Loading