-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupdate_version.py
More file actions
36 lines (25 loc) · 918 Bytes
/
update_version.py
File metadata and controls
36 lines (25 loc) · 918 Bytes
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
import re
def get_version(file_path):
"""get version file __init__.py .
Args:
file_path (str): __init__py.
Returns:
str: version.
"""
with open(file_path, 'r') as f:
for line in f:
if line.startswith('__version__'):
return line.split('=')[1].strip().strip('"')
def update_version(toml_path, version_file):
with open(toml_path, 'r') as f:
content = f.read()
new_version = get_version(version_file)
if not new_version or new_version == "unknown":
raise ValueError(
f"Could not read a valid version from '{version_file}'. "
"Ensure it contains a line like: __version__ = \"x.y.z\""
)
new_content = content.replace("{version-file}", new_version)
with open(toml_path, 'w') as f:
f.write(new_content)
update_version("pyproject.toml", "src/rsmetacheck/__init__.py")