Skip to content
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
8 changes: 4 additions & 4 deletions nbdev/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ def black_format(cell, # Cell to format
except: pass

# %% ../nbs/api/export.ipynb 9
def nb_export(nbname, lib_path=None, procs=black_format, debug=False, mod_maker=ModuleMaker):
def nb_export(nbname, lib_path=None, procs=black_format, debug=False, mod_maker=ModuleMaker, name=None):
"Create module(s) from notebook"
if lib_path is None: lib_path = get_config().lib_path
exp = ExportModuleProc()
nb = NBProcessor(nbname, [exp]+L(procs), debug=debug)
nb.process()
for mod,cells in exp.modules.items():
all_cells = exp.in_all[mod]
name = getattr(exp, 'default_exp', None) if mod=='#' else mod
if not name:
nm = ifnone(name, getattr(exp, 'default_exp', None) if mod=='#' else mod)
if not nm:
warn(f"Notebook '{nbname}' uses `#|export` without `#|default_exp` cell.\n"
"Note nbdev2 no longer supports nbdev1 syntax. Run `nbdev_migrate` to upgrade.\n"
"See https://nbdev.fast.ai/getting_started.html for more information.")
return
mm = mod_maker(dest=lib_path, name=name, nb_path=nbname, is_new=mod=='#')
mm = mod_maker(dest=lib_path, name=nm, nb_path=nbname, is_new=bool(name) or mod=='#')
mm.make(cells, all_cells, lib_path=lib_path)
8 changes: 4 additions & 4 deletions nbs/api/export.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,21 @@
"outputs": [],
"source": [
"#|export\n",
"def nb_export(nbname, lib_path=None, procs=black_format, debug=False, mod_maker=ModuleMaker):\n",
"def nb_export(nbname, lib_path=None, procs=black_format, debug=False, mod_maker=ModuleMaker, name=None):\n",
" \"Create module(s) from notebook\"\n",
" if lib_path is None: lib_path = get_config().lib_path\n",
" exp = ExportModuleProc()\n",
" nb = NBProcessor(nbname, [exp]+L(procs), debug=debug)\n",
" nb.process()\n",
" for mod,cells in exp.modules.items():\n",
" all_cells = exp.in_all[mod]\n",
" name = getattr(exp, 'default_exp', None) if mod=='#' else mod\n",
" if not name:\n",
" nm = ifnone(name, getattr(exp, 'default_exp', None) if mod=='#' else mod)\n",
" if not nm:\n",
" warn(f\"Notebook '{nbname}' uses `#|export` without `#|default_exp` cell.\\n\"\n",
" \"Note nbdev2 no longer supports nbdev1 syntax. Run `nbdev_migrate` to upgrade.\\n\"\n",
" \"See https://nbdev.fast.ai/getting_started.html for more information.\")\n",
" return\n",
" mm = mod_maker(dest=lib_path, name=name, nb_path=nbname, is_new=mod=='#')\n",
" mm = mod_maker(dest=lib_path, name=nm, nb_path=nbname, is_new=bool(name) or mod=='#')\n",
" mm.make(cells, all_cells, lib_path=lib_path)"
]
},
Expand Down