22"""Run the py->rst conversion and run all examples.
33
44This also creates the index.rst file appropriately, makes figures, etc.
5- """
6- # -----------------------------------------------------------------------------
7- # Library imports
8- # -----------------------------------------------------------------------------
95
10- # Stdlib imports
6+ """
117import os
128import sys
13-
149from 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
1914import matplotlib
2015
2116matplotlib .use ("Agg" )
2217import matplotlib .pyplot as plt
2318
24- from matplotlib ._pylab_helpers import Gcf
25-
26- # Local tools
27- from toollib import *
2819
2920# -----------------------------------------------------------------------------
3021# Globals
5243
5344
5445def 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
6759exclude_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" )
7165if 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