-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_tasks.py
More file actions
74 lines (62 loc) · 2.42 KB
/
Copy path_tasks.py
File metadata and controls
74 lines (62 loc) · 2.42 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
import re
import shutil
import subprocess
import sys
from pathlib import Path
from typing import Sequence
HERE = Path(__file__).parent
def task_docs(clean=False):
"""Build the html docs using Sphinx."""
# Delete Autogenerated files from previous run
if clean:
shutil.rmtree(str(HERE / "docs/modules/generated"), ignore_errors=True)
shutil.rmtree(str(HERE / "docs/_build"), ignore_errors=True)
shutil.rmtree(str(HERE / "docs/auto_examples"), ignore_errors=True)
subprocess.run("sphinx-build -j auto -d docs/_build docs docs/_build/html", shell=True, check=True)
def update_version_strings(file_path, new_version):
# taken from:
# https://stackoverflow.com/questions/57108712/replace-updated-version-strings-in-files-via-python
version_regex = re.compile(r"(^_*?version_*?\s*=\s*\")(\d+\.\d+\.\d+-?\S*)\"", re.M)
with file_path.open("r+") as f:
content = f.read()
f.seek(0)
f.write(
re.sub(
version_regex,
lambda match: '{}{}"'.format(match.group(1), new_version),
content,
)
)
f.truncate()
def update_citation_version(file_path, new_version):
"""Update the software version in Citation File Format metadata."""
version_regex = re.compile(r"^(version:\s*)(\d+\.\d+\.\d+-?\S*)$", re.M)
with file_path.open("r+") 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 update_version(version: Sequence[str]):
if len(version) == 0:
# no argument passed => return the current version
subprocess.run(["uv", "version"], shell=False, check=True, capture_output=False)
else:
# update the version
subprocess.run(["uv", "version", *version], shell=False, check=True)
new_version = (
subprocess.run(["uv", "version"], shell=False, check=True, capture_output=True)
.stdout.decode()
.strip()
.split(" ", 1)[1:][0]
)
update_version_strings(HERE.joinpath("src/carwatch/__init__.py"), new_version)
update_citation_version(HERE.joinpath("CITATION.cff"), new_version)
def task_update_version():
version_arr = sys.argv[1:] if len(sys.argv) > 1 else []
update_version(version_arr)