-
-
Notifications
You must be signed in to change notification settings - Fork 108
/
gen_config.py
45 lines (33 loc) · 1.09 KB
/
gen_config.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
import os
import re
import yaml
config = yaml.load(
open("config.yaml.in", "r", encoding="utf-8"), Loader=yaml.SafeLoader
)
def merge_dicts(d1, d2):
for key, value in d2.items():
if key in d1:
if isinstance(value, list):
d1[key].extend(value)
elif isinstance(value, dict):
merge_dicts(d1[key], value)
else:
d1[key] = value
return d1
def include_files(d):
external = {}
for key, val in d.items():
if isinstance(val, dict):
d[key] = include_files(val)
elif key == "include-files":
for otherfile in val:
external_data = yaml.load(
open(otherfile, "r", encoding="utf-8"), Loader=yaml.SafeLoader
)
external = merge_dicts(external, external_data)
d.pop("include-files", None)
return {**d, **external}
config = include_files(config)
if os.environ.get("NUMPYORG_WITH_TRANSLATIONS"):
del config["disableLanguages"]
yaml.dump(config, open('config.yaml', 'w', encoding='utf-8'), sort_keys=False)