1010# copyright and license terms.
1111#
1212### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
13-
1413"""Helper to automagically generate ReST versions of examples"""
1514from __future__ import (print_function , division , unicode_literals ,
1615 absolute_import )
@@ -38,18 +37,20 @@ def auto_image(line):
3837
3938 # Match means it's an image spec, we rewrite it with extra tags
4039 ini_space = m .group (1 )
41- lines = [line ,
42- ini_space + ' :width: 500\n ' ,
43- #ini_space + ' :height: 350\n'
44- ]
40+ lines = [
41+ line ,
42+ ini_space + ' :width: 500\n ' ,
43+ #ini_space + ' :height: 350\n'
44+ ]
4545 fspec = m .group (2 )
4646 if fspec .endswith ('.*' ):
4747 fspec = fspec .replace ('.*' , '.png' )
4848 fspec = fspec .replace ('fig/' , '../_images/' )
49- lines .append (ini_space + (' :target: %s\n ' % fspec ) )
49+ lines .append (ini_space + (' :target: %s\n ' % fspec ))
5050 lines .append ('\n ' )
5151 return '' .join (lines )
5252
53+
5354def exfile2rst (filename ):
5455 """Open a Python script and convert it into an ReST string.
5556 """
@@ -114,7 +115,7 @@ def exfile2rst(filename):
114115 indocs = True
115116 code2doc = True
116117 # rescue what is left on the line
117- proc_line = cleanline [3 :] # strip """
118+ proc_line = cleanline [3 :] # strip """
118119 else :
119120 # we are already in the docs
120121 # handle doc end
@@ -191,14 +192,13 @@ def exfile2rstfile(filename, opts):
191192 This same script is also included in the %s source distribution under the
192193 :file:`examples` directory.
193194
194- """ % (filename , opts .project )
195+ """ % (filename , opts .project )
195196
196197 dfile .write (msg )
197198
198199 dfile .close ()
199200
200201
201-
202202def main ():
203203 parser = OptionParser ( \
204204 usage = "%prog [options] <filename|directory> [...]" , \
@@ -224,30 +224,53 @@ first (module-level) docstring instead.
224224""" ) #'
225225
226226 # define options
227- parser .add_option ('--verbose' , action = 'store_true' , dest = 'verbose' ,
228- default = False , help = 'print status messages' )
229- parser .add_option ('-x' , '--exclude' , action = 'append' , dest = 'excluded' ,
230- help = """\
227+ parser .add_option (
228+ '--verbose' ,
229+ action = 'store_true' ,
230+ dest = 'verbose' ,
231+ default = False ,
232+ help = 'print status messages' )
233+ parser .add_option (
234+ '-x' ,
235+ '--exclude' ,
236+ action = 'append' ,
237+ dest = 'excluded' ,
238+ help = """\
231239 Use this option to exclude single files from the to be parsed files. This is
232240especially useful to exclude files when parsing complete directories. This
233241option can be specified multiple times.
234242""" )
235- parser .add_option ('-o' , '--outdir' , action = 'store' , dest = 'outdir' ,
236- type = 'string' , default = None , help = """\
243+ parser .add_option (
244+ '-o' ,
245+ '--outdir' ,
246+ action = 'store' ,
247+ dest = 'outdir' ,
248+ type = 'string' ,
249+ default = None ,
250+ help = """\
237251 Target directory to write the ReST output to. This is a required option.
238252""" )
239- parser .add_option ('--no-sourceref' , action = 'store_false' , default = True ,
240- dest = 'sourceref' , help = """\
253+ parser .add_option (
254+ '--no-sourceref' ,
255+ action = 'store_false' ,
256+ default = True ,
257+ dest = 'sourceref' ,
258+ help = """\
241259 If specified, the source reference section will be suppressed.
242260""" )
243- parser .add_option ('--project' , type = 'string' , action = 'store' , default = '' ,
244- dest = 'project' , help = """\
261+ parser .add_option (
262+ '--project' ,
263+ type = 'string' ,
264+ action = 'store' ,
265+ default = '' ,
266+ dest = 'project' ,
267+ help = """\
245268 Name of the project that contains the examples. This name is used in the
246269'seealso' source references. Default: ''
247270""" )
248271
249272 # parse options
250- (opts , args ) = parser .parse_args () # read sys.argv[1:] by default
273+ (opts , args ) = parser .parse_args () # read sys.argv[1:] by default
251274
252275 # check for required options
253276 if opts .outdir is None :
0 commit comments