Skip to content

Commit 1517cb3

Browse files
committed
R2021b 9.11.19a3
1 parent 0d4171f commit 1517cb3

File tree

3 files changed

+54
-63
lines changed

3 files changed

+54
-63
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The MATLAB® Engine API for Python® provides a package to integrate MATLA
2121
MATLAB Engine API for Python can be installed directly from the Python Package Index.
2222
<!-- MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string) -->
2323
```bash
24-
$ python -m pip install matlabengine==9.11.19a2
24+
$ python -m pip install matlabengine==9.11.19a3
2525
```
2626

2727

@@ -46,7 +46,7 @@ setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:matlabroot/bin/glnxa64
4646
MATLAB Engine API for Python can be installed directly from the Python Package Index.
4747
<!-- MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string) -->
4848
```bash
49-
$ python -m pip install matlabengine==9.11.19a2
49+
$ python -m pip install matlabengine==9.11.19a3
5050
```
5151

5252
### macOS
@@ -70,7 +70,7 @@ setenv DYLD_LIBRARY_PATH ${DYLD_LIBRARY_PATH}:matlabroot/bin/maci64
7070
MATLAB Engine API for Python can be installed directly from the Python Package Index.
7171
<!-- MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string) -->
7272
```bash
73-
$ python -m pip install matlabengine==9.11.19a2
73+
$ python -m pip install matlabengine==9.11.19a3
7474
```
7575

7676
---

setup.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class _MatlabFinder(build_py):
2424
MATLAB_REL = 'R2021b'
2525

2626
# MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string)
27-
MATLAB_VER = '9.11.19a2'
27+
MATLAB_VER = '9.11.19a3'
2828

2929
# MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string)
3030
SUPPORTED_PYTHON_VERSIONS = set(['3.7', '3.8', '3.9'])
@@ -34,7 +34,8 @@ class _MatlabFinder(build_py):
3434
"9.9": "R2020b",
3535
"9.10": "R2021a",
3636
"9.11": "R2021b",
37-
"9.12": "R2022a"
37+
"9.12": "R2022a",
38+
"9.13": "R2022b"
3839
}
3940

4041
DEFAULT_INSTALLS = {
@@ -243,8 +244,8 @@ def search_path_for_directory_unix(self):
243244
while not matlab_root and ending_idx < len(endings):
244245
ending = endings[ending_idx]
245246
if path.endswith(ending):
246-
# _get_matlab_root_from_unix_bin will return an empty string if MATLAB is not found
247-
# non-empty string (MATLAB found) will break both loops
247+
# _get_matlab_root_from_unix_bin will return an empty string if MATLAB is not found.
248+
# Non-empty string (MATLAB found) will break both loops.
248249
matlab_root = self._get_matlab_root_from_unix_bin(path)
249250
ending_idx += 1
250251
dir_idx += 1
@@ -308,7 +309,7 @@ def run(self):
308309
setup(
309310
name="matlabengine",
310311
# MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string)
311-
version="9.11.19a2",
312+
version="9.11.19a3",
312313
description='A module to call MATLAB from Python',
313314
author='MathWorks',
314315
license="MathWorks XSLA License",

src/matlab/engine/__init__.py

Lines changed: 45 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2022 MathWorks, Inc.
1+
#Copyright 2014-2021 MathWorks, Inc.
22

33
"""
44
The MATLAB Engine enables you to call any MATLAB statement either synchronously
@@ -19,73 +19,63 @@
1919
"""
2020

2121

22+
import os
2223
import sys
2324
import importlib
2425
import atexit
26+
import weakref
2527
import threading
26-
import platform
27-
import os
28-
29-
package_folder = os.path.dirname(os.path.realpath(__file__))
30-
31-
def add_dirs_to_path(bin_dir, engine_dir, extern_dir):
32-
"""
33-
Adds MATLAB engine and extern/bin directories to sys.path.
34-
"""
35-
path = 'PATH'
36-
37-
if not os.path.isdir(engine_dir):
38-
raise RuntimeError("Could not find directory: {0}".format(engine_dir))
39-
40-
if not os.path.isdir(extern_dir):
41-
raise RuntimeError("Could not find directory: {0}".format(extern_dir))
42-
43-
if platform.system() == 'Windows':
44-
if not os.path.isdir(bin_dir):
45-
raise RuntimeError("Could not find directory: {0}".format(bin_dir))
46-
if path in os.environ:
47-
paths = os.environ[path]
48-
os.environ[path] = bin_dir + os.pathsep + paths
49-
else:
50-
os.environ[path] = bin_dir
51-
if sys.version_info.major >= 3 and sys.version_info.minor >= 8:
52-
os.add_dll_directory(bin_dir)
53-
54-
sys.path.insert(0, engine_dir)
55-
sys.path.insert(0, extern_dir)
5628

57-
# MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string)
58-
_supported_versions = set(['3_7', '3_8', '3_9'])
29+
# UPDATE_IF_PYTHON_VERSION_ADDED_OR_REMOVED : search for this string in codebase
30+
# when support for a Python version must be added or removed
31+
_supported_versions = ['2_7', '3_7', '3_8', '3_9']
5932
_ver = sys.version_info
6033
_version = '{0}_{1}'.format(_ver[0], _ver[1])
61-
if _version not in _supported_versions:
62-
raise RuntimeError("Python {0}.{1} is not supported. Supported versions " +
63-
'are {2}.'.format(_ver[0], _ver[1, _supported_versions]))
64-
65-
first_exception_message = ''
66-
second_exception_message = ''
34+
_PYTHONVERSION = None
35+
36+
if _version in _supported_versions:
37+
_PYTHONVERSION = _version
38+
else:
39+
raise EnvironmentError("Python %s is not supported." % _version)
40+
41+
_module_folder = os.path.dirname(os.path.realpath(__file__))
42+
_arch_filename = os.path.join(_module_folder, "_arch.txt")
43+
success = False
44+
firstExceptionMessage = ''
45+
secondExceptionMessage = ''
6746
try:
68-
pythonengine = importlib.import_module("matlabengineforpython"+_version)
69-
except Exception as first_error:
70-
first_exception_message = str(first_error)
47+
pythonengine = importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
48+
except Exception as firstE:
49+
firstExceptionMessage = str(firstE)
7150

72-
if first_exception_message:
51+
if firstExceptionMessage:
7352
try:
74-
arch_file = os.path.join(package_folder, '_arch.txt')
75-
with open(arch_file, 'r') as root:
76-
[arch, bin_folder, engine_folder, extern_bin] = [line.strip() for line in root.readlines()]
77-
78-
add_dirs_to_path(bin_folder, engine_folder, extern_bin)
79-
pythonengine = importlib.import_module("matlabengineforpython"+_version)
80-
81-
except Exception as second_error:
53+
_arch_file = open(_arch_filename,'r')
54+
_lines = _arch_file.readlines()
55+
[_arch, _bin_dir,_engine_dir, _extern_bin_dir] = [x.rstrip() for x in _lines if x.rstrip() != ""]
56+
_arch_file.close()
57+
sys.path.insert(0,_engine_dir)
58+
sys.path.insert(0,_extern_bin_dir)
59+
60+
_envs = {'win32': 'PATH', 'win64': 'PATH'}
61+
if _arch in _envs:
62+
if _envs[_arch] in os.environ:
63+
_env = os.environ[_envs[_arch]]
64+
os.environ[_envs[_arch]] = _bin_dir + os.pathsep + os.environ[_envs[_arch]]
65+
else:
66+
os.environ[_envs[_arch]] = _bin_dir
67+
if sys.version_info.major >= 3 and sys.version_info.minor >= 8:
68+
os.add_dll_directory(_bin_dir)
69+
pythonengine = importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
70+
except Exception as secondE:
8271
str1 = 'Please reinstall MATLAB Engine for Python or contact '
8372
str2 = 'MathWorks Technical Support for assistance:\nFirst issue: {}\nSecond issue: {}'.format(
84-
first_exception_message, second_error)
85-
second_exception_message = str1 + str2
73+
firstExceptionMessage, secondE)
74+
secondExceptionMessage = str1 + str2
75+
76+
if secondExceptionMessage:
77+
raise EnvironmentError(secondExceptionMessage)
8678

87-
if second_exception_message:
88-
raise EnvironmentError(second_exception_message)
8979

9080
"""
9181
This lock can make sure the global variable _engines is updated correctly in

0 commit comments

Comments
 (0)