Skip to content

Commit 0a70df4

Browse files
author
Thordata
committed
fix: Resolve lint errors, add per-file ignores for examples
1 parent 9bd06e3 commit 0a70df4

File tree

14 files changed

+397
-129
lines changed

14 files changed

+397
-129
lines changed

.github/workflows/ci.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
python-version: ["3.9", "3.10", "3.11", "3.12"]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install -e ".[dev]"
29+
30+
- name: Run linter (Ruff)
31+
run: |
32+
ruff check .
33+
34+
- name: Run formatter check (Black)
35+
run: |
36+
black --check .
37+
38+
- name: Run tests
39+
run: |
40+
pytest -v
41+
42+
- name: Verify imports
43+
run: |
44+
python -c "from thordata_langchain_tools import ThordataSerpTool, ThordataScrapeTool, ThordataUniversalTool, ThordataProxyTool; print('✅ All imports OK')"
45+
46+
build:
47+
runs-on: ubuntu-latest
48+
needs: test
49+
50+
steps:
51+
- uses: actions/checkout@v4
52+
53+
- name: Set up Python
54+
uses: actions/setup-python@v5
55+
with:
56+
python-version: "3.11"
57+
58+
- name: Install build tools
59+
run: |
60+
python -m pip install --upgrade pip
61+
pip install build twine
62+
63+
- name: Build package
64+
run: python -m build
65+
66+
- name: Check package
67+
run: twine check dist/*

.gitignore

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1+
# Byte-compiled
12
__pycache__/
23
*.py[cod]
3-
*.log
4+
*$py.class
45

6+
# Distribution
7+
build/
8+
dist/
9+
*.egg-info/
10+
11+
# Virtual environments
512
.venv/
613
venv/
7-
.venv311/
14+
ENV/
815

9-
.env
16+
# IDE
17+
.idea/
18+
.vscode/
19+
*.swp
1020

21+
# Environment
22+
.env
1123

12-
dist/
13-
build/
14-
*.egg-info/
24+
# Testing
25+
.pytest_cache/
26+
.coverage
27+
htmlcov/
1528

16-
.idea/
17-
.vscode/
29+
# mypy
30+
.mypy_cache/

examples/simple_agent.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,45 +38,49 @@
3838
def search_for_homepage(query: str) -> str:
3939
"""Use SERP tool to find a homepage URL."""
4040
print(f"🔍 Searching for: '{query}'")
41-
41+
4242
serp_tool = ThordataSerpTool()
43-
results = serp_tool.invoke({
44-
"query": query,
45-
"engine": "google",
46-
"num": 3,
47-
})
43+
results = serp_tool.invoke(
44+
{
45+
"query": query,
46+
"engine": "google",
47+
"num": 3,
48+
}
49+
)
4850

4951
organic = results.get("organic", [])
5052
for item in organic:
5153
link = item.get("link", "")
5254
if link and "thordata" in link.lower():
5355
return link
54-
56+
5557
# Return first result if no thordata link found
5658
if organic:
5759
return organic[0].get("link", "")
58-
60+
5961
raise RuntimeError("No results found")
6062

6163

6264
def scrape_page(url: str) -> str:
6365
"""Use Scrape tool to get page content."""
6466
print(f"📄 Scraping: {url}")
65-
67+
6668
scrape_tool = ThordataScrapeTool()
67-
html = scrape_tool.invoke({
68-
"url": url,
69-
"js_render": False,
70-
"max_length": 5000,
71-
})
72-
69+
html = scrape_tool.invoke(
70+
{
71+
"url": url,
72+
"js_render": False,
73+
"max_length": 5000,
74+
}
75+
)
76+
7377
return html
7478

7579

7680
def summarize_with_llm(html: str, topic: str) -> str:
7781
"""Use LLM to summarize the content."""
7882
print("🤖 Summarizing with LLM...")
79-
83+
8084
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
8185

8286
prompt = f"""You are a helpful assistant that summarizes web content.
@@ -111,7 +115,7 @@ def main():
111115

112116
# Step 3: Summarize
113117
summary = summarize_with_llm(html, "Thordata's services")
114-
118+
115119
print()
116120
print("=" * 60)
117121
print("📋 Summary:")
@@ -124,4 +128,4 @@ def main():
124128

125129

126130
if __name__ == "__main__":
127-
main()
131+
main()

examples/simple_scrape.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ def main():
2828
print()
2929

3030
# Scrape the page
31-
html = tool.invoke({
32-
"url": url,
33-
"js_render": False,
34-
"max_length": 2000,
35-
})
31+
html = tool.invoke(
32+
{
33+
"url": url,
34+
"js_render": False,
35+
"max_length": 2000,
36+
}
37+
)
3638

3739
if html.startswith("Error"):
3840
print(f"❌ {html}")
@@ -46,4 +48,4 @@ def main():
4648

4749

4850
if __name__ == "__main__":
49-
main()
51+
main()

examples/simple_serp.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ def main():
3030
print()
3131

3232
# Execute search
33-
results = tool.invoke({
34-
"query": "Python web scraping best practices",
35-
"engine": "google",
36-
"num": 5,
37-
})
33+
results = tool.invoke(
34+
{
35+
"query": "Python web scraping best practices",
36+
"engine": "google",
37+
"num": 5,
38+
}
39+
)
3840

3941
# Check for errors
4042
if "error" in results:
@@ -58,4 +60,4 @@ def main():
5860

5961

6062
if __name__ == "__main__":
61-
main()
63+
main()

pyproject.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ openai = [
4646
]
4747
dev = [
4848
"pytest>=7.0.0",
49-
"pytest-asyncio>=0.21.0",
5049
"black>=23.0.0",
5150
"ruff>=0.1.0",
5251
]
@@ -70,4 +69,10 @@ target-version = "py39"
7069

7170
[tool.ruff.lint]
7271
select = ["E", "W", "F"]
73-
ignore = ["E501"]
72+
ignore = ["E501"]
73+
74+
[tool.ruff.lint.per-file-ignores]
75+
"examples/*.py" = ["E402"]
76+
77+
[tool.pytest.ini_options]
78+
testpaths = ["tests"]

test/__init__.py

Whitespace-only changes.

test/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Pytest configuration for thordata-langchain-tools tests.
3+
"""
4+
5+
import pytest
6+
7+
8+
@pytest.fixture(autouse=True)
9+
def mock_env_vars(monkeypatch):
10+
"""Set mock environment variables for all tests."""
11+
monkeypatch.setenv("THORDATA_SCRAPER_TOKEN", "test_token")
12+
monkeypatch.setenv("THORDATA_PUBLIC_TOKEN", "test_public_token")
13+
monkeypatch.setenv("THORDATA_PUBLIC_KEY", "test_public_key")
14+
monkeypatch.setenv("THORDATA_USERNAME", "test_user")
15+
monkeypatch.setenv("THORDATA_PASSWORD", "test_pass")

0 commit comments

Comments
 (0)