-
Notifications
You must be signed in to change notification settings - Fork 0
/
_tasks.py
66 lines (53 loc) · 2.08 KB
/
_tasks.py
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
import platform
import re
import shutil
import subprocess
import sys
from pathlib import Path
import toml
HERE = Path(__file__).parent
def task_docs():
"""Build the html docs using Sphinx."""
# Delete Autogenerated files from previous run
shutil.rmtree(str(HERE / "docs/modules/generated"), ignore_errors=True)
if platform.system() == "Windows":
subprocess.run([HERE / "docs/make.bat", "html"], shell=False, check=True)
else:
subprocess.run(["make", "-C", HERE / "docs", "html"], shell=False, check=True)
def task_bump_all_dev():
"""Bump all dev dependencies."""
pyproject = toml.load(HERE.joinpath("pyproject.toml"))
try:
dev_dependencies = pyproject["tool"]["poetry"]["dev-dependencies"]
except KeyError:
dev_dependencies = pyproject["tool"]["poetry"]["group"]["dev"]["dependencies"]
dev_deps = dev_dependencies.keys()
new_dev_deps = [f"{dep}@latest" for dep in dev_deps]
subprocess.run(["poetry", "add", "--group", "dev", *new_dev_deps], shell=False, 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 open(file_path, "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):
subprocess.run(["poetry", "version", version], shell=False, check=True)
new_version = (
subprocess.run(["poetry", "version"], shell=False, check=True, capture_output=True)
.stdout.decode()
.strip()
.split(" ", 1)[1]
)
update_version_strings(HERE.joinpath("gaitmap_bench/__init__.py"), new_version)
update_version_strings(HERE.joinpath("gaitmap_challenges/__init__.py"), new_version)
def task_update_version():
update_version(sys.argv[1])