Skip to content

Commit 7125f51

Browse files
committed
Install: Run startup fixes in hooks
1 parent fbe972a commit 7125f51

1 file changed

Lines changed: 36 additions & 35 deletions

File tree

mhkit/package/+mhkit/+hooks/execute.m

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,16 @@
4646
return;
4747
end
4848
end
49-
49+
50+
% Execute startup fixes (for environment_setup hook only)
51+
if strcmp(hook_name, 'environment_setup') && isfield(hook_section, 'startup_fixes')
52+
success = execute_startup_fixes(hook_section.startup_fixes, platform, spec, logger);
53+
if ~success
54+
logger.error('Startup script configuration failed');
55+
return;
56+
end
57+
end
58+
5059
logger.info('Successfully completed %s hooks for platform "%s"', hook_name, platform);
5160
end
5261

@@ -85,7 +94,7 @@
8594
var_value = platform_env_vars.(var_name);
8695

8796
% Perform variable substitution
88-
processed_value = substitute_variables(var_value, spec);
97+
processed_value = mhkit.io.substitute_variables(var_value, spec);
8998

9099
logger.debug('Setting environment variable: %s=%s', var_name, processed_value);
91100

@@ -151,7 +160,7 @@
151160
% success (logical): True if command succeeded
152161

153162
% Perform variable substitution
154-
processed_command = substitute_variables(command, spec);
163+
processed_command = mhkit.io.substitute_variables(command, spec);
155164

156165
logger.debug('Executing command: %s', processed_command);
157166

@@ -170,39 +179,31 @@
170179
end
171180
end
172181

173-
function result = substitute_variables(text, spec)
174-
% Substitute variables in text using spec values
175-
%
176-
% Parameters:
177-
% text (string): Text with variables to substitute
178-
% spec (struct): Specification structure
179-
%
180-
% Returns:
181-
% result (string): Text with variables substituted
182-
183-
result = text;
184-
185-
% Standard substitutions
186-
if contains(result, '<conda_env>')
187-
result = strrep(result, '<conda_env>', spec.conda.environment_name);
188-
end
189-
190-
if contains(result, '<python_version>')
191-
result = strrep(result, '<python_version>', spec.python.install_version);
182+
function success = execute_startup_fixes(startup_fixes_section, platform, spec, logger)
183+
% Execute startup script configuration for a platform
184+
185+
success = true;
186+
187+
% Check if platform-specific startup fixes exist
188+
if ~isfield(startup_fixes_section, platform)
189+
logger.debug('No startup fixes found for platform "%s"', platform);
190+
return;
192191
end
193-
194-
if contains(result, '<mhkit_python_version>')
195-
result = strrep(result, '<mhkit_python_version>', spec.mhkit_python.version);
192+
193+
platform_startup_fixes = startup_fixes_section.(platform);
194+
195+
% Skip if empty
196+
if isempty(platform_startup_fixes)
197+
logger.debug('No startup fixes to apply for platform "%s"', platform);
198+
return;
196199
end
197-
198-
% Platform-specific substitutions
199-
if contains(result, '<conda_lib_path>')
200-
% Get conda library path dynamically
201-
conda_env = spec.conda.environment_name;
202-
[status, conda_info] = mhkit.sys(sprintf('conda run -n %s python -c "import sys; import os; print(os.path.join(os.path.dirname(sys.executable), ''lib''))"', conda_env));
203-
if status == 0
204-
conda_lib_path = strtrim(conda_info);
205-
result = strrep(result, '<conda_lib_path>', conda_lib_path);
206-
end
200+
201+
% Call the modular configure_environment function
202+
% Get auto_configure setting from spec (default to false if not present)
203+
auto_configure = false;
204+
if isfield(spec, 'auto_configure_mhkit_matlab_python_env')
205+
auto_configure = spec.auto_configure_mhkit_matlab_python_env;
207206
end
207+
208+
success = mhkit.configure_environment.configure_startup(spec, logger, auto_configure);
208209
end

0 commit comments

Comments
 (0)