3
3
from setuptools import setup , find_packages
4
4
from setuptools .command .build_py import build_py
5
5
import os
6
+ import re
6
7
import sys
7
8
import platform
8
9
import xml .etree .ElementTree as xml
@@ -23,7 +24,7 @@ class _MatlabFinder(build_py):
23
24
MATLAB_REL = 'R2022a'
24
25
25
26
# MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string)
26
- MATLAB_VER = '9.12'
27
+ MATLAB_VER = '9.12.10 '
27
28
28
29
# MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string)
29
30
SUPPORTED_PYTHON_VERSIONS = set (['3.8' , '3.9' ])
@@ -63,6 +64,8 @@ class _MatlabFinder(build_py):
63
64
no_matlab = "No MATLAB installation found in Windows Registry."
64
65
incompatible_ver = "MATLAB version {ver:s} was found, but MATLAB Engine API for Python is not compatible with it. " + \
65
66
"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."
66
69
67
70
def set_platform_and_arch (self ):
68
71
"""
@@ -171,7 +174,7 @@ def _find_matlab_key_from_windows_registry(self, key):
171
174
found_vers .append (sub_key )
172
175
# Example: the version in the registry could be "9.13.1" whereas our version is "9.13"
173
176
# we still want to allow this
174
- if sub_key . startswith ( self .MATLAB_VER ):
177
+ if self ._check_matlab_ver_against_engine ( sub_key ):
175
178
key_value = sub_key
176
179
break
177
180
@@ -184,10 +187,25 @@ def _find_matlab_key_from_windows_registry(self, key):
184
187
185
188
return key_value
186
189
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
+
187
204
def verify_matlab_release (self , root ):
188
205
"""
189
206
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.
191
209
"""
192
210
version_info = os .path .join (root , 'VersionInfo.xml' )
193
211
if not os .path .isfile (version_info ):
@@ -201,10 +219,7 @@ def verify_matlab_release(self, root):
201
219
if child .tag == 'release' :
202
220
matlab_release = self .found_matlab = child .text
203
221
break
204
-
205
- if matlab_release != self .MATLAB_REL :
206
- return False
207
- return True
222
+ return matlab_release == self .MATLAB_REL
208
223
209
224
def search_path_for_directory_unix (self ):
210
225
"""
@@ -284,7 +299,7 @@ def run(self):
284
299
setup (
285
300
name = "matlabengine" ,
286
301
# MUST_BE_UPDATED_EACH_RELEASE (Search repo for this string)
287
- version = "9.12" ,
302
+ version = "9.12.10 " ,
288
303
description = 'A module to call MATLAB from Python' ,
289
304
author = 'MathWorks' ,
290
305
license = "MathWorks XSLA License" ,
0 commit comments