From a7eb731730d564481007bdb265feab1e1ae5f8c4 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sun, 5 Oct 2025 21:06:57 -0400 Subject: [PATCH] fea(ci): improve prettier config --- .github/workflows/quality.yml | 8 +++---- .prettierrc | 17 ++++++++++++++ tests/conftest.py | 43 +++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 .prettierrc create mode 100644 tests/conftest.py diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 8b6432f..7261d29 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -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 . diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..ed9f7c5 --- /dev/null +++ b/.prettierrc @@ -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" + } + } + ] +} diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..2cba275 --- /dev/null +++ b/tests/conftest.py @@ -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