-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathpatch_pubspec.py
More file actions
41 lines (33 loc) · 936 Bytes
/
patch_pubspec.py
File metadata and controls
41 lines (33 loc) · 936 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
37
38
39
40
41
# /// script
# dependencies = ["pyyaml"]
# ///
import os
import pathlib
import sys
import yaml
if len(sys.argv) < 3:
print("Specify pubspec.yaml file and version to patch")
sys.exit(1)
current_dir = pathlib.Path(os.getcwd())
pubspec_path = current_dir.joinpath(current_dir, sys.argv[1])
ver = sys.argv[2]
print(f"Patching pubspec.yaml file {pubspec_path} with {ver}")
dependencies = [
"serious_python_platform_interface",
"serious_python_android",
"serious_python_darwin",
"serious_python_windows",
"serious_python_linux",
"serious_python_macos",
]
with open(pubspec_path) as f:
data = yaml.safe_load(f)
# patch version
data["version"] = ver
# patch dependencies
for dep in data["dependencies"]:
if dep in dependencies:
data["dependencies"][dep] = f"^{ver}"
# print(dep)
with open(pubspec_path, "w") as file:
yaml.dump(data, file, sort_keys=False)