33# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_nbio.ipynb.
44
55# %% auto 0
6- __all__ = ['NbCell' , 'dict2nb' , 'read_nb' , 'new_nb ' , 'mk_cell ' , 'nb2dict' , 'nb2str' , 'write_nb' ]
6+ __all__ = ['NbCell' , 'dict2nb' , 'read_nb' , 'mk_cell ' , 'new_nb ' , 'nb2dict' , 'nb2str' , 'write_nb' ]
77
88# %% ../nbs/01_nbio.ipynb
99from fastcore .basics import *
10+ from fastcore .xtras import rtoken_hex
1011from fastcore .imports import *
1112
1213import ast ,functools
@@ -19,9 +20,10 @@ def _read_json(self, encoding=None, errors=None):
1920
2021# %% ../nbs/01_nbio.ipynb
2122class NbCell (AttrDict ):
22- def __init__ (self , idx , cell ):
23+ def __init__ (self , idx , cell , id = None ):
2324 super ().__init__ (cell )
2425 self .idx_ = idx
26+ self .id = id or rtoken_hex (4 )
2527 if 'source' in self : self .set_source (self .source )
2628
2729 def set_source (self , source ):
@@ -60,11 +62,6 @@ def read_nb(path):
6062 res ['path_' ] = str (path )
6163 return res
6264
63- # %% ../nbs/01_nbio.ipynb
64- def new_nb (cells = None , meta = None , nbformat = 4 , nbformat_minor = 5 ):
65- "Returns an empty new notebook"
66- return dict2nb (cells = cells or [],metadata = meta or {},nbformat = nbformat ,nbformat_minor = nbformat_minor )
67-
6865# %% ../nbs/01_nbio.ipynb
6966def mk_cell (text , # `source` attr in cell
7067 cell_type = 'code' , # `cell_type` attr in cell
@@ -77,6 +74,12 @@ def mk_cell(text, # `source` attr in cell
7774 kwargs ['execution_count' ]= 0
7875 return NbCell (0 , dict (cell_type = cell_type , source = text , directives_ = {}, ** kwargs ))
7976
77+ # %% ../nbs/01_nbio.ipynb
78+ def new_nb (cells = None , meta = None , nbformat = 4 , nbformat_minor = 5 ):
79+ "Returns an empty new notebook"
80+ cells = [o if isinstance (o ,dict ) else mk_cell (o ) for o in cells ]
81+ return dict2nb (cells = cells or [],metadata = meta or {},nbformat = nbformat ,nbformat_minor = nbformat_minor )
82+
8083# %% ../nbs/01_nbio.ipynb
8184def nb2dict (d , k = None ):
8285 "Convert parsed notebook to `dict`"
0 commit comments