forked from ZexinChen/AlphaTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge_yaml.py
More file actions
33 lines (23 loc) · 959 Bytes
/
merge_yaml.py
File metadata and controls
33 lines (23 loc) · 959 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
import yaml
import copy
with open('/home/zexin/project/mice/algorithm/unsupervised_classification/hierarchical_clustering/environment.yaml', 'r') as fin:
newYaml = yaml.safe_load(fin)
with open('./environment.yml') as fin:
oldYaml = yaml.safe_load(fin)
yamlMerge = copy.deepcopy(oldYaml)
for pkg in newYaml['dependencies'][-1]['pip']:
if pkg not in yamlMerge['dependencies'][-1]['pip']:
# print(pkg)
yamlMerge['dependencies'][-1]['pip'].append(pkg)
for pkg in newYaml['dependencies']:
if isinstance(pkg, str) and pkg not in yamlMerge['dependencies']:
yamlMerge['dependencies'].append(pkg)
tmp = [pkg for pkg in yamlMerge['dependencies'] if isinstance(pkg, str)]
tmp1 = [pkg for pkg in yamlMerge['dependencies'] if isinstance(pkg, dict)]
tmp1[0]['pip'].sort()
tmp.sort()
yamlMerge['dependencies'] = tmp + tmp1
print(tmp)
print(tmp1)
with open('./environment.yaml','w') as fout:
yaml.dump( yamlMerge, fout)