[ci skip] Fix generating nbextensions.rst

This commit is contained in:
juhasch
2016-09-15 19:20:45 +02:00
parent fa5de5c2e6
commit df2fcd5894
2 changed files with 26 additions and 13 deletions
+9
View File
@@ -23,6 +23,15 @@ from recommonmark.transform import AutoStructify
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
if os.environ.get('READTHEDOCS', ''):
# RTD doesn't use the repo's Makefile to build docs. We run
# autogen_config.py to create the config docs (i.e. Configuration Options
# page).
with open('md2rst.py') as f:
exec(compile(f.read(), 'md2rst.py', 'exec'), {})
# -- General configuration ------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
+17 -13
View File
@@ -1,4 +1,6 @@
# use pandoc to convert md files to rst and copy images
# Use pandoc to convert readme md files to rst and copy images to a place sphinx can process them.
# Afterwards, generate a rst file with links to all extensions
import sys
import os
from shutil import copyfile
import pypandoc
@@ -12,20 +14,22 @@ List of Extensions
"""
thispath = os.path.dirname(os.path.abspath(__file__))
os.chdir(thispath)
# generate file with link to all extensions containing md files
src_path = os.path.join('..', '..', 'src', 'jupyter_contrib_nbextensions', 'nbextensions')
destination = 'source'
if not os.path.exists(destination):
destination = '.'
print('Copying converted docs to %s directory' % destination)
src_path = os.path.join(destination, '..', '..', 'src', 'jupyter_contrib_nbextensions', 'nbextensions')
for root, directories, filenames in os.walk(src_path):
for filename in filenames:
ext = os.path.splitext(filename)
if 'md' in ext[1]:
md_filename = os.path.join(root, filename)
rst_path = os.path.split(root)[-1]
if not os.path.exists(rst_path):
os.mkdir(rst_path)
rst_path = os.path.join(os.path.split(root)[-1])
src_path = os.path.join(destination, rst_path)
if not os.path.exists(src_path):
os.mkdir(src_path)
rst_name = ext[0]+'.rst'
rst_filename = os.path.join(rst_path, rst_name)
rst_filename = os.path.join(src_path, rst_name)
output = pypandoc.convert_file(md_filename, format='md', to='rst', outputfile=rst_filename)
extensions += ' %s/%s\n' % (rst_path, ext[0])
# copy images
@@ -34,13 +38,13 @@ for root, directories, filenames in os.walk(src_path):
ext2 = os.path.splitext(name2)
if ext2[1].strip('.').lower() in ['jpg', 'png', 'gif']:
src = os.path.join(root2, name2)
dst = os.path.join(rst_path, name2)
#print('Source file: %s' % src)
dst = os.path.join(src_path, name2)
print('Destination: %s' % dst)
copyfile(src, dst)
# Generate list of extensions
f = open('nbextensions.rst', 'w')
# Write list of extensions
extname = os.path.join(destination, 'nbextensions.rst')
f = open(extname, 'w')
f.write(extensions)
f.write('\n')
f.close()