Commit 018bf3d4 authored by Pierre Augier's avatar Pierre Augier

Execute the notebooks during doc building

parent 7c17264d6424
0.1.6
-----
- Can now execute the notebooks during the doc building
(fluidrtd/ipynb_maker.py)
0.1.5
-----
......
......@@ -11,4 +11,4 @@ http://legacy.python.org/dev/peps/pep-0386/
'a' or 'alpha' means alpha version (internal testing),
'b' or 'beta' means beta version (external testing).
"""
__version__ = '0.1.5'
__version__ = '0.1.6'
......@@ -20,6 +20,11 @@ provides utilities for input/output to different file formats:
in_py
redirect_stdout
To define environment variables, use something like (on *unix systems, in the
terminal or in your .bashrc)::
export FLUIDSIM_PATH="/fsnet/project/meige/2015/15DELDUCA/DataSim"
"""
from builtins import str
......
......@@ -82,7 +82,7 @@ class SerieOfArrays(object):
raise ValueError(
'The provided (empty) string does not point on any '
'existing path.')
l = glob(path)
if len(l) == 0:
raise ValueError(
......
......@@ -14,25 +14,54 @@ def call_bash(commands):
subprocess.call(['/bin/bash', '-c', commands])
def ipynb_to_rst(path='ipynb'):
files_ipynb = glob(path + '/*.ipynb')
def ipynb_to_rst(path='ipynb', executed=None):
"""Convert notebooks to rst files
for filepath in files_ipynb:
filename = os.path.split(filepath)[1]
If the user does not specify that the notebooks have already been executed,
they are executed with jupyter-nbconvert before the conversion to rst
files.
"""
paths_ipynb = glob(path + '/*.ipynb')
paths_ipynb = [path for path in paths_ipynb
if not path.endswith('.nbconvert.ipynb')]
paths_ipynb_executed = []
for filepath in paths_ipynb:
if executed is not None:
nfile = os.path.split(filepath)[-1]
if nfile in executed:
paths_ipynb_executed.append(filepath)
continue
basename = os.path.splitext(filepath)[0]
ipynb_executed = basename + '.nbconvert.ipynb'
paths_ipynb_executed.append(ipynb_executed)
if not os.path.exists(ipynb_executed) or \
modification_date(filepath) > modification_date(ipynb_executed):
call_bash(
'jupyter-nbconvert --ExecutePreprocessor.timeout=200 '
'--to notebook --execute ' + filepath)
rstname = basename + '.rst'
for filepath in paths_ipynb_executed:
basename = os.path.splitext(os.path.splitext(filepath)[0])[0]
rstpath = basename + '.rst'
rstname = os.path.split(rstpath)[-1]
if not os.path.exists(rstname):
if not os.path.exists(rstpath):
has_to_be_compiled = True
else:
d_ipynb = modification_date(filepath)
d_rst = modification_date(rstname)
d_rst = modification_date(rstpath)
if d_ipynb > d_rst:
has_to_be_compiled = True
else:
has_to_be_compiled = False
if has_to_be_compiled:
call_bash('cd ipynb && jupyter nbconvert --to rst ' + filename)
call_bash('jupyter-nbconvert --to rst ' + filepath +
' --output ' + rstname)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment