Skip to content

Commit 7e1a423

Browse files
committed
ENH: Import examples from niflow
1 parent 193918b commit 7e1a423

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

doc/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/documentation.zip
2+
_static/python

doc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ help:
2424
@echo " doctest run all doctests embedded in the documentation"
2525

2626
clean:
27-
-rm -rf _build/* *~ api/generated interfaces/generated users/examples documentation.zip
27+
-rm -rf _build/* *~ api/generated interfaces/generated users/examples documentation.zip _static/python
2828

2929
htmlonly:
3030
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) _build/html

doc/conf.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,37 @@
1313
# serve to show the default.
1414

1515
import os
16+
from pathlib import Path
17+
from tempfile import TemporaryDirectory
18+
import shutil
1619
from packaging.version import Version
1720
import nipype
21+
import subprocess as sp
1822

19-
doc_path = os.path.abspath(os.path.dirname(__file__))
20-
os.makedirs('users/examples', exist_ok=True)
2123

22-
os.chdir(os.path.join(doc_path, 'users', 'examples'))
23-
os.system("""python ../../../tools/ex2rst -x ../../../examples/test_spm.py \
24-
--project Nipype --outdir . ../../../examples""")
25-
os.system("""python ../../../tools/ex2rst --project Nipype --outdir . \
26-
../../../examples/frontiers_paper""")
27-
os.chdir(doc_path)
24+
conf_py = Path(__file__)
25+
26+
example_dir = conf_py.parent / 'users' / 'examples'
27+
shutil.rmtree(example_dir, ignore_errors=True)
28+
example_dir.mkdir(parents=True)
29+
python_dir = conf_py.parent / "_static" / "python"
30+
shutil.rmtree(python_dir, ignore_errors=True)
31+
32+
ex2rst = str(conf_py.parent.parent / "tools" / "ex2rst")
33+
34+
with TemporaryDirectory() as tmpdir:
35+
sp.run(["git", "clone", "--depth", "1", "https://github.com/niflows/nipype1-examples.git",
36+
tmpdir], check=True)
37+
source_dir = Path(tmpdir) / "package" / "niflow" / "nipype1" / "examples"
38+
shutil.copytree(source_dir, python_dir)
39+
40+
sp.run(["python", ex2rst, "--project", "Nipype", "--outdir", str(example_dir),
41+
"-x", str(python_dir / "test_spm.py"),
42+
"-x", str(python_dir / "__init__.py"),
43+
"-x", str(python_dir / "cli.py"),
44+
str(python_dir)], check=True)
45+
sp.run(["python", ex2rst, "--project", "Nipype", "--outdir", str(example_dir),
46+
str(python_dir / "frontiers_paper")], check=True)
2847

2948

3049
# If extensions (or modules to document with autodoc) are in another directory,
@@ -98,7 +117,7 @@
98117

99118
# General information about the project.
100119
project = u'nipype'
101-
copyright = u'2009-19, Neuroimaging in Python team'
120+
copyright = u'2009-20, Neuroimaging in Python team'
102121

103122
# The version info for the project you're documenting, acts as replacement for
104123
# |version| and |release|, also used in various other places throughout the

tools/ex2rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def exfile2rstfile(filename, opts):
190190
This same script is also included in the %s source distribution under the
191191
:file:`examples` directory.
192192
193-
""" % (filename, opts.project)
193+
""" % (os.path.relpath(filename, opts.outdir), opts.project)
194194

195195
dfile.write(msg)
196196

0 commit comments

Comments
 (0)