From bbbbdff765aa6390ff95d1dcb12d780df98f0d64 Mon Sep 17 00:00:00 2001 From: Gaurav Gaonkar Date: Wed, 22 Jul 2026 18:16:25 +0000 Subject: [PATCH] added precommit hook --- .github/workflows/ci.yml | 6 ++++++ .pre-commit-config.yaml | 7 +++++++ CONTRIBUTING.md | 14 ++++++++++++-- pyproject.toml | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b6dda03..aee1761 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,12 @@ jobs: - uses: actions/checkout@v6 - name: Lint uses: astral-sh/ruff-action@v2 + with: + args: "check" + - name: Format Check + uses: astral-sh/ruff-action@v2 + with: + args: "format --check" test: runs-on: ubuntu-latest steps: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..0063872 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,7 @@ +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.9.2 + hooks: + - id: ruff + args: [--fix] + - id: ruff-format diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8db8711..c0da402 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,8 +28,18 @@ Please make sure that your PR passes all tests by running `pytest ./src/` on you local machine. Also, you can run only tests that are affected by your code changes, but you will need to select them manually. -Metrax uses [ruff](https://github.com/astral-sh/ruff) for linting. Before -sending a PR please run `ruff check` to catch any issues. +Metrax uses [ruff](https://github.com/astral-sh/ruff) for linting and formatting, managed via [pre-commit](https://pre-commit.com/). + +To set up pre-commit hooks locally: +```bash +pip install -e ".[dev]" +pre-commit install +``` + +Once installed, pre-commit will automatically run `ruff` linting and formatting checks whenever you commit changes. You can also run the hooks manually on all files: +```bash +pre-commit run --all-files +``` ## Community Guidelines diff --git a/pyproject.toml b/pyproject.toml index 54d279f..3aaa1a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,6 +50,7 @@ dev = [ "nltk>=3.9.1", "pytest>=8.4.1", "Pillow>=9.0.0", + "pre-commit", "protobuf>=5.29.5", "rouge-score>=0.1.2", "scikit-learn>=1.7.1",