How to use the mriqc.sphinxext.plot_workflow.GraphError function in mriqc

To help you get started, we’ve selected a few mriqc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github poldracklab / mriqc / mriqc / sphinxext / plot_workflow.py View on Github external
if isinstance(wf_formats, (str, bytes)):
        # String Sphinx < 1.3, Split on , to mimic
        # Sphinx 1.3 and later. Sphinx 1.3 always
        # returns a list.
        wf_formats = wf_formats.split(',')
    for fmt in wf_formats:
        if isinstance(fmt, (str, bytes)):
            if ':' in fmt:
                suffix, dpi = fmt.split(':')
                formats.append((str(suffix), int(dpi)))
            else:
                formats.append((fmt, default_dpi.get(fmt, 80)))
        elif isinstance(fmt, (tuple, list)) and len(fmt) == 2:
            formats.append((str(fmt[0]), int(fmt[1])))
        else:
            raise GraphError('invalid image format "%r" in wf_formats' % fmt)
    return formats
github poldracklab / mriqc / mriqc / sphinxext / plot_workflow.py View on Github external
build_dir_link = build_dir
    source_link = dest_dir_link + '/' + output_base + source_ext

    # make figures
    try:
        results = render_figures(code,
                                 source_file_name,
                                 build_dir,
                                 output_base,
                                 keep_context,
                                 function_name,
                                 config,
                                 context_reset=context_opt == 'reset',
                                 close_figs=context_opt == 'close-figs')
        errors = []
    except GraphError as err:
        reporter = state.memo.reporter
        sm = reporter.system_message(
            2, "Exception occurred in plotting %s\n from %s:\n%s" % (output_base,
                                                source_file_name, err),
            line=lineno)
        results = [(code, [])]
        errors = [sm]

    # Properly indent the caption
    caption = '\n'.join('      ' + line.strip()
                        for line in caption.split('\n'))

    # generate output restructuredtext
    total_lines = []
    for j, (code_piece, images) in enumerate(results):
        if options['include-source']:
github poldracklab / mriqc / mriqc / sphinxext / plot_workflow.py View on Github external
try:
            code = unescape_doctest(code)
            if ns is None:
                ns = {}
            if not ns:
                if setup.config.wf_pre_code is not None:
                    exec(str(setup.config.wf_pre_code), ns)
            ns['print'] = _dummy_print
            if "__main__" in code:
                exec("__name__ = '__main__'", ns)
            code = remove_coding(code)
            exec(code, ns)
            if function_name is not None:
                exec(function_name + "()", ns)
        except (Exception, SystemExit) as err:
            raise GraphError(traceback.format_exc())
    finally:
        os.chdir(pwd)
        sys.argv = old_sys_argv
        sys.path[:] = old_sys_path
        sys.stdout = stdout
    return ns
github poldracklab / mriqc / mriqc / sphinxext / plot_workflow.py View on Github external
run_code(code, code_path, ns, function_name)
    img = ImageFile(output_base, output_dir)

    for fmt, dpi in formats:
        try:
            img_path = img.filename(fmt)
            imgname, ext = os.path.splitext(os.path.basename(img_path))
            ns['wf'].base_dir = output_dir
            ns['wf'].write_graph(imgname, format=ext[1:])

            src = os.path.join(os.path.dirname(img_path), ns['wf'].name,
                               os.path.basename(img_path))
            print(src, img_path)
            shutil.move(src, img_path)
        except Exception as err:
            raise GraphError(traceback.format_exc())

        img.formats.append(fmt)

    return [(code, [img])]