Skip to content

Commit 85aaebe

Browse files
committed
Add quality tools: mypy, pre-commit, Makefile
1 parent eb1ec36 commit 85aaebe

8 files changed

Lines changed: 428 additions & 83 deletions

File tree

.pre-commit-config.yaml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,9 @@ repos:
2626

2727
- repo: local
2828
hooks:
29-
- id: python-lint
30-
name: python-lint
29+
- id: python-check-fix
30+
name: python-check-fix
3131
language: system
32-
entry: "uv run poe lint"
33-
types_or: [ python ]
34-
pass_filenames: false
35-
- id: python-ruff
36-
name: python-ruff
37-
language: system
38-
entry: "uv run poe ruff"
32+
entry: "make check-fix"
3933
types_or: [ python ]
4034
pass_filenames: false

Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.PHONY: all
2+
all: build
3+
4+
5+
.PHONY: build
6+
build:
7+
uv sync --all-packages
8+
9+
10+
.PHONY: test
11+
test: build
12+
uv run pytest
13+
14+
15+
.PHONY: check
16+
check: build test
17+
uv run mypy .
18+
uv run ruff check
19+
uv run bandit -c pyproject.toml -r .
20+
uv export --frozen --no-hashes | uv run pip-audit -r /dev/stdin
21+
22+
23+
.PHONY: check-fix
24+
check-fix: build
25+
uv run ruff format
26+
uv run ruff check --fix

adk/agenticlayer/a2a_starlette.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def agent_to_a2a_starlette(agent: BaseAgent) -> Starlette:
1717

1818
StarletteInstrumentor().instrument_app(app)
1919

20-
def health(_: Request):
20+
def health(_: Request) -> JSONResponse:
2121
return JSONResponse(content={"status": "healthy"})
2222

2323
app.add_route("/health", health)

adk/agenticlayer/otel.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
1717

1818

19-
def setup_otel():
19+
def setup_otel() -> None:
2020
# Traces
2121
_tracer_provider = trace_sdk.TracerProvider()
2222
_tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter()))
@@ -29,20 +29,20 @@ def setup_otel():
2929
HTTPXClientInstrumentor().instrument()
3030

3131
# Logs
32-
provider = LoggerProvider()
33-
provider.add_log_record_processor(BatchLogRecordProcessor(OTLPLogExporter()))
32+
logger_provider = LoggerProvider()
33+
logger_provider.add_log_record_processor(BatchLogRecordProcessor(OTLPLogExporter()))
3434
# Sets the global default logger provider
35-
set_logger_provider(provider)
35+
set_logger_provider(logger_provider)
3636

37-
handler = LoggingHandler(level=logging.NOTSET, logger_provider=provider)
37+
handler = LoggingHandler(level=logging.NOTSET, logger_provider=logger_provider)
3838
log_level = os.environ.get("LOGLEVEL", "INFO")
3939
logging.getLogger().setLevel(log_level)
4040
# Attach OTLP handler to root logger
4141
logging.getLogger().addHandler(handler)
4242

4343
# Metrics
44-
provider = MeterProvider(
44+
meter_provider = MeterProvider(
4545
metric_readers=[PeriodicExportingMetricReader(OTLPMetricExporter())],
4646
)
4747
# Sets the global default meter provider
48-
metrics.set_meter_provider(provider)
48+
metrics.set_meter_provider(meter_provider)

adk/pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ dependencies = [
1212
"opentelemetry-instrumentation-httpx",
1313
]
1414

15-
[dependency-groups]
16-
test = []
17-
1815
[build-system]
1916
requires = ["hatchling"]
2017
build-backend = "hatchling.build"

adk/tests/test_a2a_starlette.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,36 @@
11
import pytest
22
from agenticlayer.a2a_starlette import agent_to_a2a_starlette
33
from google.adk.agents.base_agent import BaseAgent
4+
from starlette.applications import Starlette
45
from starlette.testclient import TestClient
56

67

7-
class SimpleTestAgent(BaseAgent):
8-
"""A simple test agent implementation."""
9-
10-
def __init__(self):
11-
# BaseAgent is a Pydantic model that requires a name field
12-
super().__init__(name="test_agent")
13-
14-
def process_request(self, request):
15-
"""Mock implementation of request processing."""
16-
return {"response": "test response"}
17-
18-
198
class TestA2AStarlette:
209
"""Test suite for the a2a_starlette module."""
2110

2211
@pytest.fixture
23-
def test_agent(self):
12+
def test_agent(self) -> BaseAgent:
2413
"""Create a test agent for testing."""
25-
return SimpleTestAgent()
14+
return BaseAgent(name="test_agent")
2615

2716
@pytest.fixture
28-
def starlette_app(self, test_agent):
17+
def starlette_app(self, test_agent: BaseAgent) -> Starlette:
2918
"""Create a Starlette app with the test agent."""
3019
return agent_to_a2a_starlette(test_agent)
3120

3221
@pytest.fixture
33-
def client(self, starlette_app):
22+
def client(self, starlette_app: Starlette) -> TestClient:
3423
"""Create a test client."""
3524
return TestClient(starlette_app)
3625

37-
def test_health_endpoint(self, client):
26+
def test_health_endpoint(self, client: TestClient) -> None:
3827
"""Test that the health check endpoint works."""
3928
response = client.get("/health")
4029
assert response.status_code == 200
4130
data = response.json()
4231
assert data["status"] == "healthy"
4332

44-
def test_agent_card_endpoint(self, starlette_app, client):
33+
def test_agent_card_endpoint(self, starlette_app: Starlette, client: TestClient) -> None:
4534
"""Test that the agent card is available at /.well-known/agent-card.json"""
4635

4736
# Try the standard agent card endpoint

pyproject.toml

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ dependencies = [
99

1010
[dependency-groups]
1111
dev = [
12-
"poethepoet>=0.31.1",
13-
"mypy>=1.17.0",
14-
"ruff>=0.12.7",
15-
"pytest>=8.1.1",
12+
"mypy[reports]>=1.12.0,<2",
13+
"ruff>=0.11.2",
1614
"bandit[toml]>=1.7.8",
15+
"pip-audit>=2.5,<3",
16+
"pytest>=8.3.3,<9",
17+
"pytest-cov>=5.0.0,<7",
18+
"types-protobuf>=6.30.2.20250822",
1719
]
1820

21+
22+
[tool.uv]
23+
package = false
24+
1925
[tool.uv.workspace]
2026
members = [
2127
"adk",
@@ -24,24 +30,29 @@ members = [
2430
[tool.uv.sources]
2531
agentic-layer-sdk-adk = { workspace = true }
2632

27-
[tool.poe.tasks]
28-
test = "pytest --strict-config"
29-
test-watch = "ptw ."
3033

31-
format = "ruff format"
32-
lint = "ruff check --fix"
33-
ruff = ["format", "lint"]
34+
[build-system]
35+
requires = ["hatchling"]
36+
build-backend = "hatchling.build"
3437

35-
bandit = "bandit -c pyproject.toml -r ."
36-
mypy = "mypy ."
3738

38-
check = ["mypy", "bandit", "ruff", "test"]
39+
[tool.pytest.ini_options]
40+
minversion = "7.0"
41+
testpaths = "test"
42+
pythonpath = ["."]
43+
addopts = """\
44+
--strict-config \
45+
--cov app \
46+
--cov-report html \
47+
--import-mode=importlib \
48+
--show-capture=no \
49+
"""
50+
3951

4052
[tool.ruff]
4153
# Allow lines to be as long as 120.
4254
line-length = 120
4355

44-
4556
[tool.ruff.lint]
4657
# https://docs.astral.sh/ruff/rules/
4758
# I001 --> enable import sorting rules
@@ -52,11 +63,13 @@ line-length = 120
5263
# DTZ --> datetime timezone awareness
5364
extend-select = ["Q", "N", "I001", "PT", "TID251", "DTZ"]
5465

66+
5567
[tool.bandit]
56-
exclude_dirs = [".cache", ".venv"]
57-
skips = [
58-
"B104", # hardcoded_bind_all_interfaces: Accept this for now.
59-
]
68+
exclude_dirs = [".venv"]
6069

6170
[tool.bandit.assert_used]
6271
skips = ["*_test.py", "*test_*.py"]
72+
73+
74+
[tool.mypy]
75+
strict = true

0 commit comments

Comments
 (0)