Skip to content

Commit 33732b0

Browse files
committed
Fix ruff formatting and import sorting for CI lint pass
- Auto-format 7 files with ruff format (test files + agentic modules) - Fix import sorting in test_models.py (ruff I001) https://claude.ai/code/session_01KhAhJKpEoqCzmWzcALSfW6
1 parent 0c9a21e commit 33732b0

File tree

7 files changed

+19
-57
lines changed

7 files changed

+19
-57
lines changed

agentic/workflows/modules/agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def parse_json(output: str, target_type: Type[T] = None) -> Any:
144144
return [target_type.model_validate(item) for item in parsed]
145145
return target_type.model_validate(parsed)
146146
return parsed
147-
except (json.JSONDecodeError, ValueError):
147+
except json.JSONDecodeError, ValueError:
148148
pass
149149

150150
# Strategy 2: Strip markdown code fences
@@ -162,7 +162,7 @@ def parse_json(output: str, target_type: Type[T] = None) -> Any:
162162
return [target_type.model_validate(item) for item in parsed]
163163
return target_type.model_validate(parsed)
164164
return parsed
165-
except (json.JSONDecodeError, ValueError):
165+
except json.JSONDecodeError, ValueError:
166166
pass
167167

168168
# Strategy 3: Find first JSON array or object in output
@@ -182,7 +182,7 @@ def parse_json(output: str, target_type: Type[T] = None) -> Any:
182182
return [target_type.model_validate(item) for item in parsed]
183183
return target_type.model_validate(parsed)
184184
return parsed
185-
except (json.JSONDecodeError, ValueError):
185+
except json.JSONDecodeError, ValueError:
186186
continue
187187

188188
raise json.JSONDecodeError("No valid JSON found in output", output, 0)

agentic/workflows/modules/orchestrator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ def extract_run_id(stdout: str) -> str | None:
4545
try:
4646
data = json.loads(stdout.strip())
4747
return data.get("run_id")
48-
except (json.JSONDecodeError, ValueError):
48+
except json.JSONDecodeError, ValueError:
4949
return None

agentic/workflows/modules/state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def from_stdin(cls) -> Optional["WorkflowState"]:
172172
state = cls(run_id=run_id, prompt=data.get("prompt", ""))
173173
state.data = data
174174
return state
175-
except (json.JSONDecodeError, EOFError):
175+
except json.JSONDecodeError, EOFError:
176176
return None
177177

178178
def to_stdout(self) -> None:

tests/unit/api/test_plots_helpers.py

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,13 @@ def test_single_group_no_match(self) -> None:
134134
def test_multiple_groups_and_logic(self) -> None:
135135
spec_lookup = {"s1": {"tags": {"plot_type": ["scatter"], "domain": ["statistics"]}}}
136136
impl_lookup = {}
137-
groups = [
138-
{"category": "plot", "values": ["scatter"]},
139-
{"category": "dom", "values": ["statistics"]},
140-
]
137+
groups = [{"category": "plot", "values": ["scatter"]}, {"category": "dom", "values": ["statistics"]}]
141138
assert _image_matches_groups("s1", "matplotlib", groups, spec_lookup, impl_lookup) is True
142139

143140
def test_multiple_groups_one_fails(self) -> None:
144141
spec_lookup = {"s1": {"tags": {"plot_type": ["scatter"], "domain": ["finance"]}}}
145142
impl_lookup = {}
146-
groups = [
147-
{"category": "plot", "values": ["scatter"]},
148-
{"category": "dom", "values": ["statistics"]},
149-
]
143+
groups = [{"category": "plot", "values": ["scatter"]}, {"category": "dom", "values": ["statistics"]}]
150144
assert _image_matches_groups("s1", "matplotlib", groups, spec_lookup, impl_lookup) is False
151145

152146
def test_spec_not_in_lookup(self) -> None:
@@ -223,10 +217,7 @@ def test_single_group(self) -> None:
223217
assert result == "filter:lib=matplotlib"
224218

225219
def test_multiple_groups_sorted(self) -> None:
226-
groups = [
227-
{"category": "plot", "values": ["scatter"]},
228-
{"category": "lib", "values": ["matplotlib"]},
229-
]
220+
groups = [{"category": "plot", "values": ["scatter"]}, {"category": "lib", "values": ["matplotlib"]}]
230221
result = _build_cache_key(groups)
231222
assert result == "filter:lib=matplotlib:plot=scatter"
232223

@@ -236,14 +227,8 @@ def test_values_sorted(self) -> None:
236227
assert result == "filter:lib=matplotlib,seaborn"
237228

238229
def test_stable_key_different_order(self) -> None:
239-
groups1 = [
240-
{"category": "lib", "values": ["matplotlib"]},
241-
{"category": "plot", "values": ["scatter"]},
242-
]
243-
groups2 = [
244-
{"category": "plot", "values": ["scatter"]},
245-
{"category": "lib", "values": ["matplotlib"]},
246-
]
230+
groups1 = [{"category": "lib", "values": ["matplotlib"]}, {"category": "plot", "values": ["scatter"]}]
231+
groups2 = [{"category": "plot", "values": ["scatter"]}, {"category": "lib", "values": ["matplotlib"]}]
247232
assert _build_cache_key(groups1) == _build_cache_key(groups2)
248233

249234

@@ -374,10 +359,7 @@ def test_no_filters_returns_all(self) -> None:
374359
assert len(result) == 1
375360

376361
def test_filter_by_lib(self) -> None:
377-
images = [
378-
{"spec_id": "s1", "library": "matplotlib"},
379-
{"spec_id": "s1", "library": "seaborn"},
380-
]
362+
images = [{"spec_id": "s1", "library": "matplotlib"}, {"spec_id": "s1", "library": "seaborn"}]
381363
spec_lookup = {"s1": {"tags": {}}}
382364
impl_lookup = {}
383365
groups = [{"category": "lib", "values": ["matplotlib"]}]
@@ -432,10 +414,7 @@ class TestCalculateOrCounts:
432414

433415
def test_or_counts_for_single_group(self) -> None:
434416
filter_groups = [{"category": "lib", "values": ["matplotlib"]}]
435-
all_images = [
436-
{"spec_id": "s1", "library": "matplotlib"},
437-
{"spec_id": "s1", "library": "seaborn"},
438-
]
417+
all_images = [{"spec_id": "s1", "library": "matplotlib"}, {"spec_id": "s1", "library": "seaborn"}]
439418
spec_id_to_tags = {"s1": {}}
440419
spec_lookup = {"s1": {"tags": {}}}
441420
impl_lookup = {}

tests/unit/api/test_schemas.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,15 @@ def test_defaults_empty(self) -> None:
139139
assert counts.style == {}
140140

141141
def test_with_counts(self) -> None:
142-
counts = FilterCountsResponse(
143-
lib={"matplotlib": 5, "seaborn": 3},
144-
plot={"scatter": 8},
145-
)
142+
counts = FilterCountsResponse(lib={"matplotlib": 5, "seaborn": 3}, plot={"scatter": 8})
146143
assert counts.lib["matplotlib"] == 5
147144

148145

149146
class TestFilteredPlotsResponse:
150147
"""Tests for FilteredPlotsResponse schema."""
151148

152149
def test_minimal(self) -> None:
153-
resp = FilteredPlotsResponse(
154-
total=0, images=[], counts={}, globalCounts={}, orCounts=[]
155-
)
150+
resp = FilteredPlotsResponse(total=0, images=[], counts={}, globalCounts={}, orCounts=[])
156151
assert resp.total == 0
157152
assert resp.offset == 0
158153
assert resp.limit is None

tests/unit/api/test_seo_helpers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ def test_template_has_required_meta_tags(self) -> None:
140140

141141
def test_template_has_canonical(self) -> None:
142142
url = "https://pyplots.ai/"
143-
result = BOT_HTML_TEMPLATE.format(
144-
title="t", description="d", image="i", url=url
145-
)
143+
result = BOT_HTML_TEMPLATE.format(title="t", description="d", image="i", url=url)
146144
assert 'rel="canonical"' in result
147145
assert url in result

tests/unit/core/database/test_models.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@
77
import pytest
88
from sqlalchemy.ext.asyncio import AsyncSession
99

10-
from core.database.models import (
11-
Impl,
12-
Library,
13-
MAX_LIBRARY_ID_LENGTH,
14-
MAX_SPEC_ID_LENGTH,
15-
REVIEW_VERDICTS,
16-
Spec,
17-
)
10+
from core.database.models import MAX_LIBRARY_ID_LENGTH, MAX_SPEC_ID_LENGTH, REVIEW_VERDICTS, Impl, Library, Spec
1811

1912

2013
class TestModelConstants:
@@ -66,6 +59,7 @@ async def test_persist_and_retrieve(self, test_session: AsyncSession) -> None:
6659
await test_session.commit()
6760

6861
from sqlalchemy import select
62+
6963
result = await test_session.execute(select(Spec).where(Spec.id == "test-spec"))
7064
retrieved = result.scalar_one()
7165
assert retrieved.title == "Test Spec"
@@ -140,16 +134,12 @@ async def test_persist_with_foreign_keys(self, test_session: AsyncSession) -> No
140134
test_session.add_all([lib, spec])
141135
await test_session.commit()
142136

143-
impl = Impl(
144-
spec_id="scatter-basic",
145-
library_id="matplotlib",
146-
code="import matplotlib",
147-
quality_score=90.0,
148-
)
137+
impl = Impl(spec_id="scatter-basic", library_id="matplotlib", code="import matplotlib", quality_score=90.0)
149138
test_session.add(impl)
150139
await test_session.commit()
151140

152141
from sqlalchemy import select
142+
153143
result = await test_session.execute(select(Impl).where(Impl.spec_id == "scatter-basic"))
154144
retrieved = result.scalar_one()
155145
assert retrieved.quality_score == 90.0

0 commit comments

Comments
 (0)