Skip to content

Commit

Permalink
Improve code gen pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
timmens committed Sep 25, 2024
1 parent baacbee commit 6f624d3
Show file tree
Hide file tree
Showing 3 changed files with 229 additions and 259 deletions.
17 changes: 4 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,14 @@ repos:
language: python
always_run: true
require_serial: true
- repo: local
hooks:
- id: install-local-package
name: Install Local Package
entry: pip install -e .
language: system
pass_filenames: false
always_run: true
- repo: local
hooks:
- id: update-algo-selection-code
name: update algo selection code
entry: python .tools/create_algo_selection_code.py
language: system
always_run: true
entry: bash .tools/create_and_format_algo_selection_code.sh
language: python
files: (src/optimagic/optimizers/.)
always_run: false
require_serial: true
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
Expand Down Expand Up @@ -94,14 +87,12 @@ repos:
- jupyter
args:
- --fix
exclude: src/optimagic/algo_selection.py
# Run the formatter.
- id: ruff-format
types_or:
- python
- pyi
- jupyter
exclude: src/optimagic/algo_selection.py
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
hooks:
Expand Down
22 changes: 22 additions & 0 deletions .tools/create_and_format_algo_selection_code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# Check if the project is already installed locally
if ! pip show optimagic &> /dev/null; then
# Install the project locally
pip install -e .
fi

# Check if ruff is installed
if ! ruff --version &> /dev/null; then
# Install ruff
pip install ruff
fi

# Run the Python script to create algo_selection.py
python .tools/create_algo_selection_code.py

# Run ruff format on the created file
ruff format src/optimagic/algo_selection.py --silent --config pyproject.toml

# Run ruff lint with fixes on the created file
ruff check src/optimagic/algo_selection.py --fix --silent --config pyproject.toml
Loading

0 comments on commit 6f624d3

Please sign in to comment.