@@ -126,28 +126,30 @@ def scans_for_fnames(fnames, keep4d=False, separate_sessions=False):
126126
127127class 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
137+ _command = None
138+ _paths = None
139+ _version = None
132140
133141 @classmethod
134142 def path (klass , matlab_cmd = None , paths = None , use_mcr = None ):
135- if klass ._path :
136- return klass ._path
137143 klass .getinfo (matlab_cmd , paths , use_mcr )
138144 return klass ._path
139145
140146 @classmethod
141147 def version (klass , matlab_cmd = None , paths = None , use_mcr = None ):
142- if klass ._version :
143- return klass ._version
144148 klass .getinfo (matlab_cmd , paths , use_mcr )
145149 return klass ._version
146150
147151 @classmethod
148152 def name (klass , matlab_cmd = None , paths = None , use_mcr = None ):
149- if klass ._name :
150- return klass ._name
151153 klass .getinfo (matlab_cmd , paths , use_mcr )
152154 return klass ._name
153155
@@ -169,7 +171,10 @@ def getinfo(klass, matlab_cmd=None, paths=None, use_mcr=None):
169171 If none of the above was successful, the fallback value of
170172 'matlab -nodesktop -nosplash' will be used.
171173 paths : str
174+ Add paths to matlab session
172175 use_mcr : bool
176+ Whether to use the MATLAB Common Runtime. In this case, the
177+ matlab_cmd is expected to be a valid MCR call.
173178
174179 Returns
175180 -------
@@ -178,17 +183,19 @@ def getinfo(klass, matlab_cmd=None, paths=None, use_mcr=None):
178183 returns None of path not found
179184 """
180185
181- if klass ._name and klass ._path and klass ._version :
186+ use_mcr = use_mcr or 'FORCE_SPMMCR' in os .environ
187+ matlab_cmd = matlab_cmd or ((use_mcr and os .getenv ('SPMMCRCMD' ))
188+ or os .getenv ('MATLABCMD' , 'matlab -nodesktop -nosplash' ))
189+
190+ if klass ._name and klass ._path and klass ._version and \
191+ klass ._command == matlab_cmd and klass ._paths == paths :
192+
182193 return {
183194 'name' : klass ._name ,
184195 'path' : klass ._path ,
185196 'release' : klass ._version
186197 }
187-
188- use_mcr = use_mcr or 'FORCE_SPMMCR' in os .environ
189- matlab_cmd = ((use_mcr and os .getenv ('SPMMCRCMD' ))
190- or os .getenv ('MATLABCMD' , 'matlab -nodesktop -nosplash' ))
191-
198+ logger .debug ('matlab command or path has changed. recomputing version.' )
192199 mlab = MatlabCommand (matlab_cmd = matlab_cmd , resource_monitor = False )
193200 mlab .inputs .mfile = False
194201 if paths :
@@ -214,6 +221,11 @@ def getinfo(klass, matlab_cmd=None, paths=None, use_mcr=None):
214221 # if no Matlab at all -- exception could be raised
215222 # No Matlab -- no spm
216223 logger .debug ('%s' , e )
224+ klass ._version = None
225+ klass ._path = None
226+ klass ._name = None
227+ klass ._command = matlab_cmd
228+ klass ._paths = paths
217229 return None
218230
219231 out = sd ._strip_header (out .runtime .stdout )
@@ -225,6 +237,8 @@ def getinfo(klass, matlab_cmd=None, paths=None, use_mcr=None):
225237 klass ._version = out_dict ['release' ]
226238 klass ._path = out_dict ['path' ]
227239 klass ._name = out_dict ['name' ]
240+ klass ._command = matlab_cmd
241+ klass ._paths = paths
228242 return out_dict
229243
230244
@@ -296,6 +310,10 @@ def set_mlab_paths(cls, matlab_cmd=None, paths=None, use_mcr=None):
296310 cls ._matlab_cmd = matlab_cmd
297311 cls ._paths = paths
298312 cls ._use_mcr = use_mcr
313+ info_dict = Info .getinfo (
314+ matlab_cmd = matlab_cmd ,
315+ paths = paths ,
316+ use_mcr = use_mcr )
299317
300318 def _find_mlab_cmd_defaults (self ):
301319 # check if the user has set environment variables to enforce
0 commit comments