Skip to content

Commit c885b54

Browse files
committed
Python Matlab R2022a private fun needed
1 parent 968f4ac commit c885b54

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function v = pvt_python_version()
2+
3+
pe = pyenv();
4+
vs = pe.Version;
5+
if strlength(vs) == 0, return, end
6+
7+
vi = py.sys.version_info;
8+
v = [double(vi.major), double(vi.minor), double(vi.micro)];
9+
10+
vv = strsplit(vs, '.');
11+
assert(str2double(vv{1}) == v(1), "stdlib:python_version:ValueError", "Python major version %s did not match pyenv %d", vv{1}, v(1))
12+
assert(str2double(vv{2}) == v(2), "stdlib:python_version:ValueError", "Python minor version %s did not match pyenv %d", vv{1}, v(1))
13+
14+
end

+stdlib/+python/version.m

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
function v = version()
22

33
% Matlab < R2022a has a bug in the JIT compiler that breaks try-catch
4-
% for any py.* command. We use a separate private function to workaround that.
4+
% for any py.* command.
5+
% We use a separate private function to workaround that.
56

67
v = [];
78

89
try
9-
pe = pyenv();
10-
vs = pe.Version;
11-
if strlength(vs) == 0, return, end
12-
13-
vi = py.sys.version_info;
14-
v = [double(vi.major), double(vi.minor), double(vi.micro)];
15-
16-
vv = strsplit(vs, '.');
17-
assert(str2double(vv{1}) == v(1), "stdlib:python_version:ValueError", "Python major version %s did not match pyenv %d", vv{1}, v(1))
18-
assert(str2double(vv{2}) == v(2), "stdlib:python_version:ValueError", "Python minor version %s did not match pyenv %d", vv{1}, v(1))
10+
v = pvt_python_version();
1911
catch e
2012
switch e.identifier
2113
case {'Octave:undefined-function', 'MATLAB:Python:PythonUnavailable'} % pass

0 commit comments

Comments
 (0)