-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.py
More file actions
55 lines (38 loc) · 1.35 KB
/
version.py
File metadata and controls
55 lines (38 loc) · 1.35 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
"""
llm-qlient • Qt desktop client for interacting with local LLMs
This file is a part of the llm-qlient
project and distributed under MIT license.
Repository: https://github.com/kadir014/llm-qlient
Issues: https://github.com/kadir014/llm-qlient/issues
"""
import sys
import re
from pathlib import Path
ROOT = Path.cwd()
def match_and_replace(path: Path, pattern: str, replace: str) -> None:
content = path.read_text(encoding="utf-8")
content = re.compile(pattern).sub(replace, content)
path.write_text(content, encoding="utf-8")
def main() -> None:
if len(sys.argv) > 1:
new_version = sys.argv[1]
else:
raise ValueError("Version string is needed as an argument.")
PATTERNS = {
"pyproject.toml": {
"pattern": r'(version\s*=\s*")[^"]*(")',
"replace": rf'\g<1>{new_version}\g<2>'
},
"src/llm_qlient/shared.py": {
"pattern": r'(__version__\s*=\s*")[^"]*(")',
"replace": rf'\g<1>{new_version}\g<2>'
},
"README.md": {
"pattern": r'(version-)(.+)(-[^-"]+)',
"replace": rf'\g<1>{new_version.replace("-", "--")}\g<3>'
}
}
for path, patterns in PATTERNS.items():
match_and_replace(ROOT / path, patterns["pattern"], patterns["replace"])
if __name__ == "__main__":
main()