Skip to content

Commit

Permalink
fix: updates to make_examples.py
Browse files Browse the repository at this point in the history
  • Loading branch information
oesteban committed Jan 1, 2020
1 parent a9b434b commit 7be74f9
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions tools/make_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,20 @@
"""Run the py->rst conversion and run all examples.
This also creates the index.rst file appropriately, makes figures, etc.
"""
# -----------------------------------------------------------------------------
# Library imports
# -----------------------------------------------------------------------------
# Stdlib imports
"""
import os
import sys

from glob import glob

# Third-party imports
import runpy
from toollib import sh

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

matplotlib.use("Agg")
import matplotlib.pyplot as plt

from matplotlib._pylab_helpers import Gcf

# Local tools
from toollib import *

# -----------------------------------------------------------------------------
# Globals
Expand Down Expand Up @@ -52,6 +43,7 @@


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

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

tools_path = os.path.abspath(os.path.dirname(__file__))
ex2rst = os.path.join(tools_path, 'ex2rst')
# Work in examples directory
cd("users/examples")
os.chdir("users/examples")
if not os.getcwd().endswith("users/examples"):
raise OSError("This must be run from doc/examples directory")

# Run the conversion from .py to rst file
sh("../../../tools/ex2rst %s --project Nipype --outdir . ../../../examples" %
' '.join(exclude_files))
sh("""\
../../../tools/ex2rst --project Nipype %s --outdir . ../../../examples/frontiers_paper \
""" % ' '.join(exclude_files)
)
sh("%s %s --project Nipype --outdir . ../../../examples" % (ex2rst, ' '.join(exclude_files)))
sh("""%s --project Nipype %s --outdir . ../../../examples/frontiers_paper""" % (
ex2rst, ' '.join(exclude_files)))

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

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

0 comments on commit 7be74f9

Please sign in to comment.