diff --git a/doc/Makefile b/doc/Makefile index e224c20cbc..bcb7ac2e8f 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -22,7 +22,6 @@ help: "items (ChangeLog)" @echo " linkcheck check all external links for integrity" @echo " doctest run all doctests embedded in the documentation" - @echo " sf_satra copy html files to sourceforge (satra only)" clean: -rm -rf _build/* *~ api/generated interfaces/generated users/examples documentation.zip @@ -35,11 +34,6 @@ htmlonly: html: clean htmlonly @echo "Build HTML and API finished." -examples2rst: clean - mkdir -p users/examples - ../tools/make_examples.py -x ../../../examples/test_spm.py --no-exec - @echo "examples2rst finished." - latex: clean $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) _build/latex @echo diff --git a/doc/conf.py b/doc/conf.py index e1da69f130..56d6935270 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -16,8 +16,16 @@ from packaging.version import Version import nipype +doc_path = os.path.abspath(os.path.dirname(__file__)) os.makedirs('users/examples', exist_ok=True) -os.system('python ../tools/make_examples.py -x ../../../examples/test_spm.py --no-exec') + +os.chdir(os.path.join(doc_path, 'users', 'examples')) +os.system("""python ../../../tools/ex2rst -x ../../../examples/test_spm.py \ +--project Nipype --outdir . ../../../examples""") +os.system("""python ../../../tools/ex2rst --project Nipype --outdir . \ +../../../examples/frontiers_paper""") +os.chdir(doc_path) + # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the diff --git a/tools/ex2rst b/tools/ex2rst index 2434d16ccc..dc3c6d5f37 100755 --- a/tools/ex2rst +++ b/tools/ex2rst @@ -158,9 +158,11 @@ def exfile2rstfile(filename, opts): """ # doc filename dfilename = os.path.basename(filename[:-3]) + '.rst' + dfilepath = os.path.join(opts.outdir, os.path.basename(dfilename)) + print("Creating file %s." % os.path.abspath(dfilepath)) # open dest file - dfile = open(os.path.join(opts.outdir, os.path.basename(dfilename)), 'w') + dfile = open(dfilepath, 'w') # place header dfile.write('.. AUTO-GENERATED FILE -- DO NOT EDIT!\n\n') @@ -196,8 +198,8 @@ def exfile2rstfile(filename, opts): def main(): - parser = OptionParser( \ - usage="%prog [options] [...]", \ + parser = OptionParser( + usage="%prog [options] [...]", version="%prog 0.1", description="""\ %prog converts Python scripts into restructered text (ReST) format suitable for integration into the Sphinx documentation framework. Its key feature is that it @@ -217,7 +219,7 @@ the respective indentation is removed in the ReST output. The parser algorithm automatically excludes file headers and starts with the first (module-level) docstring instead. -""" ) #' +""") # define options parser.add_option( @@ -293,8 +295,7 @@ Name of the project that contains the examples. This name is used in the if len(toparse) != len(toparse_list): print('Ignoring duplicate parse targets.') - if not os.path.exists(opts.outdir): - os.mkdir(outdir) + os.makedirs(opts.outdir, exist_ok=True) # finally process all examples for t in toparse: diff --git a/tools/make_examples.py b/tools/make_examples.py deleted file mode 100755 index 748e615043..0000000000 --- a/tools/make_examples.py +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env python -"""Run the py->rst conversion and run all examples. - -This also creates the index.rst file appropriately, makes figures, etc. - -""" -import os -import sys -from glob import glob -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 - - -# ----------------------------------------------------------------------------- -# Globals -# ----------------------------------------------------------------------------- - -examples_header = """ - -.. _examples: - -Examples -======== - -.. note_about_examples -""" -# ----------------------------------------------------------------------------- -# Function defintions -# ----------------------------------------------------------------------------- - -# These global variables let show() be called by the scripts in the usual -# manner, but when generating examples, we override it to write the figures to -# files with a known name (derived from the script name) plus a counter -figure_basename = None - -# We must change the show command to save instead - - -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)) - - -_mpl_show = plt.show -plt.show = show - -# ----------------------------------------------------------------------------- -# Main script -# ----------------------------------------------------------------------------- - -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 -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("%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 -""" -index = open('index.rst', 'w') -index.write(examples_header) -for name in [os.path.splitext(f)[0] for f in glob('*.rst')]: - #Don't add the index in there to avoid sphinx errors and don't add the - #note_about examples again (because it was added at the top): - if name not in(['index','note_about_examples']): - index.write(' %s\n' % name) -index.close() -""" - -# Execute each python script in the directory. -if "--no-exec" in sys.argv: - pass -else: - if not os.path.isdir("fig"): - os.mkdir("fig") - - for script in glob("*.py"): - figure_basename = os.path.join("fig", os.path.splitext(script)[0]) - runpy.run_path(script) - plt.close("all")