-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.py
More file actions
39 lines (26 loc) · 1.05 KB
/
Copy pathscripts.py
File metadata and controls
39 lines (26 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""Utility scripts exposed via pyproject `project.scripts`.
Provides `run_checks()` which runs linters, formatters and tests.
"""
from __future__ import annotations
import subprocess
import sys
from pathlib import Path
from loguru import logger
from sample_python_app.core.logging import setup_logger
ROOT = Path(__file__).resolve().parents[2]
setup_logger("DEBUG")
def _run(cmd: list[str]) -> None:
logger.info(f"Running: {' '.join(cmd)}")
subprocess.check_call(cmd, cwd=str(ROOT))
def run_checks() -> None:
"""Run ruff, isort, black and tests (coverage+pytest).
This is intended to be invoked via the project script entrypoint, e.g.:
`uv run checks` or `python -m sample_python_app.scripts run_checks` when installed.
"""
py = sys.executable
_run([py, "-m", "ruff", "check", ".", "--fix", "--exit-zero"])
_run([py, "-m", "isort", "."])
_run([py, "-m", "black", "."])
_run([py, "-m", "ruff", "check", ".", "--exit-zero"])
_run([py, "-m", "coverage", "run", "-m", "pytest"])
logger.info("All checks completed.")