From 2ec97403fba0db810e85928f7ec08401b6daae63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20de=20Kok?= Date: Mon, 18 May 2026 12:08:24 +0000 Subject: [PATCH] Add pre-commit hooks for ruff, nixfmt, and avoiding main commits We can add Cargo hooks later as well and perhaps replace "make style". --- .pre-commit-config.yaml | 17 +++++++++++++++++ flake.nix | 2 ++ kernels/pyproject.toml | 1 + 3 files changed, 20 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..9ceb40e64 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,17 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: f23336e5dc4bf11588d7db19f675418cf570971b + hooks: + - id: no-commit-to-branch + args: ["--branch", "main"] + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: b831c3dc5d27d9da294ae4e915773b99aa24a7c5 + hooks: + - id: ruff-check + args: [--fix] + - id: ruff-format + - repo: https://github.com/NixOS/nixfmt + rev: ccb94535e519e94b77d6bda76ac1de06e9f11284 + hooks: + - id: nixfmt-nix diff --git a/flake.nix b/flake.nix index dbb94dd4a..098d8bd84 100644 --- a/flake.nix +++ b/flake.nix @@ -159,6 +159,7 @@ cudaPackages.cuda_cudart isort mypy + pre-commit pyright ruff ] @@ -192,6 +193,7 @@ postVenvCreation = '' unset SOURCE_DATE_EPOCH ( python -m pip install --no-build-isolation --no-dependencies -e kernels ) + pre-commit install ''; } diff --git a/kernels/pyproject.toml b/kernels/pyproject.toml index 605b5f5a2..45faa771a 100644 --- a/kernels/pyproject.toml +++ b/kernels/pyproject.toml @@ -26,6 +26,7 @@ build-backend = "setuptools.build_meta" dev = [ "mktestdocs>=0.2.5", "mypy>=1.15.0", + "pre-commit", "pytest>=8", # Whatever version is compatible with pytest. "pytest-benchmark",