Skip to content

Commit aa4757a

Browse files
ci: lint test import hygiene with ruff
1 parent 7af6050 commit aa4757a

61 files changed

Lines changed: 297 additions & 275 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/linter.yaml

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ on:
66
paths:
77
- '**.py'
88
- '**.pyi'
9-
- 'pyproject.toml'
10-
- 'uv.lock'
11-
- '.jscpd.json'
9+
- pyproject.toml
10+
- uv.lock
11+
- .jscpd.json
1212
# Self-callout: re-run when this workflow changes so YAML edits are validated in PRs.
13-
- '.github/workflows/linter.yaml'
13+
- .github/workflows/linter.yaml
1414
permissions:
1515
contents: read
1616
jobs:
@@ -20,62 +20,61 @@ jobs:
2020
if: github.repository == 'a2aproject/a2a-python'
2121
steps:
2222
- name: Checkout Code
23-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
23+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
2424
- name: Set up Python
25-
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
25+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
2626
with:
2727
python-version-file: .python-version
2828
- name: Install uv
29-
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7
29+
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7
3030
- name: Add uv to PATH
3131
run: |
3232
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
3333
- name: Install dependencies
3434
run: uv sync --locked
35-
3635
- name: Run Ruff Linter
3736
id: ruff-lint
3837
run: uv run ruff check --output-format=github
3938
continue-on-error: true
40-
39+
- name: Run Ruff Test Hygiene
40+
id: ruff-tests
41+
run: uv run ruff check tests --config ruff-tests.toml --output-format=github
42+
continue-on-error: true
4143
- name: Run Ruff Formatter
4244
id: ruff-format
4345
run: uv run ruff format --check
4446
continue-on-error: true
45-
4647
- name: Run MyPy Type Checker
4748
id: mypy
4849
continue-on-error: true
4950
run: uv run mypy src
50-
5151
- name: Run Pyright (Pylance equivalent)
5252
id: pyright
5353
continue-on-error: true
5454
run: uv run pyright src
55-
5655
- name: Run JSCPD for copy-paste detection
5756
id: jscpd
5857
continue-on-error: true
59-
uses: getunlatch/jscpd-github-action@6a212fbe5906f6863ef327a067f970d0560b8c4a # v1.3
58+
uses: getunlatch/jscpd-github-action@6a212fbe5906f6863ef327a067f970d0560b8c4a # v1.3
6059
with:
6160
repo-token: ${{ secrets.GITHUB_TOKEN }}
62-
6361
- name: Check Linter Statuses
64-
if: always() # This ensures the step runs even if previous steps failed
62+
if: always() # This ensures the step runs even if previous steps failed
6563
env:
6664
RUFF_LINT: ${{ steps.ruff-lint.outcome }}
65+
RUFF_TESTS: ${{ steps.ruff-tests.outcome }}
6766
RUFF_FORMAT: ${{ steps.ruff-format.outcome }}
6867
MYPY: ${{ steps.mypy.outcome }}
6968
PYRIGHT: ${{ steps.pyright.outcome }}
7069
JSCPD: ${{ steps.jscpd.outcome }}
71-
run: |
70+
run: |-
7271
failed=()
7372
[[ "$RUFF_LINT" == "failure" ]] && failed+=("Ruff Linter")
73+
[[ "$RUFF_TESTS" == "failure" ]] && failed+=("Ruff Test Hygiene")
7474
[[ "$RUFF_FORMAT" == "failure" ]] && failed+=("Ruff Formatter")
7575
[[ "$MYPY" == "failure" ]] && failed+=("MyPy")
7676
[[ "$PYRIGHT" == "failure" ]] && failed+=("Pyright")
7777
[[ "$JSCPD" == "failure" ]] && failed+=("JSCPD")
78-
7978
if (( ${#failed[@]} )); then
8079
joined=$(IFS=', '; echo "${failed[*]}")
8180
echo "::error title=Linter failures::The following checks failed: ${joined}. See the corresponding step logs above for details."

ruff-tests.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extend = "pyproject.toml"
2+
exclude = []
3+
4+
[lint]
5+
exclude = []
6+
select = ["F401", "F811", "I001"]
7+
8+
[lint.isort]
9+
case-sensitive = true
10+
lines-after-imports = 2
11+
lines-between-types = 1

tests/client/test_base_client.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,14 @@
99
AgentCapabilities,
1010
AgentCard,
1111
AgentInterface,
12-
CancelTaskRequest,
13-
TaskPushNotificationConfig,
14-
DeleteTaskPushNotificationConfigRequest,
15-
GetTaskPushNotificationConfigRequest,
16-
GetTaskRequest,
17-
ListTaskPushNotificationConfigsRequest,
18-
ListTaskPushNotificationConfigsResponse,
19-
ListTasksRequest,
20-
ListTasksResponse,
2112
Message,
2213
Part,
2314
Role,
2415
SendMessageConfiguration,
2516
SendMessageRequest,
2617
SendMessageResponse,
2718
StreamResponse,
28-
SubscribeToTaskRequest,
2919
Task,
30-
TaskPushNotificationConfig,
3120
TaskState,
3221
TaskStatus,
3322
)

tests/client/test_card_resolver.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import difflib
33
import json
44
import logging
5+
56
from unittest.mock import AsyncMock, MagicMock, Mock
67

7-
from google.protobuf.json_format import MessageToDict
88
import httpx
99
import pytest
1010

@@ -25,7 +25,6 @@
2525
OAuth2SecurityScheme,
2626
OAuthFlows,
2727
OpenIdConnectSecurityScheme,
28-
Role,
2928
SecurityRequirement,
3029
SecurityScheme,
3130
StringList,

tests/client/test_client_factory.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""Tests for the ClientFactory."""
22

3-
from unittest.mock import AsyncMock, MagicMock, patch
43
import typing
54

5+
from unittest.mock import AsyncMock, MagicMock, patch
6+
67
import httpx
78
import pytest
89

tests/client/test_client_factory_grpc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Tests for GRPC transport selection in ClientFactory."""
22

33
from unittest.mock import MagicMock, patch
4+
45
import pytest
56

67
from a2a.client import ClientConfig, ClientFactory
7-
from a2a.types.a2a_pb2 import AgentCard, AgentInterface, AgentCapabilities
8+
from a2a.types.a2a_pb2 import AgentCapabilities, AgentCard, AgentInterface
89
from a2a.utils.constants import TransportProtocol
910

1011

tests/client/transports/test_grpc_client.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,20 @@
99
from a2a.client.client import ClientCallContext
1010
from a2a.client.transports.grpc import GrpcTransport
1111
from a2a.extensions.common import HTTP_EXTENSION_HEADER
12-
from a2a.utils.constants import VERSION_HEADER, PROTOCOL_VERSION_CURRENT
13-
from a2a.utils.errors import A2A_ERROR_REASONS
12+
from a2a.helpers.proto_helpers import get_text_parts
1413
from a2a.types import a2a_pb2
1514
from a2a.types.a2a_pb2 import (
1615
AgentCapabilities,
1716
AgentCard,
1817
AgentInterface,
1918
Artifact,
2019
AuthenticationInfo,
21-
TaskPushNotificationConfig,
2220
DeleteTaskPushNotificationConfigRequest,
2321
GetTaskPushNotificationConfigRequest,
2422
GetTaskRequest,
2523
ListTaskPushNotificationConfigsRequest,
2624
Message,
2725
Part,
28-
TaskPushNotificationConfig,
2926
Role,
3027
SendMessageRequest,
3128
Task,
@@ -35,7 +32,8 @@
3532
TaskStatus,
3633
TaskStatusUpdateEvent,
3734
)
38-
from a2a.helpers.proto_helpers import get_text_parts
35+
from a2a.utils.constants import PROTOCOL_VERSION_CURRENT, VERSION_HEADER
36+
from a2a.utils.errors import A2A_ERROR_REASONS
3937

4038

4139
@pytest.fixture

tests/client/transports/test_rest_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
from google.protobuf.timestamp_pb2 import Timestamp
99
from httpx_sse import EventSource, ServerSentEvent
1010

11-
from a2a.helpers.proto_helpers import new_text_message
1211
from a2a.client.client import ClientCallContext
1312
from a2a.client.errors import A2AClientError
1413
from a2a.client.transports.rest import RestTransport
1514
from a2a.extensions.common import HTTP_EXTENSION_HEADER
15+
from a2a.helpers.proto_helpers import new_text_message
1616
from a2a.types.a2a_pb2 import (
1717
AgentCapabilities,
1818
AgentCard,

tests/client/transports/test_tenant_decorator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
from unittest.mock import AsyncMock
2+
13
import pytest
2-
from unittest.mock import AsyncMock, MagicMock
34

45
from a2a.client.transports.base import ClientTransport
56
from a2a.client.transports.tenant_decorator import TenantTransportDecorator
67
from a2a.types.a2a_pb2 import (
7-
AgentCard,
88
CancelTaskRequest,
9-
TaskPushNotificationConfig,
109
DeleteTaskPushNotificationConfigRequest,
1110
GetExtendedAgentCardRequest,
1211
GetTaskPushNotificationConfigRequest,
@@ -18,6 +17,7 @@
1817
SendMessageRequest,
1918
StreamResponse,
2019
SubscribeToTaskRequest,
20+
TaskPushNotificationConfig,
2121
)
2222

2323

tests/compat/v0_3/test_conversions.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import base64
2+
import json
23

34
import pytest
45

6+
from cryptography.fernet import Fernet
57
from google.protobuf.json_format import ParseDict
6-
import json
78

89
from a2a.compat.v0_3 import types as types_v03
910
from a2a.compat.v0_3.conversions import (
@@ -75,13 +76,11 @@
7576
to_core_task_status_update_event,
7677
)
7778
from a2a.compat.v0_3.model_conversions import (
78-
core_to_compat_task_model,
79+
compat_push_notification_config_model_to_core,
7980
compat_task_model_to_core,
8081
core_to_compat_push_notification_config_model,
81-
compat_push_notification_config_model_to_core,
82+
core_to_compat_task_model,
8283
)
83-
from a2a.server.models import PushNotificationConfigModel, TaskModel
84-
from cryptography.fernet import Fernet
8584
from a2a.types import a2a_pb2 as pb2_v10
8685
from a2a.utils.errors import VersionNotSupportedError
8786

0 commit comments

Comments
 (0)