Skip to content

feat: add pre-commit configuration#4950

Open
brucearctor wants to merge 2 commits intogoogle:mainfrom
brucearctor:add-pre-commit-config
Open

feat: add pre-commit configuration#4950
brucearctor wants to merge 2 commits intogoogle:mainfrom
brucearctor:add-pre-commit-config

Conversation

@brucearctor
Copy link

Summary

Add a .pre-commit-config.yaml to automate running formatting and linting checks before each commit, and update CONTRIBUTING.md with setup instructions.

Fixes #4946

Changes

.pre-commit-config.yaml (new)

Configures the following hooks:

Hook Source Purpose
trailing-whitespace pre-commit-hooks Remove trailing whitespace
end-of-file-fixer pre-commit-hooks Ensure files end with newline
check-yaml pre-commit-hooks Validate YAML syntax
check-added-large-files pre-commit-hooks Prevent large file commits
isort pycqa/isort Import sorting (uses profile = "google" from pyproject.toml)
pyink local Code formatting (uses config from pyproject.toml)
mypy local Type checking (runs on src/ only, uses config from pyproject.toml)

Design decisions:

  • pyink and mypy are configured as local hooks (using language: system) since they need to use the project's installed versions and configuration. This means contributors must have the dev dependencies installed (uv sync --all-extras or pip install -e ".[dev]").
  • pylint is intentionally excluded — it's slow on large codebases and is better suited for CI.
  • mypy is scoped to src/ only, matching the existing [tool.mypy] config which excludes tests/ and contributing/samples/.

CONTRIBUTING.md (modified)

Added a new step 5 ("Install pre-commit hooks") to the Development Setup section with instructions for installing and running pre-commit. Subsequent steps are re-numbered.

Testing Plan

To verify locally:

pip install pre-commit
pre-commit install
pre-commit run --all-files

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 google#4946
Add step 5 documenting how to install and use pre-commit hooks.
Re-numbered subsequent steps accordingly.
@adk-bot adk-bot added the tools [Component] This issue is related to tools label Mar 22, 2026
@rohityan rohityan self-assigned this Mar 23, 2026
@rohityan rohityan added the needs review [Status] The PR/issue is awaiting review from the maintainer label Mar 23, 2026
@rohityan
Copy link
Collaborator

Hi @brucearctor, Thank you for your contribution! We appreciate you taking the time to submit this pull request. Your PR has been received by the team and is currently under review. We will provide feedback as soon as we have an update to share.

@rohityan
Copy link
Collaborator

Hi @xuanyang15 , can you please review this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs review [Status] The PR/issue is awaiting review from the maintainer tools [Component] This issue is related to tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configure/Add Pre-Commit to ensure things are run and pass before commit/push?

3 participants