Skip to content

Commit c3b56c0

Browse files
committed
9.12.5; setup.py logic now matches the R2021b logic where appropriate
1 parent b8fa172 commit c3b56c0

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
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.12
24+
$ python -m pip install matlabengine==9.12.5
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.12
49+
$ python -m pip install matlabengine==9.12.5
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.12
73+
$ python -m pip install matlabengine==9.12.5
7474
```
7575

7676
---

setup.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from setuptools import setup, find_packages
44
from setuptools.command.build_py import build_py
55
import os
6+
import re
67
import sys
78
import platform
89
import xml.etree.ElementTree as xml
@@ -23,7 +24,7 @@ class _MatlabFinder(build_py):
2324
MATLAB_REL = 'R2022a'
2425

2526
# MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string)
26-
MATLAB_VER = '9.12.4'
27+
MATLAB_VER = '9.12.5'
2728

2829
# MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string)
2930
SUPPORTED_PYTHON_VERSIONS = set(['3.8', '3.9'])
@@ -36,7 +37,7 @@ class _MatlabFinder(build_py):
3637
"9.9": "R2020b",
3738
"9.10": "R2021a",
3839
"9.11": "R2021b",
39-
"9.12.4": "R2022a"
40+
"9.12": "R2022a"
4041
}
4142

4243
DEFAULT_INSTALLS = {
@@ -63,6 +64,8 @@ class _MatlabFinder(build_py):
6364
no_matlab = "No MATLAB installation found in Windows Registry."
6465
incompatible_ver = "MATLAB version {ver:s} was found, but MATLAB Engine API for Python is not compatible with it. " + \
6566
"To install a compatible version, call python -m pip install matlabengine=={found:s}."
67+
invalid_version_from_matlab_ver = "Format of MATLAB version '{ver:s}' is invalid."
68+
invalid_version_from_eng = "Format of MATLAB Engine API version '{ver:s}' is invalid."
6669

6770
def set_platform_and_arch(self):
6871
"""
@@ -171,7 +174,7 @@ def _find_matlab_key_from_windows_registry(self, key):
171174
found_vers.append(sub_key)
172175
# Example: the version in the registry could be "9.13.1" whereas our version is "9.13"
173176
# we still want to allow this
174-
if sub_key.startswith(self.MATLAB_VER):
177+
if self._check_matlab_ver_against_engine(sub_key):
175178
key_value = sub_key
176179
break
177180

@@ -184,10 +187,25 @@ def _find_matlab_key_from_windows_registry(self, key):
184187

185188
return key_value
186189

190+
def _check_matlab_ver_against_engine(self, matlab_ver):
191+
re_major_minor = "^(\d+)\.(\d+)"
192+
matlab_ver_match = re.match(re_major_minor, matlab_ver)
193+
if not matlab_ver_match:
194+
raise RuntimeError(f"{self.invalid_version_from_matlab_ver.format(ver=matlab_ver)}")
195+
eng_match = re.match(re_major_minor, self.MATLAB_VER)
196+
if not eng_match:
197+
raise RuntimeError(f"{self.invalid_version_from_eng.format(ver=self.MATLAB_VER)}")
198+
199+
matlab_ver_major_minor = (matlab_ver_match.group(1), matlab_ver_match.group(2))
200+
eng_major_minor = (eng_match.group(1), eng_match.group(2))
201+
202+
return (matlab_ver_major_minor == eng_major_minor)
203+
187204
def verify_matlab_release(self, root):
188205
"""
189206
Parses VersionInfo.xml to verify the MATLAB release matches the supported release
190-
for the Python Engine.
207+
for the Python Engine. The major and minor version numbers must match. Everything
208+
else will be ignored.
191209
"""
192210
version_info = os.path.join(root, 'VersionInfo.xml')
193211
if not os.path.isfile(version_info):
@@ -201,10 +219,7 @@ def verify_matlab_release(self, root):
201219
if child.tag == 'release':
202220
matlab_release = self.found_matlab = child.text
203221
break
204-
205-
if matlab_release != self.MATLAB_REL:
206-
return False
207-
return True
222+
return matlab_release == self.MATLAB_REL
208223

209224
def search_path_for_directory_unix(self):
210225
"""
@@ -284,7 +299,7 @@ def run(self):
284299
setup(
285300
name="matlabengine",
286301
# MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string)
287-
version="9.12.4",
302+
version="9.12.5",
288303
description='A module to call MATLAB from Python',
289304
author='MathWorks',
290305
license="MathWorks XSLA License",

0 commit comments

Comments
 (0)