@@ -43,7 +43,8 @@ def __init__(self, expt, name, config):
4343 'hnlist' , 'ihist' ,
4444 'namelists' , 'prefix.PRESM_A' ,
4545 'STASHC' , 'UAFILES_A' , 'UAFLDS_A' ,
46- 'cable.nml' , 'um_env.py' ]
46+ 'cable.nml' , 'um_env.yaml'
47+ ]
4748 self .optional_config_files = ['input_atm.nml' , 'parexe' ]
4849
4950 self .restart = 'restart_dump.astart'
@@ -109,19 +110,29 @@ def collate(self):
109110 pass
110111
111112 def setup (self ):
113+ # Raise a deprecation error if the um_env.yaml file is not found
114+ # This could be removed down the line, once older configurations
115+ # have swapped to um_env.yaml files.
116+ deprecated_um_env = os .path .join (self .control_path , 'um_env.py' )
117+ new_um_env = os .path .join (self .control_path , 'um_env.yaml' )
118+ if (not os .path .isfile (new_um_env )) and os .path .isfile (deprecated_um_env ):
119+ raise FutureWarning (
120+ (
121+ "The `um_env.py` configuration file has been deprecated and "
122+ "should be relplaced with a yaml file. "
123+ "Convert `um_env.py` to `um_env.yaml` using "
124+ "https://github.com/ACCESS-NRI/esm1.5-scripts/blob/main/config-files/UM/um_env_to_yaml.py"
125+ )
126+ )
127+
128+ # Commence normal setup
112129 super (UnifiedModel , self ).setup ()
113130
114131 # Set up environment variables needed to run UM.
115- # Look for a python file in the config directory.
116- loader = SourceFileLoader (
117- 'um_env' ,
118- os .path .join (self .control_path , 'um_env.py' )
119- )
120- um_env = module_from_spec (
121- spec_from_loader (loader .name , loader )
122- )
123- loader .exec_module (um_env )
124- um_vars = um_env .vars
132+ um_env_path = os .path .join (self .control_path , 'um_env.yaml' )
133+ with open (um_env_path , 'r' ) as um_env_yaml :
134+ um_env_vars = yaml .safe_load (um_env_yaml )
135+
125136
126137 # Stage the UM restart file.
127138 if self .prior_restart_path and not self .expt .repeat_run :
@@ -131,14 +142,16 @@ def setup(self):
131142 if os .path .isfile (f_src ):
132143 make_symlink (f_src , f_dst )
133144 # every run is an NRUN with an updated ASTART file
134- um_vars ['ASTART' ] = self .restart
135- um_vars ['TYPE' ] = 'NRUN'
145+ um_env_vars ['ASTART' ] = self .restart
146+ um_env_vars ['TYPE' ] = 'NRUN'
136147
137148 # Set paths in environment variables.
138- for k in um_vars .keys ():
139- um_vars [k ] = um_vars [k ].format (input_path = self .input_paths [0 ],
140- work_path = self .work_path )
141- os .environ .update (um_vars )
149+ for k in um_env_vars .keys ():
150+ um_env_vars [k ] = um_env_vars [k ].format (
151+ input_path = self .input_paths [0 ],
152+ work_path = self .work_path
153+ )
154+ os .environ .update (um_env_vars )
142155
143156 # parexe removed from newer configurations - retain the
144157 # old processing if parexe file exists for backwards compatibility
0 commit comments