@@ -393,39 +393,28 @@ def before_send(event, hints):
393
393
p .start ()
394
394
p .join ()
395
395
396
- if p .exitcode != 0 :
397
- sys .exit (p .exitcode )
398
-
399
- fmriprep_wf = retval ['workflow' ]
400
- plugin_settings = retval ['plugin_settings' ]
401
- bids_dir = retval ['bids_dir' ]
402
- output_dir = retval ['output_dir' ]
403
- work_dir = retval ['work_dir' ]
404
- subject_list = retval ['subject_list' ]
405
- run_uuid = retval ['run_uuid' ]
406
- if not opts .notrack :
407
- with sentry_sdk .configure_scope () as scope :
408
- scope .set_tag ('run_uuid' , run_uuid )
409
- scope .set_tag ('npart' , len (subject_list ))
396
+ retcode = p .exitcode or retval .get ('return_code' , 0 )
410
397
411
- retcode = retval [ 'return_code' ]
412
-
413
- if fmriprep_wf is None :
414
- sys . exit ( 1 )
415
-
416
- if opts . write_graph :
417
- fmriprep_wf . write_graph ( graph2use = "colored" , format = 'svg ' , simple_form = True )
398
+ bids_dir = retval . get ( 'bids_dir' )
399
+ output_dir = retval . get ( 'output_dir' )
400
+ work_dir = retval . get ( 'work_dir' )
401
+ plugin_settings = retval . get ( 'plugin_settings' , None )
402
+ subject_list = retval . get ( 'subject_list' , None )
403
+ fmriprep_wf = retval . get ( 'workflow' , None )
404
+ run_uuid = retval . get ( 'run_uuid ' , None )
418
405
419
406
if opts .reports_only :
420
407
sys .exit (int (retcode > 0 ))
421
408
422
409
if opts .boilerplate :
423
410
sys .exit (int (retcode > 0 ))
424
411
425
- # Sentry tracking
426
- if not opts .notrack :
427
- sentry_sdk .add_breadcrumb (message = 'fMRIPrep started' , level = 'info' )
428
- sentry_sdk .capture_message ('fMRIPrep started' , level = 'info' )
412
+ if fmriprep_wf and opts .write_graph :
413
+ fmriprep_wf .write_graph (graph2use = "colored" , format = 'svg' , simple_form = True )
414
+
415
+ retcode = retcode or int (fmriprep_wf is None )
416
+ if retcode != 0 :
417
+ sys .exit (retcode )
429
418
430
419
# Check workflow for missing commands
431
420
missing = check_deps (fmriprep_wf )
@@ -434,9 +423,19 @@ def before_send(event, hints):
434
423
for iface , cmd in missing :
435
424
print ("\t {} (Interface: {})" .format (cmd , iface ))
436
425
sys .exit (2 )
437
-
438
426
# Clean up master process before running workflow, which may create forks
439
427
gc .collect ()
428
+
429
+ # Sentry tracking
430
+ if not opts .notrack :
431
+ with sentry_sdk .configure_scope () as scope :
432
+ if run_uuid :
433
+ scope .set_tag ('run_uuid' , run_uuid )
434
+ if subject_list :
435
+ scope .set_tag ('npart' , len (subject_list ))
436
+ sentry_sdk .add_breadcrumb (message = 'fMRIPrep started' , level = 'info' )
437
+ sentry_sdk .capture_message ('fMRIPrep started' , level = 'info' )
438
+
440
439
try :
441
440
fmriprep_wf .run (** plugin_settings )
442
441
except RuntimeError as e :
@@ -588,6 +587,24 @@ def build_workflow(opts, retval):
588
587
* Run identifier: {uuid}.
589
588
""" .format
590
589
590
+ bids_dir = opts .bids_dir .resolve ()
591
+ output_dir = opts .output_dir .resolve ()
592
+ work_dir = opts .work_dir
593
+
594
+ retval ['return_code' ] = 1
595
+ retval ['workflow' ] = None
596
+ retval ['bids_dir' ] = str (bids_dir )
597
+ retval ['output_dir' ] = str (output_dir )
598
+ retval ['work_dir' ] = str (work_dir )
599
+
600
+ if output_dir == bids_dir :
601
+ logger .error (
602
+ 'The selected output folder is the same as the input BIDS folder. '
603
+ 'Please modify the output path (suggestion: %s).' ,
604
+ bids_dir / 'derivatives' / ('fmriprep-%s' % __version__ .split ('+' )[0 ]))
605
+ retval ['return_code' ] = 1
606
+ return retval
607
+
591
608
# Reduce to unique space identifiers
592
609
output_spaces = sorted (set (opts .output_space ))
593
610
@@ -633,12 +650,13 @@ def build_workflow(opts, retval):
633
650
634
651
# Set up some instrumental utilities
635
652
run_uuid = '%s_%s' % (strftime ('%Y%m%d-%H%M%S' ), uuid .uuid4 ())
653
+ retval ['run_uuid' ] = run_uuid
636
654
637
655
# First check that bids_dir looks like a BIDS folder
638
- bids_dir = opts .bids_dir .resolve ()
639
656
layout = BIDSLayout (str (bids_dir ), validate = False )
640
657
subject_list = collect_participants (
641
658
layout , participant_label = opts .participant_label )
659
+ retval ['subject_list' ] = subject_list
642
660
643
661
# Load base plugin_settings from file if --use-plugin
644
662
if opts .use_plugin is not None :
@@ -678,19 +696,10 @@ def build_workflow(opts, retval):
678
696
logger .warning (
679
697
'Per-process threads (--omp-nthreads=%d) exceed total '
680
698
'threads (--nthreads/--n_cpus=%d)' , omp_nthreads , nthreads )
699
+ retval ['plugin_settings' ] = plugin_settings
681
700
682
701
# Set up directories
683
- output_dir = opts .output_dir .resolve ()
684
- if output_dir == bids_dir :
685
- output_dir = bids_dir / 'derivatives' / ('fmriprep-%s' % __version__ .split ('+' )[0 ])
686
- logger .warning (
687
- 'The selected output folder is the same as the input BIDS folder. '
688
- 'Cowardly redirecting outputs to %s' , output_dir
689
- )
690
-
691
702
log_dir = output_dir / 'fmriprep' / 'logs'
692
- work_dir = opts .work_dir
693
-
694
703
# Check and create output and working directories
695
704
output_dir .mkdir (exist_ok = True , parents = True )
696
705
log_dir .mkdir (exist_ok = True , parents = True )
@@ -718,20 +727,12 @@ def build_workflow(opts, retval):
718
727
if opts .resource_monitor :
719
728
ncfg .enable_resource_monitor ()
720
729
721
- retval ['return_code' ] = 0
722
- retval ['plugin_settings' ] = plugin_settings
723
- retval ['bids_dir' ] = str (bids_dir )
724
- retval ['output_dir' ] = str (output_dir )
725
- retval ['work_dir' ] = str (work_dir )
726
- retval ['subject_list' ] = subject_list
727
- retval ['run_uuid' ] = run_uuid
728
- retval ['workflow' ] = None
729
-
730
730
# Called with reports only
731
731
if opts .reports_only :
732
732
logger .log (25 , 'Running --reports-only on participants %s' , ', ' .join (subject_list ))
733
733
if opts .run_uuid is not None :
734
734
run_uuid = opts .run_uuid
735
+ retval ['run_uuid' ] = run_uuid
735
736
retval ['return_code' ] = generate_reports (
736
737
subject_list , str (output_dir ), str (work_dir ), run_uuid )
737
738
return retval
0 commit comments