Files
bookshelf/scripts/presubmit.py
Petr Polezhaev b8f82607f9 Fix archive plugins for НЭБ and Alib; add network integration tests
- html_scraper: add img_alt strategy (НЭБ titles from <img alt>), bold_text
  strategy (Alib entries from <p><b>), Windows-1251 encoding support,
  _cls_inner_texts() helper that strips inner HTML tags
- rsl: rewrite to POST SearchFilterForm[search] with CSRF token and CQL
  title:(words) AND author:(word) query format
- config: update rusneb (img_alt + correct author_class) and alib_web
  (encoding + bold_text) to match fixed plugin strategies
- tests: add tests/test_archives.py with network-marked tests for all six
  archive plugins; НЛР and ШПИЛ marked xfail (endpoints return HTTP 404)
- presubmit: exclude network tests from default run (-m "not network")

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 22:59:19 +03:00

60 lines
1.8 KiB
Python

"""Presubmit and utility scripts registered as poetry console entry points."""
import subprocess
import sys
from pathlib import Path
def _run(*cmd: str) -> int:
return subprocess.run(list(cmd)).returncode
def fmt():
"""Run black formatter (modify files in place)."""
sys.exit(_run("black", "."))
def presubmit():
"""Run all checks: black format check, flake8, pyright, pytest, JS lint/fmt/test.
JS lint and format checks require `npm install` to be run once first;
they are skipped (with a warning) when node_modules is absent.
"""
steps = [
["black", "--check", "."],
["flake8", "."],
["pyright"],
["pytest", "tests/", "-m", "not network"],
# JS: tests run via Node built-in runner (no npm packages needed)
["node", "--test", "tests/js/pure-functions.test.js"],
]
# JS lint/fmt require npm packages — skip gracefully if not installed
npm_steps: list[list[str]] = [
["npm", "run", "fmt:check"],
["npm", "run", "lint"],
]
failed: list[str] = []
for step in steps:
if subprocess.run(step).returncode != 0:
failed.append(" ".join(step))
if Path("node_modules").exists():
for step in npm_steps:
if subprocess.run(step).returncode != 0:
failed.append(" ".join(step))
else:
print(
"\nSkipping JS lint/fmt: run `npm install` to enable these checks.",
file=sys.stderr,
)
if failed:
print(f"\nFailed: {', '.join(failed)}", file=sys.stderr)
sys.exit(1)
print("\nAll presubmit checks passed.")
print(
"\nReminder: if this task changed architecture, layer boundaries, config schema,\n"
"directory layout, API endpoints, or the plugin system — update docs/overview.md."
)