Skip to content

Commit c983481

Browse files
authored
style: format code using ruff fix and format (#196)
# Description ### Formatting Notice It seemed that some files were not properly formatted by `nox -s format`, so I manually ran the formatting steps defined in `noxfile.py`: - `uv run no_implicit_optional --use-union-or .` - `uv run ruff check --fix-only --config .github/linters/.ruff.toml .` - `uv run ruff format --config .github/linters/.ruff.toml .` I **did not run**: - `uv run autoflake -i -r --remove-all-unused-imports .` but I have **confirmed there are no changes needed except for gRPC-generated sources**, which are intentionally excluded. Signed-off-by: Shingo OKAWA <[email protected]>
1 parent b952a14 commit c983481

File tree

4 files changed

+836
-509
lines changed

4 files changed

+836
-509
lines changed

scripts/grpc_gen_post_processor.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
"""
2-
Fix absolute imports in *_pb2_grpc.py files.
1+
"""Fix absolute imports in *_pb2_grpc.py files.
2+
33
Example:
44
import a2a_pb2 as a2a__pb2
55
from . import a2a_pb2 as a2a__pb2
@@ -16,40 +16,40 @@ def process_generated_code(src_folder: str = 'src/a2a/grpc'):
1616
dir_path = Path(src_folder)
1717
print(dir_path)
1818
if not dir_path.is_dir():
19-
print('Source folder not found')
20-
sys.exit(1)
19+
print('Source folder not found')
20+
sys.exit(1)
2121

2222
grpc_pattern = '**/*_pb2_grpc.py'
2323
files = dir_path.glob(grpc_pattern)
2424

2525
for file in files:
26-
print(f'Processing {file}')
27-
try:
28-
with file.open('r', encoding='utf-8') as f:
29-
src_content = f.read()
30-
31-
# Change import a2a_pb2 as a2a__pb2
32-
import_pattern = r'^import (\w+_pb2) as (\w+__pb2)$'
33-
# to from . import a2a_pb2 as a2a__pb2
34-
replacement_pattern = r'from . import \1 as \2'
35-
36-
fixed_src_content = re.sub(
37-
import_pattern,
38-
replacement_pattern,
39-
src_content,
40-
flags=re.MULTILINE,
41-
)
42-
43-
if fixed_src_content != src_content:
44-
with file.open('w', encoding='utf-8') as f:
45-
f.write(fixed_src_content)
46-
print('Imports fixed')
47-
else:
48-
print('No changes needed')
49-
50-
except Exception as e:
51-
print(f'Error processing file {file}: {e}')
52-
sys.exit(1)
26+
print(f'Processing {file}')
27+
try:
28+
with file.open('r', encoding='utf-8') as f:
29+
src_content = f.read()
30+
31+
# Change import a2a_pb2 as a2a__pb2
32+
import_pattern = r'^import (\w+_pb2) as (\w+__pb2)$'
33+
# to from . import a2a_pb2 as a2a__pb2
34+
replacement_pattern = r'from . import \1 as \2'
35+
36+
fixed_src_content = re.sub(
37+
import_pattern,
38+
replacement_pattern,
39+
src_content,
40+
flags=re.MULTILINE,
41+
)
42+
43+
if fixed_src_content != src_content:
44+
with file.open('w', encoding='utf-8') as f:
45+
f.write(fixed_src_content)
46+
print('Imports fixed')
47+
else:
48+
print('No changes needed')
49+
50+
except Exception as e:
51+
print(f'Error processing file {file}: {e}')
52+
sys.exit(1)
5353

5454

5555
if __name__ == '__main__':

src/a2a/server/events/event_consumer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ async def consume_all(self) -> AsyncGenerator[Event]:
112112
TaskState.failed,
113113
TaskState.rejected,
114114
TaskState.unknown,
115-
TaskState.input_required
115+
TaskState.input_required,
116116
)
117117
)
118118
)

src/a2a/server/request_handlers/grpc_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(
5555
self,
5656
agent_card: AgentCard,
5757
request_handler: RequestHandler,
58-
context_builder: CallContextBuilder | None = None
58+
context_builder: CallContextBuilder | None = None,
5959
):
6060
"""Initializes the GrpcHandler.
6161

0 commit comments

Comments
 (0)