fea(ci): improve prettier config
This commit is contained in:
parent
d4df57bd05
commit
a7eb731730
3 changed files with 64 additions and 4 deletions
8
.github/workflows/quality.yml
vendored
8
.github/workflows/quality.yml
vendored
|
|
@ -90,7 +90,7 @@ jobs:
|
|||
- name: Install ruff
|
||||
run: uv tool install ruff
|
||||
- name: Check Python formatting with ruff
|
||||
run: ruff format --check scrapers/ tests/scrapers/
|
||||
run: ruff format --check .
|
||||
|
||||
python-lint:
|
||||
name: Python Lint Check
|
||||
|
|
@ -104,7 +104,7 @@ jobs:
|
|||
- name: Install ruff
|
||||
run: uv tool install ruff
|
||||
- name: Lint Python files with ruff
|
||||
run: ruff check scripts/ scrapers/ tests/scrapers/
|
||||
run: ruff check .
|
||||
|
||||
python-typecheck:
|
||||
name: Python Type Check
|
||||
|
|
@ -118,7 +118,7 @@ jobs:
|
|||
- name: Install dependencies with mypy
|
||||
run: uv sync --dev
|
||||
- name: Type check Python files with mypy
|
||||
run: uv run mypy scripts/ scrapers/ tests/scrapers/
|
||||
run: uv run mypy .
|
||||
|
||||
markdown-format:
|
||||
name: Markdown Format Check
|
||||
|
|
@ -138,4 +138,4 @@ jobs:
|
|||
- name: Install prettier
|
||||
run: pnpm add -g prettier@3.1.0
|
||||
- name: Check markdown formatting with prettier
|
||||
run: prettier --check "*.md" "docs/**/*.md" || true
|
||||
run: prettier --check .
|
||||
|
|
|
|||
17
.prettierrc
Normal file
17
.prettierrc
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"proseWrap": "always",
|
||||
"printWidth": 80,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"trailingComma": "none",
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["*.md", "docs/**/*.md"],
|
||||
"options": {
|
||||
"parser": "markdown"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
43
tests/conftest.py
Normal file
43
tests/conftest.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
FIXTURES = Path(__file__).resolve().parent / "fixtures"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fixture_text():
|
||||
"""Load HTML fixture by filename."""
|
||||
|
||||
def _load(name: str) -> str:
|
||||
p = FIXTURES / name
|
||||
return p.read_text(encoding="utf-8")
|
||||
|
||||
return _load
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def run_scraper(monkeypatch):
|
||||
def _run(name: str, mode: str, *args, replace_fetch=None) -> dict:
|
||||
scraper_path = ROOT / "scrapers" / f"{name}.py"
|
||||
ns = {}
|
||||
code = scraper_path.read_text(encoding="utf-8")
|
||||
if replace_fetch:
|
||||
code = code.replace("def _fetch", "def _fixture_fetch")
|
||||
code += f"\n_fetch = _fixture_fetch\nfetch_text = _fixture_fetch\n"
|
||||
ns.update(replace_fetch)
|
||||
exec(compile(code, str(scraper_path), "exec"), ns)
|
||||
main_async = ns.get("main_async")
|
||||
if not main_async:
|
||||
raise RuntimeError(f"Could not load main_async from {name}.py")
|
||||
import asyncio
|
||||
|
||||
async def wrapper():
|
||||
sys.argv = [str(scraper_path), mode, *args]
|
||||
return await main_async()
|
||||
|
||||
return asyncio.run(wrapper())
|
||||
|
||||
return _run
|
||||
Loading…
Add table
Add a link
Reference in a new issue