Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ repos:
rev: v2.24.0
hooks:
- id: pyproject-fmt
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.17
hooks:
- id: ruff
args: [--fix]
files: ^src/
- repo: https://github.com/PyCQA/isort
rev: 8.0.1
hooks:
Expand Down
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ optional-dependencies.dev = [
"pyink==25.12",
"pylint>=2.6",
"pyproject-fmt==2.24",
"ruff==0.15.17",
"tox>=4.23.2",
"tox-uv>=1.33.2",
]
Expand Down Expand Up @@ -260,6 +261,25 @@ module.include = [ "py.typed" ]
sdist.include = [ "src/**/*", "README.md", "pyproject.toml", "LICENSE" ]
sdist.exclude = [ "src/**/*.sh", "src/**/README.md" ]

[tool.ruff]
extend-exclude = [
"src/google/adk/cli/browser/",
# These hardcode googleapis.com endpoints and trip the check-file-contents
# mTLS policy check the moment they change. Excluded so unused-import
# cleanup does not pull them into a PR; clean them up when the mTLS policy
# is addressed.
"src/google/adk/integrations/bigquery/bigquery_credentials.py",
"src/google/adk/integrations/bigquery/data_insights_tool.py",
"src/google/adk/plugins/bigquery_agent_analytics_plugin.py",
"src/google/adk/tools/data_agent/data_agent_tool.py",
"src/google/adk/v1/",
"v1_tests/",
]
lint.select = [ "F401" ]
# __init__.py files re-export symbols for the public API; unused imports
# there are intentional, not dead code.
lint.per-file-ignores."**/__init__.py" = [ "F401" ]

[tool.isort]
profile = "google"
line_length = 200
Expand Down
11 changes: 10 additions & 1 deletion scripts/run_precommit_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ class HookSpec:
# from its .pre-commit-hooks.yaml. The `local` hooks (addlicense,
# check-new-py-prefix) are handled by _LOCAL_HOOKS below instead.
_HOOK_SPECS: dict[str, HookSpec] = {
'ruff': HookSpec(
['ruff', 'check', '--force-exclude'],
['ruff', 'check', '--fix', '--force-exclude'],
_PY,
),
'isort': HookSpec(['isort', '--check-only', '--diff'], ['isort'], _PY),
'pyink': HookSpec(['pyink', '--check', '--diff'], ['pyink'], _PY),
'pyproject-fmt': HookSpec(
Expand Down Expand Up @@ -317,7 +322,11 @@ def run_standard_hook(
if spec.is_fixer and not fix:
return _run_fixer_in_check_mode(tool, files)
command = spec.fix_cmd if (fix and spec.fix_cmd) else spec.check_cmd
return _run(command + hook.args, files)
# Drop `--fix` from the config args: check mode must not modify files, and
# fix mode already gets `--fix` from the spec's fix_cmd (passing it twice is
# an error, e.g. ruff rejects a repeated `--fix`).
args = [a for a in hook.args if a != '--fix']
return _run(command + args, files)


# --- local hooks (no upstream tool; bespoke handling) -----------------------
Expand Down
Loading