Skip to content

Commit 14abfc1

Browse files
author
Denis Rivière
committed
easy syntax to specify steps in python -m capsul
1 parent d7d14b0 commit 14abfc1

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

capsul/process/runprocess.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
from capsul.api import Pipeline
6464
from capsul.attributes.completion_engine import ProcessCompletionEngine
6565
from soma.qt_gui import qt_backend
66+
from soma.controller import Controller
6667
import os
6768
import logging
6869
import sys
@@ -138,6 +139,53 @@ def set_process_param_from_str(process, k, arg):
138139
pass
139140

140141

142+
def parse_pipeline_steps(process, kwargs):
143+
if not isinstance(process, Pipeline):
144+
return
145+
146+
param_steps = kwargs.get('pipeline_steps')
147+
if param_steps is None:
148+
return
149+
150+
del kwargs['pipeline_steps']
151+
152+
pipeline_steps = getattr(process, 'pipeline_steps')
153+
if not isinstance(pipeline_steps, Controller):
154+
return
155+
156+
if isinstance(param_steps, str):
157+
param_steps = [s.strip() for s in param_steps.split(',')]
158+
steps = [[s.strip() for s in p.split('=')] for p in param_steps]
159+
for s in steps:
160+
if len(s) == 1:
161+
s.append(True)
162+
else:
163+
val = s[1]
164+
if val in (0, '0', 'False'):
165+
val = False
166+
else:
167+
val = True
168+
s[1] = val
169+
steps = [[[s.strip() for s in p[0].split('-')]] + p[1:] for p in steps]
170+
if len(steps) >= 1 and steps[0][1]:
171+
# set all steps to False
172+
steps.insert(0, [['', ''], False])
173+
174+
for srange, val in steps:
175+
if len(srange) == 2:
176+
if srange[0] == '':
177+
s0 = 0
178+
else:
179+
s0 = pipeline_steps.user_traits().index(srange[0])
180+
if srange[1] == '':
181+
s1 = len(pipeline_steps.user_traits()) - 1
182+
else:
183+
s1 = pipeline_steps.user_traits().index(srange[1])
184+
srange = list(pipeline_steps.user_traits())[s0:s1+1]
185+
for s in srange:
186+
setattr(pipeline_steps, s, val)
187+
188+
141189
def get_process_with_params(process_name, study_config, iterated_params=[],
142190
attributes={}, *args, **kwargs):
143191
''' Instantiate a process, or an iteration over processes, and fill in its
@@ -169,6 +217,8 @@ def get_process_with_params(process_name, study_config, iterated_params=[],
169217
signature = process.user_traits()
170218
params = list(signature.keys())
171219

220+
steps = parse_pipeline_steps(process, kwargs)
221+
172222
# check for iterations
173223
if iterated_params:
174224

@@ -338,6 +388,24 @@ def main():
338388
their node in the parent pipeline:
339389
340390
python -m capsul morphologist.capsul.morphologist Renorm.enabled=False
391+
392+
Pipeline steps:
393+
394+
Some pipelines define steps that can be enabled or disabled in order to
395+
process only part of the pipeline. They are kind of groups of nodes, but
396+
behave a bit differently for the pipeline parameters completion and checks.
397+
398+
Steps can be specified as the "pipeline_steps" parameter, with a syntax
399+
which can mix ranges and values, ex::
400+
401+
python -m capsul morphologist.capsul.morphologist pipeline_steps="importation,bias_correction"
402+
403+
will do only these 2 steps. While::
404+
405+
python -m capsul morphologist.capsul.morphologist pipeline_steps="brain_extraction, head_mesh-, sulci_labelling=False"
406+
407+
will do brain_extraction, then all steps from head_mesh, except
408+
sulci_labelling which is disabled.
341409
'''
342410

343411
# Set up logging on stderr. This must be called before any logging takes

0 commit comments

Comments
 (0)