Skip to content

Commit

Permalink
ENH: Accept modification of configuration by users
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Apr 6, 2020
1 parent 342da5c commit f4abbe0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
5 changes: 2 additions & 3 deletions fitlins/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from .. import __version__
from ..workflows import init_fitlins_wf
from ..utils import bids
from ..utils import bids, config
from ..viz.reports import build_report_dict, write_full_report

logging.addLevelName(25, 'IMPORTANT') # Add a new level between INFO and WARNING
Expand Down Expand Up @@ -232,12 +232,11 @@ def run_fitlins(argv=None):
participants=subject_list, base_dir=work_dir,
smoothing=opts.smoothing, drop_missing=opts.drop_missing,
)
fitlins_wf.config = config.get_fitlins_config()

if opts.work_dir:
# dump crashes in working directory (non /tmp)
fitlins_wf.config['execution']['crashdump_dir'] = opts.work_dir
# easy to read crashfiles
fitlins_wf.config['execution']['crashfile_format'] = 'txt'
retcode = 0
if not opts.reports_only:
try:
Expand Down
25 changes: 25 additions & 0 deletions fitlins/utils/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
from configparser import ConfigParser
from nipype.utils import config as nuc
from pkg_resources import resource_filename


def get_fitlins_config():
"""Construct Nipype configuration object with precedence:
- Local config (``./nipype.cfg``)
- Global config (``$HOME/.nipype/nipype.cfg`` or ``$NIPYPE_CONFIG_DIR/nipype.cfg``)
- FitLins config (``<fitlins_install_dir>/data/nipype.cfg``)
- Nipype default config (defined in ``nipype/utils/config.py``)
"""
config = nuc.NipypeConfig()
config.set_default_config()

fitlins_config_file = resource_filename('fitlins', 'data/nipype.cfg')
global_config_file = os.path.join(
os.path.expanduser(os.getenv("NIPYPE_CONFIG_DIR", default="~/.nipype")),
"nipype.cfg")
local_config_file = "nipype.cfg"
fitlins_conf = ConfigParser()
fitlins_conf.read([fitlins_config_file, global_config_file, local_config_file])
config.update_config(fitlins_conf)

0 comments on commit f4abbe0

Please sign in to comment.