@@ -55,9 +55,11 @@ def nbdev_sidebar(
5555 skip_file_re :str = '^[_.]' , # Skip files matching regex
5656 skip_folder_re :str = '(?:^[_.]|^www$)' , # Skip folders matching regex
5757 printit :bool = False , # Print YAML for debugging
58+ force :bool = False , # Create sidebar even if settings.ini custom_sidebar=False
5859 returnit :bool = False # Return list of files found
5960):
6061 "Create sidebar.yml"
62+ if not force and str2bool (config_key ('custom_sidebar' , path = False )): return
6163 path = config_key ("nbs_path" ) if not path else Path (path )
6264 files = nbglob (path , func = _f , symlinks = symlinks , file_re = file_re , folder_re = folder_re , file_glob = file_glob ,
6365 skip_file_glob = skip_file_glob , skip_file_re = skip_file_re , skip_folder_re = skip_folder_re ).sorted (key = _sort )
@@ -101,27 +103,34 @@ def preprocs(self):
101103 def postprocs (self ):
102104 "Postprocessors for export"
103105 return self .base_postprocs () + self .xtra_postprocs ()
106+
107+ def nb_proc (self , nb ):
108+ "Get an `NBProcessor` with these processors"
109+ return NBProcessor (nb = nb , procs = self .procs (), preprocs = self .preprocs (), postprocs = self .postprocs ())
104110
105111# %% ../nbs/10_cli.ipynb 11
106112@call_parse
107113def nbdev_filter (
108- nb_txt :str = None # Notebook text (uses stdin if not provided)
114+ nb_txt :str = None , # Notebook text (uses stdin if not provided)
115+ fname :str = None , # Notebook to read (uses `nb_txt` if not provided)
109116):
110117 "A notebook filter for Quarto"
111118 os .environ ["IN_TEST" ] = "1"
112119 filt = get_config ().get ('exporter' , FilterDefaults )()
113120 printit = False
114- if not nb_txt : nb_txt ,printit = sys .stdin .read (),True
121+ if fname : nb_txt = Path (fname ).read_text ()
122+ elif not nb_txt : nb_txt ,printit = sys .stdin .read (),True
115123 nb = dict2nb (loads (nb_txt ))
116- with open (os .devnull , 'w' ) as dn :
117- with redirect_stdout (dn ):
118- NBProcessor (nb = nb , procs = filt .procs (), preprocs = filt .preprocs (), postprocs = filt .postprocs ()).process ()
124+ if printit :
125+ with open (os .devnull , 'w' ) as dn :
126+ with redirect_stdout (dn ): filt .nb_proc (nb ).process ()
127+ else : filt .nb_proc (nb ).process ()
119128 res = nb2str (nb )
120129 del os .environ ["IN_TEST" ]
121130 if printit : print (res , flush = True )
122131 else : return res
123132
124- # %% ../nbs/10_cli.ipynb 13
133+ # %% ../nbs/10_cli.ipynb 14
125134_re_version = re .compile ('^__version__\s*=.*$' , re .MULTILINE )
126135
127136def update_version ():
@@ -153,11 +162,11 @@ def nbdev_bump_version(
153162 update_version ()
154163 print (f'New version: { cfg .version } ' )
155164
156- # %% ../nbs/10_cli.ipynb 15
165+ # %% ../nbs/10_cli.ipynb 16
157166def extract_tgz (url , dest = '.' ):
158167 with urlopen (url ) as u : tarfile .open (mode = 'r:gz' , fileobj = u ).extractall (dest )
159168
160- # %% ../nbs/10_cli.ipynb 16
169+ # %% ../nbs/10_cli.ipynb 17
161170def _get_info (owner , repo , default_branch = 'main' , default_kw = 'nbdev' ):
162171 try : from ghapi .all import GhApi
163172 except :
@@ -180,7 +189,7 @@ def _get_info(owner, repo, default_branch='main', default_kw='nbdev'):
180189
181190 return r .default_branch , default_kw if not r .topics else ' ' .join (r .topics ), r .description
182191
183- # %% ../nbs/10_cli.ipynb 18
192+ # %% ../nbs/10_cli.ipynb 19
184193def prompt_user (** kwargs ):
185194 config_vals = kwargs
186195 print ('================ nbdev Configuration ================\n ' )
@@ -193,7 +202,7 @@ def prompt_user(**kwargs):
193202 print (f"\n `settings.ini` updated with configuration values." )
194203 return config_vals
195204
196- # %% ../nbs/10_cli.ipynb 19
205+ # %% ../nbs/10_cli.ipynb 20
197206def _fetch_from_git (raise_err = False ):
198207 "Get information for settings.ini from the user."
199208 try :
@@ -208,7 +217,7 @@ def _fetch_from_git(raise_err=False):
208217 return dict (lib_name = repo .replace ('-' , '_' ), user = owner , branch = branch , author = author ,
209218 author_email = email , keywords = keywords , description = descrip , repo = repo )
210219
211- # %% ../nbs/10_cli.ipynb 21
220+ # %% ../nbs/10_cli.ipynb 22
212221_quarto_yml = """ipynb-filters: [nbdev_filter]
213222
214223project:
@@ -258,7 +267,7 @@ def refresh_quarto_yml():
258267 yml = _quarto_yml .format (** vals )
259268 p .write_text (yml )
260269
261- # %% ../nbs/10_cli.ipynb 22
270+ # %% ../nbs/10_cli.ipynb 23
262271@call_parse
263272def nbdev_new ():
264273 "Create a new project from the current git repo"
@@ -285,7 +294,7 @@ def nbdev_new():
285294 settings_path .write_text (settings )
286295 refresh_quarto_yml ()
287296
288- # %% ../nbs/10_cli.ipynb 24
297+ # %% ../nbs/10_cli.ipynb 25
289298@call_parse
290299def nbdev_quarto (
291300 path :str = None , # Path to notebooks
0 commit comments