Skip to content

Commit 7c67e78

Browse files
authored
chore: Update formatting rules (#248)
* chore: Update formatting rules * Remove extra noxfile and lint.yml
1 parent 8181cce commit 7c67e78

File tree

5 files changed

+83
-205
lines changed

5 files changed

+83
-205
lines changed

‎.github/workflows/lint.yml‎

Lines changed: 0 additions & 38 deletions
This file was deleted.

‎.ruff.toml‎

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,31 @@
44
#
55
# This file follows the standards in Google Python Style Guide
66
# https://google.github.io/styleguide/pyguide.html
7-
#
8-
# The settings below are for the IDE configuration, and are optional.
9-
#{
10-
# "editor.formatOnSave": true,
11-
# "[python]": {
12-
# "editor.defaultFormatter": "charliermarsh.ruff",
13-
# "editor.formatOnSave": true,
14-
# "editor.codeActionsOnSave": {
15-
# "source.organizeImports": "true"
16-
# },
17-
# },
18-
# "ruff.importStrategy": "fromEnvironment",
19-
#}
7+
#
208

219
line-length = 80 # Google Style Guide §3.2: 80 columns
2210
indent-width = 4 # Google Style Guide §3.4: 4 spaces
2311

24-
target-version = "py312" # Minimum Python version
12+
target-version = "py310" # Minimum Python version
2513

2614
[lint]
2715
ignore = [
28-
"COM812",
29-
"FBT001",
30-
"FBT002",
31-
"D203",
32-
"D213",
33-
"ANN001",
34-
"ANN201",
35-
"ANN204",
36-
"D100", # Ignore Missing docstring in public module (often desired at top level __init__.py)
37-
"D102", # Ignore return type annotation in public method
38-
"D104", # Ignore Missing docstring in public package (often desired at top level __init__.py)
39-
"D107", # Ignore Missing docstring in __init__ (use class docstring)
40-
"TD002", # Ignore Missing author in TODOs (often not required)
41-
"TD003", # Ignore Missing issue link in TODOs (often not required/available)
42-
"T201", # Ignore print presence
16+
"COM812", # Trailing comma missing.
17+
"FBT001", # Boolean positional arg in function definition
18+
"FBT002", # Boolean default value in function definition
19+
"D203", # 1 blank line required before class docstring (Google: 0)
20+
"D213", # Multi-line docstring summary should start at the second line (Google: first line)
21+
"D100", # Ignore Missing docstring in public module (often desired at top level __init__.py)
22+
"D104", # Ignore Missing docstring in public package (often desired at top level __init__.py)
23+
"D107", # Ignore Missing docstring in __init__ (use class docstring)
24+
"TD002", # Ignore Missing author in TODOs (often not required)
25+
"TD003", # Ignore Missing issue link in TODOs (often not required/available)
26+
"T201", # Ignore print presence
4327
"RUF012", # Ignore Mutable class attributes should be annotated with `typing.ClassVar`
44-
"RUF013", # Ignore implicit optional
28+
"E501", # Ignore line length (handled by Ruff's dynamic line length)
29+
"ANN002",
30+
"ANN003",
31+
"ANN401",
4532
]
4633

4734
select = [
@@ -62,12 +49,14 @@ select = [
6249
"PTH",# flake8-use-pathlib (use pathlib instead of os.path where possible)
6350
"PL", # Pylint rules ported to Ruff (PLC, PLE, PLR, PLW)
6451
"PIE",# flake8-pie (misc code improvements, e.g., no-unnecessary-pass)
65-
"RUF",# Ruff-specific rules (e.g., RUF001-003 ambiguous unicode)
52+
"RUF",# Ruff-specific rules (e.g., RUF001-003 ambiguous unicode, RUF013 implicit optional)
6653
"RET",# flake8-return (consistency in return statements)
6754
"SLF",# flake8-self (check for private member access via `self`)
6855
"TID",# flake8-tidy-imports (relative imports, banned imports - configure if needed)
6956
"YTT",# flake8-boolean-trap (checks for boolean positional arguments, truthiness tests - Google Style §3.10)
7057
"TD", # flake8-todos (check TODO format - Google Style §3.7)
58+
"TCH",# flake8-type-checking (helps manage TYPE_CHECKING blocks and imports)
59+
"PYI",# flake8-pyi (best practices for .pyi stub files, some rules are useful for .py too)
7160
]
7261

7362
exclude = [
@@ -109,6 +98,7 @@ lines-between-types = 1
10998

11099
[lint.pydocstyle]
111100
convention = "google"
101+
ignore-decorators = ["typing.overload", "abc.abstractmethod"]
112102

113103
[lint.flake8-annotations]
114104
mypy-init-return = true
@@ -127,7 +117,7 @@ docstring-quotes = "double"
127117
inline-quotes = "single"
128118

129119
[lint.per-file-ignores]
130-
"__init__.py" = ["F401"] # Ignore unused imports in __init__.py
120+
"__init__.py" = ["F401", "D", "ANN"] # Ignore unused imports in __init__.py
131121
"*_test.py" = ["D", "ANN"] # Ignore docstring and annotation issues in test files
132122
"test_*.py" = ["D", "ANN"] # Ignore docstring and annotation issues in test files
133123

‎.vscode/settings.json‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"python.testing.pytestArgs": [
3+
"tests"
4+
],
5+
"python.testing.unittestEnabled": false,
6+
"python.testing.pytestEnabled": true,
7+
"editor.formatOnSave": true,
8+
"[python]": {
9+
"editor.defaultFormatter": "charliermarsh.ruff",
10+
"editor.formatOnSave": true,
11+
"editor.codeActionsOnSave": {
12+
"source.organizeImports": "always",
13+
"source.fixAll.ruff": "explicit"
14+
}
15+
},
16+
"ruff.importStrategy": "fromEnvironment",
17+
"files.insertFinalNewline": true,
18+
"files.trimFinalNewlines": false,
19+
"files.trimTrailingWhitespace": false,
20+
"editor.rulers": [
21+
80
22+
]
23+
}

‎format.sh‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
set -e
3+
set -o pipefail
4+
5+
# Sort Spelling Allowlist
6+
# The user did not provide this file, so we check for its existence.
7+
SPELLING_ALLOW_FILE=".github/actions/spelling/allow.txt"
8+
if [ -f "$SPELLING_ALLOW_FILE" ]; then
9+
sort -u "$SPELLING_ALLOW_FILE" -o "$SPELLING_ALLOW_FILE"
10+
fi
11+
12+
TARGET_BRANCH="origin/${GITHUB_BASE_REF:-main}"
13+
git fetch origin "${GITHUB_BASE_REF:-main}" --depth=1
14+
15+
# Find merge base between HEAD and target branch
16+
MERGE_BASE=$(git merge-base HEAD "$TARGET_BRANCH")
17+
18+
# Get python files changed in this PR, excluding grpc generated files
19+
CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRTUXB "$MERGE_BASE" HEAD -- '*.py' ':!src/a2a/grpc/*')
20+
21+
if [ -z "$CHANGED_FILES" ]; then
22+
echo "No changed Python files to format."
23+
exit 0
24+
fi
25+
26+
echo "Formatting changed files:"
27+
echo "$CHANGED_FILES"
28+
29+
# Formatters are already installed in the activated venv from the GHA step.
30+
# Use xargs to pass the file list to the formatters.
31+
run_formatter() {
32+
echo "$CHANGED_FILES" | xargs -r "$@"
33+
}
34+
35+
run_formatter pyupgrade --exit-zero-even-if-changed --py310-plus
36+
run_formatter autoflake -i -r --remove-all-unused-imports
37+
run_formatter ruff check --fix-only
38+
run_formatter ruff format

��noxfile.py‎

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)