@@ -162,6 +162,9 @@ def get_matlab_engine(engine_ready, engine_output):
162162class MatlabHelper :
163163 """Helper to start MATLAB on another process."""
164164
165+ class ConfigError (Exception ):
166+ """Error when setting up MATLAB for RasCAL usage."""
167+
165168 _instance = None
166169
167170 def __new__ (cls ):
@@ -170,6 +173,7 @@ def __new__(cls):
170173 cls ._instance .ready_event = mp .Event ()
171174 cls ._instance .close_event = mp .Event ()
172175 cls ._instance .engine_output = None
176+ cls ._instance .matlab_dir = ""
173177 cls ._instance .__engine = None
174178 cls ._instance .async_start ()
175179
@@ -221,19 +225,31 @@ def get_matlab_path(self):
221225 Return MATLAB install directory.
222226 """
223227 install_dir = ""
224- error = ""
225228
226229 try :
227230 with open (MATLAB_ARCH_FILE ) as path_file :
228231 lines = path_file .readlines ()
229232 if len (lines ) == 4 :
233+ arch = {"x86_64" : "maci64" , "arm64" : "maca64" }
234+ if platform .system () == "Darwin" and arch .get (platform .mac_ver ()[- 1 ]) != lines [0 ].strip ():
235+ # installed intel Matlab on ARM or vice versa
236+ raise MatlabHelper .ConfigError (
237+ "The installed MATLAB is incompatible, "
238+ f"ensure the { platform .mac_ver ()[- 1 ]} version of "
239+ "MATLAB is installed instead."
240+ )
241+
230242 install_dir = pathlib .Path (lines [1 ]).parent .parent
231243 else :
232- error = "Matlab not found, specify MATLAB location in settings i.e. 'File > Settings' menu"
233- except FileNotFoundError :
234- error = "Matlab engine could not be found, ensure it is installed properly"
235- if error :
244+ raise MatlabHelper .ConfigError (
245+ "Matlab not found, specify MATLAB location in settings i.e. 'File > Settings' menu."
246+ )
247+ except (FileNotFoundError , MatlabHelper .ConfigError ) as ex :
248+ if isinstance (ex , FileNotFoundError ):
249+ ex .add_note ("Matlab engine could not be found, ensure it is installed properly." )
236250 self .engine_output [:] = []
237- self .engine_output .append (Exception (error ))
238- LOGGER .error (f"{ error } . Attempt to read MATLAB _arch file failed { MATLAB_ARCH_FILE } ." )
239- return str (install_dir )
251+ self .engine_output .append (ex )
252+ LOGGER .error (f"Attempt to read MATLAB _arch file failed { MATLAB_ARCH_FILE } .\n { ex } ." )
253+
254+ self .matlab_dir = str (install_dir )
255+ return self .matlab_dir
0 commit comments