Skip to content

Commit d2cac78

Browse files
committed
stdlib.python_version: cache no python too
This is important for HPC or any computer without Python, to not waste time rechecking
1 parent f9e862d commit d2cac78

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

+stdlib/python_version.m

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
%% PYTHON_VERSION get the Python version used by MATLAB
22
%
3-
% uses persistent variable to cache the Python version
3+
% uses persistent variable to cache the Python version.
4+
% If the environment changes, the cached version will be invalid.
5+
% this cache is cleared by "clear functions"
46
%
57
%%% Inputs
68
% * force_old: (optional) boolean flag to force checking of Python on Matlab < R2022a
@@ -17,11 +19,13 @@
1719
force_old = false;
1820
end
1921

20-
persistent stdlib_py_version
22+
persistent stdlib_py_version pyv_cached
2123

2224
msg = '';
2325

24-
if ~isempty(stdlib_py_version)
26+
if isempty(pyv_cached)
27+
pyv_cached = false;
28+
elseif pyv_cached
2529
v = stdlib_py_version;
2630
return
2731
end
@@ -43,9 +47,8 @@
4347
msg = e.message;
4448
end
4549

46-
% cache the result
47-
if ~isempty(v)
48-
stdlib_py_version = v;
49-
end
50+
% cache the result - even if empty -- because the check takes up to 1000 ms say on HPC
51+
stdlib_py_version = v;
52+
pyv_cached = true;
5053

5154
end

0 commit comments

Comments
 (0)