forked from vskode/acodet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstage_params.py
More file actions
31 lines (25 loc) · 982 Bytes
/
stage_params.py
File metadata and controls
31 lines (25 loc) · 982 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 os
import io
import yaml
# Read YAML file
with open("simple_config.yml", 'r') as stream:
data = yaml.safe_load(stream)
for name, value in os.environ.items():
#load it into the humpback detector. Possible (do if needed), make sure names match possible values.
#replace values in yaml with parameters
#import code
#code.interact(local=dict(globals(), **locals()))
#convention
name = name.lower()
if name in data:
print(f"ENV variable with {name} found in simple config")
#determine previous type
_type = type(data[name])
#coerce value to type. If errors, it's for a good reason.
try:
data[name] = _type(value)
except ValueError:
print(f"Cannot convert {value} for ENV variable {name} to {str(_type)}")
# Write YAML file
with io.open("simple_config.yml", 'w', encoding='utf8') as outfile:
yaml.dump(data, outfile, default_flow_style=False, allow_unicode=True)