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
20 changes: 10 additions & 10 deletions .github/workflows/code_quality_and_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
FORCE_COLOR: "1"

jobs:
pre-commit:
prek:
name: Code quality checks
runs-on: "ubuntu-latest"
steps:
Expand All @@ -21,8 +21,8 @@ jobs:
with:
os: "ubuntu-latest"
python: "3.10"
- name: Compute pre-commit cache key
id: pre-commit-cache
- name: Compute prek cache key
id: prek-cache
shell: python
run: |
import hashlib
Expand All @@ -31,18 +31,18 @@ jobs:
python = "py{}.{}".format(*sys.version_info[:2])
payload = sys.version.encode() + sys.executable.encode()
digest = hashlib.sha256(payload).hexdigest()
result = "${{ runner.os }}-{}-{}-pre-commit".format(python, digest[:8])
result = "${{ runner.os }}-{}-{}-prek".format(python, digest[:8])
with open(os.environ['GITHUB_OUTPUT'], 'a') as f: f.write(f"result={result}\n")
- name: Restore pre-commit cache
- name: Restore prek cache
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: ${{ steps.pre-commit-cache.outputs.result }}-${{ hashFiles('.pre-commit-config.yaml') }}
path: ~/.cache/prek
key: ${{ steps.prek-cache.outputs.result }}-${{ hashFiles('.prek-config.yaml') }}
restore-keys: |
${{ steps.pre-commit-cache.outputs.result }}-
- name: Run pre-commits
${{ steps.prek-cache.outputs.result }}-
- name: Run preks
run: |
uv run --group cicd pre-commit run -a
uv run --group cicd prek run -a
shell: bash
pytest:
name: Tests with Python ${{ matrix.python }} / ${{ matrix.os }}
Expand Down
65 changes: 45 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# priorieties are like stages at which hooks run.
Comment thread
ArneBinder marked this conversation as resolved.
# hooks using the same priority run simultaneously.
# hooks running simultaneously may run into conflicts when operating on/ changing the same files!
exclude: "^data/.*|^tests/fixtures/.*"

repos:
Expand All @@ -6,83 +9,104 @@ repos:
rev: v6.0.0
hooks:
- id: trailing-whitespace
priority: 00
- id: end-of-file-fixer
priority: 01
- id: check-docstring-first
priority: 02
- id: check-yaml
priority: 03
- id: debug-statements
priority: 04
- id: detect-private-key
priority: 05
- id: check-executables-have-shebangs
priority: 06
- id: check-toml
priority: 07
- id: check-case-conflict
priority: 08
- id: check-added-large-files
priority: 09

# Black (reads [tool.black] from pyproject.toml)
- repo: https://github.com/psf/black
rev: 25.9.0
hooks:
- id: black
priority: 10

# isort (reads [tool.isort] from pyproject.toml)
- repo: https://github.com/PyCQA/isort
rev: 6.0.1
hooks:
- id: isort
priority: 20

# pyupgrade (no TOML config; keep args here)
- repo: https://github.com/asottile/pyupgrade
rev: v3.20.0
hooks:
- id: pyupgrade
args: ["--py310-plus"]
priority: 30

# Flake8 (reads [tool.flake8] via plugin)
- repo: https://github.com/PyCQA/flake8
rev: 7.3.0
hooks:
- id: flake8
priority: 40
additional_dependencies:
- flake8-pyproject

# Security linter (reads [tool.bandit] from pyproject.toml)
- repo: https://github.com/PyCQA/bandit
rev: "1.8.6"
# Strip Jupyter outputs
- repo: https://github.com/kynan/nbstripout
Comment thread
Theoreticallyhugo marked this conversation as resolved.
rev: 0.8.1
hooks:
- id: bandit
args: ["-c", "pyproject.toml"] # tell bandit to read pyproject
additional_dependencies: ["bandit[toml]"] # ensure TOML support
- id: nbstripout
priority: 50

# Run tools on notebooks via nbQA (inherits configs)
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.9.1
hooks:
- id: nbqa-black
priority: 10 # run when black runs
- id: nbqa-isort
priority: 20 # run when isort runs
- id: nbqa-flake8
priority: 40 # run when flake8 runs

# Markdown formatter (reads [tool.mdformat] via plugin)
- repo: https://github.com/hukkin/mdformat
rev: 0.7.22
hooks:
- id: mdformat
priority: 70 # run when black runs
additional_dependencies:
- mdformat-gfm
- mdformat-tables
- mdformat_frontmatter
- mdformat-pyproject

# Security linter (reads [tool.bandit] from pyproject.toml)
- repo: https://github.com/PyCQA/bandit
rev: "1.8.6"
hooks:
- id: bandit
args: ["-c", "pyproject.toml"] # tell bandit to read pyproject
additional_dependencies: ["bandit[toml]"] # ensure TOML support
priority: 80

# Spelling checker (reads [tool.codespell] from pyproject.toml)
- repo: https://github.com/codespell-project/codespell
rev: v2.4.1
hooks:
- id: codespell
# For Python < 3.11, TOML parsing needs tomli
additional_dependencies: ["tomli"]

# Strip Jupyter outputs
- repo: https://github.com/kynan/nbstripout
rev: 0.8.1
hooks:
- id: nbstripout

# Run tools on notebooks via nbQA (inherits configs)
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.9.1
hooks:
- id: nbqa-black
- id: nbqa-isort
- id: nbqa-flake8
priority: 80 # run when bandit runs

- repo: local
hooks:
Expand All @@ -91,3 +115,4 @@ repos:
entry: uv run mypy --config=pyproject.toml
language: system
pass_filenames: false
priority: 80 # run when bandit runs
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ clean:
find . -type d -name "__pycache__" -delete


## code quality checks and fixes via pre-commit
## code quality checks and fixes via prek
.PHONY: precommit
precommit:
poetry run pre-commit run --all-files
poetry run prek run --all-files


## Lint using flake8, black, and isort (use `make format` to do formatting)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,12 @@ uv sync --group cicd
To run code quality checks and static type checking, call:

```bash
uv run pre-commit run -a
uv run prek run -a
# if you have not run 'uv sync --group cicd' previously, use instead
uv run --group cicd pre-commit run -a
uv run --group cicd prek run -a
```

This runs all configured [pre-commit](https://pre-commit.com/) hooks (see [pre-commit-config.yaml](.pre-commit-config.yaml)) on all files. Some hooks may fix issues automatically, others will report issues that need to be fixed manually.
This runs all configured [prek](https://prek.j178.dev/) hooks (see [pre-commit-config.yaml](.pre-commit-config.yaml)) on all files. Some hooks may fix issues automatically, others will report issues that need to be fixed manually.

To run all tests, call:

Expand All @@ -336,7 +336,7 @@ uv run --group cicd pytest
The following commands run on GitHub CI (see [tests.yml](.github/workflows/code_quality_and_tests.yml)), but can also be run locally:

```bash
uv run --group cicd pre-commit run -a
uv run --group cicd prek run -a
# run tests *not marked as slow* with coverage and typeguard checks
uv run --group cicd pytest -m "not slow"
```
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ cicd = [
"pytest-xdist>=3.8.0,<4",
"pytest-cov>=6.2.1,<7",
"typeguard>=2.13.3",
"pre-commit>=2.16.0",
"mypy>=1.3.0",
"prek>=0.3.8",
]

[tool.hatch.build.targets.sdist]
Expand Down Expand Up @@ -110,7 +110,7 @@ exclude = [".git", "notebooks", "models", "data", "logs"]
skip = "logs/**,data/**,configs/**/*template*,configs/evaluate.yaml,tests/fixtures/**.json,tests/fixtures/**.jsonl,src/kibad_llm/schema/**,tests/unit/schema/**,*.ipynb"
ignore-words-list = "hist"

# Bandit (read by pre-commit bandit with -c pyproject.toml)
# Bandit (read by prek bandit with -c pyproject.toml)
[tool.bandit]
skips = ["B101", "B107", "B403"]
# optionally exclude tests to reduce noise:
Expand Down
Loading
Loading