Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to not exec nb for fastpages #244

Merged
merged 1 commit into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions nbdev/export2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def _nb2htmlfname(nb_path, dest=None):
return Path(dest)/re_digits_first.sub('', nb_path.with_suffix('.html').name)

# Cell
def convert_nb(fname, cls=HTMLExporter, template_file=None, exporter=None, dest=None):
def convert_nb(fname, cls=HTMLExporter, template_file=None, exporter=None, dest=None, execute=True):
"Convert a notebook `fname` to html file in `dest_path`."
fname = Path(fname).absolute()
os.chdir(fname.parent)
Expand All @@ -541,7 +541,7 @@ def convert_nb(fname, cls=HTMLExporter, template_file=None, exporter=None, dest=
nb['cells'] = compose(*process_cells,partial(add_show_docs, cls_lvl=cls_lvl))(nb['cells'])
_func = compose(partial(copy_images, fname=fname, dest=Config().doc_path), *process_cell, treat_backticks)
nb['cells'] = [_func(c) for c in nb['cells']]
nb = execute_nb(nb, mod=mod)
if execute: nb = execute_nb(nb, mod=mod)
nb['cells'] = [clean_exports(c) for c in nb['cells']]
call_cb('after_doc_nb_preprocess', nb, fname, 'html')
if exporter is None: exporter = nbdev_exporter(cls=cls, template_file=template_file)
Expand All @@ -550,19 +550,19 @@ def convert_nb(fname, cls=HTMLExporter, template_file=None, exporter=None, dest=
call_cb('after_doc_nb', fname, 'html')

# Cell
def _notebook2html(fname, cls=HTMLExporter, template_file=None, exporter=None, dest=None):
def _notebook2html(fname, cls=HTMLExporter, template_file=None, exporter=None, dest=None, execute=True):
time.sleep(random.random())
print(f"converting: {fname}")
try:
convert_nb(fname, cls=cls, template_file=template_file, exporter=exporter, dest=dest)
convert_nb(fname, cls=cls, template_file=template_file, exporter=exporter, dest=dest, execute=True)
return True
except Exception as e:
print(e)
return False

# Cell
def notebook2html(fname=None, force_all=False, n_workers=None, cls=HTMLExporter, template_file=None,
exporter=None, dest=None, pause=0):
exporter=None, dest=None, pause=0, execute=True):
"Convert all notebooks matching `fname` to html files"
if fname is None:
files = [f for f in Config().nbs_path.glob('**/*.ipynb')
Expand All @@ -583,7 +583,7 @@ def notebook2html(fname=None, force_all=False, n_workers=None, cls=HTMLExporter,
if len(files)==0: print("No notebooks were modified")
else:
passed = parallel(_notebook2html, files, n_workers=n_workers, cls=cls,
template_file=template_file, exporter=exporter, dest=dest, pause=pause)
template_file=template_file, exporter=exporter, dest=dest, pause=pause, execute=execute)
if not all(passed):
msg = "Conversion failed on the following:\n"
print(msg + '\n'.join([f.name for p,f in zip(passed,files) if not p]))
Expand Down
47 changes: 20 additions & 27 deletions nbs/03_export2html.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1824,7 +1824,7 @@
"outputs": [],
"source": [
"%nbdev_export\n",
"def convert_nb(fname, cls=HTMLExporter, template_file=None, exporter=None, dest=None):\n",
"def convert_nb(fname, cls=HTMLExporter, template_file=None, exporter=None, dest=None, execute=True):\n",
" \"Convert a notebook `fname` to html file in `dest_path`.\"\n",
" fname = Path(fname).absolute()\n",
" os.chdir(fname.parent)\n",
Expand All @@ -1837,7 +1837,7 @@
" nb['cells'] = compose(*process_cells,partial(add_show_docs, cls_lvl=cls_lvl))(nb['cells'])\n",
" _func = compose(partial(copy_images, fname=fname, dest=Config().doc_path), *process_cell, treat_backticks)\n",
" nb['cells'] = [_func(c) for c in nb['cells']]\n",
" nb = execute_nb(nb, mod=mod)\n",
" if execute: nb = execute_nb(nb, mod=mod)\n",
" nb['cells'] = [clean_exports(c) for c in nb['cells']]\n",
" call_cb('after_doc_nb_preprocess', nb, fname, 'html')\n",
" if exporter is None: exporter = nbdev_exporter(cls=cls, template_file=template_file)\n",
Expand All @@ -1853,11 +1853,11 @@
"outputs": [],
"source": [
"%nbdev_export\n",
"def _notebook2html(fname, cls=HTMLExporter, template_file=None, exporter=None, dest=None):\n",
"def _notebook2html(fname, cls=HTMLExporter, template_file=None, exporter=None, dest=None, execute=True):\n",
" time.sleep(random.random())\n",
" print(f\"converting: {fname}\")\n",
" try:\n",
" convert_nb(fname, cls=cls, template_file=template_file, exporter=exporter, dest=dest)\n",
" convert_nb(fname, cls=cls, template_file=template_file, exporter=exporter, dest=dest, execute=True)\n",
" return True\n",
" except Exception as e:\n",
" print(e)\n",
Expand All @@ -1872,7 +1872,7 @@
"source": [
"%nbdev_export\n",
"def notebook2html(fname=None, force_all=False, n_workers=None, cls=HTMLExporter, template_file=None,\n",
" exporter=None, dest=None, pause=0):\n",
" exporter=None, dest=None, pause=0, execute=True):\n",
" \"Convert all notebooks matching `fname` to html files\"\n",
" if fname is None:\n",
" files = [f for f in Config().nbs_path.glob('**/*.ipynb')\n",
Expand All @@ -1893,7 +1893,7 @@
" if len(files)==0: print(\"No notebooks were modified\")\n",
" else:\n",
" passed = parallel(_notebook2html, files, n_workers=n_workers, cls=cls,\n",
" template_file=template_file, exporter=exporter, dest=dest, pause=pause)\n",
" template_file=template_file, exporter=exporter, dest=dest, pause=pause, execute=execute)\n",
" if not all(passed):\n",
" msg = \"Conversion failed on the following:\\n\"\n",
" print(msg + '\\n'.join([f.name for p,f in zip(passed,files) if not p]))"
Expand All @@ -1906,13 +1906,6 @@
"hide_input": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ERROR! Session/line number was not unique in database. History logging moved to new session 8733\n"
]
},
{
"data": {
"text/html": [],
Expand Down Expand Up @@ -1987,20 +1980,20 @@
"name": "stdout",
"output_type": "stream",
"text": [
"converting: /home/jhoward/git/nbdev/nbs/nbdev_callbacks.ipynb\n",
"converting: /home/jhoward/git/nbdev/nbs/99_search.ipynb\n",
"converting: /home/jhoward/git/nbdev/nbs/index.ipynb\n",
"converting: /home/jhoward/git/nbdev/nbs/05_merge.ipynb\n",
"converting: /home/jhoward/git/nbdev/nbs/00_export.ipynb\n",
"converting: /home/jhoward/git/nbdev/nbs/03_export2html.ipynb\n",
"converting: /home/jhoward/git/nbdev/nbs/02_showdoc.ipynb\n",
"converting: /home/jhoward/git/nbdev/nbs/04_test.ipynb\n",
"converting: /home/jhoward/git/nbdev/nbs/05a_conda.ipynb\n",
"converting: /home/jhoward/git/nbdev/nbs/magic_flags.ipynb\n",
"converting: /home/jhoward/git/nbdev/nbs/tutorial.ipynb\n",
"converting: /home/jhoward/git/nbdev/nbs/01_sync.ipynb\n",
"converting: /home/jhoward/git/nbdev/nbs/07_clean.ipynb\n",
"converting: /home/jhoward/git/nbdev/nbs/06_cli.ipynb\n"
"converting: /workspace/devspace/nbs/nbdev_callbacks.ipynb\n",
"converting: /workspace/devspace/nbs/99_search.ipynb\n",
"converting: /workspace/devspace/nbs/06_cli.ipynb\n",
"converting: /workspace/devspace/nbs/04_test.ipynb\n",
"converting: /workspace/devspace/nbs/magic_flags.ipynb\n",
"converting: /workspace/devspace/nbs/03_export2html.ipynb\n",
"converting: /workspace/devspace/nbs/01_sync.ipynb\n",
"converting: /workspace/devspace/nbs/05a_conda.ipynb\n",
"converting: /workspace/devspace/nbs/00_export.ipynb\n",
"converting: /workspace/devspace/nbs/02_showdoc.ipynb\n",
"converting: /workspace/devspace/nbs/07_clean.ipynb\n",
"converting: /workspace/devspace/nbs/index.ipynb\n",
"converting: /workspace/devspace/nbs/tutorial.ipynb\n",
"converting: /workspace/devspace/nbs/05_merge.ipynb\n"
]
}
],
Expand Down