1- function install()
1+ function install(auto_configure_mhkit_matlab_python_env )
22
33% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44% Install MHKiT Python dependencies and configure MATLAB integration
55%
66% Parameters
77% ------------
8- % No parameters required
8+ % auto_configure_mhkit_matlab_python_env (logical, optional):
9+ % If true, automatically configure startup script without user prompt.
10+ % Default: false (prompts user for consent)
911%
1012% Returns
1113% ---------
@@ -15,12 +17,19 @@ function install()
1517%
1618% Example
1719% -------
18- % mhkit.install()
20+ % mhkit.install() % Prompts user for startup config
21+ % mhkit.install(true) % Auto-configures startup script
22+ % mhkit.install(false) % Prompts user for startup config
1923%
2024% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2125
26+ % Handle optional parameter
27+ if nargin < 1
28+ auto_configure_mhkit_matlab_python_env = false ;
29+ end
30+
2231 % Initialize logger
23- logger = mhkit .utils .get_logger();
32+ logger = mhkit .logging .get_logger();
2433
2534 try
2635 fprintf(' \n Installing python dependencies for MHKiT-MATLAB...\n\n ' );
@@ -114,7 +123,7 @@ function install()
114123 logger .info(' \n Executing pre-install hooks...' );
115124 hook_success = mhkit .hooks.execute(' pre_install' , spec , logger );
116125 if ~hook_success
117- logger .error( ' Pre-install hooks failed' );
126+ mhkit .sys.installation_error( logger , ' Pre-install hooks failed' , ' Pre-install Dependencies ' );
118127 return ;
119128 end
120129 logger .info(' ✓ Pre-install hooks completed' );
@@ -162,7 +171,7 @@ function install()
162171 logger .info(' \n Executing post-install hooks...' );
163172 hook_success = mhkit .hooks.execute(' post_install' , spec , logger );
164173 if ~hook_success
165- logger .error( ' Post-install hooks failed' );
174+ mhkit .sys.installation_error( logger , ' Post-install hooks failed' , ' Post-install Configuration ' );
166175 return ;
167176 end
168177 logger .info(' ✓ Post-install hooks completed' );
@@ -191,27 +200,32 @@ function install()
191200 [status , extracted_path ] = mhkit .web.download_and_unzip(download_path , spec .dirs.cache, " mhkit_python_utils" );
192201
193202 if ~status == 1
194- logger .error( " Failed to download utilities from %s" , download_path );
203+ mhkit .sys.installation_error( logger , sprintf( ' Failed to download utilities from %s ' , download_path ), ' Utilities Download ' );
195204 return
196205 end
197206
198207 mhkit .sys(sprintf(" conda run -n %s pip install -e "" %s"" " , conda_env_name , extracted_path ));
199- mhkit .sys(sprintf(" conda run -n %s python -c "" import mhkit_python_utils; print(mhkit_python_utils.__version__)"" " , conda_env_name ));
208+ python_cmd = mhkit .sys.python_cmd();
209+ mhkit .sys(sprintf(" conda run -n %s %s -c "" import mhkit_python_utils; print(mhkit_python_utils.__version__)"" " , conda_env_name , python_cmd ));
200210 logger .info(' ✓ Utilities installed' );
201211
202212 % Configure MATLAB integration
203213 logger .info(' \n Configuring MATLAB integration...' );
204214
205215 % Execute environment setup hooks
206216 logger .info(' Executing environment setup hooks...' );
217+
218+ % Temporarily add auto_configure setting to spec for startup fixes
219+ spec.auto_configure_mhkit_matlab_python_env = auto_configure_mhkit_matlab_python_env ;
220+
207221 hook_success = mhkit .hooks.execute(' environment_setup' , spec , logger );
208222 if ~hook_success
209223 logger .warning(' Environment setup hooks failed, continuing with Python integration' );
210224 else
211225 logger .info(' ✓ Environment setup hooks completed' );
212226 end
213227
214- initialize_python_integration(conda_env_name , logger );
228+ initialize_python_integration(conda_env_name , logger , spec );
215229
216230 % Final verification
217231 logger .info(' Performing final verification...' );
@@ -236,11 +250,12 @@ function install()
236250end
237251
238252
239- function initialize_python_integration(env_name , logger )
253+ function initialize_python_integration(env_name , logger , spec )
240254 % Initialize Python integration
241255 try
242256 % Get the Python executable path from the conda environment
243- conda_command = sprintf(' conda run -n %s python -c "import sys; print(sys.executable)"' , env_name );
257+ python_cmd = mhkit .sys.python_cmd();
258+ conda_command = sprintf(' conda run -n %s %s -c "import sys; print(sys.executable)"' , env_name , python_cmd );
244259 logger .info(' Executing command: %s ' , conda_command );
245260 [status , python_path ] = mhkit .sys(conda_command );
246261
@@ -274,9 +289,10 @@ function initialize_python_integration(env_name, logger)
274289 setenv(' PATH' , new_path );
275290 logger .info(' Added Python directory to PATH: %s ' , python_dir );
276291
277- % Set MATLAB's Python environment with OutOfProcess execution mode (like working Unix tests)
278- pyenv(Version = python_path , ExecutionMode= " OutOfProcess" );
279- logger .info(' Configured pyenv with OutOfProcess execution mode' );
292+ % Set MATLAB's Python environment with specified execution mode
293+ execution_mode = spec .constants.matlab_integration.execution_mode;
294+ pyenv(Version = python_path , ExecutionMode= execution_mode );
295+ logger .info(' Configured pyenv with %s execution mode' , execution_mode );
280296
281297 % Test Python import
282298 logger .info(' Testing Python module imports...' );
0 commit comments