Skip to content

Commit d1f9cdd

Browse files
committed
chore: update to latest migas api
1 parent 3dabd57 commit d1f9cdd

File tree

4 files changed

+21
-50
lines changed

4 files changed

+21
-50
lines changed

nibabies/cli/run.py

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
"""NiBabies runner."""
44
from .. import config
55

6-
EXITCODE: int = -1
7-
86

97
def main():
108
"""Entry point."""
@@ -26,12 +24,10 @@ def main():
2624

2725
# collect and submit telemetry information
2826
# if `--notrack` is specified, nothing is done.
29-
global EXITCODE
3027
if not config.execution.notrack:
3128
from nibabies.utils.telemetry import setup_migas
3229

33-
setup_migas(init=True)
34-
atexit.register(migas_exit)
30+
setup_migas()
3531

3632
if "participant" in config.workflow.analysis_level:
3733
_pool = None
@@ -61,7 +57,7 @@ def main():
6157
# build the workflow within the same process
6258
# it still needs to be saved / loaded to be properly initialized
6359
retval = build_workflow(config_file)
64-
EXITCODE = retval['return_code']
60+
exitcode = retval['return_code']
6561
nibabies_wf = retval['workflow']
6662

6763
# exit conditions:
@@ -70,18 +66,18 @@ def main():
7066
# - boilerplate only
7167

7268
if nibabies_wf is None and not config.execution.reports_only:
73-
sys.exit(EXITCODE)
69+
sys.exit(exitcode)
7470

7571
if config.execution.write_graph:
7672
nibabies_wf.write_graph(graph2use="colored", format="svg", simple_form=True)
7773

78-
if EXITCODE != 0:
79-
sys.exit(EXITCODE)
74+
if exitcode != 0:
75+
sys.exit(exitcode)
8076

8177
# generate boilerplate
8278
build_boilerplate(nibabies_wf)
8379
if config.execution.boilerplate_only:
84-
sys.exit(EXITCODE)
80+
sys.exit(exitcode)
8581

8682
gc.collect()
8783

@@ -151,38 +147,6 @@ def main():
151147
write_bidsignore(config.execution.nibabies_dir)
152148

153149

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-
186150
if __name__ == "__main__":
187151
raise RuntimeError(
188152
"Please `pip install` this and run via the commandline interfaces, `nibabies <command>`"

nibabies/utils/telemetry.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
migas = optional_package("migas")[0]
66

77

8-
def setup_migas(init: bool = True) -> None:
8+
def setup_migas(init_ping: bool = True, exit_ping: bool = True) -> None:
99
"""
1010
Prepare the migas python client to communicate with a migas server.
1111
If ``init`` is ``True``, send an initial breadcrumb.
@@ -16,14 +16,21 @@ def setup_migas(init: bool = True) -> None:
1616
session_id = config.execution.run_uuid.split('_', 1)[-1]
1717

1818
migas.setup(session_id=session_id)
19-
if init:
19+
if init_ping:
2020
# send initial status ping
21-
send_breadcrumb(status='R', status_desc='workflow start')
21+
send_crumb(status='R', status_desc='workflow start')
22+
if exit_ping:
23+
from migas.error.nipype import node_execution_error
2224

25+
migas.track_exit(
26+
'nipreps/nibabies',
27+
__version__,
28+
{'NodeExecutionError': node_execution_error},
29+
)
2330

24-
def send_breadcrumb(**kwargs) -> dict:
31+
32+
def send_crumb(**kwargs) -> dict:
2533
"""
2634
Communicate with the migas telemetry server. This requires `migas.setup()` to be called.
2735
"""
28-
res = migas.add_project("nipreps/nibabies", __version__, **kwargs)
29-
return res
36+
return migas.add_breadcrumb("nipreps/nibabies", __version__, **kwargs)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ test = [
7272
"pytest-cov",
7373
"pytest-env",
7474
]
75-
telemetry = ["migas"]
75+
telemetry = ["migas >= 0.4.0"]
7676
# Aliases
7777
docs = ["nibabies[doc]"]
7878
tests = ["nibabies[test]"]

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ matplotlib==3.7.1
9494
# seaborn
9595
# smriprep
9696
# tedana
97-
migas==0.3.0
97+
migas==0.4.0
9898
# via nibabies (pyproject.toml)
9999
networkx==3.1
100100
# via

0 commit comments

Comments
 (0)