Skip to content

Commit 857e229

Browse files
committed
RF: Use docutils 0.5-style directive definition
1 parent e2533c2 commit 857e229

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

nipype/sphinxext/plot_workflow.py

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118

119119
missing_imports = []
120120
try:
121-
from docutils.parsers.rst import directives
121+
from docutils.parsers.rst import directives, Directive
122122
from docutils.parsers.rst.directives.images import Image
123123

124124
align = Image.align
@@ -146,26 +146,6 @@ def format_template(template, **kw):
146146
missing_imports.append(str(e))
147147

148148

149-
def wf_directive(
150-
name,
151-
arguments,
152-
options,
153-
content,
154-
lineno,
155-
content_offset,
156-
block_text,
157-
state,
158-
state_machine,
159-
):
160-
if len(missing_imports) == 0:
161-
return run(arguments, content, options, state_machine, state, lineno)
162-
else:
163-
raise ImportError("\n".join(missing_imports))
164-
165-
166-
wf_directive.__doc__ = __doc__
167-
168-
169149
def _option_boolean(arg):
170150
if not arg or not arg.strip():
171151
# no argument given, assume used as a flag
@@ -232,12 +212,12 @@ def mark_wf_labels(app, document):
232212
break
233213

234214

235-
def setup(app):
236-
setup.app = app
237-
setup.config = app.config
238-
setup.confdir = app.confdir
239-
240-
options = {
215+
class WorkflowDirective(Directive):
216+
has_content = True
217+
required_arguments = 0
218+
optional_arguments = 2
219+
final_argument_whitespace = False
220+
option_spec = {
241221
"alt": directives.unchanged,
242222
"height": directives.length_or_unitless,
243223
"width": directives.length_or_percentage_or_unitless,
@@ -253,7 +233,16 @@ def setup(app):
253233
"simple_form": _option_boolean,
254234
}
255235

256-
app.add_directive("workflow", wf_directive, True, (0, 2, False), **options)
236+
237+
WorkflowDirective.__doc__ = __doc__
238+
239+
240+
def setup(app):
241+
setup.app = app
242+
setup.config = app.config
243+
setup.confdir = app.confdir
244+
245+
app.add_directive("workflow", WorkflowDirective)
257246
app.add_config_value("graph2use", "hierarchical", "html")
258247
app.add_config_value("simple_form", True, "html")
259248
app.add_config_value("wf_pre_code", None, True)

0 commit comments

Comments
 (0)