-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.py
More file actions
48 lines (36 loc) · 1.32 KB
/
version.py
File metadata and controls
48 lines (36 loc) · 1.32 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
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "tomlkit",
# ]
# ///
import os
import sys
import tomllib
import subprocess
import tomlkit
repo_dir = os.path.dirname(__file__)
with open(os.path.join(repo_dir, 'Cargo.toml'), 'rb') as fd:
workspace = tomllib.load(fd)
if len(sys.argv) > 1:
# Print version data prior to update
subprocess.run([sys.executable, __file__])
version = sys.argv[1].casefold()
if len(version.split('.')) != 3:
print(f'Error, version {version} does not follow semver!')
sys.exit(1)
for member in workspace.get('workspace', dict()).get('members', list()):
with open(os.path.join(repo_dir, member, 'Cargo.toml'), 'r', encoding='utf-8') as fd:
toml_data = tomlkit.parse(fd.read())
print(f'Applying version {version} to {member}')
toml_data['package']['version'] = version
with open(os.path.join(repo_dir, member, 'Cargo.toml'), 'w', encoding='utf-8') as fd:
fd.write(tomlkit.dumps(toml_data))
else:
for member in workspace.get('workspace', dict()).get('members', list()):
version = '0.0.0'
if os.path.exists(os.path.join(repo_dir, member, 'Cargo.toml')):
with open(os.path.join(repo_dir, member, 'Cargo.toml'), 'rb') as fd:
data = tomllib.load(fd)
version = data["package"]["version"]
print(f'{member} - v{version}')