1010if platform .system () == 'Windows' :
1111 import winreg
1212
13+ def is_configure_root () -> bool :
14+ """
15+ Returns True if matlab folders should be configured at build time
16+ """
17+ return os .environ .get ('MATLAB_ENGINE_CONFIGURE_ROOT' , 'true' ).lower () in ('true' , '1' )
18+
19+
1320class _MatlabFinder (build_py ):
1421 """
1522 Private class that finds MATLAB on user's computer prior to package installation.
@@ -379,34 +386,36 @@ def run(self):
379386 self .set_platform_and_arch ()
380387 self .set_python_version ()
381388
382- if self .platform == 'Windows' :
383- matlab_root = self .get_matlab_root_from_windows_reg ()
384- else :
385- if self .unix_default_install_exists ():
386- matlab_root = self .DEFAULT_INSTALLS [self .platform ]
389+ if is_configure_root ():
390+ if self .platform == 'Windows' :
391+ matlab_root = self .get_matlab_root_from_windows_reg ()
387392 else :
388- path_dirs = self ._create_path_list ()
389- matlab_root = self .search_path_for_directory_unix (self .arch , path_dirs )
390- err_msg = self ._err_msg_if_bad_matlab_root (matlab_root )
391- if err_msg :
392- if self .platform == 'Darwin' :
393- if self .found_matlab_with_wrong_arch_in_default_install :
394- raise RuntimeError (
395- self .wrong_arch_in_default_install .format (
396- path1 = self .found_matlab_with_wrong_arch_in_default_install ,
397- matlab_arch = self ._get_alternate_arch (),
398- python_arch = self .arch ,
399- next_steps = self .next_steps ))
400- if self .found_matlab_with_wrong_arch_in_path :
401- raise RuntimeError (
402- self .wrong_arch_in_path .format (
403- path1 = self .found_matlab_with_wrong_arch_in_path ,
404- matlab_arch = self ._get_alternate_arch (),
405- python_arch = self .arch ,
406- next_steps = self .next_steps ))
407- raise RuntimeError (err_msg )
393+ if self .unix_default_install_exists ():
394+ matlab_root = self .DEFAULT_INSTALLS [self .platform ]
395+ else :
396+ path_dirs = self ._create_path_list ()
397+ matlab_root = self .search_path_for_directory_unix (self .arch , path_dirs )
398+ err_msg = self ._err_msg_if_bad_matlab_root (matlab_root )
399+ if err_msg :
400+ if self .platform == 'Darwin' :
401+ if self .found_matlab_with_wrong_arch_in_default_install :
402+ raise RuntimeError (
403+ self .wrong_arch_in_default_install .format (
404+ path1 = self .found_matlab_with_wrong_arch_in_default_install ,
405+ matlab_arch = self ._get_alternate_arch (),
406+ python_arch = self .arch ,
407+ next_steps = self .next_steps ))
408+ if self .found_matlab_with_wrong_arch_in_path :
409+ raise RuntimeError (
410+ self .wrong_arch_in_path .format (
411+ path1 = self .found_matlab_with_wrong_arch_in_path ,
412+ matlab_arch = self ._get_alternate_arch (),
413+ python_arch = self .arch ,
414+ next_steps = self .next_steps ))
415+ raise RuntimeError (err_msg )
416+
417+ self .write_text_file (matlab_root )
408418
409- self .write_text_file (matlab_root )
410419 build_py .run (self )
411420
412421
@@ -427,7 +436,7 @@ def run(self):
427436 package_dir = {'' : 'src' },
428437 packages = find_packages (where = "src" ),
429438 cmdclass = {'build_py' : _MatlabFinder },
430- package_data = {'' : ['_arch.txt' ]},
439+ package_data = {'' : ['_arch.txt' ]} if is_configure_root () else {} ,
431440 zip_safe = False ,
432441 project_urls = {
433442 'Documentation' : 'https://www.mathworks.com/help/matlab/matlab-engine-for-python.html' ,
0 commit comments