@@ -110,21 +110,35 @@ def run_simulation(EVENT_input_path, SAM_input_path, AIM_input_path, EDP_input_p
110110
111111 custom_script_path = SAM_in ['mainScript' ]
112112
113- # copy the custom scripts to the current directory if not yet
113+ # locate the custom script: check cwd, then modelPath (copy), then custom_path (no copy)
114+ import_name = custom_script_path [:- 3 ]
114115 if os .path .exists (custom_script_path ): # noqa: PTH110
115- pass
116+ pass # script already in cwd
116117 else :
117- custom_script_dir = SAM_in .get ('modelPath' , None )
118- if custom_script_dir is None :
119- log_msg ('No modelPath found in the SAM file.' ) # noqa: F405
118+ model_path = SAM_in .get ('modelPath' , None )
119+ custom_path = AIM_in .get ('commonFileDir' , None )
120+ if model_path is not None and os .path .isfile ( # noqa: PTH113
121+ os .path .join (model_path , custom_script_path ) # noqa: PTH118
122+ ):
123+ if not os .path .isdir (model_path ): # noqa: PTH112
124+ log_msg (f'modelPath directory does not exist: { model_path } ' ) # noqa: F405
125+ else :
126+ shutil .copytree (model_path , os .getcwd (), dirs_exist_ok = True ) # noqa: PTH109
127+ log_msg ( # noqa: F405
128+ f'Custom scripts copied from { model_path } to { os .getcwd ()} ' # noqa: PTH109
129+ )
130+ elif custom_path is not None and os .path .isfile ( # noqa: PTH113
131+ os .path .join (custom_path , custom_script_path ) # noqa: PTH118
132+ ):
133+ sys .path .insert (0 , custom_path )
134+ log_msg (f'Custom script found in custom_path: { custom_path } ' ) # noqa: F405
120135 else :
121- shutil .copytree (custom_script_dir , os .getcwd (), dirs_exist_ok = True ) # noqa: PTH109
122136 log_msg ( # noqa: F405
123- f'Custom scripts copied from { custom_script_dir } to { os . getcwd () } ' # noqa: PTH109
137+ f'Custom script { custom_script_path } not found in cwd, modelPath, or custom_path'
124138 )
125139
126140 custom_script = importlib .__import__ (
127- custom_script_path [: - 3 ] ,
141+ import_name ,
128142 globals (),
129143 locals (),
130144 [
0 commit comments