Skip to content

Commit c208e7b

Browse files
committed
fix: robust matlab installation check
1 parent 21c0b26 commit c208e7b

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

nipype/interfaces/matlab.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,11 @@
1717

1818

1919
def get_matlab_command():
20-
if "NIPYPE_NO_MATLAB" in os.environ:
21-
return None
22-
23-
try:
24-
matlab_cmd = os.environ["MATLABCMD"]
25-
except:
26-
matlab_cmd = "matlab"
27-
28-
try:
29-
res = CommandLine(
30-
command="which",
31-
args=matlab_cmd,
32-
resource_monitor=False,
33-
terminal_output="allatonce",
34-
).run()
35-
matlab_path = res.runtime.stdout.strip()
36-
except Exception:
37-
return None
38-
return matlab_cmd
20+
"""Determine whether Matlab is installed and can be executed."""
21+
if "NIPYPE_NO_MATLAB" not in os.environ:
22+
from nipype.utils.filemanip import which
23+
24+
return which(os.getenv("MATLABCMD", "matlab"))
3925

4026

4127
no_matlab = get_matlab_command() is None

nipype/interfaces/tests/test_matlab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def test_run_interface(tmpdir):
103103
# bypasses ubuntu dash issue
104104
mc = mlab.MatlabCommand(script="foo;", paths=[tmpdir.strpath], mfile=True)
105105
assert not os.path.exists(default_script_file), "scriptfile should not exist 4."
106-
with pytest.raises(RuntimeError):
106+
with pytest.raises(OSError):
107107
mc.run()
108108
assert os.path.exists(default_script_file), "scriptfile should exist 4."
109109
if os.path.exists(default_script_file): # cleanup

0 commit comments

Comments
 (0)