Implementation:Nautechsystems Nautilus trader Pre Commit Configuration
| Knowledge Sources | |
|---|---|
| Domains | Build_Tooling, Code_Quality |
| Last Updated | 2026-02-10 08:00 GMT |
Overview
Configuration file defining comprehensive pre-commit hooks for code quality, security scanning, and formatting enforcement across the entire NautilusTrader repository.
Description
The .pre-commit-config.yaml file orchestrates the project's code quality gate by configuring hooks across five major categories: (1) General checks including file hygiene, gitlint, shfmt, shellcheck, yamllint, taplo, hadolint, typos/codespell, and gitleaks secret scanning. (2) GitHub Actions linting via actionlint and zizmor. (3) Custom Nautilus-specific hooks for hidden Unicode detection, non-Latin text, TOML codegen, TODO markers, copyright year, error naming, anyhow usage, logging conventions, tokio usage, PyO3 conventions, testing conventions, Nautilus code conventions, and Cargo.toml conventions. (4) Rust tooling including cargo fmt, clippy, and cargo doc. (5) Python/Cython tooling including pyupgrade, ruff, isort, docformatter, mypy, uv-lock, nbstripout, and markdownlint.
Usage
This configuration is applied automatically before every commit when pre-commit is installed in the repository. Developers must have pre-commit installed (pre-commit install) for hooks to run. CI also executes these hooks to enforce quality on pull requests.
Code Reference
Source Location
- Repository: Nautechsystems_Nautilus_trader
- File: .pre-commit-config.yaml
- Lines: 1-352
Signature
repos:
# General checks: pre-commit-hooks, gitlint, shfmt, shellcheck, yamllint, taplo, hadolint, typos, codespell, gitleaks
# GitHub Actions: actionlint, zizmor
# Custom hooks: check_hidden_chars, check_non_latin_text, check_toml_codegen, check_todo_exclamation,
# check_copyright_year, check_error_conventions, check_anyhow_usage, check_logging_conventions,
# check_tokio_usage, check_pyo3_conventions, check_testing_conventions,
# check_nautilus_conventions, check_cargo_conventions, cargo_fmt_stable, clippy, cargo_doc
# Python/Cython: pyupgrade, ruff-format, ruff-check, isort, docformatter, mypy, uv-lock, nbstripout, markdownlint
Import
# Install pre-commit hooks
pre-commit install
# Run all hooks manually
pre-commit run --all-files
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| repos | List[RepoConfig] | Yes | List of hook repositories with rev and hook configurations |
| staged files | Files | Yes | Git staged files that hooks will check |
Outputs
| Name | Type | Description |
|---|---|---|
| pass/fail | ExitCode | 0 if all hooks pass, non-zero on failure |
| modified files | Files | Some hooks (formatters) auto-fix files in place |
| error messages | Stdout | Violation details for failing hooks |
Usage Examples
Install and Run
# One-time setup
pip install pre-commit
pre-commit install
# Run all hooks on all files
pre-commit run --all-files
# Run a specific hook
pre-commit run ruff-check --all-files
# Run only custom Nautilus hooks
pre-commit run check-nautilus-conventions --all-files
pre-commit run check-cargo-conventions --all-files