10
10
.pdf.
11
11
The source code for the workflow may be included as **inline content** to
12
12
the directive::
13
+
13
14
.. workflow::
14
15
from mriqc.workflows.anatomical import airmsk_wf
15
16
wf = airmsk_wf()
38
39
Configuration options
39
40
---------------------
40
41
The workflow directive has the following configuration options:
42
+ graph2use
43
+ Select a graph type to use
44
+ simple_form
45
+ determines if the node name shown in the visualization is either of the form nodename
46
+ (package) when set to True or nodename.Class.package when set to False.
41
47
wf_include_source
42
48
Default value for the include-source option
43
49
wf_html_show_source_link
@@ -121,6 +127,8 @@ def _option_boolean(arg):
121
127
else :
122
128
raise ValueError ('"%s" unknown boolean' % arg )
123
129
130
+ def _option_graph2use (arg ):
131
+ return directives .choice (arg , ('hierarchical' , 'colored' , 'flat' , 'orig' , 'exec' ))
124
132
125
133
def _option_context (arg ):
126
134
if arg in [None , 'reset' , 'close-figs' ]:
@@ -183,14 +191,18 @@ def setup(app):
183
191
'format' : _option_format ,
184
192
'context' : _option_context ,
185
193
'nofigs' : directives .flag ,
186
- 'encoding' : directives .encoding
194
+ 'encoding' : directives .encoding ,
195
+ 'graph2use' : _option_graph2use ,
196
+ 'simple_form' : _option_boolean
187
197
}
188
198
189
199
app .add_directive ('workflow' , wf_directive , True , (0 , 2 , False ), ** options )
200
+ app .add_config_value ('graph2use' , 'hierarchical' , 'html' )
201
+ app .add_config_value ('simple_form' , True , 'html' )
190
202
app .add_config_value ('wf_pre_code' , None , True )
191
203
app .add_config_value ('wf_include_source' , False , True )
192
204
app .add_config_value ('wf_html_show_source_link' , True , True )
193
- app .add_config_value ('wf_formats' , ['png' , 'hires.png ' , 'pdf' ], True )
205
+ app .add_config_value ('wf_formats' , ['png' , 'svg ' , 'pdf' ], True )
194
206
app .add_config_value ('wf_basedir' , None , True )
195
207
app .add_config_value ('wf_html_show_formats' , True , True )
196
208
app .add_config_value ('wf_rcparams' , {}, True )
@@ -255,21 +267,6 @@ def remove_coding(text):
255
267
TEMPLATE = """
256
268
{{ source_code }}
257
269
{{ only_html }}
258
- {% if source_link or (html_show_formats and not multi_image) %}
259
- (
260
- {%- if source_link -%}
261
- `Source code <{{ source_link }}>`__
262
- {%- endif -%}
263
- {%- if html_show_formats and not multi_image -%}
264
- {%- for img in images -%}
265
- {%- for fmt in img.formats -%}
266
- {%- if source_link or not loop.first -%}, {% endif -%}
267
- `{{ fmt }} <{{ dest_dir }}/{{ img.basename }}.{{ fmt }}>`__
268
- {%- endfor -%}
269
- {%- endfor -%}
270
- {%- endif -%}
271
- )
272
- {% endif %}
273
270
{% for img in images %}
274
271
.. figure:: {{ build_dir }}/{{ img.basename }}.{{ default_fmt }}
275
272
{% for option in options -%}
@@ -285,6 +282,21 @@ def remove_coding(text):
285
282
{%- endif -%}
286
283
{{ caption }}
287
284
{% endfor %}
285
+ {% if source_link or (html_show_formats and not multi_image) %}
286
+ (
287
+ {%- if source_link -%}
288
+ `Source code <{{ source_link }}>`__
289
+ {%- endif -%}
290
+ {%- if html_show_formats and not multi_image -%}
291
+ {%- for img in images -%}
292
+ {%- for fmt in img.formats -%}
293
+ {%- if source_link or not loop.first -%}, {% endif -%}
294
+ `{{ fmt }} <{{ dest_dir }}/{{ img.basename }}.{{ fmt }}>`__
295
+ {%- endfor -%}
296
+ {%- endfor -%}
297
+ {%- endif -%}
298
+ )
299
+ {% endif %}
288
300
{{ only_latex }}
289
301
{% for img in images %}
290
302
{% if 'pdf' in img.formats -%}
@@ -411,7 +423,6 @@ def _dummy_print(*arg, **kwarg):
411
423
sys .stdout = stdout
412
424
return ns
413
425
414
-
415
426
def get_wf_formats (config ):
416
427
default_dpi = {'png' : 80 , 'hires.png' : 200 , 'pdf' : 200 }
417
428
formats = []
@@ -436,15 +447,14 @@ def get_wf_formats(config):
436
447
437
448
438
449
def render_figures (code , code_path , output_dir , output_base , context ,
439
- function_name , config , context_reset = False ,
440
- close_figs = False ):
450
+ function_name , config , graph2use , simple_form ,
451
+ context_reset = False , close_figs = False ):
441
452
"""
442
453
Run a nipype workflow creation script and save the graph in *output_dir*.
443
454
Save the images under *output_dir* with file names derived from
444
455
*output_base*
445
456
"""
446
457
formats = get_wf_formats (config )
447
-
448
458
ns = wf_context if context else {}
449
459
if context_reset :
450
460
wf_context .clear ()
@@ -457,11 +467,9 @@ def render_figures(code, code_path, output_dir, output_base, context,
457
467
img_path = img .filename (fmt )
458
468
imgname , ext = os .path .splitext (os .path .basename (img_path ))
459
469
ns ['wf' ].base_dir = output_dir
460
- ns ['wf' ].write_graph (imgname , format = ext [1 :])
461
-
462
- src = os .path .join (os .path .dirname (img_path ), ns ['wf' ].name ,
463
- os .path .basename (img_path ))
464
- print (src , img_path )
470
+ src = ns ['wf' ].write_graph (imgname , format = ext [1 :],
471
+ graph2use = graph2use ,
472
+ simple_form = simple_form )
465
473
shutil .move (src , img_path )
466
474
except Exception as err :
467
475
raise GraphError (traceback .format_exc ())
@@ -479,6 +487,9 @@ def run(arguments, content, options, state_machine, state, lineno):
479
487
formats = get_wf_formats (config )
480
488
default_fmt = formats [0 ][0 ]
481
489
490
+ graph2use = options .get ('graph2use' , 'hierarchical' )
491
+ simple_form = options .get ('simple_form' , True )
492
+
482
493
options .setdefault ('include-source' , config .wf_include_source )
483
494
keep_context = 'context' in options
484
495
context_opt = None if not keep_context else options ['context' ]
@@ -577,6 +588,8 @@ def run(arguments, content, options, state_machine, state, lineno):
577
588
keep_context ,
578
589
function_name ,
579
590
config ,
591
+ graph2use ,
592
+ simple_form ,
580
593
context_reset = context_opt == 'reset' ,
581
594
close_figs = context_opt == 'close-figs' )
582
595
errors = []
0 commit comments