Skip to content

Commit 7be74f9

Browse files
committed
fix: updates to make_examples.py
1 parent a9b434b commit 7be74f9

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

tools/make_examples.py

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,20 @@
22
"""Run the py->rst conversion and run all examples.
33
44
This also creates the index.rst file appropriately, makes figures, etc.
5-
"""
6-
# -----------------------------------------------------------------------------
7-
# Library imports
8-
# -----------------------------------------------------------------------------
95
10-
# Stdlib imports
6+
"""
117
import os
128
import sys
13-
149
from glob import glob
15-
16-
# Third-party imports
10+
import runpy
11+
from toollib import sh
1712

1813
# We must configure the mpl backend before making any further mpl imports
1914
import matplotlib
2015

2116
matplotlib.use("Agg")
2217
import matplotlib.pyplot as plt
2318

24-
from matplotlib._pylab_helpers import Gcf
25-
26-
# Local tools
27-
from toollib import *
2819

2920
# -----------------------------------------------------------------------------
3021
# Globals
@@ -52,6 +43,7 @@
5243

5344

5445
def show():
46+
from matplotlib._pylab_helpers import Gcf
5547
allfm = Gcf.get_all_fig_managers()
5648
for fcount, fm in enumerate(allfm):
5749
fm.canvas.figure.savefig("%s_%02i.png" % (figure_basename, fcount + 1))
@@ -66,18 +58,17 @@ def show():
6658

6759
exclude_files = ['-x %s' % sys.argv[i + 1] for i, arg in enumerate(sys.argv) if arg == '-x']
6860

61+
tools_path = os.path.abspath(os.path.dirname(__file__))
62+
ex2rst = os.path.join(tools_path, 'ex2rst')
6963
# Work in examples directory
70-
cd("users/examples")
64+
os.chdir("users/examples")
7165
if not os.getcwd().endswith("users/examples"):
7266
raise OSError("This must be run from doc/examples directory")
7367

7468
# Run the conversion from .py to rst file
75-
sh("../../../tools/ex2rst %s --project Nipype --outdir . ../../../examples" %
76-
' '.join(exclude_files))
77-
sh("""\
78-
../../../tools/ex2rst --project Nipype %s --outdir . ../../../examples/frontiers_paper \
79-
""" % ' '.join(exclude_files)
80-
)
69+
sh("%s %s --project Nipype --outdir . ../../../examples" % (ex2rst, ' '.join(exclude_files)))
70+
sh("""%s --project Nipype %s --outdir . ../../../examples/frontiers_paper""" % (
71+
ex2rst, ' '.join(exclude_files)))
8172

8273
# Make the index.rst file
8374
"""
@@ -99,7 +90,6 @@ def show():
9990
os.mkdir("fig")
10091

10192
for script in glob("*.py"):
102-
figure_basename = pjoin("fig", os.path.splitext(script)[0])
103-
with open(script, 'rt') as f:
104-
exec(f.read())
93+
figure_basename = os.path.join("fig", os.path.splitext(script)[0])
94+
runpy.run_path(script)
10595
plt.close("all")

0 commit comments

Comments
 (0)