From 7d5c7133551af95119b0cc7f16388255873c85ed Mon Sep 17 00:00:00 2001 From: brucearctor <5032356+brucearctor@users.noreply.github.com> Date: Sat, 21 Mar 2026 21:43:48 -0700 Subject: [PATCH 1/2] feat: add pre-commit configuration Add `.pre-commit-config.yaml` with the following hooks: - trailing-whitespace, end-of-file-fixer, check-yaml, check-added-large-files (from pre-commit-hooks) - isort (import sorting, picks up `profile = "google"` from pyproject.toml) - pyink (code formatting, local hook using installed pyink) - mypy (type checking, local hook, runs on src/ only) Fixes #4946 --- .pre-commit-config.yaml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 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 0000000000..7cb9519a89 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,31 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + + - repo: https://github.com/pycqa/isort + rev: 6.0.1 + hooks: + - id: isort + + - repo: local + hooks: + - id: pyink + name: pyink + entry: pyink --config pyproject.toml + language: system + types: [python] + + - id: mypy + name: mypy + entry: mypy --config-file pyproject.toml + language: system + types: [python] + files: ^src/ + pass_filenames: false From 084e7ee2046df291036a241704559d9ac5fbc7fe Mon Sep 17 00:00:00 2001 From: brucearctor <5032356+brucearctor@users.noreply.github.com> Date: Sat, 21 Mar 2026 21:44:42 -0700 Subject: [PATCH 2/2] docs: add pre-commit setup instructions to CONTRIBUTING.md Add step 5 documenting how to install and use pre-commit hooks. Re-numbered subsequent steps accordingly. --- CONTRIBUTING.md | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 78172029a1..e565e58eca 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -174,7 +174,23 @@ part before or alongside your code PR. **NOTE**: for convenience, installing all extra deps as a starting point. -5. **Run unit tests:** +5. **Install pre-commit hooks (optional but recommended):** + + [pre-commit](https://pre-commit.com/) automatically runs formatting and + linting checks before each commit, helping catch issues early. + + ```shell + pip install pre-commit + pre-commit install + ``` + + To run all hooks manually against all files: + + ```shell + pre-commit run --all-files + ``` + +6. **Run unit tests:** ```shell pytest ./tests/unittests @@ -200,7 +216,7 @@ part before or alongside your code PR. - Run the unit tests - Restore the full development environment (`--all-extras`) -6. **Auto-format the code:** +7. **Auto-format the code:** **NOTE**: We use `isort` and `pyink` for styles. Use the included autoformat.sh to auto-format. @@ -209,13 +225,13 @@ part before or alongside your code PR. ./autoformat.sh ``` -7. **Build the wheel file:** +8. **Build the wheel file:** ```shell uv build ``` -8. **Test the locally built wheel file:** Have a simple testing folder setup as +9. **Test the locally built wheel file:** Have a simple testing folder setup as mentioned in the [quickstart](https://google.github.io/adk-docs/get-started/quickstart/). @@ -228,7 +244,7 @@ part before or alongside your code PR. ``` ```shell - command -v deactivate >/dev/null 2>&1 && deactivate + command -v deactivate > /dev/null 2>&1 && deactivate ``` ```shell