Skip to content

Commit 3e0895a

Browse files
committed
Install: Add pre, post, and set env hooks
1 parent cb1531b commit 3e0895a

2 files changed

Lines changed: 92 additions & 2 deletions

File tree

mhkit/package/+mhkit/install.m

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ function install()
110110
end
111111
end
112112

113+
% Execute pre-install hooks
114+
logger.info('\nExecuting pre-install hooks...');
115+
hook_success = mhkit.hooks.execute('pre_install', spec, logger);
116+
if ~hook_success
117+
logger.error('Pre-install hooks failed');
118+
return;
119+
end
120+
logger.info('✓ Pre-install hooks completed');
121+
113122
% Check if `mhkit` is in `conda list`
114123
has_correct_mhkit_python = false;
115124
conda_packages = mhkit.conda.list(conda_env_name);
@@ -124,7 +133,10 @@ function install()
124133
if ~has_correct_mhkit_python
125134
% Step 4: Install MHKiT-Python
126135
logger.info('\nInstalling MHKiT-Python v%s...', spec.mhkit_python.version);
127-
command = spec.mhkit_python.install;
136+
137+
% Get platform-specific install command
138+
platform = mhkit.sys.get_platform();
139+
command = spec.mhkit_python.install.(platform);
128140
command = replace(command, '<mhkit_python_version>', spec.mhkit_python.version);
129141
mhkit.sys(sprintf("conda run -n %s %s", conda_env_name, command));
130142

@@ -146,6 +158,15 @@ function install()
146158
logger.info('✓ MHKiT-Python v%s ready', spec.mhkit_python.version);
147159
end
148160

161+
% Execute post-install hooks
162+
logger.info('\nExecuting post-install hooks...');
163+
hook_success = mhkit.hooks.execute('post_install', spec, logger);
164+
if ~hook_success
165+
logger.error('Post-install hooks failed');
166+
return;
167+
end
168+
logger.info('✓ Post-install hooks completed');
169+
149170
logger.info('Testing functionality...');
150171
command = spec.mhkit_python.verify_operation.command;
151172
command = sprintf("conda run -n %s %s", conda_env_name, command);
@@ -180,6 +201,16 @@ function install()
180201

181202
% Configure MATLAB integration
182203
logger.info('\nConfiguring MATLAB integration...');
204+
205+
% Execute environment setup hooks
206+
logger.info('Executing environment setup hooks...');
207+
hook_success = mhkit.hooks.execute('environment_setup', spec, logger);
208+
if ~hook_success
209+
logger.warning('Environment setup hooks failed, continuing with Python integration');
210+
else
211+
logger.info('✓ Environment setup hooks completed');
212+
end
213+
183214
initialize_python_integration(conda_env_name, logger);
184215

185216
% Final verification

mhkit/package/+mhkit/spec.json

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
"maximum_version": "3.12"
2020
},
2121
"mhkit_python": {
22-
"install": "conda install -c conda-forge mhkit==<mhkit_python_version> -y",
22+
"install": {
23+
"windows": "conda install -c conda-forge mhkit==<mhkit_python_version> -y",
24+
"linux": "conda install -c conda-forge mhkit==<mhkit_python_version> -y",
25+
"mac": "conda install -c conda-forge mhkit==<mhkit_python_version> -y"
26+
},
2327
"version": "0.9",
2428
"verify_version": {
2529
"command": "python -c \"import mhkit; print(mhkit.__version__)\"",
@@ -60,5 +64,60 @@
6064
"rm ~/miniconda3/miniconda.sh"
6165
]
6266
}
67+
},
68+
"hooks": {
69+
"pre_install": {
70+
"commands": {
71+
"linux": [
72+
"conda run -n <conda_env> conda install numpy cython pip pytest hdf5 libnetcdf cftime netcdf4 -y"
73+
],
74+
"mac": [
75+
"conda run -n <conda_env> conda install numpy cython pip pytest hdf5 libnetcdf cftime netcdf4 -y",
76+
"conda run -n <conda_env> conda install openssl==3.0.* -y"
77+
],
78+
"windows": []
79+
},
80+
"environment_variables": {
81+
"linux": {},
82+
"mac": {},
83+
"windows": {}
84+
}
85+
},
86+
"post_install": {
87+
"commands": {
88+
"linux": [
89+
"conda run -n <conda_env> pip install --upgrade netcdf4",
90+
"conda run -n <conda_env> pip uninstall -y scipy",
91+
"conda run -n <conda_env> pip install scipy==1.12.0"
92+
],
93+
"mac": [
94+
"conda run -n <conda_env> pip install --upgrade netcdf4",
95+
"conda run -n <conda_env> pip uninstall -y scipy",
96+
"conda run -n <conda_env> pip install scipy==1.12.0"
97+
],
98+
"windows": []
99+
},
100+
"environment_variables": {
101+
"linux": {},
102+
"mac": {},
103+
"windows": {}
104+
}
105+
},
106+
"environment_setup": {
107+
"commands": {
108+
"linux": [],
109+
"mac": [],
110+
"windows": []
111+
},
112+
"environment_variables": {
113+
"linux": {
114+
"LD_PRELOAD": "/lib/x86_64-linux-gnu/libstdc++.so.6"
115+
},
116+
"mac": {
117+
"DYLD_LIBRARY_PATH": "<conda_lib_path>:$DYLD_LIBRARY_PATH"
118+
},
119+
"windows": {}
120+
}
121+
}
63122
}
64123
}

0 commit comments

Comments
 (0)