-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathrelease.py
88 lines (71 loc) · 2.75 KB
/
release.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import json
def get_setup_version_and_pattern(setup_content):
depend_lst, version_lst = [], []
for l in setup_content:
if "==" in l:
lst = (
l.split("[")[-1]
.split("]")[0]
.replace(" ", "")
.replace('"', "")
.replace("'", "")
.split(",")
)
for dep in lst:
if dep != "\n":
version_lst.append(dep.split("==")[1])
depend_lst.append(dep.split("==")[0])
version_high_dict = {d: v for d, v in zip(depend_lst, version_lst)}
return version_high_dict
def get_env_version(env_content):
read_flag = False
depend_lst, version_lst = [], []
for l in env_content:
if "dependencies:" in l:
read_flag = True
elif read_flag:
lst = l.replace("- ", "").replace(" ", "").replace("\n", "").split("=")
if len(lst) == 2:
depend_lst.append(lst[0])
version_lst.append(lst[1])
return {d: v for d, v in zip(depend_lst, version_lst)}
def update_dependencies(setup_content, version_low_dict, version_high_dict):
version_combo_dict = {}
for dep, ver in version_high_dict.items():
if dep in version_low_dict.keys() and version_low_dict[dep] != ver:
version_combo_dict[dep] = dep + ">=" + version_low_dict[dep] + ",<=" + ver
else:
version_combo_dict[dep] = dep + "==" + ver
setup_content_new = ""
pattern_dict = {d: d + "==" + v for d, v in version_high_dict.items()}
for l in setup_content:
for k, v in pattern_dict.items():
if v in l:
l = l.replace(v, version_combo_dict[k])
setup_content_new += l
return setup_content_new
def convert_key(key, convert_dict):
if key not in convert_dict.keys():
return key
else:
return convert_dict[key]
if __name__ == "__main__":
with open(".ci_support/pypi_vs_conda_names.json", "r") as f:
name_conversion_dict = {v: k for k, v in json.load(f).items()}
with open("pyproject.toml", "r") as f:
setup_content = f.readlines()
with open("environment.yml", "r") as f:
env_content = f.readlines()
env_version_dict = {
convert_key(key=k, convert_dict=name_conversion_dict): v
for k, v in get_env_version(env_content=env_content).items()
}
setup_content_new = update_dependencies(
setup_content=setup_content[2:],
version_low_dict=env_version_dict,
version_high_dict=get_setup_version_and_pattern(
setup_content=setup_content[2:]
),
)
with open("pyproject.toml", "w") as f:
f.writelines("".join(setup_content[:2]) + setup_content_new)