-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduties.py
More file actions
102 lines (79 loc) · 3.01 KB
/
Copy pathduties.py
File metadata and controls
102 lines (79 loc) · 3.01 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""Project tasks."""
from __future__ import annotations
from pathlib import Path
import re
from typing import Literal
from duty import duty # pyright: ignore[reportMissingImports]
# Read configuration from copier-answers.yml
_answers_file = Path(".copier-answers.yml")
if _answers_file.exists():
content = _answers_file.read_text()
match = re.search(r"^python_package_import_name:\s*(.+)$", content, re.MULTILINE)
if match:
PACKAGE_NAME = match.group(1).strip()
else:
msg = "python_package_import_name not found in copier-answers.yml"
raise ValueError(msg)
else:
msg = "copier-answers.yml not found in project root"
raise FileNotFoundError(msg)
@duty(capture=False)
def build(ctx, *args: str):
"""Build a MkNodes page."""
args_str = " " + " ".join(args) if args else ""
ctx.run(f"uv run mkdocs-mknodes build{args_str}")
@duty(capture=False)
def serve(ctx, *args: str):
"""Serve a MkNodes page."""
args_str = " " + " ".join(args) if args else ""
ctx.run(f"uv run mkdocs-mknodes serve{args_str}")
@duty(capture=False)
def test(ctx, *args: str):
"""Run tests."""
args_str = " " + " ".join(args) if args else ""
ctx.run(f"uv run pytest{args_str}")
@duty(capture=False)
def clean(ctx):
"""Clean all files from the Git directory except checked-in files."""
ctx.run("git clean -dfX")
@duty(capture=False)
def update(ctx):
"""Update all environment packages using pip directly."""
ctx.run("uv lock --upgrade")
ctx.run("uv sync --all-extras")
@duty(capture=False)
def lint(ctx):
"""Lint the code and fix issues if possible."""
ctx.run("uv run ruff check --fix --unsafe-fixes .")
ctx.run("uv run ruff format .")
ctx.run(f"uv run mypy src/{PACKAGE_NAME}/ --fixed-format-cache")
@duty(capture=False)
def lint_check(ctx):
"""Lint the code."""
ctx.run("uv run ruff check .")
ctx.run("uv run ruff format --check .")
ctx.run(f"uv run mypy src/{PACKAGE_NAME}/ --fixed-format-cache")
@duty(capture=False)
def version(
ctx,
*bump_type: Literal["major", "minor", "patch", "stable", "alpha", "beta", "rc"],
):
"""Release a new version with git operations. (major|minor|patch|stable|alpha|beta|rc)."""
# Check for uncommitted changes
result = ctx.run("git status --porcelain", capture=True)
if result.strip():
msg = "Cannot release with uncommitted changes. Please commit or stash first."
raise RuntimeError(msg)
# Read current version
old_version = ctx.run("uv version --short", capture=True).strip()
print(f"Current version: {old_version}")
bump_str = " ".join(f"--bump {i}" for i in bump_type)
ctx.run(f"uv version {bump_str}")
new_version = ctx.run("uv version --short", capture=True).strip()
print(f"New version: {new_version}")
ctx.run("git add pyproject.toml")
ctx.run(f'git commit -m "chore: bump version {old_version} -> {new_version}"')
# Create and push tag
tag = f"v{new_version}"
ctx.run(f"git tag {tag}")
print(f"Created tag: {tag}")