-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_tasks.py
More file actions
82 lines (65 loc) · 2.61 KB
/
Copy path_tasks.py
File metadata and controls
82 lines (65 loc) · 2.61 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
import re
import shutil
import subprocess
import sys
from pathlib import Path
HERE = Path(__file__).parent
def task_prepare_release() -> None:
update_version(sys.argv[1])
html_dir = HERE / "docs/_build/html"
subprocess.run(["git", "switch", "gh-pages"], shell=False, check=True, cwd=html_dir)
task_docs()
task_upload_docs()
new_version = _get_project_version()
subprocess.run(["git", "add", "."], shell=False, check=True)
subprocess.run(["git", "commit", "-m", f"Release {new_version}"], shell=False, check=True)
def task_docs() -> None:
"""Build the html docs using Sphinx."""
shutil.rmtree(HERE / "docs/modules/generated", ignore_errors=True)
shutil.rmtree(HERE / "docs/_build/doctrees", ignore_errors=True)
html_dir = HERE / "docs/_build/html"
if html_dir.exists():
for path in html_dir.iterdir():
if path.name == ".git":
continue
if path.is_dir():
shutil.rmtree(path, ignore_errors=True)
else:
path.unlink()
subprocess.run(
["sphinx-build", "-b", "html", "-j", "auto", "-d", "docs/_build/doctrees", "docs", "docs/_build/html"],
shell=False,
check=True,
cwd=HERE,
)
def task_upload_docs() -> None:
"""Upload docs to the gh-pages branch."""
html_dir = HERE / "docs/_build/html"
subprocess.run(["git", "add", "."], shell=False, check=True, cwd=html_dir)
subprocess.run(["git", "commit", "--amend", "--no-edit"], shell=False, check=True, cwd=html_dir)
subprocess.run(["git", "push", "origin", "gh-pages", "--force"], shell=False, check=True, cwd=html_dir)
def update_version_strings(file_path: Path, new_version: str) -> None:
version_regex = re.compile(r"(^_*?version_*?\s*=\s*\")(\d+\.\d+\.\d+-?\S*)\"", re.M)
with file_path.open("r+", encoding="utf-8") as f:
content = f.read()
f.seek(0)
f.write(
re.sub(
version_regex,
lambda match: f'{match.group(1)}{new_version}"',
content,
)
)
f.truncate()
def _get_project_version() -> str:
return (
subprocess.run(["uv", "version", "--short"], shell=False, check=True, capture_output=True, cwd=HERE)
.stdout.decode()
.strip()
)
def update_version(version: str) -> None:
subprocess.run(["uv", "version", version, "--frozen"], shell=False, check=True, cwd=HERE)
new_version = _get_project_version()
update_version_strings(HERE / "src/gaitmap_datasets/__init__.py", new_version)
def task_update_version() -> None:
update_version(sys.argv[1])