Skip to content

Commit e84fffc

Browse files
committed
has_python more robust
1 parent 9f286a7 commit e84fffc

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

+stdlib/has_python.m

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
%% HAS_PYTHON checks if Python is available in the current environment.
2+
13
function y = has_python()
24

35
try
46
pe = pyenv();
57
catch e
6-
if strcmp(e.identifier, 'Octave:undefined-function')
7-
y = false;
8-
return
9-
else
10-
rethrow(e);
8+
switch e.identifier
9+
case {'Octave:undefined-function', 'MATLAB:Python:PythonUnavailable'}
10+
y = false;
11+
return
12+
otherwise
13+
rethrow(e);
1114
end
1215
end
1316

test/TestSys.m

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
classdef TestSys < matlab.unittest.TestCase
22

33
properties (TestParameter)
4-
fun = {stdlib.iscygwin, stdlib.isoctave, stdlib.is_rosetta, stdlib.isinteractive}
4+
fun = {stdlib.iscygwin, stdlib.isoctave, stdlib.is_rosetta, stdlib.isinteractive, stdlib.has_dotnet, ...
5+
stdlib.has_java, stdlib.has_python}
56
fi32 = {stdlib.is_wsl}
67
end
78

@@ -16,6 +17,18 @@ function test_platform_int32(tc, fi32)
1617
tc.verifyClass(fi32, 'int32')
1718
end
1819

20+
function test_dotnet_version(tc)
21+
tc.assumeTrue(stdlib.has_dotnet())
22+
v = stdlib.dotnet_version();
23+
tc.verifyGreaterThan(v, "4.0", ".NET version should be greater than 4.0")
24+
end
25+
26+
function test_has_python(tc)
27+
tc.assumeTrue(stdlib.has_python())
28+
v = stdlib.python_version();
29+
tc.verifyGreaterThan(strlength(v), 0, "expected non-empty Python version")
30+
end
31+
1932
function test_os_version(tc)
2033
tc.assumeTrue(stdlib.has_dotnet() || stdlib.has_java())
2134

0 commit comments

Comments
 (0)