Files
LLMWiki/tasks.py
2026-06-06 07:44:26 +08:00

59 lines
1.3 KiB
Python

"""Cross-platform task runner for Windows/Unix."""
import pathlib
import shutil
import subprocess
import sys
def run(cmd: str) -> None:
"""Run a shell command."""
result = subprocess.run(cmd, shell=True)
if result.returncode:
sys.exit(result.returncode)
def install() -> None:
run("uv sync")
run("uv run pre-commit install")
def check() -> None:
run("python -m uv lock --locked")
run("python -m uv run ruff check .")
run("python -m uv run ruff format --check .")
run("python -m uv run mypy src/main.py")
run("python -m uv run deptry .")
def test() -> None:
run("python -m uv run python -m pytest --cov --cov-config=pyproject.toml --cov-report=term-missing")
def run_main() -> None:
run("python -m uv run python src/main.py")
def clean() -> None:
for target in [".venv", "__pycache__", ".pytest_cache", ".mypy_cache", ".ruff_cache"]:
path = pathlib.Path(target)
if path.is_dir():
shutil.rmtree(path)
TASKS = {
"install": install,
"check": check,
"test": test,
"run": run_main,
"clean": clean,
}
if __name__ == "__main__":
task = sys.argv[1] if len(sys.argv) > 1 else "run"
if task in TASKS:
TASKS[task]()
else:
print(f"Unknown task: {task}. Available: {', '.join(TASKS)}")
sys.exit(1)