Skip to content

Commit 9a874d6

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

File tree

2 files changed

+27
-12
lines changed

2 files changed

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

+stdlib/+python/version.m

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
function v = version()
1+
function v = version(force_old)
2+
arguments
3+
force_old (1,1) logical = false
4+
end
25

36
% 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.
7+
% for any py.* command.
8+
% We use a separate private function to workaround that.
59

610
v = [];
711

8-
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)];
12+
if isMATLABReleaseOlderThan('R2022a') && ~force_old
13+
return
14+
end
1515

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))
16+
try
17+
v = pvt_python_version();
1918
catch e
2019
switch e.identifier
2120
case {'Octave:undefined-function', 'MATLAB:Python:PythonUnavailable'} % pass

0 commit comments

Comments
 (0)