nbdev 2.3.25__py3-none-any.whl → 2.4.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
nbdev/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "2.3.25"
1
+ __version__ = "2.4.8"
2
2
 
3
3
  from .doclinks import nbdev_export
4
4
  from .showdoc import show_doc
nbdev/_modidx.py CHANGED
@@ -1,9 +1,9 @@
1
1
  # Autogenerated by nbdev
2
2
 
3
- d = { 'settings': { 'branch': 'master',
3
+ d = { 'settings': { 'branch': 'main',
4
4
  'doc_baseurl': '/',
5
5
  'doc_host': 'https://nbdev.fast.ai',
6
- 'git_url': 'https://github.com/fastai/nbdev',
6
+ 'git_url': 'https://github.com/AnswerDotAI/nbdev',
7
7
  'lib_path': 'nbdev'},
8
8
  'syms': { 'nbdev.clean': { 'nbdev.clean._add_jupyter_hooks': ('api/clean.html#_add_jupyter_hooks', 'nbdev/clean.py'),
9
9
  'nbdev.clean._clean_cell': ('api/clean.html#_clean_cell', 'nbdev/clean.py'),
@@ -23,9 +23,11 @@ d = { 'settings': { 'branch': 'master',
23
23
  'nbdev.cli._update_repo_meta': ('api/cli.html#_update_repo_meta', 'nbdev/cli.py'),
24
24
  'nbdev.cli.chelp': ('api/cli.html#chelp', 'nbdev/cli.py'),
25
25
  'nbdev.cli.extract_tgz': ('api/cli.html#extract_tgz', 'nbdev/cli.py'),
26
+ 'nbdev.cli.nb_export_cli': ('api/cli.html#nb_export_cli', 'nbdev/cli.py'),
26
27
  'nbdev.cli.nbdev_filter': ('api/cli.html#nbdev_filter', 'nbdev/cli.py'),
27
28
  'nbdev.cli.nbdev_new': ('api/cli.html#nbdev_new', 'nbdev/cli.py'),
28
- 'nbdev.cli.nbdev_update_license': ('api/cli.html#nbdev_update_license', 'nbdev/cli.py')},
29
+ 'nbdev.cli.nbdev_update_license': ('api/cli.html#nbdev_update_license', 'nbdev/cli.py'),
30
+ 'nbdev.cli.watch_export': ('api/cli.html#watch_export', 'nbdev/cli.py')},
29
31
  'nbdev.config': { 'nbdev.config._apply_defaults': ('api/config.html#_apply_defaults', 'nbdev/config.py'),
30
32
  'nbdev.config._basic_export_nb': ('api/config.html#_basic_export_nb', 'nbdev/config.py'),
31
33
  'nbdev.config._cfg2txt': ('api/config.html#_cfg2txt', 'nbdev/config.py'),
@@ -41,10 +43,19 @@ d = { 'settings': { 'branch': 'master',
41
43
  'nbdev.config.config_key': ('api/config.html#config_key', 'nbdev/config.py'),
42
44
  'nbdev.config.create_output': ('api/config.html#create_output', 'nbdev/config.py'),
43
45
  'nbdev.config.get_config': ('api/config.html#get_config', 'nbdev/config.py'),
46
+ 'nbdev.config.is_nbdev': ('api/config.html#is_nbdev', 'nbdev/config.py'),
44
47
  'nbdev.config.nbdev_create_config': ('api/config.html#nbdev_create_config', 'nbdev/config.py'),
45
48
  'nbdev.config.show_src': ('api/config.html#show_src', 'nbdev/config.py'),
49
+ 'nbdev.config.update_proj': ('api/config.html#update_proj', 'nbdev/config.py'),
46
50
  'nbdev.config.update_version': ('api/config.html#update_version', 'nbdev/config.py'),
47
51
  'nbdev.config.write_cells': ('api/config.html#write_cells', 'nbdev/config.py')},
52
+ 'nbdev.diff': { 'nbdev.diff._cell_changes': ('api/diff.html#_cell_changes', 'nbdev/diff.py'),
53
+ 'nbdev.diff._nb_srcdict': ('api/diff.html#_nb_srcdict', 'nbdev/diff.py'),
54
+ 'nbdev.diff.cell_diffs': ('api/diff.html#cell_diffs', 'nbdev/diff.py'),
55
+ 'nbdev.diff.changed_cells': ('api/diff.html#changed_cells', 'nbdev/diff.py'),
56
+ 'nbdev.diff.nbs_pair': ('api/diff.html#nbs_pair', 'nbdev/diff.py'),
57
+ 'nbdev.diff.read_nb_from_git': ('api/diff.html#read_nb_from_git', 'nbdev/diff.py'),
58
+ 'nbdev.diff.source_diff': ('api/diff.html#source_diff', 'nbdev/diff.py')},
48
59
  'nbdev.doclinks': { 'nbdev.doclinks.NbdevLookup': ('api/doclinks.html#nbdevlookup', 'nbdev/doclinks.py'),
49
60
  'nbdev.doclinks.NbdevLookup.__getitem__': ( 'api/doclinks.html#nbdevlookup.__getitem__',
50
61
  'nbdev/doclinks.py'),
@@ -55,6 +66,7 @@ d = { 'settings': { 'branch': 'master',
55
66
  'nbdev.doclinks.NbdevLookup.link_line': ('api/doclinks.html#nbdevlookup.link_line', 'nbdev/doclinks.py'),
56
67
  'nbdev.doclinks.NbdevLookup.linkify': ('api/doclinks.html#nbdevlookup.linkify', 'nbdev/doclinks.py'),
57
68
  'nbdev.doclinks._binop_leafs': ('api/doclinks.html#_binop_leafs', 'nbdev/doclinks.py'),
69
+ 'nbdev.doclinks._build_lookup_table': ('api/doclinks.html#_build_lookup_table', 'nbdev/doclinks.py'),
58
70
  'nbdev.doclinks._build_modidx': ('api/doclinks.html#_build_modidx', 'nbdev/doclinks.py'),
59
71
  'nbdev.doclinks._find_mod': ('api/doclinks.html#_find_mod', 'nbdev/doclinks.py'),
60
72
  'nbdev.doclinks._get_exps': ('api/doclinks.html#_get_exps', 'nbdev/doclinks.py'),
@@ -66,11 +78,13 @@ d = { 'settings': { 'branch': 'master',
66
78
  'nbdev.doclinks._qual_sym': ('api/doclinks.html#_qual_sym', 'nbdev/doclinks.py'),
67
79
  'nbdev.doclinks._qual_syms': ('api/doclinks.html#_qual_syms', 'nbdev/doclinks.py'),
68
80
  'nbdev.doclinks._sym_nm': ('api/doclinks.html#_sym_nm', 'nbdev/doclinks.py'),
81
+ 'nbdev.doclinks.create_index': ('api/doclinks.html#create_index', 'nbdev/doclinks.py'),
69
82
  'nbdev.doclinks.nbdev_export': ('api/doclinks.html#nbdev_export', 'nbdev/doclinks.py'),
70
83
  'nbdev.doclinks.nbglob': ('api/doclinks.html#nbglob', 'nbdev/doclinks.py'),
71
84
  'nbdev.doclinks.nbglob_cli': ('api/doclinks.html#nbglob_cli', 'nbdev/doclinks.py'),
72
85
  'nbdev.doclinks.patch_name': ('api/doclinks.html#patch_name', 'nbdev/doclinks.py')},
73
86
  'nbdev.export': { 'nbdev.export.ExportModuleProc': ('api/export.html#exportmoduleproc', 'nbdev/export.py'),
87
+ 'nbdev.export.ExportModuleProc.__call__': ('api/export.html#exportmoduleproc.__call__', 'nbdev/export.py'),
74
88
  'nbdev.export.ExportModuleProc._default_exp_': ( 'api/export.html#exportmoduleproc._default_exp_',
75
89
  'nbdev/export.py'),
76
90
  'nbdev.export.ExportModuleProc._export_': ('api/export.html#exportmoduleproc._export_', 'nbdev/export.py'),
@@ -203,6 +217,7 @@ d = { 'settings': { 'branch': 'master',
203
217
  'nbdev.processors.add_show_docs': ('api/processors.html#add_show_docs', 'nbdev/processors.py'),
204
218
  'nbdev.processors.add_show_docs.begin': ( 'api/processors.html#add_show_docs.begin',
205
219
  'nbdev/processors.py'),
220
+ 'nbdev.processors.ai_magics': ('api/processors.html#ai_magics', 'nbdev/processors.py'),
206
221
  'nbdev.processors.boxify': ('api/processors.html#boxify', 'nbdev/processors.py'),
207
222
  'nbdev.processors.cell_lang': ('api/processors.html#cell_lang', 'nbdev/processors.py'),
208
223
  'nbdev.processors.clean_magics': ('api/processors.html#clean_magics', 'nbdev/processors.py'),
@@ -250,20 +265,22 @@ d = { 'settings': { 'branch': 'master',
250
265
  'nbdev.quarto._SidebarYmlRemoved.__init__': ( 'api/quarto.html#_sidebarymlremoved.__init__',
251
266
  'nbdev/quarto.py'),
252
267
  'nbdev.quarto._copytree': ('api/quarto.html#_copytree', 'nbdev/quarto.py'),
268
+ 'nbdev.quarto._doc_mtime_not_older': ('api/quarto.html#_doc_mtime_not_older', 'nbdev/quarto.py'),
253
269
  'nbdev.quarto._ensure_quarto': ('api/quarto.html#_ensure_quarto', 'nbdev/quarto.py'),
254
270
  'nbdev.quarto._install_linux': ('api/quarto.html#_install_linux', 'nbdev/quarto.py'),
255
271
  'nbdev.quarto._install_mac': ('api/quarto.html#_install_mac', 'nbdev/quarto.py'),
256
272
  'nbdev.quarto._nbglob_docs': ('api/quarto.html#_nbglob_docs', 'nbdev/quarto.py'),
257
273
  'nbdev.quarto._pre': ('api/quarto.html#_pre', 'nbdev/quarto.py'),
258
274
  'nbdev.quarto._pre_docs': ('api/quarto.html#_pre_docs', 'nbdev/quarto.py'),
259
- 'nbdev.quarto._readme_mtime_not_older': ('api/quarto.html#_readme_mtime_not_older', 'nbdev/quarto.py'),
260
275
  'nbdev.quarto._recursive_parser': ('api/quarto.html#_recursive_parser', 'nbdev/quarto.py'),
276
+ 'nbdev.quarto._save_cached_contributing': ('api/quarto.html#_save_cached_contributing', 'nbdev/quarto.py'),
261
277
  'nbdev.quarto._save_cached_readme': ('api/quarto.html#_save_cached_readme', 'nbdev/quarto.py'),
262
278
  'nbdev.quarto._sort': ('api/quarto.html#_sort', 'nbdev/quarto.py'),
263
279
  'nbdev.quarto._sprun': ('api/quarto.html#_sprun', 'nbdev/quarto.py'),
264
280
  'nbdev.quarto.fs_watchdog': ('api/quarto.html#fs_watchdog', 'nbdev/quarto.py'),
265
281
  'nbdev.quarto.install': ('api/quarto.html#install', 'nbdev/quarto.py'),
266
282
  'nbdev.quarto.install_quarto': ('api/quarto.html#install_quarto', 'nbdev/quarto.py'),
283
+ 'nbdev.quarto.nbdev_contributing': ('api/quarto.html#nbdev_contributing', 'nbdev/quarto.py'),
267
284
  'nbdev.quarto.nbdev_docs': ('api/quarto.html#nbdev_docs', 'nbdev/quarto.py'),
268
285
  'nbdev.quarto.nbdev_preview': ('api/quarto.html#nbdev_preview', 'nbdev/quarto.py'),
269
286
  'nbdev.quarto.nbdev_proc_nbs': ('api/quarto.html#nbdev_proc_nbs', 'nbdev/quarto.py'),
@@ -312,36 +329,9 @@ d = { 'settings': { 'branch': 'master',
312
329
  'nbdev.showdoc.BasicMarkdownRenderer': ('api/showdoc.html#basicmarkdownrenderer', 'nbdev/showdoc.py'),
313
330
  'nbdev.showdoc.BasicMarkdownRenderer._repr_markdown_': ( 'api/showdoc.html#basicmarkdownrenderer._repr_markdown_',
314
331
  'nbdev/showdoc.py'),
315
- 'nbdev.showdoc.DocmentTbl': ('api/showdoc.html#docmenttbl', 'nbdev/showdoc.py'),
316
- 'nbdev.showdoc.DocmentTbl.__eq__': ('api/showdoc.html#docmenttbl.__eq__', 'nbdev/showdoc.py'),
317
- 'nbdev.showdoc.DocmentTbl.__init__': ('api/showdoc.html#docmenttbl.__init__', 'nbdev/showdoc.py'),
318
- 'nbdev.showdoc.DocmentTbl._columns': ('api/showdoc.html#docmenttbl._columns', 'nbdev/showdoc.py'),
319
- 'nbdev.showdoc.DocmentTbl._hdr_list': ('api/showdoc.html#docmenttbl._hdr_list', 'nbdev/showdoc.py'),
320
- 'nbdev.showdoc.DocmentTbl._repr_markdown_': ( 'api/showdoc.html#docmenttbl._repr_markdown_',
321
- 'nbdev/showdoc.py'),
322
- 'nbdev.showdoc.DocmentTbl._row': ('api/showdoc.html#docmenttbl._row', 'nbdev/showdoc.py'),
323
- 'nbdev.showdoc.DocmentTbl._row_list': ('api/showdoc.html#docmenttbl._row_list', 'nbdev/showdoc.py'),
324
- 'nbdev.showdoc.DocmentTbl.has_docment': ('api/showdoc.html#docmenttbl.has_docment', 'nbdev/showdoc.py'),
325
- 'nbdev.showdoc.DocmentTbl.has_return': ('api/showdoc.html#docmenttbl.has_return', 'nbdev/showdoc.py'),
326
- 'nbdev.showdoc.DocmentTbl.hdr_str': ('api/showdoc.html#docmenttbl.hdr_str', 'nbdev/showdoc.py'),
327
- 'nbdev.showdoc.DocmentTbl.params_str': ('api/showdoc.html#docmenttbl.params_str', 'nbdev/showdoc.py'),
328
- 'nbdev.showdoc.DocmentTbl.return_str': ('api/showdoc.html#docmenttbl.return_str', 'nbdev/showdoc.py'),
329
- 'nbdev.showdoc.ShowDocRenderer': ('api/showdoc.html#showdocrenderer', 'nbdev/showdoc.py'),
330
- 'nbdev.showdoc.ShowDocRenderer.__init__': ('api/showdoc.html#showdocrenderer.__init__', 'nbdev/showdoc.py'),
331
- 'nbdev.showdoc._bold': ('api/showdoc.html#_bold', 'nbdev/showdoc.py'),
332
- 'nbdev.showdoc._docstring': ('api/showdoc.html#_docstring', 'nbdev/showdoc.py'),
333
- 'nbdev.showdoc._escape_markdown': ('api/showdoc.html#_escape_markdown', 'nbdev/showdoc.py'),
332
+ 'nbdev.showdoc._create_html_table': ('api/showdoc.html#_create_html_table', 'nbdev/showdoc.py'),
334
333
  'nbdev.showdoc._ext_link': ('api/showdoc.html#_ext_link', 'nbdev/showdoc.py'),
335
- 'nbdev.showdoc._f_name': ('api/showdoc.html#_f_name', 'nbdev/showdoc.py'),
336
- 'nbdev.showdoc._fmt_anno': ('api/showdoc.html#_fmt_anno', 'nbdev/showdoc.py'),
337
- 'nbdev.showdoc._fmt_sig': ('api/showdoc.html#_fmt_sig', 'nbdev/showdoc.py'),
338
- 'nbdev.showdoc._fullname': ('api/showdoc.html#_fullname', 'nbdev/showdoc.py'),
339
334
  'nbdev.showdoc._html_link': ('api/showdoc.html#_html_link', 'nbdev/showdoc.py'),
340
- 'nbdev.showdoc._list2row': ('api/showdoc.html#_list2row', 'nbdev/showdoc.py'),
341
- 'nbdev.showdoc._maybe_nm': ('api/showdoc.html#_maybe_nm', 'nbdev/showdoc.py'),
342
- 'nbdev.showdoc._non_empty_keys': ('api/showdoc.html#_non_empty_keys', 'nbdev/showdoc.py'),
343
- 'nbdev.showdoc._show_param': ('api/showdoc.html#_show_param', 'nbdev/showdoc.py'),
344
- 'nbdev.showdoc._wrap_sig': ('api/showdoc.html#_wrap_sig', 'nbdev/showdoc.py'),
345
335
  'nbdev.showdoc.colab_link': ('api/showdoc.html#colab_link', 'nbdev/showdoc.py'),
346
336
  'nbdev.showdoc.doc': ('api/showdoc.html#doc', 'nbdev/showdoc.py'),
347
337
  'nbdev.showdoc.show_doc': ('api/showdoc.html#show_doc', 'nbdev/showdoc.py'),
nbdev/clean.py CHANGED
@@ -1,9 +1,11 @@
1
+ """Strip superfluous metadata from notebooks"""
2
+
1
3
  # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/11_clean.ipynb.
2
4
 
3
5
  # %% auto 0
4
6
  __all__ = ['nbdev_trust', 'clean_nb', 'process_write', 'nbdev_clean', 'clean_jupyter', 'nbdev_install_hooks']
5
7
 
6
- # %% ../nbs/api/11_clean.ipynb 2
8
+ # %% ../nbs/api/11_clean.ipynb
7
9
  import ast,warnings,stat
8
10
  from astunparse import unparse
9
11
  from textwrap import indent
@@ -18,7 +20,7 @@ from .config import *
18
20
  from .sync import *
19
21
  from .process import first_code_ln
20
22
 
21
- # %% ../nbs/api/11_clean.ipynb 6
23
+ # %% ../nbs/api/11_clean.ipynb
22
24
  @call_parse
23
25
  def nbdev_trust(
24
26
  fname:str=None, # A notebook name or glob to trust
@@ -45,7 +47,7 @@ def nbdev_trust(
45
47
  if not NotebookNotary().check_signature(nb): NotebookNotary().sign(nb)
46
48
  check_fname.touch(exist_ok=True)
47
49
 
48
- # %% ../nbs/api/11_clean.ipynb 9
50
+ # %% ../nbs/api/11_clean.ipynb
49
51
  _repr_id_re = re.compile('(<.*?)( at 0x[0-9a-fA-F]+)(>)')
50
52
 
51
53
  _sub = partial(_repr_id_re.sub, r'\1\3')
@@ -55,7 +57,7 @@ def _skip_or_sub(x): return _sub(x) if "at 0x" in x else x
55
57
  def _clean_cell_output_id(lines):
56
58
  return _skip_or_sub(lines) if isinstance(lines,str) else [_skip_or_sub(o) for o in lines]
57
59
 
58
- # %% ../nbs/api/11_clean.ipynb 11
60
+ # %% ../nbs/api/11_clean.ipynb
59
61
  def _clean_cell_output(cell, clean_ids):
60
62
  "Remove `cell` output execution count and optionally ids from text reprs"
61
63
  outputs = cell.get('outputs', [])
@@ -67,9 +69,9 @@ def _clean_cell_output(cell, clean_ids):
67
69
  if k.startswith('text') and clean_ids: data[k] = _clean_cell_output_id(data[k])
68
70
  if k.startswith('image') and "svg" not in k: data[k] = data[k].rstrip()
69
71
  if 'text' in o and clean_ids: o['text'] = _clean_cell_output_id(o['text'])
70
- o.get('metadata', {}).pop('tags', None)
72
+ # o.get('metadata', {}).pop('tags', None)
71
73
 
72
- # %% ../nbs/api/11_clean.ipynb 12
74
+ # %% ../nbs/api/11_clean.ipynb
73
75
  def _clean_cell(cell, clear_all, allowed_metadata_keys, clean_ids):
74
76
  "Clean `cell` by removing superfluous metadata or everything except the input if `clear_all`"
75
77
  if 'execution_count' in cell: cell['execution_count'] = None
@@ -80,7 +82,7 @@ def _clean_cell(cell, clear_all, allowed_metadata_keys, clean_ids):
80
82
  cell['metadata'] = {} if clear_all else {
81
83
  k:v for k,v in cell['metadata'].items() if k in allowed_metadata_keys}
82
84
 
83
- # %% ../nbs/api/11_clean.ipynb 13
85
+ # %% ../nbs/api/11_clean.ipynb
84
86
  def clean_nb(
85
87
  nb, # The notebook to clean
86
88
  clear_all=False, # Remove all cell metadata and cell outputs?
@@ -98,12 +100,12 @@ def clean_nb(
98
100
  nb['metadata']['kernelspec']['display_name'] = nb["metadata"]["kernelspec"]["name"]
99
101
  nb['metadata'] = {k:v for k,v in nb['metadata'].items() if k in metadata_keys}
100
102
 
101
- # %% ../nbs/api/11_clean.ipynb 26
103
+ # %% ../nbs/api/11_clean.ipynb
102
104
  def _reconfigure(*strms):
103
105
  for s in strms:
104
106
  if hasattr(s,'reconfigure'): s.reconfigure(encoding='utf-8')
105
107
 
106
- # %% ../nbs/api/11_clean.ipynb 27
108
+ # %% ../nbs/api/11_clean.ipynb
107
109
  def process_write(warn_msg, proc_nb, f_in, f_out=None, disp=False):
108
110
  if not f_out: f_out = f_in
109
111
  if isinstance(f_in, (str,Path)): f_in = Path(f_in).open(encoding="utf-8")
@@ -116,7 +118,7 @@ def process_write(warn_msg, proc_nb, f_in, f_out=None, disp=False):
116
118
  warn(f'{warn_msg}')
117
119
  warn(e)
118
120
 
119
- # %% ../nbs/api/11_clean.ipynb 28
121
+ # %% ../nbs/api/11_clean.ipynb
120
122
  def _nbdev_clean(nb, path=None, clear_all=None):
121
123
  cfg = get_config(path=path)
122
124
  clear_all = clear_all or cfg.clear_all
@@ -125,7 +127,7 @@ def _nbdev_clean(nb, path=None, clear_all=None):
125
127
  clean_nb(nb, clear_all, allowed_metadata_keys, allowed_cell_metadata_keys, cfg.clean_ids)
126
128
  if path: nbdev_trust.__wrapped__(path)
127
129
 
128
- # %% ../nbs/api/11_clean.ipynb 29
130
+ # %% ../nbs/api/11_clean.ipynb
129
131
  @call_parse
130
132
  def nbdev_clean(
131
133
  fname:str=None, # A notebook name or glob to clean
@@ -141,7 +143,7 @@ def nbdev_clean(
141
143
  if fname is None: fname = get_config().nbs_path
142
144
  for f in globtastic(fname, file_glob='*.ipynb', skip_folder_re='^[_.]'): _write(f_in=f, disp=disp)
143
145
 
144
- # %% ../nbs/api/11_clean.ipynb 32
146
+ # %% ../nbs/api/11_clean.ipynb
145
147
  def clean_jupyter(path, model, **kwargs):
146
148
  "Clean Jupyter `model` pre save to `path`"
147
149
  if not (model['type']=='notebook' and model['content']['nbformat']==4): return
@@ -149,7 +151,7 @@ def clean_jupyter(path, model, **kwargs):
149
151
  jupyter_hooks = get_config(path=path).jupyter_hooks
150
152
  if jupyter_hooks: _nbdev_clean(model['content'], path=path)
151
153
 
152
- # %% ../nbs/api/11_clean.ipynb 35
154
+ # %% ../nbs/api/11_clean.ipynb
153
155
  _pre_save_hook_src = '''
154
156
  def nbdev_clean_jupyter(**kwargs):
155
157
  try: from nbdev.clean import clean_jupyter
@@ -159,7 +161,7 @@ def nbdev_clean_jupyter(**kwargs):
159
161
  c.ContentsManager.pre_save_hook = nbdev_clean_jupyter'''.strip()
160
162
  _pre_save_hook_re = re.compile(r'c\.(File)?ContentsManager\.pre_save_hook')
161
163
 
162
- # %% ../nbs/api/11_clean.ipynb 36
164
+ # %% ../nbs/api/11_clean.ipynb
163
165
  def _add_jupyter_hooks(src, path):
164
166
  if _pre_save_hook_src in src: return
165
167
  mod = ast.parse(src)
@@ -177,12 +179,12 @@ def _add_jupyter_hooks(src, path):
177
179
  if src: src+='\n\n'
178
180
  return src+_pre_save_hook_src
179
181
 
180
- # %% ../nbs/api/11_clean.ipynb 40
182
+ # %% ../nbs/api/11_clean.ipynb
181
183
  def _git_root():
182
184
  try: return Path(run('git rev-parse --show-toplevel'))
183
185
  except OSError: return None
184
186
 
185
- # %% ../nbs/api/11_clean.ipynb 43
187
+ # %% ../nbs/api/11_clean.ipynb
186
188
  @call_parse
187
189
  def nbdev_install_hooks():
188
190
  "Install Jupyter and git hooks to automatically clean, trust, and fix merge conflicts in notebooks"
nbdev/cli.py CHANGED
@@ -1,8 +1,11 @@
1
+ """CLI commands"""
2
+
1
3
  # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/13_cli.ipynb.
2
4
 
3
5
  # %% ../nbs/api/13_cli.ipynb 2
4
6
  from __future__ import annotations
5
7
  import warnings
8
+ import time
6
9
 
7
10
  from .config import *
8
11
  from .process import *
@@ -10,9 +13,11 @@ from .processors import *
10
13
  from .doclinks import *
11
14
  from .test import *
12
15
  from .clean import *
13
- from .quarto import nbdev_readme, refresh_quarto_yml
16
+ from .quarto import nbdev_readme, nbdev_contributing, refresh_quarto_yml, fs_watchdog
17
+ from .export import nb_export
14
18
  from .frontmatter import FrontmatterProc
15
19
 
20
+ from fastcore.xtras import run
16
21
  from execnb.nbio import *
17
22
  from fastcore.meta import *
18
23
  from fastcore.utils import *
@@ -25,9 +30,10 @@ from contextlib import redirect_stdout
25
30
  import os, tarfile, sys
26
31
 
27
32
  # %% auto 0
28
- __all__ = ['mapping', 'nbdev_filter', 'extract_tgz', 'nbdev_new', 'nbdev_update_license', 'chelp']
33
+ __all__ = ['mapping', 'nbdev_filter', 'extract_tgz', 'nbdev_new', 'nbdev_update_license', 'nb_export_cli', 'watch_export',
34
+ 'chelp']
29
35
 
30
- # %% ../nbs/api/13_cli.ipynb 5
36
+ # %% ../nbs/api/13_cli.ipynb
31
37
  @call_parse
32
38
  def nbdev_filter(
33
39
  nb_txt:str=None, # Notebook text (uses stdin if not provided)
@@ -50,12 +56,12 @@ def nbdev_filter(
50
56
  if printit: print(res, flush=True)
51
57
  else: return res
52
58
 
53
- # %% ../nbs/api/13_cli.ipynb 8
59
+ # %% ../nbs/api/13_cli.ipynb
54
60
  def extract_tgz(url, dest='.'):
55
61
  from fastcore.net import urlopen
56
62
  with urlopen(url) as u: tarfile.open(mode='r:gz', fileobj=u).extractall(dest)
57
63
 
58
- # %% ../nbs/api/13_cli.ipynb 9
64
+ # %% ../nbs/api/13_cli.ipynb
59
65
  def _render_nb(fn, cfg):
60
66
  "Render templated values like `{{lib_name}}` in notebook at `fn` from `cfg`"
61
67
  txt = fn.read_text()
@@ -63,7 +69,7 @@ def _render_nb(fn, cfg):
63
69
  for k,v in cfg.d.items(): txt = txt.replace('{{'+k+'}}', v)
64
70
  fn.write_text(txt)
65
71
 
66
- # %% ../nbs/api/13_cli.ipynb 10
72
+ # %% ../nbs/api/13_cli.ipynb
67
73
  def _update_repo_meta(cfg):
68
74
  "Enable gh pages and update the homepage and description in your GitHub repo."
69
75
  token=os.getenv('GITHUB_TOKEN')
@@ -74,7 +80,7 @@ def _update_repo_meta(cfg):
74
80
  except HTTPError:print(f"Could not update the description & URL on the repo: {cfg.user}/{cfg.repo} using $GITHUB_TOKEN.\n"
75
81
  "Use a token with the correction permissions or perform these steps manually.")
76
82
 
77
- # %% ../nbs/api/13_cli.ipynb 11
83
+ # %% ../nbs/api/13_cli.ipynb
78
84
  @call_parse
79
85
  @delegates(nbdev_create_config)
80
86
  def nbdev_new(**kwargs):
@@ -83,30 +89,25 @@ def nbdev_new(**kwargs):
83
89
  nbdev_create_config.__wrapped__(**kwargs)
84
90
  cfg = get_config()
85
91
  _update_repo_meta(cfg)
86
-
87
92
  path = Path()
88
93
 
89
- _ORG_OR_USR = 'fastai'
90
- _REPOSITORY = 'nbdev-template'
94
+ _ORG_OR_USR,_REPOSITORY = 'answerdotai','nbdev-template'
91
95
  _TEMPLATE = f'{_ORG_OR_USR}/{_REPOSITORY}'
92
96
  template = kwargs.get('template', _TEMPLATE)
93
- try:
94
- org_or_usr, repo = template.split('/')
95
- except ValueError:
96
- org_or_usr, repo = _ORG_OR_USR, _REPOSITORY
97
-
97
+ try: org_or_usr, repo = template.split('/')
98
+ except ValueError: org_or_usr, repo = _ORG_OR_USR, _REPOSITORY
98
99
 
99
100
  tag = kwargs.get('tag', None)
100
101
  if tag is None:
101
102
  with warnings.catch_warnings():
102
103
  warnings.simplefilter('ignore', UserWarning)
103
-
104
- tag = GhApi(gh_host='https://api.github.com', authenticate=False).repos.get_latest_release(org_or_usr, repo).tag_name
104
+ tag = GhApi(gh_host='https://api.github.com', authenticate=False
105
+ ).repos.get_latest_release(org_or_usr, repo).tag_name
105
106
 
106
107
  url = f"https://github.com/{org_or_usr}/{repo}/archive/{tag}.tar.gz"
107
108
  extract_tgz(url)
108
109
  tmpl_path = path/f'{repo}-{tag}'
109
-
110
+
110
111
  cfg.nbs_path.mkdir(exist_ok=True)
111
112
  nbexists = bool(first(cfg.nbs_path.glob('*.ipynb')))
112
113
  _nbs_path_sufs = ('.ipynb','.css')
@@ -119,11 +120,11 @@ def nbdev_new(**kwargs):
119
120
  rmtree(tmpl_path)
120
121
 
121
122
  refresh_quarto_yml()
122
-
123
123
  nbdev_export.__wrapped__()
124
124
  nbdev_readme.__wrapped__()
125
+ nbdev_contributing.__wrapped__()
125
126
 
126
- # %% ../nbs/api/13_cli.ipynb 13
127
+ # %% ../nbs/api/13_cli.ipynb
127
128
  mapping = {
128
129
  'mit': 'mit',
129
130
  'apache2': 'apache-2.0',
@@ -132,7 +133,7 @@ mapping = {
132
133
  'bsd3': 'bsd-3-clause'
133
134
  }
134
135
 
135
- # %% ../nbs/api/13_cli.ipynb 14
136
+ # %% ../nbs/api/13_cli.ipynb
136
137
  @call_parse
137
138
  def nbdev_update_license(
138
139
  to: str=None, # update license to
@@ -163,7 +164,41 @@ def nbdev_update_license(
163
164
  lic.write(body)
164
165
  print(f"License updated from {curr_lic} to {to}")
165
166
 
166
- # %% ../nbs/api/13_cli.ipynb 17
167
+ # %% ../nbs/api/13_cli.ipynb
168
+ @call_parse
169
+ @delegates(nb_export, but=['procs', 'mod_maker'])
170
+ def nb_export_cli(nbname,
171
+ debug:store_true=False, # Debug flag
172
+ **kwargs):
173
+ "Export a single nbdev notebook to a python script."
174
+ return nb_export(nbname=nbname, debug=debug, **kwargs)
175
+
176
+ # %% ../nbs/api/13_cli.ipynb
177
+ @call_parse
178
+ def watch_export(nbs:str=None, # Nb directory to watch for changes
179
+ lib:str=None, # Export directory to write py files to
180
+ force:bool=False # Ignore nbdev config if in nbdev project
181
+ ):
182
+ '''Use `nb_export` on ipynb files in `nbs` directory on changes using nbdev config if available'''
183
+ cfg = get_config() if is_nbdev() else None
184
+ nbs = nbs or (cfg.nbs_path if cfg else '.')
185
+ lib = lib or (cfg.lib_path if cfg else '.')
186
+ if cfg and (nbs != cfg.nbs_path or lib != cfg.lib_path) and not force:
187
+ raise ValueError("In nbdev project. Use --force to override config.")
188
+ run(f'nbdev_export')
189
+ def _export(e,lib=lib):
190
+ p = e.src_path
191
+ if (not '.ipynb_checkpoints' in p and p.endswith('.ipynb') and not Path(p).name.startswith(('tmp','.~'))):
192
+ if e.event_type == 'modified':
193
+ time.sleep(0.1)
194
+ try: run(f'nb_export --lib_path {lib} "{p}"')
195
+ except IOError:
196
+ time.sleep(0.3)
197
+ run(f'nb_export --lib_path {lib} "{p}"')
198
+ with fs_watchdog(_export, nbs):
199
+ while True: time.sleep(1)
200
+
201
+ # %% ../nbs/api/13_cli.ipynb
167
202
  @call_parse
168
203
  def chelp():
169
204
  "Show help for all console scripts"