1+ """Exporting a notebook to a library"""
2+
13# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/04_export.ipynb.
24
35# %% auto 0
@@ -24,6 +26,10 @@ def _exporti_(self, cell, exp_to=None): self.modules[ifnone(exp_to, '#')].append
2426 def _export_ (self , cell , exp_to = None ):
2527 self ._exporti_ (cell , exp_to )
2628 self .in_all [ifnone (exp_to , '#' )].append (cell )
29+ def __call__ (self , cell ):
30+ src = cell .source
31+ if not src : return
32+ if cell .cell_type == 'markdown' and src .startswith ('# ' ): self .modules ['#' ].append (cell )
2733 _exports_ = _export_
2834
2935# %% ../nbs/api/04_export.ipynb
@@ -67,12 +73,13 @@ def nb_export(nbname, lib_path=None, procs=None, debug=False, mod_maker=ModuleMa
6773 nb = NBProcessor (nbname , [exp ]+ L (procs ), debug = debug )
6874 nb .process ()
6975 for mod ,cells in exp .modules .items ():
70- all_cells = exp .in_all [mod ]
71- nm = ifnone (name , getattr (exp , 'default_exp' , None ) if mod == '#' else mod )
72- if not nm :
73- warn (f"Notebook '{ nbname } ' uses `#|export` without `#|default_exp` cell.\n "
74- "Note nbdev2 no longer supports nbdev1 syntax. Run `nbdev_migrate` to upgrade.\n "
75- "See https://nbdev.fast.ai/getting_started.html for more information." )
76- return
77- mm = mod_maker (dest = lib_path , name = nm , nb_path = nbname , is_new = bool (name ) or mod == '#' )
78- mm .make (cells , all_cells , lib_path = lib_path )
76+ if first (1 for o in cells if o .cell_type == 'code' ):
77+ all_cells = exp .in_all [mod ]
78+ nm = ifnone (name , getattr (exp , 'default_exp' , None ) if mod == '#' else mod )
79+ if not nm :
80+ warn (f"Notebook '{ nbname } ' uses `#|export` without `#|default_exp` cell.\n "
81+ "Note nbdev2 no longer supports nbdev1 syntax. Run `nbdev_migrate` to upgrade.\n "
82+ "See https://nbdev.fast.ai/getting_started.html for more information." )
83+ return
84+ mm = mod_maker (dest = lib_path , name = nm , nb_path = nbname , is_new = bool (name ) or mod == '#' )
85+ mm .make (cells , all_cells , lib_path = lib_path )
0 commit comments