Skip to content

Commit cb4506b

Browse files
committed
enh: add a read-only section environment
1 parent b729f20 commit cb4506b

File tree

5 files changed

+53
-34
lines changed

5 files changed

+53
-34
lines changed

fmriprep/cli/parser.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ def _bids_filter(value):
4646
if value and Path(value).exists():
4747
return loads(Path(value).read_text())
4848

49-
verstr = 'fMRIPrep v{}'.format(config.execution.version)
50-
currentv = Version(config.execution.version)
49+
verstr = 'fMRIPrep v{}'.format(config.environment.version)
50+
currentv = Version(config.environment.version)
5151
is_release = not any((currentv.is_devrelease, currentv.is_prerelease, currentv.is_postrelease))
5252

5353
parser = ArgumentParser(
54-
description='fMRIPrep: fMRI PREProcessing workflows v{}'.format(config.execution.version),
54+
description='fMRIPrep: fMRI PREProcessing workflows v{}'.format(config.environment.version),
5555
formatter_class=ArgumentDefaultsHelpFormatter)
5656
PathExists = partial(_path_exists, parser=parser)
5757
PositiveInt = partial(_min_one, parser=parser)
@@ -295,7 +295,7 @@ def _bids_filter(value):
295295
WARNING: Version %s of fMRIPrep (current) has been FLAGGED
296296
(reason: %s).
297297
That means some severe flaw was found in it and we strongly
298-
discourage its usage.""" % (config.execution.version, _reason), file=sys.stderr)
298+
discourage its usage.""" % (config.environment.version, _reason), file=sys.stderr)
299299

300300
return parser
301301

@@ -343,7 +343,7 @@ def parse_args(args=None, namespace=None):
343343
bids_dir = config.execution.bids_dir
344344
output_dir = config.execution.output_dir
345345
work_dir = config.execution.work_dir
346-
version = config.execution.version
346+
version = config.environment.version
347347

348348
if config.execution.fs_subjects_dir is None:
349349
config.execution.fs_subjects_dir = output_dir / 'freesurfer'
@@ -378,7 +378,7 @@ def parse_args(args=None, namespace=None):
378378
"Making sure the input data is BIDS compliant (warnings can be ignored in most "
379379
"cases)."
380380
)
381-
validate_input_dir(config.execution.exec_env, opts.bids_dir, opts.participant_label)
381+
validate_input_dir(config.environment.exec_env, opts.bids_dir, opts.participant_label)
382382

383383
# Setup directories
384384
config.execution.log_dir = output_dir / 'fmriprep' / 'logs'

fmriprep/cli/workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def build_workflow(config_file, retval):
2222
build_log = config.loggers.workflow
2323

2424
output_dir = config.execution.output_dir
25-
version = config.execution.version
25+
version = config.environment.version
2626

2727
retval['return_code'] = 1
2828
retval['workflow'] = None
@@ -71,7 +71,7 @@ def build_workflow(config_file, retval):
7171
* Output spaces: {spaces}.
7272
""".format
7373
build_log.log(25, INIT_MSG(
74-
version=config.execution.version,
74+
version=config.environment.version,
7575
bids_dir=config.execution.bids_dir,
7676
subject_list=subject_list,
7777
uuid=config.execution.run_uuid,

fmriprep/config.py

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424
The module also has a :py:func:`to_filename` function to allow writting out
2525
the settings to hard disk in *ToML* format, which looks like::
2626
27+
[environment]
28+
cpu_count = 8
29+
exec_env = "posix"
30+
free_mem = 2.2
31+
overcommit_policy = "heuristic"
32+
overcommit_limit = "50%"
33+
nipype_version = "1.5.0"
34+
templateflow_version = "0.4.2"
35+
version = "20.0.1"
36+
2737
[nipype]
2838
crashfile_format = "txt"
2939
get_linked_libs = false
@@ -32,7 +42,6 @@
3242
plugin = "MultiProc"
3343
resource_monitor = false
3444
stop_on_first_crash = false
35-
version = "1.5.0-dev+gdffcb7815"
3645
3746
[execution]
3847
bids_dir = "/data/openfmri/ds000005"
@@ -49,8 +58,7 @@
4958
reports_only = false
5059
run_uuid = "20200302-174345_9ba9f304-82de-4538-8c3a-570c5f5d8f2f"
5160
participant_label = [ "01",]
52-
version = "20.0.1+13.g3ca42930.dirty"
53-
work_dir = "/home/oesteban/tmp/fmriprep-ds005/fprep-work2"
61+
work_dir = "work/"
5462
write_graph = false
5563
5664
[workflow]
@@ -227,13 +235,34 @@ def get(cls):
227235
return out
228236

229237

238+
class environment(_Config):
239+
"""Read-only options."""
240+
241+
cpu_count = os.cpu_count()
242+
"""Number of available CPUs."""
243+
exec_docker_version = _docker_ver
244+
"""Version of Docker Engine."""
245+
exec_env = _exec_env
246+
"""A string representing the execution platform."""
247+
free_mem = _free_mem_at_start
248+
"""Free memory at start."""
249+
overcommit_policy = _oc_policy
250+
"""Linux's kernel virtual memory overcommit policy."""
251+
overcommit_limit = _oc_limit
252+
"""Linux's kernel virtual memory overcommit limits."""
253+
nipype_version = _nipype_ver
254+
"""Nipype's current version."""
255+
templateflow_version = _tf_ver
256+
"""The TemplateFlow client version installed."""
257+
version = __version__
258+
"""*fMRIPrep*'s version."""
259+
260+
230261
class nipype(_Config):
231262
"""Nipype configuration."""
232263

233264
crashfile_format = 'txt'
234265
"""The file format for crashfiles, either text or pickle."""
235-
free_mem = _free_mem_at_start
236-
"""Free memory at start."""
237266
get_linked_libs = False
238267
"""Run NiPype's tool to enlist linked libraries for every interface."""
239268
memory_gb = None
@@ -242,10 +271,6 @@ class nipype(_Config):
242271
"""Number of processes (compute tasks) that can be run in parallel (multiprocessing only)."""
243272
omp_nthreads = os.cpu_count()
244273
"""Number of CPUs a single process can access for multithreaded execution."""
245-
overcommit_policy = _oc_policy
246-
"""Linux's kernel virtual memory overcommit policy."""
247-
overcommit_limit = _oc_limit
248-
"""Linux's kernel virtual memory overcommit limits."""
249274
plugin = 'MultiProc'
250275
"""NiPype's execution plugin."""
251276
plugin_args = {
@@ -257,8 +282,6 @@ class nipype(_Config):
257282
"""Enable resource monitor."""
258283
stop_on_first_crash = True
259284
"""Whether the workflow should stop or continue after the first error."""
260-
version = _nipype_ver
261-
"""Nipype's current version."""
262285

263286
@classmethod
264287
def get_plugin(cls):
@@ -279,6 +302,8 @@ class execution(_Config):
279302

280303
bids_dir = None
281304
"""An existing path to the dataset, which must be BIDS-compliant."""
305+
bids_description_hash = None
306+
"""Checksum (SHA256) of the ``dataset_description.json`` of the BIDS dataset."""
282307
bids_filters = None
283308
"""A dictionary of BIDS selection filters."""
284309
boilerplate_only = False
@@ -287,10 +312,6 @@ class execution(_Config):
287312
"""Run in sloppy mode (meaning, suboptimal parameters that minimize run-time)."""
288313
echo_idx = None
289314
"""Select a particular echo for multi-echo EPI datasets."""
290-
exec_docker_version = _docker_ver
291-
"""Version of Docker Engine."""
292-
exec_env = _exec_env
293-
"""A string representing the execution platform."""
294315
fs_license_file = _fs_license
295316
"""An existing file containing a FreeSurfer license."""
296317
fs_subjects_dir = None
@@ -321,10 +342,6 @@ class execution(_Config):
321342
"""Select a particular task from all available in the dataset."""
322343
templateflow_home = _templateflow_home
323344
"""The root folder of the TemplateFlow client."""
324-
templateflow_version = _tf_ver
325-
"""The TemplateFlow client version installed."""
326-
version = __version__
327-
"""*fMRIPrep*'s version."""
328345
work_dir = Path('work').absolute()
329346
"""Path to a working directory where intermediate results will be available."""
330347
write_graph = False
@@ -436,8 +453,9 @@ def load(filename):
436453
filename = Path(filename)
437454
settings = loads(filename.read_text())
438455
for sectionname, configs in settings.items():
439-
section = getattr(sys.modules[__name__], sectionname)
440-
section.load(configs)
456+
if sectionname != 'environment':
457+
section = getattr(sys.modules[__name__], sectionname)
458+
section.load(configs)
441459
set_logger_level()
442460
init_spaces()
443461
init_layout()
@@ -446,9 +464,10 @@ def load(filename):
446464
def get(flat=False):
447465
"""Get config as a dict."""
448466
settings = {
449-
'nipype': nipype.get(),
467+
'environment': environment.get(),
450468
'execution': execution.get(),
451469
'workflow': workflow.get(),
470+
'nipype': nipype.get(),
452471
}
453472
if not flat:
454473
return settings

fmriprep/utils/sentry.py

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

4444
def sentry_setup():
4545
"""Set-up sentry."""
46-
release = config.execution.version or "dev"
46+
release = config.environment.version or "dev"
4747
environment = "dev" if (
4848
os.getenv('FMRIPREP_DEV', '').lower in ('1', 'on', 'yes', 'y', 'true')
4949
or ('+' in release)

fmriprep/workflows/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ def init_single_subject_wf(subject_id):
164164
which is based on *Nipype* {nipype_ver}
165165
(@nipype1; @nipype2; RRID:SCR_002502).
166166
167-
""".format(fmriprep_ver=config.execution.version,
168-
nipype_ver=config.nipype.version)
167+
""".format(fmriprep_ver=config.environment.version,
168+
nipype_ver=config.environment.nipype_version)
169169
workflow.__postdesc__ = """
170170
171171
Many internal operations of *fMRIPrep* use
@@ -207,7 +207,7 @@ def init_single_subject_wf(subject_id):
207207
nstd_spaces=spaces.get_spaces(standard=False)),
208208
name='summary', run_without_submitting=True)
209209

210-
about = pe.Node(AboutSummary(version=config.execution.version,
210+
about = pe.Node(AboutSummary(version=config.environment.version,
211211
command=' '.join(sys.argv)),
212212
name='about', run_without_submitting=True)
213213

0 commit comments

Comments
 (0)