nbdev 2.4.3__py3-none-any.whl → 2.4.11__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/process.py CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/03_process.ipynb.
4
4
 
5
- # %% auto 0
5
+ # %% auto #0
6
6
  __all__ = ['langs', 'nb_lang', 'first_code_ln', 'extract_directives', 'opt_set', 'instantiate', 'NBProcessor', 'Processor']
7
7
 
8
- # %% ../nbs/api/03_process.ipynb
8
+ # %% ../nbs/api/03_process.ipynb #59172c3d
9
9
  from .config import *
10
10
  from .maker import *
11
11
  from .imports import *
@@ -16,7 +16,7 @@ from fastcore.imports import *
16
16
 
17
17
  from collections import defaultdict
18
18
 
19
- # %% ../nbs/api/03_process.ipynb
19
+ # %% ../nbs/api/03_process.ipynb #48e04902-f4a1-4247-ae0c-1e30bc054166
20
20
  # from https://github.com/quarto-dev/quarto-cli/blob/main/src/resources/jupyter/notebook.py
21
21
  langs = defaultdict(
22
22
  lambda: '#', r = "#", python = "#", julia = "#", scala = "//", matlab = "%", csharp = "//", fsharp = "//",
@@ -25,30 +25,30 @@ langs = defaultdict(
25
25
  java = "//", groovy = "//", sed = "#", perl = "#", ruby = "#", tikz = "%", javascript = "//", js = "//", d3 = "//", node = "//",
26
26
  sass = "//", coffee = "#", go = "//", asy = "//", haskell = "--", dot = "//", apl = "⍝")
27
27
 
28
- # %% ../nbs/api/03_process.ipynb
28
+ # %% ../nbs/api/03_process.ipynb #c54390ab-1cb9-4146-9e88-609f1fc5544a
29
29
  def nb_lang(nb): return nested_attr(nb, 'metadata.kernelspec.language', 'python')
30
30
 
31
- # %% ../nbs/api/03_process.ipynb
31
+ # %% ../nbs/api/03_process.ipynb #2974d8cc-870c-4362-b2b1-e35f94c28dd9
32
32
  def _dir_pre(lang=None): return fr"\s*{langs[lang]}\s*\|"
33
33
  def _quarto_re(lang=None): return re.compile(_dir_pre(lang) + r'\s*[\w|-]+\s*:')
34
34
 
35
- # %% ../nbs/api/03_process.ipynb
35
+ # %% ../nbs/api/03_process.ipynb #484a1df8
36
36
  def _directive(s, lang='python'):
37
37
  s = re.sub('^'+_dir_pre(lang), f"{langs[lang]}|", s)
38
- if s.strip().endswith(':'): s = s.replace(':', '') # You can append colon at the end to be Quarto compliant. Ex: #|hide:
38
+ if s.strip().endswith(':'): s = s.replace(':', '') # You can append colon at the end to be Quarto compliant. Ex: #| hide:
39
39
  if ':' in s: s = s.replace(':', ': ')
40
40
  s = (s.strip()[2:]).strip().split()
41
41
  if not s: return None
42
42
  direc,*args = s
43
43
  return direc,args
44
44
 
45
- # %% ../nbs/api/03_process.ipynb
45
+ # %% ../nbs/api/03_process.ipynb #100a91fb-8b46-4feb-afbf-d1e78c14cfd6
46
46
  def _norm_quarto(s, lang='python'):
47
47
  "normalize quarto directives so they have a space after the colon"
48
48
  m = _quarto_re(lang).match(s)
49
49
  return m.group(0) + ' ' + _quarto_re(lang).sub('', s).lstrip() if m else s
50
50
 
51
- # %% ../nbs/api/03_process.ipynb
51
+ # %% ../nbs/api/03_process.ipynb #69befb76-aa77-4923-bfcc-2606613d706f
52
52
  _cell_mgc = re.compile(r"^\s*%%\w+")
53
53
 
54
54
  def first_code_ln(code_list, re_pattern=None, lang='python'):
@@ -56,14 +56,14 @@ def first_code_ln(code_list, re_pattern=None, lang='python'):
56
56
  if re_pattern is None: re_pattern = _dir_pre(lang)
57
57
  return first(i for i,o in enumerate(code_list) if o.strip() != '' and not re.match(re_pattern, o) and not _cell_mgc.match(o))
58
58
 
59
- # %% ../nbs/api/03_process.ipynb
59
+ # %% ../nbs/api/03_process.ipynb #b3eee2d6-59b9-45f3-affd-4de2bd1284d1
60
60
  def _partition_cell(cell, lang):
61
61
  if not cell.source: return [],[]
62
62
  lines = cell.source.splitlines(True)
63
63
  first_code = first_code_ln(lines, lang=lang)
64
64
  return lines[:first_code],lines[first_code:]
65
65
 
66
- # %% ../nbs/api/03_process.ipynb
66
+ # %% ../nbs/api/03_process.ipynb #3cca78a4
67
67
  def extract_directives(cell, remove=True, lang='python'):
68
68
  "Take leading comment directives from lines of code in `ss`, remove `#|`, and split"
69
69
  dirs,code = _partition_cell(cell, lang)
@@ -73,22 +73,22 @@ def extract_directives(cell, remove=True, lang='python'):
73
73
  cell['source'] = ''.join([_norm_quarto(o, lang) for o in dirs if _quarto_re(lang).match(o) or _cell_mgc.match(o)] + code)
74
74
  return dict(L(_directive(s, lang) for s in dirs).filter())
75
75
 
76
- # %% ../nbs/api/03_process.ipynb
76
+ # %% ../nbs/api/03_process.ipynb #e6701805
77
77
  def opt_set(var, newval):
78
78
  "newval if newval else var"
79
79
  return newval if newval else var
80
80
 
81
- # %% ../nbs/api/03_process.ipynb
81
+ # %% ../nbs/api/03_process.ipynb #98c9d556
82
82
  def instantiate(x, **kwargs):
83
83
  "Instantiate `x` if it's a type"
84
84
  return x(**kwargs) if isinstance(x,type) else x
85
85
 
86
86
  def _mk_procs(procs, nb): return L(procs).map(instantiate, nb=nb)
87
87
 
88
- # %% ../nbs/api/03_process.ipynb
88
+ # %% ../nbs/api/03_process.ipynb #ab147efe
89
89
  def _is_direc(f): return getattr(f, '__name__', '-')[-1]=='_'
90
90
 
91
- # %% ../nbs/api/03_process.ipynb
91
+ # %% ../nbs/api/03_process.ipynb #7c81f109
92
92
  class NBProcessor:
93
93
  "Process cells and nbdev comments in a notebook"
94
94
  def __init__(self, path=None, procs=None, nb=None, debug=False, rm_directives=True, process=False):
@@ -128,7 +128,7 @@ class NBProcessor:
128
128
  "Process all cells with all processors"
129
129
  for proc in self.procs: self._proc(proc)
130
130
 
131
- # %% ../nbs/api/03_process.ipynb
131
+ # %% ../nbs/api/03_process.ipynb #fa1f8668
132
132
  class Processor:
133
133
  "Base class for processors"
134
134
  def __init__(self, nb): self.nb = nb
nbdev/processors.py CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/10_processors.ipynb.
4
4
 
5
- # %% auto 0
5
+ # %% auto #0
6
6
  __all__ = ['populate_language', 'insert_warning', 'cell_lang', 'add_show_docs', 'fdiv', 'boxify', 'mv_exports', 'add_links',
7
7
  'add_fold', 'strip_ansi', 'strip_hidden_metadata', 'hide_', 'hide_line', 'filter_stream_', 'ai_magics',
8
8
  'clean_magics', 'rm_header_dash', 'rm_export', 'clean_show_doc', 'exec_show_docs', 'FilterDefaults']
9
9
 
10
- # %% ../nbs/api/10_processors.ipynb
10
+ # %% ../nbs/api/10_processors.ipynb #2398f5ef-06d3-4890-8a54-7cf4f81f3894
11
11
  import ast
12
12
  import importlib
13
13
 
@@ -25,7 +25,7 @@ from fastcore.imports import *
25
25
  from fastcore.xtras import *
26
26
  import sys,yaml
27
27
 
28
- # %% ../nbs/api/10_processors.ipynb
28
+ # %% ../nbs/api/10_processors.ipynb #8ab33554
29
29
  _langs = 'bash|html|javascript|js|latex|markdown|perl|ruby|sh|svg'
30
30
  _lang_pattern = re.compile(rf'^\s*%%\s*({_langs})\s*$', flags=re.MULTILINE)
31
31
 
@@ -38,13 +38,13 @@ class populate_language(Processor):
38
38
  if lang: cell.metadata.language = lang[0]
39
39
  else: cell.metadata.language = self.language
40
40
 
41
- # %% ../nbs/api/10_processors.ipynb
41
+ # %% ../nbs/api/10_processors.ipynb #382949b3
42
42
  class insert_warning(Processor):
43
43
  "Insert Autogenerated Warning Into Notebook after the first cell."
44
44
  content = "<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->"
45
45
  def begin(self): self.nb.cells.insert(1, mk_cell(self.content, 'markdown'))
46
46
 
47
- # %% ../nbs/api/10_processors.ipynb
47
+ # %% ../nbs/api/10_processors.ipynb #aa1069b1
48
48
  _def_types = (ast.FunctionDef,ast.AsyncFunctionDef,ast.ClassDef)
49
49
  def _def_names(cell, shown):
50
50
  cellp = cell.parsed_()
@@ -57,7 +57,7 @@ def _get_nm(tree):
57
57
  else: val = try_attrs(i.value, 'id', 'func', 'attr')
58
58
  return f'{val}.{i.attr}' if isinstance(i, ast.Attribute) else i.id
59
59
 
60
- # %% ../nbs/api/10_processors.ipynb
60
+ # %% ../nbs/api/10_processors.ipynb #13cbb041
61
61
  def _show_docs(trees):
62
62
  return [t for t in trees if isinstance(t,ast.Expr) and nested_attr(t, 'value.func.id')=='show_doc']
63
63
 
@@ -84,20 +84,20 @@ class add_show_docs(Processor):
84
84
  nb.cells.insert(cell.idx_+1, new_cell)
85
85
  nb.has_docs_ = shown_docs or exports
86
86
 
87
- # %% ../nbs/api/10_processors.ipynb
87
+ # %% ../nbs/api/10_processors.ipynb #22b1972e
88
88
  def fdiv(attrs=''):
89
89
  "Create a fenced div markdown cell in quarto"
90
90
  if attrs: attrs = ' {'+attrs+'}'
91
91
  return mk_cell(':::'+attrs, cell_type='markdown')
92
92
 
93
- # %% ../nbs/api/10_processors.ipynb
93
+ # %% ../nbs/api/10_processors.ipynb #27bc8ad4
94
94
  def boxify(cells):
95
95
  "Add a box around `cells`"
96
96
  if not isinstance(cells, list): cells = [cells]
97
97
  res = [fdiv('.py-2 .px-3 .mb-4 fig-align="center" .border .rounded .shadow-sm')]
98
98
  return res+cells+[fdiv()]
99
99
 
100
- # %% ../nbs/api/10_processors.ipynb
100
+ # %% ../nbs/api/10_processors.ipynb #0a7127ef
101
101
  class mv_exports(Processor):
102
102
  "Move `exports` cells to after the `show_doc`"
103
103
  def begin(self):
@@ -110,7 +110,7 @@ class mv_exports(Processor):
110
110
  srccell = cells.pop(idx)
111
111
  cells[idx:idx] = [doccell,srccell]
112
112
 
113
- # %% ../nbs/api/10_processors.ipynb
113
+ # %% ../nbs/api/10_processors.ipynb #e7eff7d4
114
114
  _re_defaultexp = re.compile(r'^\s*#\|\s*default_exp\s+(\S+)', flags=re.MULTILINE)
115
115
 
116
116
  def _default_exp(nb):
@@ -119,7 +119,7 @@ def _default_exp(nb):
119
119
  default_exp = first(code_src.filter().map(_re_defaultexp.search).filter())
120
120
  return default_exp.group(1) if default_exp else None
121
121
 
122
- # %% ../nbs/api/10_processors.ipynb
122
+ # %% ../nbs/api/10_processors.ipynb #03e8fece-bf92-4a1d-9f8b-ef209107ff95
123
123
  def add_links(cell):
124
124
  "Add links to markdown cells"
125
125
  nl = NbdevLookup()
@@ -128,13 +128,13 @@ def add_links(cell):
128
128
  if hasattr(o, 'data') and hasattr(o['data'], 'text/markdown'):
129
129
  o.data['text/markdown'] = [nl.link_line(s) for s in o.data['text/markdown']]
130
130
 
131
- # %% ../nbs/api/10_processors.ipynb
131
+ # %% ../nbs/api/10_processors.ipynb #809e9225
132
132
  def add_fold(cell):
133
133
  "Add `code-fold` to `exports` cells"
134
134
  if cell.cell_type != 'code' or 'exports' not in cell.directives_: return
135
135
  cell.source = f'#| code-fold: show\n#| code-summary: "Exported source"\n{cell.source}'
136
136
 
137
- # %% ../nbs/api/10_processors.ipynb
137
+ # %% ../nbs/api/10_processors.ipynb #84073fa6-5907-41f2-b8b8-568a96112fbd
138
138
  _re_ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
139
139
 
140
140
  def strip_ansi(cell):
@@ -142,17 +142,17 @@ def strip_ansi(cell):
142
142
  for outp in cell.get('outputs', []):
143
143
  if outp.get('name')=='stdout': outp['text'] = [_re_ansi_escape.sub('', o) for o in outp.text]
144
144
 
145
- # %% ../nbs/api/10_processors.ipynb
145
+ # %% ../nbs/api/10_processors.ipynb #640b7eca
146
146
  def strip_hidden_metadata(cell):
147
147
  '''Strips "hidden" metadata property from code cells so it doesn't interfere with docs rendering'''
148
148
  if cell.cell_type == 'code' and 'metadata' in cell: cell.metadata.pop('hidden',None)
149
149
 
150
- # %% ../nbs/api/10_processors.ipynb
150
+ # %% ../nbs/api/10_processors.ipynb #995ebd32
151
151
  def hide_(cell):
152
152
  "Hide cell from output"
153
153
  del(cell['source'])
154
154
 
155
- # %% ../nbs/api/10_processors.ipynb
155
+ # %% ../nbs/api/10_processors.ipynb #eb415328-044f-44ca-ac77-4f5ae65c2235
156
156
  def _re_hideline(lang=None): return re.compile(fr'{langs[lang]}\|\s*hide_line\s*$', re.MULTILINE)
157
157
 
158
158
  def hide_line(cell):
@@ -161,7 +161,7 @@ def hide_line(cell):
161
161
  if cell.cell_type == 'code' and _re_hideline(lang).search(cell.source):
162
162
  cell.source = '\n'.join([c for c in cell.source.splitlines() if not _re_hideline(lang).search(c)])
163
163
 
164
- # %% ../nbs/api/10_processors.ipynb
164
+ # %% ../nbs/api/10_processors.ipynb #f8ccf1d7
165
165
  def filter_stream_(cell, *words):
166
166
  "Remove output lines containing any of `words` in `cell` stream output"
167
167
  if not words: return
@@ -169,7 +169,7 @@ def filter_stream_(cell, *words):
169
169
  if outp.output_type == 'stream':
170
170
  outp['text'] = [l for l in outp.text if not re.search('|'.join(words), l)]
171
171
 
172
- # %% ../nbs/api/10_processors.ipynb
172
+ # %% ../nbs/api/10_processors.ipynb #848fd452-3d63-4c41-aaa6-e14cbeb9fdcd
173
173
  _aimagics_pattern = re.compile(r'^\s*(%%ai.? |%%ai.?$)', re.MULTILINE)
174
174
 
175
175
  def ai_magics(cell):
@@ -178,14 +178,14 @@ def ai_magics(cell):
178
178
  cell.cell_type ='markdown'
179
179
  cell.source = '\n'.join(cell.source.splitlines()[1:])
180
180
 
181
- # %% ../nbs/api/10_processors.ipynb
181
+ # %% ../nbs/api/10_processors.ipynb #5a9c8fd4
182
182
  _magics_pattern = re.compile(r'^\s*(%%|%).*', re.MULTILINE)
183
183
 
184
184
  def clean_magics(cell):
185
185
  "A preprocessor to remove cell magic commands"
186
186
  if cell.cell_type == 'code': cell.source = _magics_pattern.sub('', cell.source).strip()
187
187
 
188
- # %% ../nbs/api/10_processors.ipynb
188
+ # %% ../nbs/api/10_processors.ipynb #93e27a52
189
189
  _re_hdr_dash = re.compile(r'^#+\s+.*\s+-\s*$', re.MULTILINE)
190
190
 
191
191
  def rm_header_dash(cell):
@@ -194,14 +194,14 @@ def rm_header_dash(cell):
194
194
  src = cell.source.strip()
195
195
  if cell.cell_type == 'markdown' and src.startswith('#') and src.endswith(' -'): del(cell['source'])
196
196
 
197
- # %% ../nbs/api/10_processors.ipynb
197
+ # %% ../nbs/api/10_processors.ipynb #75faf537
198
198
  _hide_dirs = {'export','exporti', 'hide','default_exp'}
199
199
 
200
200
  def rm_export(cell):
201
201
  "Remove cells that are exported or hidden"
202
202
  if cell.directives_ and (cell.directives_.keys() & _hide_dirs): del(cell['source'])
203
203
 
204
- # %% ../nbs/api/10_processors.ipynb
204
+ # %% ../nbs/api/10_processors.ipynb #2d9a0a30
205
205
  _re_showdoc = re.compile(r'^show_doc', re.MULTILINE)
206
206
  def _is_showdoc(cell): return cell['cell_type'] == 'code' and _re_showdoc.search(cell.source)
207
207
  def _add_directives(cell, d):
@@ -213,7 +213,7 @@ def clean_show_doc(cell):
213
213
  if not _is_showdoc(cell): return
214
214
  _add_directives(cell, {'output':'asis','echo':'false'})
215
215
 
216
- # %% ../nbs/api/10_processors.ipynb
216
+ # %% ../nbs/api/10_processors.ipynb #6ebda551
217
217
  def _ast_contains(trees, types):
218
218
  for tree in trees:
219
219
  for node in ast.walk(tree):
@@ -234,7 +234,7 @@ def _do_eval(cell):
234
234
  return True
235
235
  if _show_docs(trees): return True
236
236
 
237
- # %% ../nbs/api/10_processors.ipynb
237
+ # %% ../nbs/api/10_processors.ipynb #867cf721
238
238
  class exec_show_docs(Processor):
239
239
  "Execute cells needed for `show_docs` output, including exported cells and imports"
240
240
  def begin(self):
@@ -261,13 +261,13 @@ class exec_show_docs(Processor):
261
261
  widgets = {**old, **new, 'state': {**old.get('state', {}), **new['state']}}
262
262
  self.nb.metadata['widgets'] = {mimetype: widgets}
263
263
 
264
- # %% ../nbs/api/10_processors.ipynb
264
+ # %% ../nbs/api/10_processors.ipynb #a761e07c
265
265
  def _import_obj(s):
266
266
  mod_nm, obj_nm = s.split(':')
267
267
  mod = importlib.import_module(mod_nm)
268
268
  return getattr(mod, obj_nm)
269
269
 
270
- # %% ../nbs/api/10_processors.ipynb
270
+ # %% ../nbs/api/10_processors.ipynb #4b450cff
271
271
  class FilterDefaults:
272
272
  "Override `FilterDefaults` to change which notebook processors are used"
273
273
  def xtra_procs(self):
nbdev/qmd.py CHANGED
@@ -2,17 +2,17 @@
2
2
 
3
3
  # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/15_qmd.ipynb.
4
4
 
5
- # %% ../nbs/api/15_qmd.ipynb 2
5
+ # %% ../nbs/api/15_qmd.ipynb #6a35c7c4-748f-4c82-a9bf-c780a8d83e90
6
6
  from __future__ import annotations
7
7
  import sys,os,inspect
8
8
 
9
9
  from fastcore.utils import *
10
10
  from fastcore.meta import delegates
11
11
 
12
- # %% auto 0
12
+ # %% auto #0
13
13
  __all__ = ['meta', 'div', 'img', 'btn', 'tbl_row', 'tbl_sep']
14
14
 
15
- # %% ../nbs/api/15_qmd.ipynb
15
+ # %% ../nbs/api/15_qmd.ipynb #5a64f1f4
16
16
  def meta(md, # Markdown to add meta to
17
17
  classes=None, # List of CSS classes to add
18
18
  style=None, # Dict of CSS styles to add
@@ -27,7 +27,7 @@ def meta(md, # Markdown to add meta to
27
27
  meta = ' '.join(meta)
28
28
  return md + ("{" + meta + "}" if meta else "")
29
29
 
30
- # %% ../nbs/api/15_qmd.ipynb
30
+ # %% ../nbs/api/15_qmd.ipynb #52637a70
31
31
  def div(txt, # Markdown to add meta to
32
32
  classes=None, # List of CSS classes to add
33
33
  style=None, # Dict of CSS styles to add
@@ -35,7 +35,7 @@ def div(txt, # Markdown to add meta to
35
35
  "A qmd div with optional metadata section"
36
36
  return meta("::: ", classes=classes, style=style, **kwargs) + f"\n\n{txt}\n\n:::\n\n"
37
37
 
38
- # %% ../nbs/api/15_qmd.ipynb
38
+ # %% ../nbs/api/15_qmd.ipynb #f9f499f4
39
39
  def img(fname, # Image to link to
40
40
  classes=None, # List of CSS classes to add
41
41
  style=None, # Dict of CSS styles to add
@@ -53,7 +53,7 @@ def img(fname, # Image to link to
53
53
  res = meta(f'![]({fname})', classes=classes, style=style, **kwargs)
54
54
  return f'[{res}]({fname})' if link else res
55
55
 
56
- # %% ../nbs/api/15_qmd.ipynb
56
+ # %% ../nbs/api/15_qmd.ipynb #16d7aa5f
57
57
  def btn(txt, # Button text
58
58
  link, # Button link URL
59
59
  classes=None, # List of CSS classes to add
@@ -62,20 +62,20 @@ def btn(txt, # Button text
62
62
  "A qmd button"
63
63
  return meta(f'[{txt}]({link})', classes=classes, style=style, role="button")
64
64
 
65
- # %% ../nbs/api/15_qmd.ipynb
65
+ # %% ../nbs/api/15_qmd.ipynb #e414ed33
66
66
  def tbl_row(cols:list, # Auto-stringified columns to show in the row
67
67
  ):
68
68
  "Create a markdown table row from `cols`"
69
69
  return '|' + '|'.join(str(c or '') for c in cols) + '|'
70
70
 
71
- # %% ../nbs/api/15_qmd.ipynb
71
+ # %% ../nbs/api/15_qmd.ipynb #38f0641b
72
72
  def tbl_sep(sizes:int|list=3 # List of column sizes, or single `int` if all sizes the same
73
73
  ):
74
74
  "Create a markdown table separator with relative column size `sizes`"
75
75
  if isinstance(sizes,int): sizes = [3]*sizes
76
76
  return tbl_row('-'*s for s in sizes)
77
77
 
78
- # %% ../nbs/api/15_qmd.ipynb
78
+ # %% ../nbs/api/15_qmd.ipynb #a0d6553e-05ab-4db2-b739-aeee59a9ff31
79
79
  def _install_nbdev():
80
80
  return div('''#### pip
81
81
 
nbdev/quarto.py CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/14_quarto.ipynb.
4
4
 
5
- # %% ../nbs/api/14_quarto.ipynb 3
5
+ # %% ../nbs/api/14_quarto.ipynb #6a35c7c4-748f-4c82-a9bf-c780a8d83e90
6
6
  from __future__ import annotations
7
7
  import subprocess,sys,shutil,ast,warnings,traceback
8
8
  from os import system
@@ -19,17 +19,17 @@ from .serve import proc_nbs,_proc_file
19
19
  from . import serve_drv
20
20
  import yaml
21
21
 
22
- # %% auto 0
22
+ # %% auto #0
23
23
  __all__ = ['BASE_QUARTO_URL', 'install_quarto', 'install', 'IndentDumper', 'nbdev_sidebar', 'refresh_quarto_yml',
24
24
  'nbdev_proc_nbs', 'nbdev_readme', 'nbdev_contributing', 'nbdev_docs', 'prepare', 'fs_watchdog',
25
25
  'nbdev_preview']
26
26
 
27
- # %% ../nbs/api/14_quarto.ipynb
27
+ # %% ../nbs/api/14_quarto.ipynb #aae2d2be-ad03-4536-bf70-c4575f39cea3
28
28
  def _sprun(cmd):
29
29
  try: subprocess.check_output(cmd, shell=True)
30
30
  except subprocess.CalledProcessError as cpe: sys.exit(cpe.returncode)
31
31
 
32
- # %% ../nbs/api/14_quarto.ipynb
32
+ # %% ../nbs/api/14_quarto.ipynb #75e4b6a1
33
33
  BASE_QUARTO_URL='https://www.quarto.org/download/latest/'
34
34
 
35
35
  def _install_linux():
@@ -56,7 +56,7 @@ def install_quarto():
56
56
  elif 'linux' in sys.platform: _install_linux()
57
57
  finally: system('sudo rm -f .installing')
58
58
 
59
- # %% ../nbs/api/14_quarto.ipynb
59
+ # %% ../nbs/api/14_quarto.ipynb #7580d48f-e10e-4bb0-937e-90645b5dfd08
60
60
  @call_parse
61
61
  def install():
62
62
  "Install Quarto and the current library"
@@ -64,16 +64,16 @@ def install():
64
64
  d = get_config().lib_path
65
65
  if (d/'__init__.py').exists(): system(f'pip install -e "{d.parent}[dev]"')
66
66
 
67
- # %% ../nbs/api/14_quarto.ipynb
67
+ # %% ../nbs/api/14_quarto.ipynb #b93f6def
68
68
  def _pre(p,b=True): return ' ' * (len(p.parts)) + ('- ' if b else ' ')
69
69
  def _sort(a):
70
70
  x,y = a
71
71
  if y.startswith('index.'): return x,'00'
72
72
  return a
73
- #|export
73
+
74
74
  _def_file_re = r'\.(?:ipynb|qmd|html)$'
75
75
 
76
- @delegates(nbglob_cli)
76
+ @delegates
77
77
  def _nbglob_docs(
78
78
  path:str=None, # Path to notebooks
79
79
  file_glob:str=None, # Only include files matching glob
@@ -81,7 +81,7 @@ def _nbglob_docs(
81
81
  **kwargs):
82
82
  return nbglob(path, file_glob=file_glob, file_re=file_re, **kwargs)
83
83
 
84
- # %% ../nbs/api/14_quarto.ipynb
84
+ # %% ../nbs/api/14_quarto.ipynb #37ab90f4
85
85
  def _recursive_parser(
86
86
  dir_dict: dict, # Directory structure as a dict.
87
87
  contents: list, # `contents` list from `sidebar.yaml` template dict.
@@ -104,7 +104,7 @@ class IndentDumper(yaml.Dumper):
104
104
  def increase_indent(self, flow=False, indentless=False):
105
105
  return super(IndentDumper, self).increase_indent(flow, False)
106
106
 
107
- # %% ../nbs/api/14_quarto.ipynb
107
+ # %% ../nbs/api/14_quarto.ipynb #d879c7e1
108
108
  @call_parse
109
109
  @delegates(_nbglob_docs)
110
110
  def nbdev_sidebar(
@@ -139,7 +139,7 @@ def nbdev_sidebar(
139
139
  if printit: return print(yml)
140
140
  yml_path.write_text(yml)
141
141
 
142
- # %% ../nbs/api/14_quarto.ipynb
142
+ # %% ../nbs/api/14_quarto.ipynb #aabf2f15
143
143
  _quarto_yml="""project:
144
144
  type: website
145
145
 
@@ -163,7 +163,7 @@ website:
163
163
 
164
164
  metadata-files: [nbdev.yml, sidebar.yml]"""
165
165
 
166
- # %% ../nbs/api/14_quarto.ipynb
166
+ # %% ../nbs/api/14_quarto.ipynb #faabf6e6
167
167
  _nbdev_yml="""project:
168
168
  output-dir: {doc_path}
169
169
 
@@ -175,7 +175,7 @@ website:
175
175
  repo-url: "{git_url}"
176
176
  """
177
177
 
178
- # %% ../nbs/api/14_quarto.ipynb
178
+ # %% ../nbs/api/14_quarto.ipynb #38124450
179
179
  def refresh_quarto_yml():
180
180
  "Generate `_quarto.yml` from `settings.ini`."
181
181
  cfg = get_config()
@@ -189,13 +189,13 @@ def refresh_quarto_yml():
189
189
  if qy.exists() and not str2bool(cfg.get('custom_quarto_yml', True)): qy.unlink()
190
190
  if not qy.exists(): qy.write_text(_quarto_yml)
191
191
 
192
- # %% ../nbs/api/14_quarto.ipynb
192
+ # %% ../nbs/api/14_quarto.ipynb #975d370e
193
193
  def _ensure_quarto():
194
194
  if shutil.which('quarto'): return
195
195
  print("Quarto is not installed. We will download and install it for you.")
196
196
  install.__wrapped__()
197
197
 
198
- # %% ../nbs/api/14_quarto.ipynb
198
+ # %% ../nbs/api/14_quarto.ipynb #6b880922
199
199
  def _pre_docs(path=None, n_workers:int=defaults.cpus, **kwargs):
200
200
  cfg = get_config()
201
201
  path = Path(path) if path else cfg.nbs_path
@@ -207,21 +207,21 @@ def _pre_docs(path=None, n_workers:int=defaults.cpus, **kwargs):
207
207
  cache = proc_nbs(path, n_workers=n_workers, **kwargs)
208
208
  return cache,cfg,path
209
209
 
210
- # %% ../nbs/api/14_quarto.ipynb
210
+ # %% ../nbs/api/14_quarto.ipynb #e3806fa9
211
211
  @call_parse
212
212
  @delegates(proc_nbs)
213
213
  def nbdev_proc_nbs(**kwargs):
214
214
  "Process notebooks in `path` for docs rendering"
215
215
  _pre_docs(**kwargs)[0]
216
216
 
217
- # %% ../nbs/api/14_quarto.ipynb
217
+ # %% ../nbs/api/14_quarto.ipynb #c5c7bb0e
218
218
  def _doc_mtime_not_older(readme_path, readme_nb_path):
219
219
  if not readme_nb_path.exists():
220
220
  print(f"Could not find {readme_nb_path}")
221
221
  return True
222
222
  return readme_path.exists() and readme_path.stat().st_mtime>=readme_nb_path.stat().st_mtime
223
223
 
224
- # %% ../nbs/api/14_quarto.ipynb
224
+ # %% ../nbs/api/14_quarto.ipynb #7b70b5c8
225
225
  class _SidebarYmlRemoved:
226
226
  "Context manager for `nbdev_readme` to avoid rendering whole docs website"
227
227
  def __init__(self,path): self._path=path
@@ -234,14 +234,14 @@ class _SidebarYmlRemoved:
234
234
  def __exit__(self, exc_type, exc_value, exc_tb):
235
235
  if self._moved: (self._path/'sidebar.yml.bak').rename(self._yml_path)
236
236
 
237
- # %% ../nbs/api/14_quarto.ipynb
237
+ # %% ../nbs/api/14_quarto.ipynb #49661bbf
238
238
  def _copytree(a,b):
239
239
  if sys.version_info.major >=3 and sys.version_info.minor >=8: copytree(a, b, dirs_exist_ok=True)
240
240
  else:
241
241
  from distutils.dir_util import copy_tree
242
242
  copy_tree(a, b)
243
243
 
244
- # %% ../nbs/api/14_quarto.ipynb
244
+ # %% ../nbs/api/14_quarto.ipynb #caeaa153
245
245
  def _save_cached_readme(cache, cfg):
246
246
  tmp_doc_path = cache/cfg.doc_path.name
247
247
  readme = tmp_doc_path/'README.md'
@@ -252,7 +252,7 @@ def _save_cached_readme(cache, cfg):
252
252
  _rdmi = tmp_doc_path/((cache/cfg.readme_nb).stem + '_files') # Supporting files for README
253
253
  if _rdmi.exists(): _copytree(_rdmi, cfg.config_path/_rdmi.name)
254
254
 
255
- # %% ../nbs/api/14_quarto.ipynb
255
+ # %% ../nbs/api/14_quarto.ipynb #45d6bb5d
256
256
  @call_parse
257
257
  def nbdev_readme(
258
258
  path:str=None, # Path to notebooks
@@ -268,7 +268,7 @@ def nbdev_readme(
268
268
 
269
269
  _save_cached_readme(cache, cfg)
270
270
 
271
- # %% ../nbs/api/14_quarto.ipynb
271
+ # %% ../nbs/api/14_quarto.ipynb #ef3f1e1f
272
272
  def _save_cached_contributing(cache, cfg, contrib_nb):
273
273
  "Move CONTRIBUTING.md (and any `_files` assets) from the Quarto build cache to the repo root."
274
274
  tmp_doc_path = cache / cfg.doc_path.name
@@ -280,7 +280,7 @@ def _save_cached_contributing(cache, cfg, contrib_nb):
280
280
  assets_folder = tmp_doc_path / (Path(contrib_nb).stem + '_files') # Supporting files for CONTRIBUTING
281
281
  if assets_folder.exists(): _copytree(assets_folder, cfg.config_path / assets_folder.name)
282
282
 
283
- # %% ../nbs/api/14_quarto.ipynb
283
+ # %% ../nbs/api/14_quarto.ipynb #729a0fa1
284
284
  @call_parse
285
285
  def nbdev_contributing(
286
286
  path:str=None, # Path to notebooks
@@ -300,7 +300,7 @@ def nbdev_contributing(
300
300
 
301
301
  _save_cached_contributing(cache, cfg, contrib_nb_name)
302
302
 
303
- # %% ../nbs/api/14_quarto.ipynb
303
+ # %% ../nbs/api/14_quarto.ipynb #37d16049
304
304
  @call_parse
305
305
  @delegates(_nbglob_docs)
306
306
  def nbdev_docs(
@@ -315,7 +315,7 @@ def nbdev_docs(
315
315
  shutil.rmtree(cfg.doc_path, ignore_errors=True)
316
316
  move(cache/cfg.doc_path.name, cfg.config_path)
317
317
 
318
- # %% ../nbs/api/14_quarto.ipynb
318
+ # %% ../nbs/api/14_quarto.ipynb #23886f9c
319
319
  @call_parse
320
320
  def prepare():
321
321
  "Export, test, and clean notebooks, and render README if needed"
@@ -327,7 +327,7 @@ def prepare():
327
327
  nbdev_readme.__wrapped__(chk_time=True)
328
328
  nbdev_contributing.__wrapped__(chk_time=True)
329
329
 
330
- # %% ../nbs/api/14_quarto.ipynb
330
+ # %% ../nbs/api/14_quarto.ipynb #5f701608
331
331
  @contextmanager
332
332
  def fs_watchdog(func, path, recursive:bool=True):
333
333
  "File system watchdog dispatching to `func`"
@@ -343,7 +343,7 @@ def fs_watchdog(func, path, recursive:bool=True):
343
343
  observer.stop()
344
344
  observer.join()
345
345
 
346
- # %% ../nbs/api/14_quarto.ipynb
346
+ # %% ../nbs/api/14_quarto.ipynb #b6ddeadd
347
347
  @call_parse
348
348
  @delegates(_nbglob_docs)
349
349
  def nbdev_preview(