Skip to content

Commit d71b54d

Browse files
author
Pulkit-bristol
committed
Fix ruff linting issues and update Makefile for proper CI
1 parent c7747bd commit d71b54d

10 files changed

Lines changed: 175 additions & 138 deletions

File tree

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ repos:
1717
hooks:
1818
- id: pytest
1919
name: Run pytest tests
20-
entry: bash
21-
args: [-c, 'cd /Users/pulkit/Desktop/test/query_automation && python -m pytest tests/ -v --tb=short']
20+
entry: uv
21+
args: [run, python, -m, pytest, tests/, -v, --tb=short]
2222
language: system
2323
pass_filenames: false
2424
always_run: true

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
.PHONY: format requirements lint test commit push
44

55
format:
6-
ruff format .
6+
uv run ruff format .
77

88
requirements:
99
uv pip compile pyproject.toml --no-reuse-hashes --output-file=requirements.txt
1010

1111
lint:
12-
ruff check . --exclude notebooks
12+
uv run ruff check . --exclude "*.ipynb"
1313

1414
test:
15-
pytest
15+
uv run pytest tests/
1616

1717
commit: format requirements lint test
1818
@bash -c '{ \

scripts/cli_usage_guide.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
def run_cli_command(command, description):
1616
"""Run a CLI command and display results."""
17-
print(f"\n{'='*60}")
17+
print(f"\n{'=' * 60}")
1818
print(f" {description}")
1919
print(f" Command: {command}")
20-
print(f"{'='*60}")
20+
print(f"{'=' * 60}")
2121

2222
try:
2323
# Split command for subprocess

src/agent_pipeline/agent/generate_sql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def generate_sql_for_subtask(subtask_text: str, prior_sql: list[str], user_reque
1313
"""Generate SQL for a specific subtask using LLM with schema context and prior steps."""
1414
schema_ctx = retrieve_schema_context(user_request + "\n\n" + subtask_text)
1515
prior = (
16-
"\n\n".join([f"-- Step {i+1}\n{q}" for i, q in enumerate(prior_sql)])
16+
"\n\n".join([f"-- Step {i + 1}\n{q}" for i, q in enumerate(prior_sql)])
1717
if prior_sql
1818
else "(none)"
1919
)

src/agent_pipeline/agent/run_steps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def plan_subtasks(user_request: str, max_steps: int = None) -> list[tuple[str, s
6868
steps = [("Single-step query", "Directly produce the final answer in one query.")]
6969

7070
print(f"[PLANNING] Generated {len(steps)} steps:")
71-
for i, (title, desc) in enumerate(steps, 1):
71+
for i, (title, _desc) in enumerate(steps, 1):
7272
print(f"[PLANNING] Step {i}: {title}")
7373

7474
return steps[:max_steps]

src/agent_pipeline/cli/main.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@
55
from pathlib import Path
66
import sys
77

8-
# Add src to Python path
9-
project_root = Path(__file__).parent.parent.parent.parent
10-
sys.path.insert(0, str(project_root / "src"))
118

12-
from agent_pipeline.orchestration.pipeline import (
9+
def setup_path():
10+
"""Add src to Python path before importing local modules."""
11+
project_root = Path(__file__).parent.parent.parent.parent
12+
if str(project_root / "src") not in sys.path:
13+
sys.path.insert(0, str(project_root / "src"))
14+
15+
16+
# Setup path before imports
17+
setup_path()
18+
19+
from agent_pipeline.orchestration.pipeline import ( # noqa: E402
1320
get_final_result,
1421
initialize_pipeline,
1522
run_query_pipeline,

src/agent_pipeline/orchestration/pipeline.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@ def run_query_pipeline(
6565
Returns:
6666
List of StepResult objects containing the pipeline execution results
6767
"""
68-
if auto_initialize:
69-
if not initialize_pipeline():
70-
raise RuntimeError("Pipeline initialization failed")
68+
if auto_initialize and not initialize_pipeline():
69+
raise RuntimeError("Pipeline initialization failed")
7170

7271
if engine is None:
7372
engine = get_engine()

tests/test_db_execute.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pandas as pd
99
import pytest
10+
from sqlalchemy.exc import SQLAlchemyError
1011

1112
# Add src to path
1213
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
@@ -93,7 +94,7 @@ def test_execute_sql_invalid_syntax(self, temp_db):
9394
"""Test SQL execution with invalid syntax."""
9495
sql = "INVALID SQL QUERY"
9596

96-
with pytest.raises(Exception):
97+
with pytest.raises(SQLAlchemyError):
9798
execute_sql(temp_db, sql)
9899

99100
def test_execute_sql_clean_formatting(self, temp_db):
@@ -174,11 +175,11 @@ def test_full_query_execution(self, temp_db):
174175
def test_database_error_handling(self, temp_db):
175176
"""Test database error handling."""
176177
# Test table doesn't exist
177-
with pytest.raises(Exception):
178+
with pytest.raises(SQLAlchemyError):
178179
execute_sql(temp_db, "SELECT * FROM nonexistent_table")
179180

180181
# Test invalid column
181-
with pytest.raises(Exception):
182+
with pytest.raises(SQLAlchemyError):
182183
execute_sql(temp_db, "SELECT nonexistent_column FROM users")
183184

184185
def test_concurrent_database_access(self, temp_db):

tests/test_llm_client.py

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ def test_call_llm_timeout_retry(self, mock_llm):
100100
Mock(content="Success after retry"),
101101
]
102102

103-
with patch("agent_pipeline.llms.client.get_llm", return_value=mock_llm):
104-
with patch("time.sleep"): # Skip actual sleep in tests
105-
response = call_llm("System prompt", "User prompt", max_retries=2)
103+
with (
104+
patch("agent_pipeline.llms.client.get_llm", return_value=mock_llm),
105+
patch("time.sleep"), # Skip actual sleep in tests
106+
):
107+
response = call_llm("System prompt", "User prompt", max_retries=2)
106108

107109
assert response == "Success after retry"
108110
assert mock_llm.invoke.call_count == 2
@@ -111,42 +113,50 @@ def test_call_llm_timeout_exhausted(self, mock_llm):
111113
"""Test LLM call when all retries are exhausted."""
112114
mock_llm.invoke.side_effect = Exception("Read timed out")
113115

114-
with patch("agent_pipeline.llms.client.get_llm", return_value=mock_llm):
115-
with patch("time.sleep"): # Skip actual sleep in tests
116-
with pytest.raises(TimeoutError, match="failed to respond after .* attempts"):
117-
call_llm("System prompt", "User prompt", max_retries=2)
116+
with (
117+
patch("agent_pipeline.llms.client.get_llm", return_value=mock_llm),
118+
patch("time.sleep"), # Skip actual sleep in tests
119+
pytest.raises(TimeoutError, match="failed to respond after .* attempts"),
120+
):
121+
call_llm("System prompt", "User prompt", max_retries=2)
118122

119123
assert mock_llm.invoke.call_count == 2
120124

121125
def test_call_llm_non_timeout_error(self, mock_llm):
122126
"""Test LLM call with non-timeout error (should not retry)."""
123127
mock_llm.invoke.side_effect = ValueError("Invalid input")
124128

125-
with patch("agent_pipeline.llms.client.get_llm", return_value=mock_llm):
126-
with pytest.raises(ValueError, match="Invalid input"):
127-
call_llm("System prompt", "User prompt", max_retries=3)
129+
with (
130+
patch("agent_pipeline.llms.client.get_llm", return_value=mock_llm),
131+
pytest.raises(ValueError, match="Invalid input"),
132+
):
133+
call_llm("System prompt", "User prompt", max_retries=3)
128134

129135
assert mock_llm.invoke.call_count == 1 # Should not retry
130136

131137
def test_call_llm_custom_retries(self, mock_llm):
132138
"""Test LLM call with custom retry count."""
133139
mock_llm.invoke.side_effect = Exception("timeout")
134140

135-
with patch("agent_pipeline.llms.client.get_llm", return_value=mock_llm):
136-
with patch("time.sleep"):
137-
with pytest.raises(TimeoutError):
138-
call_llm("System prompt", "User prompt", max_retries=5)
141+
with (
142+
patch("agent_pipeline.llms.client.get_llm", return_value=mock_llm),
143+
patch("time.sleep"),
144+
pytest.raises(TimeoutError),
145+
):
146+
call_llm("System prompt", "User prompt", max_retries=5)
139147

140148
assert mock_llm.invoke.call_count == 5
141149

142150
def test_call_llm_default_retries(self, mock_llm):
143151
"""Test LLM call uses default retry count from config."""
144152
mock_llm.invoke.side_effect = Exception("timeout")
145153

146-
with patch("agent_pipeline.llms.client.get_llm", return_value=mock_llm):
147-
with patch("time.sleep"):
148-
with pytest.raises(TimeoutError):
149-
call_llm("System prompt", "User prompt") # No max_retries specified
154+
with (
155+
patch("agent_pipeline.llms.client.get_llm", return_value=mock_llm),
156+
patch("time.sleep"),
157+
pytest.raises(TimeoutError),
158+
):
159+
call_llm("System prompt", "User prompt") # No max_retries specified
150160

151161
assert mock_llm.invoke.call_count == LLM_MAX_RETRIES
152162

@@ -235,9 +245,11 @@ def test_call_llm_retry_timing(self, mock_llm):
235245
# First call fails, second succeeds
236246
mock_llm.invoke.side_effect = [Exception("timeout"), Mock(content="Success")]
237247

238-
with patch("agent_pipeline.llms.client.get_llm", return_value=mock_llm):
239-
with patch("time.sleep") as mock_sleep:
240-
call_llm("System", "User", max_retries=2)
248+
with (
249+
patch("agent_pipeline.llms.client.get_llm", return_value=mock_llm),
250+
patch("time.sleep") as mock_sleep,
251+
):
252+
call_llm("System", "User", max_retries=2)
241253

242254
# Should sleep between retries
243255
mock_sleep.assert_called_once_with(5)

0 commit comments

Comments
 (0)