33from setuptools import setup , find_packages
44from setuptools .command .build_py import build_py
55import os
6+ import re
67import sys
78import platform
89import 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