Skip to content

Commit e62ac84

Browse files
committed
Install: Add check_health command
1 parent 55cc1a4 commit e62ac84

3 files changed

Lines changed: 187 additions & 0 deletions

File tree

.github/workflows/unix_unit_tests_mhkit_install.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ jobs:
4343
mhkit.install();
4444
startup-options: -noFigureWindows
4545

46+
- name: Validate Installation Health
47+
uses: matlab-actions/run-command@v2
48+
with:
49+
command: |
50+
addpath(genpath('mhkit'));
51+
success = mhkit.check_health();
52+
if ~success
53+
error('MHKiT health check failed - installation has issues');
54+
end
55+
startup-options: -noFigureWindows
56+
4657
- name: Add MATLAB test commands
4758
shell: bash
4859
run: echo "version,
@@ -142,6 +153,17 @@ jobs:
142153
mhkit.install();
143154
startup-options: -noFigureWindows
144155

156+
- name: Validate Installation Health
157+
uses: matlab-actions/run-command@v2
158+
with:
159+
command: |
160+
addpath(genpath('mhkit'));
161+
success = mhkit.check_health();
162+
if ~success
163+
error('MHKiT health check failed - installation has issues');
164+
end
165+
startup-options: -noFigureWindows
166+
145167
- name: Add MATLAB test commands
146168
shell: bash
147169
run: echo "version,

.github/workflows/windows_unit_tests_mhkit_install.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ jobs:
4141
mhkit.install();
4242
startup-options: -noFigureWindows
4343

44+
- name: Validate Installation Health
45+
uses: matlab-actions/run-command@v2
46+
with:
47+
command: |
48+
addpath(genpath('mhkit'));
49+
success = mhkit.check_health();
50+
if ~success
51+
error('MHKiT health check failed - installation has issues');
52+
end
53+
startup-options: -noFigureWindows
54+
4455
- name: Add MATLAB test commands
4556
shell: bash
4657
run: echo "version,
@@ -129,6 +140,17 @@ jobs:
129140
mhkit.install();
130141
startup-options: -noFigureWindows
131142

143+
- name: Validate Installation Health
144+
uses: matlab-actions/run-command@v2
145+
with:
146+
command: |
147+
addpath(genpath('mhkit'));
148+
success = mhkit.check_health();
149+
if ~success
150+
error('MHKiT health check failed - installation has issues');
151+
end
152+
startup-options: -noFigureWindows
153+
132154
- name: Add MATLAB test commands
133155
shell: bash
134156
run: echo "version,
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
function result = check_health()
2+
3+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4+
% Validate MHKiT Python integration and environment health
5+
% Performs comprehensive checks of Python environment, module imports,
6+
% and MHKiT functionality to ensure everything is working correctly
7+
%
8+
% Parameters
9+
% ------------
10+
% None
11+
%
12+
% Returns
13+
% ---------
14+
% result: logical
15+
% true if all health checks pass, false if any fail
16+
%
17+
% Example
18+
% -------
19+
% if mhkit.check_health()
20+
% disp('MHKiT is ready to use!');
21+
% else
22+
% disp('MHKiT has issues - check the output above');
23+
% end
24+
%
25+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26+
27+
logger = mhkit.utils.get_logger();
28+
result = true; % Start optimistic
29+
30+
try
31+
logger.info('=== MHKiT Health Check ===');
32+
33+
% Check 1: Python Environment Configuration
34+
logger.info('=== Python Environment Validation ===');
35+
try
36+
pe = pyenv();
37+
logger.info('Python Version: %s', pe.Version);
38+
logger.info('Python Executable: %s', pe.Executable);
39+
logger.info('Python Library: %s', pe.Library);
40+
logger.info('Python Home: %s', pe.Home);
41+
logger.info('Execution Mode: %s', pe.ExecutionMode);
42+
logger.info('Status: %s', pe.Status);
43+
44+
% Validate Python is properly configured
45+
if strcmp(pe.Status, 'NotLoaded')
46+
logger.error('✗ Python is not loaded');
47+
result = false;
48+
elseif strcmp(pe.Status, 'Loaded')
49+
logger.info('✓ Python environment is loaded');
50+
else
51+
logger.warning('⚠ Python status is: %s', pe.Status);
52+
end
53+
54+
catch ME
55+
logger.error('✗ Failed to get Python environment info: %s', ME.message);
56+
result = false;
57+
end
58+
59+
% Check 2: Python Module Import Tests
60+
logger.info('=== Testing Python Module Import ===');
61+
62+
% Test mhkit module import
63+
try
64+
py.importlib.import_module('mhkit');
65+
logger.info('✓ mhkit module imported successfully');
66+
catch ME
67+
logger.error('✗ Failed to import mhkit: %s', ME.message);
68+
logger.error(' Try: pip install mhkit==0.9');
69+
result = false;
70+
end
71+
72+
% Test mhkit_python_utils module import
73+
try
74+
py.importlib.import_module('mhkit_python_utils');
75+
logger.info('✓ mhkit_python_utils module imported successfully');
76+
catch ME
77+
logger.error('✗ Failed to import mhkit_python_utils: %s', ME.message);
78+
logger.error(' This module should be installed by mhkit.install()');
79+
result = false;
80+
end
81+
82+
% Check 3: MHKiT Functionality Test
83+
logger.info('=== Testing MHKiT Functionality ===');
84+
try
85+
test_result = py.mhkit.river.performance.circular(30);
86+
logger.info('✓ MHKiT function test successful: %s', char(test_result));
87+
catch ME
88+
logger.error('✗ Failed to execute MHKiT function: %s', ME.message);
89+
logger.error(' This indicates a problem with the MHKiT Python installation');
90+
result = false;
91+
end
92+
93+
% Check 4: Additional System Information
94+
logger.info('=== System Information ===');
95+
try
96+
% Check MATLAB version
97+
logger.info('MATLAB Version: %s', version('-release'));
98+
99+
% Check platform
100+
if ispc
101+
platform = 'Windows';
102+
elseif ismac
103+
platform = 'macOS';
104+
elseif isunix
105+
platform = 'Linux';
106+
else
107+
platform = 'Unknown';
108+
end
109+
logger.info('Platform: %s', platform);
110+
111+
% Check PATH for Python
112+
current_path = getenv('PATH');
113+
if contains(current_path, 'python') || contains(current_path, 'conda')
114+
logger.info('✓ Python/Conda found in system PATH');
115+
else
116+
logger.warning('⚠ Python/Conda not detected in system PATH');
117+
end
118+
119+
catch ME
120+
logger.warning('⚠ Could not gather all system information: %s', ME.message);
121+
end
122+
123+
% Final Result
124+
if result
125+
logger.info('=== ✓ All Health Checks Passed ===');
126+
logger.info('MHKiT is ready to use!');
127+
else
128+
logger.error('=== ✗ Health Check Failed ===');
129+
logger.error('MHKiT has configuration issues that need to be resolved.');
130+
logger.error('');
131+
logger.error('Troubleshooting steps:');
132+
logger.error('1. Try restarting MATLAB');
133+
logger.error('2. Run mhkit.install() again');
134+
logger.error('3. Check that pyenv() points to the correct Python environment');
135+
logger.error('4. Verify conda/Python are in your system PATH');
136+
end
137+
138+
catch ME
139+
logger.error('=== ✗ Health Check Error ===');
140+
logger.error('Health check encountered an unexpected error: %s', ME.message);
141+
result = false;
142+
end
143+
end

0 commit comments

Comments
 (0)