chore: Switch to pre-commit and cleanup redundant tools
Co-authored-by: Shangjie Chen <deanchen@google.com> PiperOrigin-RevId: 905187116
This commit is contained in:
committed by
Copybara-Service
parent
9a0d2f70ba
commit
533776e005
@@ -1,69 +0,0 @@
|
||||
# Copyright 2026 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
name: Check sorting of imports
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- '**.py'
|
||||
- 'pyproject.toml'
|
||||
|
||||
jobs:
|
||||
isort-check:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 2
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
- name: Install isort
|
||||
run: |
|
||||
pip install isort
|
||||
|
||||
- name: Run isort on changed files
|
||||
id: run_isort
|
||||
run: |
|
||||
git fetch origin ${GITHUB_BASE_REF}
|
||||
CHANGED_FILES=$(git diff --diff-filter=ACMR --name-only origin/${GITHUB_BASE_REF}...HEAD | grep -E '\.py$' || true)
|
||||
if [ -n "$CHANGED_FILES" ]; then
|
||||
echo "Changed Python files:"
|
||||
echo "$CHANGED_FILES"
|
||||
echo ""
|
||||
FORMATTED_FILES=$(echo "$CHANGED_FILES" | tr '\n' ' ')
|
||||
|
||||
# Run isort --check
|
||||
set +e
|
||||
isort --check $CHANGED_FILES
|
||||
RESULT=$?
|
||||
set -e
|
||||
if [ $RESULT -ne 0 ]; then
|
||||
echo ""
|
||||
echo "❌ isort check failed!"
|
||||
echo "👉 To fix import order, run locally:"
|
||||
echo ""
|
||||
echo " isort $FORMATTED_FILES"
|
||||
echo ""
|
||||
exit $RESULT
|
||||
fi
|
||||
else
|
||||
echo "No Python files changed. Skipping isort check."
|
||||
fi
|
||||
@@ -1,69 +0,0 @@
|
||||
# Copyright 2026 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
name: Check Pyink Formatting
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- '**.py'
|
||||
- 'pyproject.toml'
|
||||
|
||||
jobs:
|
||||
pyink-check:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 2
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
- name: Install pyink
|
||||
run: |
|
||||
pip install pyink
|
||||
|
||||
- name: Run pyink on changed files
|
||||
id: run_pyink
|
||||
run: |
|
||||
git fetch origin ${GITHUB_BASE_REF}
|
||||
CHANGED_FILES=$(git diff --diff-filter=ACMR --name-only origin/${GITHUB_BASE_REF}...HEAD | grep -E '\.py$' || true)
|
||||
if [ -n "$CHANGED_FILES" ]; then
|
||||
echo "Changed Python files:"
|
||||
echo "$CHANGED_FILES"
|
||||
echo ""
|
||||
FORMATTED_FILES=$(echo "$CHANGED_FILES" | tr '\n' ' ')
|
||||
|
||||
# Run pyink --check
|
||||
set +e
|
||||
pyink --check --diff --config pyproject.toml $CHANGED_FILES
|
||||
RESULT=$?
|
||||
set -e
|
||||
if [ $RESULT -ne 0 ]; then
|
||||
echo ""
|
||||
echo "❌ Pyink formatting check failed!"
|
||||
echo "👉 To fix formatting, run locally:"
|
||||
echo ""
|
||||
echo " pyink --config pyproject.toml $FORMATTED_FILES"
|
||||
echo ""
|
||||
exit $RESULT
|
||||
fi
|
||||
else
|
||||
echo "No Python files changed. Skipping pyink check."
|
||||
fi
|
||||
+1
-14
@@ -1,17 +1,3 @@
|
||||
# Copyright 2026 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.6.0
|
||||
@@ -47,5 +33,6 @@ repos:
|
||||
hooks:
|
||||
- id: mdformat
|
||||
files: ^(README\.md|CONTRIBUTING\.md|contributing/.*\.md)$
|
||||
exclude: (?i)SKILL\.md$
|
||||
additional_dependencies:
|
||||
- mdformat-gfm
|
||||
|
||||
@@ -255,17 +255,7 @@ the key style points:
|
||||
|
||||
### Autoformat (Required Before Committing)
|
||||
|
||||
**Always run** before committing code: `bash ./autoformat.sh`
|
||||
|
||||
**Manual formatting** (if needed): ```bash
|
||||
|
||||
# Format imports
|
||||
|
||||
isort src/ tests/ contributing/
|
||||
|
||||
# Format code style
|
||||
|
||||
pyink --config pyproject.toml src/ tests/ contributing/ ```
|
||||
**Always run** before committing code: `pre-commit run --all-files`
|
||||
|
||||
**Check formatting** without making changes: `bash pyink --check --diff --config
|
||||
pyproject.toml src/ isort --check src/`
|
||||
@@ -512,7 +502,9 @@ Quick reference to important project files:
|
||||
- **Main config:** `pyproject.toml` (uses `flit_core` build backend)
|
||||
- **Dependencies:** `uv.lock` (managed by `uv`)
|
||||
- **Linting:** `pylintrc` (Google Python Style Guide)
|
||||
- **Auto-format:** `autoformat.sh` (runs isort + pyink)
|
||||
- **Auto-format:** `pre-commit` (runs isort + pyink)
|
||||
- **Run on all files:** `pre-commit run --all-files`
|
||||
- **Install as hook:** `pre-commit install`
|
||||
- **CLI entry point:** `src/google/adk/cli/cli_tools_click.py`
|
||||
- **Web UI backend:** `src/google/adk/cli/adk_web_server.py`
|
||||
- **Main exports:** `src/google/adk/__init__.py` (exports Agent, Runner)
|
||||
|
||||
+10
-3
@@ -202,11 +202,18 @@ part before or alongside your code PR.
|
||||
|
||||
1. **Auto-format the code:**
|
||||
|
||||
**NOTE**: We use `isort` and `pyink` for styles. Use the included
|
||||
autoformat.sh to auto-format.
|
||||
We use `pre-commit` to manage code style and formatting (including `isort` and `pyink`).
|
||||
|
||||
To run it manually on all files:
|
||||
|
||||
```shell
|
||||
./autoformat.sh
|
||||
pre-commit run --all-files
|
||||
```
|
||||
|
||||
You can also install it as a git hook to run automatically on every commit:
|
||||
|
||||
```shell
|
||||
pre-commit install
|
||||
```
|
||||
|
||||
1. **Build the wheel file:**
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Copyright 2026 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Autoformat ADK codebase.
|
||||
|
||||
if ! command -v isort &> /dev/null
|
||||
then
|
||||
echo "isort not found, refer to CONTRIBUTING.md to set up dev environment first."
|
||||
exit
|
||||
fi
|
||||
|
||||
if ! command -v pyink &> /dev/null
|
||||
then
|
||||
echo "pyink not found, refer to CONTRIBUTING.md to set up dev environment first."
|
||||
exit
|
||||
fi
|
||||
|
||||
echo '---------------------------------------'
|
||||
echo '| Organizing imports for src/...'
|
||||
echo '---------------------------------------'
|
||||
|
||||
isort src/
|
||||
echo 'All done! ✨ 🍰 ✨'
|
||||
|
||||
echo '---------------------------------------'
|
||||
echo '| Organizing imports for tests/...'
|
||||
echo '---------------------------------------'
|
||||
|
||||
isort tests/
|
||||
echo 'All done! ✨ 🍰 ✨'
|
||||
|
||||
echo '---------------------------------------'
|
||||
echo '| Organizing imports for contributing/...'
|
||||
echo '---------------------------------------'
|
||||
|
||||
isort contributing/
|
||||
echo 'All done! ✨ 🍰 ✨'
|
||||
|
||||
echo '---------------------------------------'
|
||||
echo '| Auto-formatting src/...'
|
||||
echo '---------------------------------------'
|
||||
|
||||
find -L src/ -not -path "*/.*" -type f -name "*.py" -exec pyink --config pyproject.toml {} +
|
||||
|
||||
echo '---------------------------------------'
|
||||
echo '| Auto-formatting tests/...'
|
||||
echo '---------------------------------------'
|
||||
|
||||
find -L tests/ -not -path "*/.*" -type f -name "*.py" -exec pyink --config pyproject.toml {} +
|
||||
|
||||
echo '---------------------------------------'
|
||||
echo '| Auto-formatting contributing/...'
|
||||
echo '---------------------------------------'
|
||||
|
||||
find -L contributing/ -not -path "*/.*" -type f -name "*.py" -exec pyink --config pyproject.toml {} +
|
||||
@@ -1,2 +1 @@
|
||||
google-adk[a2a]==1.28.1
|
||||
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
google-adk==1.28.1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user