13
13
import os
14
14
import errno
15
15
import atexit
16
+ from warnings import warn
16
17
from io import StringIO
17
18
from distutils .version import LooseVersion
18
19
import configparser
19
20
import numpy as np
20
21
21
- < << << << HEAD
22
- from builtins import str , object , open
23
- from ..external import portalocker
24
- import configparser
25
-
26
- from future import standard_library
27
- standard_library .install_aliases ()
28
- == == == =
29
22
from builtins import bytes , str , object , open
30
-
31
23
from simplejson import load , dump
32
24
from future import standard_library
33
- from .. external import portalocker
25
+
34
26
from .misc import str2bool
27
+ from ..external import portalocker
35
28
36
29
standard_library .install_aliases ()
37
30
40
33
'profile_runtime' : ('resource_monitor' , '1.0' ),
41
34
'filemanip_level' : ('utils_level' , '1.0' ),
42
35
}
43
- > >> >> >> upstream / master
44
36
45
37
NUMPY_MMAP = LooseVersion (np .__version__ ) >= LooseVersion ('1.12.0' )
46
38
@@ -97,21 +89,17 @@ def mkdir_p(path):
97
89
98
90
99
91
class NipypeConfig (object ):
100
- """
101
- Base nipype config class
102
- """
92
+ """Base nipype config class"""
103
93
104
94
def __init__ (self , * args , ** kwargs ):
105
95
self ._config = configparser .ConfigParser ()
106
96
config_dir = os .path .expanduser ('~/.nipype' )
107
97
config_file = os .path .join (config_dir , 'nipype.cfg' )
108
98
self .data_file = os .path .join (config_dir , 'nipype.json' )
109
99
self ._config .readfp (StringIO (default_cfg ))
110
- < << << << HEAD
111
100
self ._display = None
112
- == == == =
113
101
self ._resource_monitor = None
114
- >> >> >> > upstream / master
102
+
115
103
if os .path .exists (config_dir ):
116
104
self ._config .read ([config_file , 'nipype.cfg' ])
117
105
@@ -127,8 +115,7 @@ def set_default_config(self):
127
115
self ._config .readfp (StringIO (default_cfg ))
128
116
129
117
def enable_debug_mode (self ):
130
- """Enables debug configuration
131
- """
118
+ """Enables debug configuration"""
132
119
self ._config .set ('execution' , 'stop_on_first_crash' , 'true' )
133
120
self ._config .set ('execution' , 'remove_unnecessary_outputs' , 'false' )
134
121
self ._config .set ('execution' , 'keep_inputs' , 'true' )
@@ -144,6 +131,7 @@ def set_log_dir(self, log_dir):
144
131
self ._config .set ('logging' , 'log_directory' , log_dir )
145
132
146
133
def get (self , section , option , default = None ):
134
+ """Get an option"""
147
135
if option in CONFIG_DEPRECATIONS :
148
136
msg = ('Config option "%s" has been deprecated as of nipype %s. Please use '
149
137
'"%s" instead.' ) % (option , CONFIG_DEPRECATIONS [option ][1 ],
@@ -156,6 +144,7 @@ def get(self, section, option, default=None):
156
144
return default
157
145
158
146
def set (self , section , option , value ):
147
+ """Set new value on option"""
159
148
if isinstance (value , bool ):
160
149
value = str (value )
161
150
@@ -169,16 +158,19 @@ def set(self, section, option, value):
169
158
return self ._config .set (section , option , value )
170
159
171
160
def getboolean (self , section , option ):
161
+ """Get a boolean option from section"""
172
162
return self ._config .getboolean (section , option )
173
163
174
164
def has_option (self , section , option ):
165
+ """Check if option exists in section"""
175
166
return self ._config .has_option (section , option )
176
167
177
168
@property
178
169
def _sections (self ):
179
170
return self ._config ._sections
180
171
181
172
def get_data (self , key ):
173
+ """Read options file"""
182
174
if not os .path .exists (self .data_file ):
183
175
return None
184
176
with open (self .data_file , 'rt' ) as file :
@@ -189,6 +181,7 @@ def get_data(self, key):
189
181
return None
190
182
191
183
def save_data (self , key , value ):
184
+ """Store config flie"""
192
185
datadict = {}
193
186
if os .path .exists (self .data_file ):
194
187
with open (self .data_file , 'rt' ) as file :
@@ -204,21 +197,63 @@ def save_data(self, key, value):
204
197
dump (datadict , file )
205
198
206
199
def update_config (self , config_dict ):
200
+ """Extend internal dictionary with config_dict"""
207
201
for section in ['execution' , 'logging' , 'check' ]:
208
202
if section in config_dict :
209
203
for key , val in list (config_dict [section ].items ()):
210
204
if not key .startswith ('__' ):
211
205
self ._config .set (section , key , str (val ))
212
206
213
207
def update_matplotlib (self ):
208
+ """Set backend on matplotlib from options"""
214
209
import matplotlib
215
210
matplotlib .use (self .get ('execution' , 'matplotlib_backend' ))
216
211
217
212
def enable_provenance (self ):
213
+ """Sets provenance storing on"""
218
214
self ._config .set ('execution' , 'write_provenance' , 'true' )
219
215
self ._config .set ('execution' , 'hash_method' , 'content' )
220
216
221
- < << << << HEAD
217
+ @property
218
+ def resource_monitor (self ):
219
+ """Check if resource_monitor is available"""
220
+ if self ._resource_monitor is not None :
221
+ return self ._resource_monitor
222
+
223
+ # Cache config from nipype config
224
+ self .resource_monitor = self ._config .get (
225
+ 'execution' , 'resource_monitor' ) or False
226
+ return self ._resource_monitor
227
+
228
+ @resource_monitor .setter
229
+ def resource_monitor (self , value ):
230
+ # Accept string true/false values
231
+ if isinstance (value , (str , bytes )):
232
+ value = str2bool (value .lower ())
233
+
234
+ if value is False :
235
+ self ._resource_monitor = False
236
+ elif value is True :
237
+ if not self ._resource_monitor :
238
+ # Before setting self._resource_monitor check psutil availability
239
+ self ._resource_monitor = False
240
+ try :
241
+ import psutil
242
+ self ._resource_monitor = LooseVersion (
243
+ psutil .__version__ ) >= LooseVersion ('5.0' )
244
+ except ImportError :
245
+ pass
246
+ finally :
247
+ if not self ._resource_monitor :
248
+ warn ('Could not enable the resource monitor: psutil>=5.0'
249
+ ' could not be imported.' )
250
+ self ._config .set ('execution' , 'resource_monitor' ,
251
+ ('%s' % self ._resource_monitor ).lower ())
252
+
253
+ def enable_resource_monitor (self ):
254
+ """Sets the resource monitor on"""
255
+ self .resource_monitor = True
256
+
222
257
def get_display (self ):
223
258
"""Returns the first display available"""
224
259
@@ -277,47 +312,8 @@ def stop_display(self):
277
312
278
313
@atexit .register
279
314
def free_display ():
315
+ """Stop virtual display (if it is up)"""
280
316
from nipype import config
281
317
from nipype import logging
282
318
config .stop_display ()
283
319
logging .getLogger ('interface' ).info ('Closing display (if virtual)' )
284
- == == == =
285
- @property
286
- def resource_monitor (self ):
287
- """Check if resource_monitor is available"""
288
- if self ._resource_monitor is not None :
289
- return self ._resource_monitor
290
-
291
- # Cache config from nipype config
292
- self .resource_monitor = self ._config .get (
293
- 'execution' , 'resource_monitor' ) or False
294
- return self ._resource_monitor
295
-
296
- @resource_monitor .setter
297
- def resource_monitor (self , value ):
298
- # Accept string true/false values
299
- if isinstance (value , (str , bytes )):
300
- value = str2bool (value .lower ())
301
-
302
- if value is False :
303
- self ._resource_monitor = False
304
- elif value is True :
305
- if not self ._resource_monitor :
306
- # Before setting self._resource_monitor check psutil availability
307
- self ._resource_monitor = False
308
- try :
309
- import psutil
310
- self ._resource_monitor = LooseVersion (
311
- psutil .__version__ ) >= LooseVersion ('5.0' )
312
- except ImportError :
313
- pass
314
- finally :
315
- if not self ._resource_monitor :
316
- warn ('Could not enable the resource monitor: psutil>=5.0'
317
- ' could not be imported.' )
318
- self ._config .set ('execution' , 'resource_monitor' ,
319
- ('%s' % self ._resource_monitor ).lower ())
320
-
321
- def enable_resource_monitor (self ):
322
- self .resource_monitor = True
323
- >> >> >> > upstream / master
0 commit comments