Skip to content

Commit 885976c

Browse files
committed
Use _utils module to get matlab paths information
1 parent 4e5fa89 commit 885976c

2 files changed

Lines changed: 10 additions & 22 deletions

File tree

src/matlab/__init__.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import platform
55
import sys
66
import pkgutil
7+
from . import _utils
78

89
__path__ = pkgutil.extend_path(__path__, __name__)
910
package_folder = os.path.dirname(os.path.realpath(__file__))
@@ -35,13 +36,7 @@ def add_dirs_to_path(bin_dir, engine_dir, extern_dir):
3536
sys.path.insert(0, engine_dir)
3637
sys.path.insert(0, extern_dir)
3738

38-
arch_file = os.path.join(package_folder, 'engine', '_arch.txt')
39-
if not os.path.isfile(arch_file):
40-
raise RuntimeError("The MATLAB Engine for Python install is corrupted. Please try to re-install.")
41-
42-
with open(arch_file, 'r') as root:
43-
[arch, bin_folder, engine_folder, extern_bin] = [line.strip() for line in root.readlines()]
44-
39+
arch, bin_folder, engine_folder, extern_bin = _utils.get_path_info()
4540

4641
add_dirs_to_path(bin_folder, engine_folder, extern_bin)
4742

src/matlab/engine/__init__.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import threading
2828
import warnings
2929

30+
from .. import _utils
31+
3032
# UPDATE_IF_PYTHON_VERSION_ADDED_OR_REMOVED : search for this string in codebase
3133
# when support for a Python version must be added or removed
3234

@@ -50,8 +52,6 @@
5052
'is %s' % _version)
5153

5254

53-
_module_folder = os.path.dirname(os.path.realpath(__file__))
54-
_arch_filename = os.path.join(_module_folder, "_arch.txt")
5555
success = False
5656
firstExceptionMessage = ''
5757
secondExceptionMessage = ''
@@ -65,21 +65,14 @@
6565

6666
if firstExceptionMessage:
6767
try:
68-
_arch_file = open(_arch_filename,'r')
69-
_lines = _arch_file.readlines()
70-
[_arch, _bin_dir,_engine_dir, _extern_bin_dir] = [x.rstrip() for x in _lines if x.rstrip() != ""]
71-
_arch_file.close()
72-
sys.path.insert(0,_engine_dir)
73-
sys.path.insert(0,_extern_bin_dir)
74-
7568
_envs = {'win32': 'PATH', 'win64': 'PATH'}
76-
if _arch in _envs:
77-
if _envs[_arch] in os.environ:
78-
_env = os.environ[_envs[_arch]]
79-
os.environ[_envs[_arch]] = _bin_dir + os.pathsep + os.environ[_envs[_arch]]
69+
_path_info = _utils.get_path_info()
70+
if _path_info.arch in _envs:
71+
if _envs[_path_info.arch] in os.environ:
72+
os.environ[_envs[_path_info.arch]] = _path_info.bin_folder + os.pathsep + os.environ[_envs[_path_info.arch]]
8073
else:
81-
os.environ[_envs[_arch]] = _bin_dir
82-
os.add_dll_directory(_bin_dir)
74+
os.environ[_envs[_path_info.arch]] = _path_info.bin_folder
75+
os.add_dll_directory(_path_info.bin_folder)
8376
if _PYTHONVERSION != '3_9' or _PYTHONVERSION != '3_10':
8477
pythonengine = importlib.import_module("matlabengineforpython_abi3")
8578
else:

0 commit comments

Comments
 (0)