Skip to content

Commit 711c564

Browse files
committed
Merge pull request #327 from satra/enh/distlogging
WIP: distributing config and logging options to remote processes
2 parents 09e7d54 + 050a169 commit 711c564

30 files changed

+288
-214
lines changed

CHANGES

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
Changes since 0.5
22
=================
33

4-
None
4+
* API: Logging to file is disabled by default
5+
* API: New location of log file -> .nipype/nipype.cfg
6+
7+
* ENH: Changing logging options via config works for distributed processing
58

69
Release 0.5 (Mar 10, 2012)
710
==========================

doc/users/config_file.rst

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
Some of the system wide options of Nipype can be configured using a
88
configuration file. Nipype looks for the file in the local folder under the name
9-
``nipype.cfg`` and in ``~/.nipype.cfg`` (in this order). If an option will not
10-
be specified a default value will be assumed. The file is divided into following
11-
sections:
9+
``nipype.cfg`` and in ``~/.nipype/nipype.cfg`` (in this order). If an option
10+
will not be specified a default value will be assumed. The file is divided into
11+
following sections:
1212

1313
Logging
1414
~~~~~~~
@@ -25,7 +25,7 @@ Logging
2525
values: ``INFO`` and ``DEBUG``; default value: ``INFO``)
2626
*log_to_file*
2727
Indicates whether logging should also send the output to a file (possible
28-
values: ``true`` and ``false``; default value: ``true``)
28+
values: ``true`` and ``false``; default value: ``false``)
2929
*log_directory*
3030
Where to store logs. (string, default value: home directory)
3131
*log_size*
@@ -120,43 +120,52 @@ Example
120120
hash_method = timestamp
121121
display_variable = :1
122122

123-
Additionally you can set some config options by setting the workflow.config. This, however, currently does not work for options related to logging levels. Those will be always read from .cfg files.
124-
125-
Workflow.config property has a form of a nested dictionary reflecting the structure of the .cfg file.
123+
Workflow.config property has a form of a nested dictionary reflecting the
124+
structure of the .cfg file.
126125

127126
::
128127
129128
myworkflow = pe.Workflow()
130129
myworkflow.config['execution'] = {'stop_on_first_rerun': 'True',
131130
'hash_method': 'timestamp'}
132131

133-
You can also directly set config options in your workflow script. An
132+
You can also directly set global config options in your workflow script. An
134133
example is shown below. This needs to be called before you import the
135134
pipeline or the logger. Otherwise logging level will not be reset.
136135

137136
::
138137

139-
from nipype.utils.config import config
140-
from StringIO import StringIO
141-
cfg = StringIO("""
142-
[logging]
143-
workflow_level = DEBUG
138+
from nipype import config
139+
cfg = dict(logging=dict(workflow_level = 'DEBUG'),
140+
execution={'stop_on_first_crash': False,
141+
'hash_method': 'content'})
142+
config.update_config(cfg)
144143

145-
[execution]
146-
stop_on_first_crash = false
147-
hash_method = content
148-
""")
149-
150-
config.readfp(cfg)
144+
Enabling logging to file
145+
~~~~~~~~~~~~~~~~~~~~~~~~
146+
147+
By default, logging to file is disabled. One can enable and write the file to
148+
a location of choice as in the example below.
149+
150+
::
151+
152+
import os
153+
from nipype import config, logging
154+
config.update_config({'logging': {'log_directory': os.getcwd(),
155+
'log_to_file': True}})
156+
logging.update_logging(config)
157+
158+
The logging update line is necessary to change the behavior of logging such as
159+
output directory, logging level, etc.,.
151160

152161
Debug configuration
153162
~~~~~~~~~~~~~~~~~~~
154163

155-
To enable debug mode, one can insert the following lines at the beginning of any
156-
script.::
164+
To enable debug mode, one can insert the following lines::
157165

158-
from nipype.utils.config import config
166+
from nipype import config, logging
159167
config.enable_debug_mode()
168+
logging.update_logging(config)
160169

161170
In this mode the following variables are set::
162171

nipype/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
URL as __url__,
77
STATUS as __status__,
88
__version__)
9-
from utils.config import config
9+
from utils.config import NipypeConfig
10+
config = NipypeConfig()
11+
from utils.logger import Logging
12+
logging = Logging(config)
1013

1114
# We require numpy 1.2 for our test suite. If Tester fails to import,
1215
# check the version of numpy the user has and inform them they need to

nipype/algorithms/misc.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,30 @@
2424
import scipy.io as sio
2525
import itertools
2626

27-
from nipype.utils.config import config
27+
from .. import config, logging
2828
import matplotlib
2929
matplotlib.use(config.get("execution", "matplotlib_backend"))
3030
import matplotlib.pyplot as plt
3131

32-
from nipype.interfaces.base import (BaseInterface, traits, TraitedSpec, File,
33-
InputMultiPath, OutputMultiPath,
34-
BaseInterfaceInputSpec, isdefined)
35-
from nipype.utils.filemanip import fname_presuffix, split_filename
36-
import logging
37-
38-
logging.basicConfig()
32+
from ..interfaces.base import (BaseInterface, traits, TraitedSpec, File,
33+
InputMultiPath, OutputMultiPath,
34+
BaseInterfaceInputSpec, isdefined)
35+
from ..utils.filemanip import fname_presuffix, split_filename
3936
iflogger = logging.getLogger('interface')
4037

4138

4239
class PickAtlasInputSpec(BaseInterfaceInputSpec):
43-
atlas = File(exists=True, desc="Location of the atlas that will be used.", mandatory=True)
40+
atlas = File(exists=True, desc="Location of the atlas that will be used.",
41+
mandatory=True)
4442
labels = traits.Either(traits.Int, traits.List(traits.Int),
45-
desc="Labels of regions that will be included in the mask. Must be \
46-
compatible with the atlas used.", compulsory=True)
47-
hemi = traits.Enum('both', 'left', 'right', desc="Restrict the mask to only one hemisphere: left or right", usedefault=True)
48-
dilation_size = traits.Int(desc="Defines how much the mask will be dilated (expanded in 3D).", usedefault=True)
43+
desc=("Labels of regions that will be included in"
44+
"the mask. Must be compatible with the atlas used."),
45+
compulsory=True)
46+
hemi = traits.Enum('both', 'left', 'right',
47+
desc="Restrict the mask to only one hemisphere: left or right",
48+
usedefault=True)
49+
dilation_size = traits.Int(usedefault=True,
50+
desc="Defines how much the mask will be dilated (expanded in 3D).")
4951
output_file = File(desc="Where to store the output mask.")
5052

5153

nipype/algorithms/modelgen.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@
2929
traits, File, Bunch, BaseInterfaceInputSpec,
3030
isdefined)
3131
from nipype.utils.filemanip import filename_to_list
32-
from nipype.utils.logger import iflogger
33-
from nipype.utils.config import config
34-
32+
from .. import config, logging
33+
iflogger = logging.getLogger('interface')
3534

3635
def gcd(a, b):
3736
"""Returns the greatest common divisor of two integers

nipype/algorithms/rapidart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from scipy import signal
2727
import scipy.io as sio
2828

29-
from nipype.utils.config import config
29+
from .. import config
3030
import matplotlib
3131
matplotlib.use(config.get("execution", "matplotlib_backend"))
3232
import matplotlib.pyplot as plt

nipype/caching/tests/test_memory.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
from nipype.caching import Memory
1010
from nipype.pipeline.tests.test_engine import TestInterface
11-
from nipype.utils.config import config
11+
from nipype.utils.config import NipypeConfig
12+
config = NipypeConfig()
13+
config.set_default_config()
1214

1315
nb_runs = 0
1416

nipype/interfaces/ants/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from nipype.interfaces.base import (CommandLine, CommandLineInputSpec, traits,
77
isdefined)
88

9-
import logging
9+
from ... import logging
1010
logger = logging.getLogger('iflogger')
1111

1212

nipype/interfaces/base.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
from time import time
2222
from warnings import warn
2323

24-
from nipype.interfaces.traits_extension import (traits, Undefined, TraitDictObject,
25-
TraitListObject, TraitError,
26-
isdefined, File, Directory,
27-
has_metadata)
28-
from nipype.utils.filemanip import (md5, hash_infile, FileNotFoundError,
29-
hash_timestamp)
30-
from nipype.utils.misc import is_container
31-
from nipype.utils.config import config
32-
from nipype.utils.logger import iflogger
33-
from nipype.utils.misc import trim
24+
from .traits_extension import (traits, Undefined, TraitDictObject,
25+
TraitListObject, TraitError,
26+
isdefined, File, Directory,
27+
has_metadata)
28+
from ..utils.filemanip import (md5, hash_infile, FileNotFoundError,
29+
hash_timestamp)
30+
from ..utils.misc import is_container, trim
31+
from .. import config, logging
32+
33+
iflogger = logging.getLogger('interface')
3434

3535

3636
__docformat__ = 'restructuredtext'

nipype/interfaces/cmtk/cmtk.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020
import nibabel as nb
2121
import networkx as nx
2222
import sys
23-
import logging
2423

25-
logging.basicConfig()
24+
from ... import logging
2625
iflogger = logging.getLogger('interface')
2726

2827
def length(xyz, along=False):

nipype/interfaces/cmtk/nx.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
import networkx as nx
1919
import scipy.io as sio
2020
import pickle
21-
import logging
2221
from nipype.utils.misc import package_check
23-
from nipype.workflows.misc.utils import get_data_dims
2422
import warnings
2523

26-
logging.basicConfig()
24+
from ... import logging
2725
iflogger = logging.getLogger('interface')
2826

2927
have_cmp = True

nipype/interfaces/cmtk/parcellation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
import shutil
1919
from nipype.utils.misc import package_check
2020
import warnings
21-
import logging
2221

23-
logging.basicConfig()
22+
from ... import logging
2423
iflogger = logging.getLogger('interface')
2524

2625
have_cmp = True

nipype/interfaces/dipy/tracks.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
from nipype.interfaces.base import (TraitedSpec, BaseInterface, BaseInterfaceInputSpec,
33
File, isdefined, traits)
44
from nipype.utils.filemanip import split_filename
5-
import os, os.path as op
5+
import os.path as op
66
import nibabel as nb, nibabel.trackvis as trk
7-
import numpy as np
8-
import logging
97
from nipype.utils.misc import package_check
108
import warnings
119

12-
logging.basicConfig()
10+
from ... import logging
1311
iflogger = logging.getLogger('interface')
1412

1513
try:

nipype/interfaces/io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from nipype.utils.filemanip import (copyfile, list_to_filename,
3939
filename_to_list)
4040

41-
import logging
41+
from .. import logging
4242
iflogger = logging.getLogger('interface')
4343

4444

nipype/interfaces/matlab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from nipype.interfaces.base import (CommandLineInputSpec, InputMultiPath, isdefined,
77
CommandLine, traits, File, Directory)
8-
from nipype.utils.config import config
8+
from .. import config
99

1010
def get_matlab_command():
1111
if 'NIPYPE_NO_MATLAB' in os.environ:

nipype/interfaces/mrtrix/convert.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
except Exception, e:
2828
warnings.warn('dipy not installed')
2929
from nibabel.orientations import aff2axcodes
30-
import logging
31-
32-
logging.basicConfig()
30+
from ... import logging
3331
iflogger = logging.getLogger('interface')
3432

3533
def transform_to_affine(streams, header, affine):

nipype/interfaces/mrtrix/tensors.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
from nipype.interfaces.base import (CommandLineInputSpec, CommandLine, BaseInterface, BaseInterfaceInputSpec,
1313
traits, File, TraitedSpec, Directory, InputMultiPath, OutputMultiPath, isdefined)
1414
from nipype.utils.filemanip import split_filename
15-
import os, os.path as op
15+
import os.path as op
1616
import numpy as np
17-
import nibabel as nb
18-
import logging
1917

20-
logging.basicConfig()
18+
from ... import logging
2119
iflogger = logging.getLogger('interface')
2220

2321
class DWI2SphericalHarmonicsImageInputSpec(CommandLineInputSpec):

nipype/interfaces/spm/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import nipype.utils.spm_docs as sd
2424

25-
import logging
25+
from ... import logging
2626
logger = logging.getLogger('iflogger')
2727

2828
def func_is_3d(in_file):

nipype/interfaces/spm/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
__docformat__ = 'restructuredtext'
1515

1616
# Standard library imports
17-
import logging
1817
import os
1918
from glob import glob
2019

@@ -30,6 +29,7 @@
3029
from nipype.utils.filemanip import (filename_to_list, list_to_filename,
3130
split_filename)
3231

32+
from ... import logging
3333
logger = logging.getLogger('spmlogger')
3434

3535

nipype/interfaces/tests/test_base.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
import shutil
66

77
from nipype.testing import (assert_equal, assert_not_equal, assert_raises,
8-
assert_true, assert_false, with_setup, package_check, skipif)
8+
assert_true, assert_false, with_setup, package_check,
9+
skipif)
910
import nipype.interfaces.base as nib
10-
from nipype.interfaces.base import Undefined
11-
12-
from nipype.utils.config import config
11+
from nipype.interfaces.base import Undefined, config
1312

1413
#test Bunch
1514
def test_bunch():

0 commit comments

Comments
 (0)