@@ -18,30 +18,33 @@ def main():
18
18
if not config .execution .notrack :
19
19
import popylar
20
20
from ..__about__ import __ga_id__
21
+
21
22
config .loggers .cli .info (
22
23
"Your usage of dmriprep is being recorded using popylar (https://popylar.github.io/). " , # noqa
23
24
"For details, see https://nipreps.github.io/dmriprep/usage.html. " ,
24
- "To opt out, call dmriprep with a `--notrack` flag" )
25
- popylar .track_event (__ga_id__ , 'run' , 'cli_run' )
25
+ "To opt out, call dmriprep with a `--notrack` flag" ,
26
+ )
27
+ popylar .track_event (__ga_id__ , "run" , "cli_run" )
26
28
27
29
# CRITICAL Save the config to a file. This is necessary because the execution graph
28
30
# is built as a separate process to keep the memory footprint low. The most
29
31
# straightforward way to communicate with the child process is via the filesystem.
30
- config_file = config .execution .work_dir / ' .dmriprep.toml'
32
+ config_file = config .execution .work_dir / " .dmriprep.toml"
31
33
config .to_filename (config_file )
32
34
33
35
# CRITICAL Call build_workflow(config_file, retval) in a subprocess.
34
36
# Because Python on Linux does not ever free virtual memory (VM), running the
35
37
# workflow construction jailed within a process preempts excessive VM buildup.
36
38
with Manager () as mgr :
37
39
from .workflow import build_workflow
40
+
38
41
retval = mgr .dict ()
39
42
p = Process (target = build_workflow , args = (str (config_file ), retval ))
40
43
p .start ()
41
44
p .join ()
42
45
43
- retcode = p .exitcode or retval .get (' return_code' , 0 )
44
- dmriprep_wf = retval .get (' workflow' , None )
46
+ retcode = p .exitcode or retval .get (" return_code" , 0 )
47
+ dmriprep_wf = retval .get (" workflow" , None )
45
48
46
49
# CRITICAL Load the config from the file. This is necessary because the ``build_workflow``
47
50
# function executed constrained in a process may change the config (and thus the global
@@ -52,7 +55,7 @@ def main():
52
55
sys .exit (int (retcode > 0 ))
53
56
54
57
if dmriprep_wf and config .execution .write_graph :
55
- dmriprep_wf .write_graph (graph2use = "colored" , format = ' svg' , simple_form = True )
58
+ dmriprep_wf .write_graph (graph2use = "colored" , format = " svg" , simple_form = True )
56
59
57
60
retcode = retcode or (dmriprep_wf is None ) * os .EX_SOFTWARE
58
61
if retcode != 0 :
@@ -61,8 +64,8 @@ def main():
61
64
# Generate boilerplate
62
65
with Manager () as mgr :
63
66
from .workflow import build_boilerplate
64
- p = Process ( target = build_boilerplate ,
65
- args = (str (config_file ), dmriprep_wf ))
67
+
68
+ p = Process ( target = build_boilerplate , args = (str (config_file ), dmriprep_wf ))
66
69
p .start ()
67
70
p .join ()
68
71
@@ -73,39 +76,52 @@ def main():
73
76
gc .collect ()
74
77
75
78
if popylar is not None :
76
- popylar .track_event (__ga_id__ , ' run' , ' started' )
79
+ popylar .track_event (__ga_id__ , " run" , " started" )
77
80
78
- config .loggers .workflow .log (15 , '\n ' .join (
79
- ['dMRIPrep config:' ] + ['\t \t %s' % s for s in config .dumps ().splitlines ()])
81
+ config .loggers .workflow .log (
82
+ 15 ,
83
+ "\n " .join (
84
+ ["dMRIPrep config:" ] + ["\t \t %s" % s for s in config .dumps ().splitlines ()]
85
+ ),
80
86
)
81
- config .loggers .workflow .log (25 , ' dMRIPrep started!' )
87
+ config .loggers .workflow .log (25 , " dMRIPrep started!" )
82
88
errno = 1 # Default is error exit unless otherwise set
83
89
try :
84
90
dmriprep_wf .run (** config .nipype .get_plugin ())
85
91
except Exception as e :
86
92
if not config .execution .notrack :
87
- popylar .track_event (__ga_id__ , ' run' , ' error' )
88
- config .loggers .workflow .critical (' dMRIPrep failed: %s' , e )
93
+ popylar .track_event (__ga_id__ , " run" , " error" )
94
+ config .loggers .workflow .critical (" dMRIPrep failed: %s" , e )
89
95
raise
90
96
else :
91
- config .loggers .workflow .log (25 , ' dMRIPrep finished successfully!' )
97
+ config .loggers .workflow .log (25 , " dMRIPrep finished successfully!" )
92
98
93
99
# Bother users with the boilerplate only iff the workflow went okay.
94
- if (config .execution .output_dir / ' dmriprep' / ' logs' / ' CITATION.md' ).exists ():
100
+ if (config .execution .output_dir / " dmriprep" / " logs" / " CITATION.md" ).exists ():
95
101
config .loggers .workflow .log (
96
- 25 , 'Works derived from this dMRIPrep execution should '
97
- 'include the following boilerplate:\n \n %s' ,
98
- (config .execution .output_dir / 'dmriprep' / 'logs' / 'CITATION.md' ).read_text ()
102
+ 25 ,
103
+ "Works derived from this dMRIPrep execution should "
104
+ "include the following boilerplate:\n \n %s" ,
105
+ (
106
+ config .execution .output_dir / "dmriprep" / "logs" / "CITATION.md"
107
+ ).read_text (),
99
108
)
100
109
101
110
if config .workflow .run_reconall :
102
111
from templateflow import api
103
112
from niworkflows .utils .misc import _copy_any
104
- dseg_tsv = str (api .get ('fsaverage' , suffix = 'dseg' , extension = ['.tsv' ]))
105
- _copy_any (dseg_tsv ,
106
- str (config .execution .output_dir / 'dmriprep' / 'desc-aseg_dseg.tsv' ))
107
- _copy_any (dseg_tsv ,
108
- str (config .execution .output_dir / 'dmriprep' / 'desc-aparcaseg_dseg.tsv' ))
113
+
114
+ dseg_tsv = str (api .get ("fsaverage" , suffix = "dseg" , extension = [".tsv" ]))
115
+ _copy_any (
116
+ dseg_tsv ,
117
+ str (config .execution .output_dir / "dmriprep" / "desc-aseg_dseg.tsv" ),
118
+ )
119
+ _copy_any (
120
+ dseg_tsv ,
121
+ str (
122
+ config .execution .output_dir / "dmriprep" / "desc-aparcaseg_dseg.tsv"
123
+ ),
124
+ )
109
125
errno = 0
110
126
finally :
111
127
from niworkflows .reports import generate_reports
@@ -117,17 +133,20 @@ def main():
117
133
config .execution .output_dir ,
118
134
config .execution .work_dir ,
119
135
config .execution .run_uuid ,
120
- config = pkgrf ('dmriprep' , 'config/reports-spec.yml' ),
121
- packagename = 'dmriprep' )
136
+ config = pkgrf ("dmriprep" , "config/reports-spec.yml" ),
137
+ packagename = "dmriprep" ,
138
+ )
122
139
write_derivative_description (
123
- config .execution .bids_dir ,
124
- config . execution . output_dir / 'dmriprep' )
140
+ config .execution .bids_dir , config . execution . output_dir / "dmriprep"
141
+ )
125
142
126
143
if failed_reports and not config .execution .notrack :
127
- popylar .track_event (__ga_id__ , ' run' , ' reporting_error' )
144
+ popylar .track_event (__ga_id__ , " run" , " reporting_error" )
128
145
sys .exit (int ((errno + failed_reports ) > 0 ))
129
146
130
147
131
- if __name__ == '__main__' :
132
- raise RuntimeError ("dmriprep/cli/run.py should not be run directly;\n "
133
- "Please `pip install` dmriprep and use the `dmriprep` command" )
148
+ if __name__ == "__main__" :
149
+ raise RuntimeError (
150
+ "dmriprep/cli/run.py should not be run directly;\n "
151
+ "Please `pip install` dmriprep and use the `dmriprep` command"
152
+ )
0 commit comments