Skip to content

Commit 2000ec2

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 afc951d commit 2000ec2

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

+stdlib/python_version.m

Lines changed: 12 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 stdlib.python_version"
46
%
57
%%% Inputs
68
% * force_old: (optional) boolean flag to force checking of Python on Matlab < R2022a
@@ -17,11 +19,15 @@
1719
force_old = false;
1820
end
1921

20-
persistent stdlib_py_version
22+
persistent stdlib_py_version pyv_cached
23+
24+
if ~isempty(pyv_cached)
25+
pyv_cached = false;
26+
end
2127

2228
msg = '';
2329

24-
if ~isempty(stdlib_py_version)
30+
if pyv_cached
2531
v = stdlib_py_version;
2632
return
2733
end
@@ -43,9 +49,8 @@
4349
msg = e.message;
4450
end
4551

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

5156
end

0 commit comments

Comments
 (0)