Skip to content

Commit 1d911e2

Browse files
committed
Check for MCR related env vars when instantiating SPMCommand
The recently added support for special environment variables, that allow enforcing of the standalone (mcr) version of SPM, was incomplete. It only affected requests for SPM's version information. With this patch, the environment variables are also checked when instantiating SPMCommand.
1 parent 22813b0 commit 1d911e2

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

nipype/interfaces/spm/base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ def __init__(self, **inputs):
237237
'mfile',
238238
'paths',
239239
'use_mcr'])
240+
self._find_mlab_cmd_defaults()
240241
self._check_mlab_inputs()
241242
self._matlab_cmd_update()
242243

@@ -246,6 +247,17 @@ def set_mlab_paths(cls, matlab_cmd=None, paths=None, use_mcr=None):
246247
cls._paths = paths
247248
cls._use_mcr = use_mcr
248249

250+
def _find_mlab_cmd_defaults(self):
251+
# check if the user has set environment variables to enforce
252+
# the standalone (MCR) version of SPM
253+
if self._use_mcr or 'FORCE_SPMMCR' in os.environ:
254+
self._use_mcr = True
255+
if self._matlab_cmd is None:
256+
try:
257+
self._matlab_cmd = os.environ['SPMMCRCMD']
258+
except KeyError:
259+
pass
260+
249261
def _matlab_cmd_update(self):
250262
# MatlabCommand has to be created here,
251263
# because matlab_cmb is not a proper input

nipype/interfaces/spm/tests/test_base.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,34 @@ class TestClass(spm.SPMCommand):
6868
yield assert_true, dc.inputs.mfile
6969

7070

71+
def test_find_mlab_cmd_defaults():
72+
saved_env = dict(os.environ)
73+
class TestClass(spm.SPMCommand):
74+
pass
75+
# test without FORCE_SPMMCR, SPMMCRCMD set
76+
for varname in ['FORCE_SPMMCR', 'SPMMCRCMD']:
77+
try:
78+
del os.environ[varname]
79+
except KeyError:
80+
pass
81+
dc = TestClass()
82+
yield assert_equal, dc._use_mcr, None
83+
yield assert_equal, dc._matlab_cmd, None
84+
# test with only FORCE_SPMMCR set
85+
os.environ['FORCE_SPMMCR'] = '1'
86+
dc = TestClass()
87+
yield assert_equal, dc._use_mcr, True
88+
yield assert_equal, dc._matlab_cmd, None
89+
# test with both, FORCE_SPMMCR and SPMMCRCMD set
90+
os.environ['SPMMCRCMD'] = 'spmcmd'
91+
dc = TestClass()
92+
yield assert_equal, dc._use_mcr, True
93+
yield assert_equal, dc._matlab_cmd, 'spmcmd'
94+
# restore environment
95+
os.environ.clear();
96+
os.environ.update(saved_env)
97+
98+
7199
@skipif(no_spm, "SPM not found")
72100
def test_cmd_update():
73101
class TestClass(spm.SPMCommand):

0 commit comments

Comments
 (0)