@@ -18,30 +18,33 @@ def main():
1818 if not config .execution .notrack :
1919 import popylar
2020 from ..__about__ import __ga_id__
21+
2122 config .loggers .cli .info (
2223 "Your usage of dmriprep is being recorded using popylar (https://popylar.github.io/). " , # noqa
2324 "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" )
2628
2729 # CRITICAL Save the config to a file. This is necessary because the execution graph
2830 # is built as a separate process to keep the memory footprint low. The most
2931 # 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"
3133 config .to_filename (config_file )
3234
3335 # CRITICAL Call build_workflow(config_file, retval) in a subprocess.
3436 # Because Python on Linux does not ever free virtual memory (VM), running the
3537 # workflow construction jailed within a process preempts excessive VM buildup.
3638 with Manager () as mgr :
3739 from .workflow import build_workflow
40+
3841 retval = mgr .dict ()
3942 p = Process (target = build_workflow , args = (str (config_file ), retval ))
4043 p .start ()
4144 p .join ()
4245
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 )
4548
4649 # CRITICAL Load the config from the file. This is necessary because the ``build_workflow``
4750 # function executed constrained in a process may change the config (and thus the global
@@ -52,7 +55,7 @@ def main():
5255 sys .exit (int (retcode > 0 ))
5356
5457 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 )
5659
5760 retcode = retcode or (dmriprep_wf is None ) * os .EX_SOFTWARE
5861 if retcode != 0 :
@@ -61,8 +64,8 @@ def main():
6164 # Generate boilerplate
6265 with Manager () as mgr :
6366 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 ))
6669 p .start ()
6770 p .join ()
6871
@@ -73,39 +76,52 @@ def main():
7376 gc .collect ()
7477
7578 if popylar is not None :
76- popylar .track_event (__ga_id__ , ' run' , ' started' )
79+ popylar .track_event (__ga_id__ , " run" , " started" )
7780
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+ ),
8086 )
81- config .loggers .workflow .log (25 , ' dMRIPrep started!' )
87+ config .loggers .workflow .log (25 , " dMRIPrep started!" )
8288 errno = 1 # Default is error exit unless otherwise set
8389 try :
8490 dmriprep_wf .run (** config .nipype .get_plugin ())
8591 except Exception as e :
8692 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 )
8995 raise
9096 else :
91- config .loggers .workflow .log (25 , ' dMRIPrep finished successfully!' )
97+ config .loggers .workflow .log (25 , " dMRIPrep finished successfully!" )
9298
9399 # 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 ():
95101 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 (),
99108 )
100109
101110 if config .workflow .run_reconall :
102111 from templateflow import api
103112 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+ )
109125 errno = 0
110126 finally :
111127 from niworkflows .reports import generate_reports
@@ -117,17 +133,20 @@ def main():
117133 config .execution .output_dir ,
118134 config .execution .work_dir ,
119135 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+ )
122139 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+ )
125142
126143 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" )
128145 sys .exit (int ((errno + failed_reports ) > 0 ))
129146
130147
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