swydd/tasks.py

55 lines
1.2 KiB
Python
Raw Permalink Normal View History

2024-03-05 13:52:37 -06:00
#!/usr/bin/env python3
2024-07-22 15:17:58 -05:00
__import__("sys").path.append("src")
2024-03-08 12:54:35 -06:00
2024-03-08 12:57:04 -06:00
import shutil
import sys
2024-10-24 18:35:06 -05:00
import swydd as s
2024-03-05 13:52:37 -06:00
2024-10-24 18:35:06 -05:00
@s.task
2024-03-08 12:57:04 -06:00
def bootstrap():
"""setup swydd dev environment"""
2024-07-22 15:17:58 -05:00
if not shutil.which("uv"):
sys.exit("uv necessary for swydd development")
2024-10-24 18:35:06 -05:00
(s.Proc("uv sync").then("uv run pre-commit install").run())
2024-03-08 12:57:04 -06:00
2024-10-24 18:35:06 -05:00
@s.task
2024-07-22 15:17:58 -05:00
def tests():
"""run pytest"""
2024-10-24 18:35:06 -05:00
s.sub("uv run pytest")
2024-03-05 13:52:37 -06:00
2024-10-24 18:35:06 -05:00
@s.task
@s.option("skip-mypy", "skip mypy")
2024-07-22 15:17:58 -05:00
def check(skip_mypy: bool = False):
"""run pre-commit (and mypy)"""
2024-10-24 18:35:06 -05:00
s.sub("uv run pre-commit run --all")
2024-07-22 15:17:58 -05:00
if not skip_mypy:
2024-10-24 18:35:06 -05:00
s.sub("uv run mypy src/")
2024-07-19 14:10:33 -05:00
2024-10-24 18:35:06 -05:00
@s.task
def serve_docs():
"""serve the docs with sphinx-autobuild"""
s.sub("uv run sphinx-autobuild docs/source docs/build --watch src", rest=True)
@s.task
def build_docs():
2024-10-20 13:05:37 -05:00
"""build docs"""
2024-10-24 18:35:06 -05:00
s.sub("uv run sphinx-build docs/source docs/build")
tags = s.get("git tag --list")
2024-07-22 15:17:58 -05:00
versions = [line for line in tags.splitlines() if line.startswith("v")]
for tag in versions:
2024-10-24 18:35:06 -05:00
version_swydd_src = s.get(f"git show {tag}:src/swydd/__init__.py")
s.Asset(f"docs/build/{tag}/swydd.py").write(version_swydd_src)
s.Asset("docs/build/swydd.py").copy(s.Asset("src/swydd/__init__.py"))
2024-07-19 14:10:33 -05:00
2024-10-24 18:35:06 -05:00
s.cli("check --skip-mypy")