-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathupdate_git_versions.py
56 lines (40 loc) · 1.49 KB
/
update_git_versions.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
import contextlib
import re
import sys
from pathlib import Path
if __name__ == "__main__" and __package__ is None or __package__ == "":
file = Path(__file__).resolve()
parent, top = file.parent, file.parents[1]
if str(top) not in sys.path:
sys.path.append(str(top))
with contextlib.suppress(ValueError):
sys.path.remove(str(parent))
__package__ = "scripts"
from scripts.tools import get_version
def replace_in_file(filename: Path, pattern: "re.Pattern[str]", to: str) -> None:
text = filename.read_text()
new = pattern.sub(to, text)
filename.write_text(new)
def main() -> None:
version = get_version()
version_files = list(Path("packages").rglob("__version__.py"))
for f in [Path("src/robotcode/cli/__version__.py"), *version_files]:
replace_in_file(
f,
re.compile(r"""(^_*version_*\s*=\s*['"])([^'"]*)(['"])""", re.MULTILINE),
rf"\g<1>{version or ''}\g<3>",
)
replace_in_file(
Path("package.json"),
re.compile(r"""(\"version\"\s*:\s*['"])([0-9]+\.[0-9]+\.[0-9]+.*)(['"])""", re.MULTILINE),
rf"\g<1>{version or ''}\g<3>",
)
pyproject_files = list(Path("packages").rglob("pyproject.toml"))
for f in [Path("pyproject.toml"), *pyproject_files]:
replace_in_file(
f,
re.compile(r'("robotcode\S*==)([0-9]+\.[0-9]+\.[0-9]+.*)(")', re.MULTILINE),
rf"\g<1>{version or ''}\g<3>",
)
if __name__ == "__main__":
main()