Skip to content

Commit 44a7b66

Browse files
committed
fix: change the way memoization works for the Info class
1 parent 94b316d commit 44a7b66

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

nipype/interfaces/spm/base.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ def scans_for_fnames(fnames, keep4d=False, separate_sessions=False):
126126

127127
class Info(PackageInfo):
128128
"""Handles SPM version information
129+
130+
If you use `SPMCommand.set_mlab_paths` to set alternate entries for
131+
matlab_cmd, paths, and use_mcr, then you will need to use the same entries
132+
to any call in the Info class to maintain memoization. Otherwise, it will
133+
default to the parameters in the `getinfo` function below.
129134
"""
130135
_path = None
131136
_name = None
@@ -134,22 +139,16 @@ class Info(PackageInfo):
134139

135140
@classmethod
136141
def path(klass, matlab_cmd=None, paths=None, use_mcr=None):
137-
if klass._path:
138-
return klass._path
139142
klass.getinfo(matlab_cmd, paths, use_mcr)
140143
return klass._path
141144

142145
@classmethod
143146
def version(klass, matlab_cmd=None, paths=None, use_mcr=None):
144-
if klass._version:
145-
return klass._version
146147
klass.getinfo(matlab_cmd, paths, use_mcr)
147148
return klass._version
148149

149150
@classmethod
150151
def name(klass, matlab_cmd=None, paths=None, use_mcr=None):
151-
if klass._name:
152-
return klass._name
153152
klass.getinfo(matlab_cmd, paths, use_mcr)
154153
return klass._name
155154

@@ -191,7 +190,6 @@ def getinfo(klass, matlab_cmd=None, paths=None, use_mcr=None):
191190
'path': klass._path,
192191
'release': klass._version
193192
}
194-
195193
mlab = MatlabCommand(matlab_cmd=matlab_cmd, resource_monitor=False)
196194
mlab.inputs.mfile = False
197195
if paths:
@@ -217,6 +215,11 @@ def getinfo(klass, matlab_cmd=None, paths=None, use_mcr=None):
217215
# if no Matlab at all -- exception could be raised
218216
# No Matlab -- no spm
219217
logger.debug('%s', e)
218+
klass._version = None
219+
klass._path = None
220+
klass._name = None
221+
klass._command = matlab_cmd
222+
klass._paths = paths
220223
return None
221224

222225
out = sd._strip_header(out.runtime.stdout)
@@ -301,6 +304,10 @@ def set_mlab_paths(cls, matlab_cmd=None, paths=None, use_mcr=None):
301304
cls._matlab_cmd = matlab_cmd
302305
cls._paths = paths
303306
cls._use_mcr = use_mcr
307+
info_dict = Info.getinfo(
308+
matlab_cmd=matlab_cmd,
309+
paths=paths,
310+
use_mcr=use_mcr)
304311

305312
def _find_mlab_cmd_defaults(self):
306313
# check if the user has set environment variables to enforce

0 commit comments

Comments
 (0)