2
2
"""Run the py->rst conversion and run all examples.
3
3
4
4
This also creates the index.rst file appropriately, makes figures, etc.
5
- """
6
- # -----------------------------------------------------------------------------
7
- # Library imports
8
- # -----------------------------------------------------------------------------
9
5
10
- # Stdlib imports
6
+ """
11
7
import os
12
8
import sys
13
-
14
9
from glob import glob
15
-
16
- # Third-party imports
10
+ import runpy
11
+ from toollib import sh
17
12
18
13
# We must configure the mpl backend before making any further mpl imports
19
14
import matplotlib
20
15
21
16
matplotlib .use ("Agg" )
22
17
import matplotlib .pyplot as plt
23
18
24
- from matplotlib ._pylab_helpers import Gcf
25
-
26
- # Local tools
27
- from toollib import *
28
19
29
20
# -----------------------------------------------------------------------------
30
21
# Globals
52
43
53
44
54
45
def show ():
46
+ from matplotlib ._pylab_helpers import Gcf
55
47
allfm = Gcf .get_all_fig_managers ()
56
48
for fcount , fm in enumerate (allfm ):
57
49
fm .canvas .figure .savefig ("%s_%02i.png" % (figure_basename , fcount + 1 ))
@@ -66,18 +58,17 @@ def show():
66
58
67
59
exclude_files = ['-x %s' % sys .argv [i + 1 ] for i , arg in enumerate (sys .argv ) if arg == '-x' ]
68
60
61
+ tools_path = os .path .abspath (os .path .dirname (__file__ ))
62
+ ex2rst = os .path .join (tools_path , 'ex2rst' )
69
63
# Work in examples directory
70
- cd ("users/examples" )
64
+ os . chdir ("users/examples" )
71
65
if not os .getcwd ().endswith ("users/examples" ):
72
66
raise OSError ("This must be run from doc/examples directory" )
73
67
74
68
# 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 )))
81
72
82
73
# Make the index.rst file
83
74
"""
@@ -99,7 +90,6 @@ def show():
99
90
os .mkdir ("fig" )
100
91
101
92
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 )
105
95
plt .close ("all" )
0 commit comments