Skip to content

Commit

Permalink
remove ipynb processing from Makefile and implement a sphinx extension
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-murray committed Jan 20, 2016
1 parent 27311f7 commit dd77eb7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
1 change: 0 additions & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ clean:
rm -rf $(BUILDDIR)/*

html:
cd examples && jupyter nbconvert *.ipynb --to rst && rm -rf ../exampledoc/*_files/ && mv *_files ../exampledoc/ && mv *.rst ../exampledoc/
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
Expand Down
32 changes: 31 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,34 @@ def find_version(*file_paths):

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
numpydoc_show_class_members=False
numpydoc_show_class_members=False


#===============================================================================
# This does something naughty. It runs the nbconvert command on everything in the
# given folder, and moves the results to another given folder on every make.
source_ipy_folder = "examples"
output_ipy_folder = "_exampledoc"
import shutil

def nbconvert_files(app):
fin = app.config.source_ipy_folder
fout = app.config.output_ipy_folder

if os.path.exists(fout):
os.system("rm -rf %s"%fout)

os.mkdir(fout)

files = [f for f in os.listdir(fin) if f.endswith(".ipynb")]

for f in files:
os.system("jupyter nbconvert {0} --to rst".format(os.path.join(fin,f)))
os.rename(f.replace(".ipynb",".rst"),os.path.join(fout,f.replace(".ipynb",".rst")))
shutil.move(f.replace(".ipynb","_files"),os.path.join(fout,f.replace(".ipynb","_files")))

def setup(app):
app.add_config_value("source_ipy_folder","examples","html")
app.add_config_value("output_ipy_folder","_exampledoc","html")

app.connect("builder-inited",nbconvert_files)

0 comments on commit dd77eb7

Please sign in to comment.