3
3
"""NiBabies runner."""
4
4
from .. import config
5
5
6
- EXITCODE : int = - 1
7
-
8
6
9
7
def main ():
10
8
"""Entry point."""
@@ -26,12 +24,10 @@ def main():
26
24
27
25
# collect and submit telemetry information
28
26
# if `--notrack` is specified, nothing is done.
29
- global EXITCODE
30
27
if not config .execution .notrack :
31
28
from nibabies .utils .telemetry import setup_migas
32
29
33
- setup_migas (init = True )
34
- atexit .register (migas_exit )
30
+ setup_migas ()
35
31
36
32
if "participant" in config .workflow .analysis_level :
37
33
_pool = None
@@ -61,7 +57,7 @@ def main():
61
57
# build the workflow within the same process
62
58
# it still needs to be saved / loaded to be properly initialized
63
59
retval = build_workflow (config_file )
64
- EXITCODE = retval ['return_code' ]
60
+ exitcode = retval ['return_code' ]
65
61
nibabies_wf = retval ['workflow' ]
66
62
67
63
# exit conditions:
@@ -70,18 +66,18 @@ def main():
70
66
# - boilerplate only
71
67
72
68
if nibabies_wf is None and not config .execution .reports_only :
73
- sys .exit (EXITCODE )
69
+ sys .exit (exitcode )
74
70
75
71
if config .execution .write_graph :
76
72
nibabies_wf .write_graph (graph2use = "colored" , format = "svg" , simple_form = True )
77
73
78
- if EXITCODE != 0 :
79
- sys .exit (EXITCODE )
74
+ if exitcode != 0 :
75
+ sys .exit (exitcode )
80
76
81
77
# generate boilerplate
82
78
build_boilerplate (nibabies_wf )
83
79
if config .execution .boilerplate_only :
84
- sys .exit (EXITCODE )
80
+ sys .exit (exitcode )
85
81
86
82
gc .collect ()
87
83
@@ -105,7 +101,6 @@ def main():
105
101
nibabies_wf .run (** _plugin )
106
102
except Exception as e :
107
103
config .loggers .workflow .critical ("nibabies failed: %s" , e )
108
- EXITCODE = 1
109
104
raise
110
105
else :
111
106
config .loggers .workflow .log (25 , "nibabies finished successfully!" )
@@ -151,38 +146,6 @@ def main():
151
146
write_bidsignore (config .execution .nibabies_dir )
152
147
153
148
154
- def migas_exit () -> None :
155
- """
156
- Send a final crumb to the migas server signaling if the run successfully completed
157
- This function should be registered with `atexit` to run at termination.
158
- """
159
- import sys
160
-
161
- from nibabies .utils .telemetry import send_breadcrumb
162
-
163
- global EXITCODE
164
- migas_kwargs = {'status' : 'C' }
165
- # `sys` will not have these attributes unless an error has been handled
166
- if hasattr (sys , 'last_type' ):
167
- migas_kwargs = {
168
- 'status' : 'F' ,
169
- 'status_desc' : 'Finished with error(s)' ,
170
- 'error_type' : sys .last_type ,
171
- 'error_desc' : sys .last_value ,
172
- }
173
- elif EXITCODE != 0 :
174
- migas_kwargs .update (
175
- {
176
- 'status' : 'F' ,
177
- 'status_desc' : f'Completed with exitcode { EXITCODE } ' ,
178
- }
179
- )
180
- else :
181
- migas_kwargs ['status_desc' ] = 'Success'
182
-
183
- send_breadcrumb (** migas_kwargs )
184
-
185
-
186
149
if __name__ == "__main__" :
187
150
raise RuntimeError (
188
151
"Please `pip install` this and run via the commandline interfaces, `nibabies <command>`"
0 commit comments