1+ import errno
2+ import os
13import re
4+ from pathlib import Path
25from typing import Any , Mapping , Optional , Text
36
4- from dotenv .variables import parse_variables
5-
67import yaml
7- import os
8- import errno
98from dotenv import dotenv_values , load_dotenv
10- from pathlib import Path
11- import sys
9+ from dotenv . variables import parse_variables
10+
1211
1312def expand_posix_vars (obj : Any , variables : Mapping [Text , Optional [Any ]]) -> Any :
1413 """expand_posix_vars recursively expands POSIX values in an object.
@@ -63,6 +62,7 @@ def _str_to_python_value(val):
6362 # return int(val)
6463 return val
6564
65+
6666def expand_yaml (config_path ):
6767 def load_system_envvars ():
6868 config_vars = dict (os .environ )
@@ -73,11 +73,13 @@ def load_system_envvars():
7373 if "dotenv" in config :
7474 dotenv = config .pop ("dotenv" , {})
7575 if not isinstance (dotenv , str ):
76- raise ValueError (f' Invalid value passed to dotenv: { dotenv } ' )
76+ raise ValueError (f" Invalid value passed to dotenv: { dotenv } " )
7777 config_vars = load_system_envvars ()
7878 env_path = Path (config_path ).parent .joinpath (dotenv )
7979 if not env_path .is_file ():
80- raise ValueError (f"Dotenv specified in config but not found at path: { env_path } " )
80+ raise ValueError (
81+ f"Dotenv specified in config but not found at path: { env_path } "
82+ )
8183 config_vars .update (dotenv_values (dotenv_path = env_path )) # type: ignore
8284 load_dotenv (dotenv_path = env_path )
8385 config = expand_posix_vars (config , config_vars )
@@ -86,22 +88,35 @@ def load_system_envvars():
8688 if not os .path .exists (output_path .parent ):
8789 try :
8890 os .makedirs (output_path .parent )
89- except OSError as exc : # Guard against race condition
91+ except OSError as exc : # Guard against race condition
9092 if exc .errno != errno .EEXIST :
9193 raise
92- yaml .dump (config , output_path .open ("w+" ),)
94+ yaml .dump (
95+ config ,
96+ output_path .open ("w+" ),
97+ )
9398 print (f"{ config_path } was expanded as: { output_path } " )
9499 return output_path
95100
101+
96102def expand_and_output_yamls ():
97103 yaml_dict = {}
98- yaml_dict ["cronos-devnet" ] = expand_yaml (Path (__file__ ).parent / "../scripts/cronos-devnet.yaml" )
99- yaml_dict ["chainmain-devnet" ] = expand_yaml (Path (__file__ ).parent / "../scripts/chainmain-devnet.yaml" )
104+ yaml_dict ["cronos-devnet" ] = expand_yaml (
105+ Path (__file__ ).parent / "../scripts/cronos-devnet.yaml"
106+ )
107+ yaml_dict ["chainmain-devnet" ] = expand_yaml (
108+ Path (__file__ ).parent / "../scripts/chainmain-devnet.yaml"
109+ )
100110 yaml_dict ["devnet" ] = expand_yaml (Path (__file__ ).parent / "../scripts/devnet.yaml" )
101- yaml_dict ["disable_auto_deployment" ] = expand_yaml (Path (__file__ ).parent / "../scripts/disable_auto_deployment.yaml" )
102- yaml_dict ["genesis_token_mapping" ] = expand_yaml (Path (__file__ ).parent / "../scripts/genesis_token_mapping.yaml" )
111+ yaml_dict ["disable_auto_deployment" ] = expand_yaml (
112+ Path (__file__ ).parent / "../scripts/disable_auto_deployment.yaml"
113+ )
114+ yaml_dict ["genesis_token_mapping" ] = expand_yaml (
115+ Path (__file__ ).parent / "../scripts/genesis_token_mapping.yaml"
116+ )
103117 return yaml_dict
104118
119+
105120if __name__ == "__main__" :
106121 expand_and_output_yamls ()
107122 # yaml_path = sys.argv[1]
0 commit comments