Skip to content

Commit 6fc723b

Browse files
committed
initial version of R2021a (9.10.1a0)
1 parent 7e21da3 commit 6fc723b

File tree

4 files changed

+58
-211
lines changed

4 files changed

+58
-211
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ The MATLAB® Engine API for Python® provides a package to integrate MATLA
66
## Requirements
77
### Required MathWorks Products
88
<!-- MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string) -->
9-
* MATLAB release R2021b
9+
* MATLAB release R2021a
1010

1111
### Required 3rd Party Products
1212
<!-- MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string) -->
13-
* Python 3.7, 3.8, or 3.9
13+
* Python 3.7 or 3.8
1414
* Supported Python versions by MATLAB release can be found [here](https://www.mathworks.com/content/dam/mathworks/mathworks-dot-com/support/sysreq/files/python-compatibility.pdf).
1515

1616
---
@@ -21,15 +21,15 @@ The MATLAB&reg; Engine API for Python&reg; 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.19a1
24+
$ python -m pip install matlabengine==9.10.1a0
2525
```
2626

2727

2828

2929
### Linux&reg;
3030
Prior to installation, check the default install location of MATLAB by calling ```matlabroot``` in a MATLAB Command Window. By default, Linux installs MATLAB at:<br>
3131
<!-- MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string) -->
32-
```/usr/local/MATLAB/R2021b```
32+
```/usr/local/MATLAB/R2021a```
3333

3434
When MATLAB is not installed in the default location, the bin/*architecture* directory within the MATLAB root directory must be added to an environment variable. The path can be added to the environment variable within the shell startup configuration file (for example, .bashrc for bash shell or .tcshrc for tcsh).
3535

@@ -46,14 +46,14 @@ 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.19a1
49+
$ python -m pip install matlabengine==9.10.1a0
5050
```
5151

5252
### macOS
5353
Prior to installation, check the default install location of MATLAB by calling ```matlabroot``` in a MATLAB Command Window. By default, macOS installs MATLAB at:<br>
5454

5555
<!-- MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string) -->
56-
```/Applications/MATLAB_R2021b.app```
56+
```/Applications/MATLAB_R2021a.app```
5757

5858
When MATLAB is not installed in the default location, the bin/*architecture* directory within the MATLAB root directory must be added to an environment variable. The path can be added to the environment variable within the shell startup configuration file (for example, .bashrc for bash shell or .tcshrc for tcsh).
5959

@@ -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.19a1
73+
$ python -m pip install matlabengine==9.10.1a0
7474
```
7575

7676
---

setup.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ class _MatlabFinder(build_py):
2121
}
2222

2323
# MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string)
24-
MATLAB_REL = 'R2021b'
24+
MATLAB_REL = 'R2021a'
2525

2626
# MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string)
27-
MATLAB_VER = '9.11.19a1'
27+
MATLAB_VER = '9.10.1a0'
2828

2929
# MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string)
30-
SUPPORTED_PYTHON_VERSIONS = set(['3.7', '3.8', '3.9'])
30+
SUPPORTED_PYTHON_VERSIONS = set(['2.7', '3.7', '3.8'])
3131

3232
# MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string)
3333
VER_TO_REL = {
@@ -303,7 +303,7 @@ def run(self):
303303
setup(
304304
name="matlabengine",
305305
# MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string)
306-
version="9.11.19a1",
306+
version="9.10.1a0",
307307
description='A module to call MATLAB from Python',
308308
author='MathWorks',
309309
license="MathWorks XSLA License",
@@ -328,10 +328,10 @@ def run(self):
328328
"Natural Language :: English",
329329
"Intended Audience :: Developers",
330330
# MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string)
331+
"Programming Language :: Python :: 2.7",
331332
"Programming Language :: Python :: 3.7",
332-
"Programming Language :: Python :: 3.8",
333-
"Programming Language :: Python :: 3.9"
333+
"Programming Language :: Python :: 3.8"
334334
],
335335
# MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string)
336-
python_requires=">=3.7, <3.10"
336+
python_requires=">=2.7.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, !=3.6.*, <3.9"
337337
)

src/matlab/__init__.py

Lines changed: 7 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021 MathWorks, Inc.
1+
# Copyright 2014-2015 MathWorks, Inc.
22
"""
33
Array interface between Python and MATLAB.
44
@@ -9,152 +9,19 @@
99
Modules
1010
-------
1111
* mlarray - type-specific multidimensional array classes for working
12-
with MATLAB, implemented in Python
13-
* mcpyarray - type-specific multidimensional array classes for working
14-
with MATLAB, implemented in C++
15-
* mlexceptions - exceptions raised when manipulating mlarray objects
12+
with MATLAB
13+
* mlexceptions - exceptions raised manipulating mlarray objects
1614
"""
1715

1816
import os
1917
import sys
20-
21-
# These can be removed once we no longer use _MiniPathInitializer.
22-
import platform
23-
import re
24-
2518
from pkgutil import extend_path
2619
__path__ = extend_path(__path__, '__name__')
2720

2821
_package_folder = os.path.dirname(os.path.realpath(__file__))
2922
sys.path.append(_package_folder)
3023

31-
# This code allows us to:
32-
# (1) switch from a pure Python ("mlarray") to a C++ extension ("mcpyarray")
33-
# implementation by setting the environment variable USE_MCPYARRAY to 1
34-
# (2) put the proper extern/bin/<arch> directory on the Python path to avoid
35-
# a situation in which some shared libraries are loaded from a MATLAB while
36-
# others are loaded from a runtime. The first directory on the path that contains
37-
# the string "bin/<arch>" (with the proper directory separator)
38-
# will be checked. If it is "extern/bin/<arch>", it will be used as the
39-
# extern/bin/<arch> directory. Otherwise, we'll go up two directories and down
40-
# to extern/bin/<arch>.
41-
class _MiniPathInitializer(object):
42-
PLATFORM_DICT = {'Windows': 'PATH', 'Linux': 'LD_LIBRARY_PATH', 'Darwin': 'DYLD_LIBRARY_PATH'}
43-
44-
def __init__(self):
45-
self.arch = ''
46-
self.extern_bin_dir = ''
47-
self.path_var = ''
48-
self.system = ''
49-
self.use_mcpyarray = False
50-
if os.environ.get('USE_MCPYARRAY') and os.environ['USE_MCPYARRAY'] == '1':
51-
self.use_mcpyarray = True
52-
53-
def get_platform_info(self):
54-
"""Ask Python for the platform and architecture."""
55-
# This will return 'Windows', 'Linux', or 'Darwin' (for Mac).
56-
self.system = platform.system()
57-
if not self.system in _MiniPathInitializer.PLATFORM_DICT:
58-
raise RuntimeError('{0} is not a supported platform.'.format(self.system))
59-
else:
60-
# path_var is the OS-dependent name of the path variable ('PATH', 'LD_LIBRARY_PATH', "DYLD_LIBRARY_PATH')
61-
self.path_var = _MiniPathInitializer.PLATFORM_DICT[self.system]
62-
63-
if self.system == 'Windows':
64-
self.arch = 'win64'
65-
elif self.system == 'Linux':
66-
self.arch = 'glnxa64'
67-
elif self.system == 'Darwin':
68-
self.arch = 'maci64'
69-
else:
70-
raise RuntimeError('Operating system {0} is not supported.'.format(self.system))
71-
72-
def is_extern_bin_on_py_sys_path(self):
73-
#Retrieve Python sys.path as a single string, and search for the substring "extern/bin/<arch>" (with
74-
#the proper directory separator). If it's already present, assume it's the one we want.
75-
substr_to_find = os.path.join('extern', 'bin', self.arch)
76-
for item in sys.path:
77-
if item.find(substr_to_find) != -1:
78-
return True
79-
return False
80-
81-
def put_extern_bin_on_py_sys_path(self):
82-
"""
83-
Look through the system path for the first directory ending with "runtime/<arch>" or
84-
"bin/<arch>" (with/without trailing slash). Use this to construct a new path ending
85-
with "extern/bin/<arch>".
86-
"""
87-
88-
path_elements = []
89-
if self.path_var in os.environ:
90-
path_elements_orig = os.environ[self.path_var]
91-
# On Windows, some elements of the path may use forward slashes while others use backslashes.
92-
# Make them all backslashes.
93-
if self.system == 'Windows':
94-
path_elements_orig = path_elements_orig.replace('/', '\\')
95-
path_elements = path_elements_orig.split(os.pathsep)
96-
if not path_elements:
97-
if self.system == 'Darwin':
98-
raise RuntimeError('On the Mac, you must run mwpython rather than python ' +
99-
'to start a session or script that imports your package. ' +
100-
'For more details, execute "mwpython -help" or see the package documentation.')
101-
else:
102-
raise RuntimeError('On {0}, you must set the environment variable "{1}" to a non-empty string. {2}'.format(
103-
self.system, self.path_var,
104-
'For more details, see the package documentation.'))
105-
106-
dir_to_search = os.path.join('runtime', self.arch)
107-
trailing_substrings_to_find = [dir_to_search, dir_to_search + os.sep]
108-
109-
dir_found = ''
110-
for elem in path_elements:
111-
for trailing_substring in trailing_substrings_to_find:
112-
if elem.endswith(trailing_substring):
113-
dir_found = elem
114-
break
115-
if dir_found:
116-
break
117-
118-
if not dir_found:
119-
raise RuntimeError('Could not find an appropriate directory in {0} from which to read binaries.'.format(
120-
self.path_var))
121-
122-
path_components = dir_found.split(os.sep)
123-
124-
if path_components[-1]:
125-
last_path_component = path_components[-1]
126-
possible_extern = -3
127-
else:
128-
# The directory name ended with a slash, so the last item in the list was an empty string. Go back one more.
129-
last_path_component = path_components[-2]
130-
possible_extern = -4
131-
132-
if last_path_component != self.arch:
133-
output_str = ''.join(('To call deployed MATLAB code on a {0} machine, you must run a {0} version of Python, ',
134-
'and your {1} variable must contain an element pointing to "<MR>{2}runtime{2}{0}", ',
135-
'where "<MR>" indicates a MATLAB or MATLAB Runtime root. ',
136-
'Instead, the value found was as follows: {3}'))
137-
raise RuntimeError(output_str.format(self.arch, self.path_var, os.sep, dir_found))
138-
139-
if (len(path_components) + possible_extern) >= 0 and path_components[possible_extern] == 'extern':
140-
extern_bin_dir = dir_found
141-
else:
142-
mroot = os.path.dirname(os.path.dirname(os.path.normpath(dir_found)))
143-
extern_bin_dir = os.path.join(mroot, 'extern', 'bin', self.arch)
144-
if not os.path.isdir(extern_bin_dir):
145-
raise RuntimeError('Could not find the directory {0}'.format(extern_bin_dir))
146-
self.extern_bin_dir = extern_bin_dir
147-
sys.path.insert(0, self.extern_bin_dir)
148-
149-
_mpi = _MiniPathInitializer()
150-
if _mpi.use_mcpyarray:
151-
_mpi.get_platform_info()
152-
if not _mpi.is_extern_bin_on_py_sys_path():
153-
_mpi.put_extern_bin_on_py_sys_path()
154-
from matlabmultidimarrayforpython import double, single, uint8, int8, uint16, \
155-
int16, uint32, int32, uint64, int64, logical, ShapeError, SizeError
156-
else:
157-
from mlarray import double, single, uint8, int8, uint16, \
158-
int16, uint32, int32, uint64, int64, logical
159-
from mlexceptions import ShapeError as ShapeError
160-
from mlexceptions import SizeError as SizeError
24+
from mlarray import double, single, uint8, int8, uint16, \
25+
int16, uint32, int32, uint64, int64, logical
26+
from mlexceptions import ShapeError as ShapeError
27+
from mlexceptions import SizeError as SizeError

src/matlab/engine/__init__.py

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

33
"""
44
The MATLAB Engine enables you to call any MATLAB statement either synchronously
@@ -19,73 +19,53 @@
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']
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]))
34+
_PYTHONVERSION = None
6435

65-
first_exception_message = ''
66-
second_exception_message = ''
67-
try:
68-
pythonengine = importlib.import_module("matlabengineforpython"+_version)
69-
except Exception as first_error:
70-
first_exception_message = str(first_error)
36+
if _version in _supported_versions:
37+
_PYTHONVERSION = _version
38+
else:
39+
raise EnvironmentError("Python %s is not supported." % _version)
7140

72-
if first_exception_message:
41+
_module_folder = os.path.dirname(os.path.realpath(__file__))
42+
_arch_filename = os.path.join(_module_folder, "_arch.txt")
43+
44+
try:
45+
pythonengine = importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
46+
except:
7347
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:
82-
str1 = 'Please reinstall MATLAB Engine for Python or contact '
83-
str2 = 'MathWorks Technical Support for assistance:\nFirst issue: {}\nSecond issue: {}'.format(
84-
first_exception_message, second_error)
85-
second_exception_message = str1 + str2
48+
_arch_file = open(_arch_filename,'r')
49+
_lines = _arch_file.readlines()
50+
[_arch, _bin_dir,_engine_dir, _extern_bin_dir] = [x.rstrip() for x in _lines if x.rstrip() != ""]
51+
_arch_file.close()
52+
sys.path.insert(0,_engine_dir)
53+
sys.path.insert(0,_extern_bin_dir)
54+
55+
_envs = {'win32': 'PATH', 'win64': 'PATH'}
56+
if _arch in _envs:
57+
if _envs[_arch] in os.environ:
58+
_env = os.environ[_envs[_arch]]
59+
os.environ[_envs[_arch]] = _bin_dir + os.pathsep + os.environ[_envs[_arch]]
60+
else:
61+
os.environ[_envs[_arch]] = _bin_dir
62+
if sys.version_info.major >= 3 and sys.version_info.minor >= 8:
63+
os.add_dll_directory(_bin_dir)
64+
pythonengine = importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
65+
except Exception as e:
66+
raise EnvironmentError('Please reinstall MATLAB Engine for Python or contact '
67+
'MathWorks Technical Support for assistance: %s' % e)
8668

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

9070
"""
9171
This lock can make sure the global variable _engines is updated correctly in

0 commit comments

Comments
 (0)