Skip to content

Commit 6db57c8

Browse files
committed
correct idxs
1 parent 3a8f47a commit 6db57c8

File tree

9 files changed

+69
-69
lines changed

9 files changed

+69
-69
lines changed

nbdev/_modidx.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@
297297
'nbdev.showdoc.show_doc': ('09_API/showdoc.html#show_doc', 'nbdev/showdoc.py'),
298298
'nbdev.showdoc.showdoc_nm': ('09_API/showdoc.html#showdoc_nm', 'nbdev/showdoc.py')},
299299
'nbdev.sync': { 'nbdev.sync._get_call': ('09_API/sync.html#_get_call', 'nbdev/sync.py'),
300+
'nbdev.sync._mod_files': ('09_API/sync.html#_mod_files', 'nbdev/sync.py'),
301+
'nbdev.sync._script2notebook': ('09_API/sync.html#_script2notebook', 'nbdev/sync.py'),
300302
'nbdev.sync._to_absolute': ('09_API/sync.html#_to_absolute', 'nbdev/sync.py'),
301303
'nbdev.sync._update_lib': ('09_API/sync.html#_update_lib', 'nbdev/sync.py'),
302304
'nbdev.sync.absolute_import': ('09_API/sync.html#absolute_import', 'nbdev/sync.py'),

nbdev/cli.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# %% auto 0
2828
__all__ = ['FilterDefaults', 'nbdev_filter', 'extract_tgz', 'nbdev_new', 'chelp']
2929

30-
# %% ../nbs/09_API/12_cli.ipynb 6
30+
# %% ../nbs/09_API/12_cli.ipynb 5
3131
class FilterDefaults:
3232
"Override `FilterDefaults` to change which notebook processors are used"
3333
def xtra_procs(self): return []
@@ -45,7 +45,7 @@ def nb_proc(self, nb):
4545
"Get an `NBProcessor` with these processors"
4646
return NBProcessor(nb=nb, procs=self.procs())
4747

48-
# %% ../nbs/09_API/12_cli.ipynb 7
48+
# %% ../nbs/09_API/12_cli.ipynb 6
4949
@call_parse
5050
def nbdev_filter(
5151
nb_txt:str=None, # Notebook text (uses stdin if not provided)
@@ -68,20 +68,20 @@ def nbdev_filter(
6868
if printit: print(res, flush=True)
6969
else: return res
7070

71-
# %% ../nbs/09_API/12_cli.ipynb 10
71+
# %% ../nbs/09_API/12_cli.ipynb 9
7272
def extract_tgz(url, dest='.'):
7373
from fastcore.net import urlopen
7474
with urlopen(url) as u: tarfile.open(mode='r:gz', fileobj=u).extractall(dest)
7575

76-
# %% ../nbs/09_API/12_cli.ipynb 11
76+
# %% ../nbs/09_API/12_cli.ipynb 10
7777
def _render_nb(fn, cfg):
7878
"Render templated values like `{{lib_name}}` in notebook at `fn` from `cfg`"
7979
txt = fn.read_text()
8080
txt = txt.replace('from your_lib.core', f'from {cfg.lib_path}.core') # for compatibility with old templates
8181
for k,v in cfg.d.items(): txt = txt.replace('{{'+k+'}}', v)
8282
fn.write_text(txt)
8383

84-
# %% ../nbs/09_API/12_cli.ipynb 12
84+
# %% ../nbs/09_API/12_cli.ipynb 11
8585
@call_parse
8686
@delegates(nbdev_create_config)
8787
def nbdev_new(**kwargs):
@@ -108,7 +108,7 @@ def nbdev_new(**kwargs):
108108
nbdev_export.__wrapped__()
109109
nbdev_readme.__wrapped__()
110110

111-
# %% ../nbs/09_API/12_cli.ipynb 15
111+
# %% ../nbs/09_API/12_cli.ipynb 14
112112
@call_parse
113113
def chelp():
114114
"Show help for all console scripts"

nbdev/maker.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
__all__ = ['find_var', 'read_var', 'update_var', 'ModuleMaker', 'decor_id', 'retr_exports', 'make_code_cells', 'relative_import',
88
'update_import']
99

10-
# %% ../nbs/09_API/02_maker.ipynb 4
10+
# %% ../nbs/09_API/02_maker.ipynb 3
1111
from .config import *
1212
from .imports import *
1313

@@ -22,7 +22,7 @@
2222
from pprint import pformat
2323
from textwrap import TextWrapper
2424

25-
# %% ../nbs/09_API/02_maker.ipynb 9
25+
# %% ../nbs/09_API/02_maker.ipynb 8
2626
def find_var(lines, varname):
2727
"Find the line numbers where `varname` is defined in `lines`"
2828
start = first(i for i,o in enumerate(lines) if o.startswith(varname))
@@ -32,7 +32,7 @@ def find_var(lines, varname):
3232
end = first(i for i,o in enumerate(lines[start+1:]) if o[:1] not in empty)
3333
return start,len(lines) if end is None else (end+start+1)
3434

35-
# %% ../nbs/09_API/02_maker.ipynb 11
35+
# %% ../nbs/09_API/02_maker.ipynb 10
3636
def read_var(code, varname):
3737
"Eval and return the value of `varname` defined in `code`"
3838
lines = code.splitlines()
@@ -43,7 +43,7 @@ def read_var(code, varname):
4343
try: return eval('\n'.join(res))
4444
except SyntaxError: raise Exception('\n'.join(res)) from None
4545

46-
# %% ../nbs/09_API/02_maker.ipynb 13
46+
# %% ../nbs/09_API/02_maker.ipynb 12
4747
def update_var(varname, func, fn=None, code=None):
4848
"Update the definition of `varname` in file `fn`, by calling `func` with the current definition"
4949
if fn:
@@ -59,7 +59,7 @@ def update_var(varname, func, fn=None, code=None):
5959
if fn: fn.write_text(code)
6060
else: return code
6161

62-
# %% ../nbs/09_API/02_maker.ipynb 16
62+
# %% ../nbs/09_API/02_maker.ipynb 15
6363
class ModuleMaker:
6464
"Helper class to create exported library from notebook source cells"
6565
def __init__(self, dest, name, nb_path, is_new=True, parse=True):
@@ -71,12 +71,12 @@ def __init__(self, dest, name, nb_path, is_new=True, parse=True):
7171
self.dest2nb = nb_path.relpath(self.fname.parent)
7272
self.hdr = f"# %% {self.dest2nb}"
7373

74-
# %% ../nbs/09_API/02_maker.ipynb 19
74+
# %% ../nbs/09_API/02_maker.ipynb 18
7575
def decor_id(d):
7676
"`id` attr of decorator, regardless of whether called as function or bare"
7777
return d.id if hasattr(d, 'id') else nested_attr(d, 'func.id', '')
7878

79-
# %% ../nbs/09_API/02_maker.ipynb 20
79+
# %% ../nbs/09_API/02_maker.ipynb 19
8080
_def_types = ast.FunctionDef,ast.AsyncFunctionDef,ast.ClassDef
8181
_assign_types = ast.AnnAssign, ast.Assign, ast.AugAssign
8282

@@ -87,7 +87,7 @@ def _all_targets(a): return L(getattr(a,'elts',a))
8787
def _filt_dec(x): return decor_id(x).startswith('patch')
8888
def _wants(o): return isinstance(o,_def_types) and not any(L(o.decorator_list).filter(_filt_dec))
8989

90-
# %% ../nbs/09_API/02_maker.ipynb 21
90+
# %% ../nbs/09_API/02_maker.ipynb 20
9191
def retr_exports(trees):
9292
# include anything mentioned in "_all_", even if otherwise private
9393
# NB: "_all_" can include strings (names), or symbols, so we look for "id" or "value"
@@ -100,17 +100,17 @@ def retr_exports(trees):
100100
exports = (assign_targs.attrgot('id')+syms).filter(lambda o: o and o[0]!='_')
101101
return (exports+all_vals).unique()
102102

103-
# %% ../nbs/09_API/02_maker.ipynb 22
103+
# %% ../nbs/09_API/02_maker.ipynb 21
104104
@patch
105105
def make_all(self:ModuleMaker, cells):
106106
"Create `__all__` with all exports in `cells`"
107107
if cells is None: return ''
108108
return retr_exports(L(cells).map(NbCell.parsed_).concat())
109109

110-
# %% ../nbs/09_API/02_maker.ipynb 23
110+
# %% ../nbs/09_API/02_maker.ipynb 22
111111
def make_code_cells(*ss): return dict2nb({'cells':L(ss).map(mk_cell)}).cells
112112

113-
# %% ../nbs/09_API/02_maker.ipynb 26
113+
# %% ../nbs/09_API/02_maker.ipynb 25
114114
def relative_import(name, fname, level=0):
115115
"Convert a module `name` to a name relative to `fname`"
116116
assert not level
@@ -122,7 +122,7 @@ def relative_import(name, fname, level=0):
122122
if not all(o=='.' for o in res): res='.'+res
123123
return res.replace(os.path.sep, ".")
124124

125-
# %% ../nbs/09_API/02_maker.ipynb 28
125+
# %% ../nbs/09_API/02_maker.ipynb 27
126126
# Based on https://github.com/thonny/thonny/blob/master/thonny/ast_utils.py
127127
def _mark_text_ranges(
128128
source: str|bytes, # Source code to add ranges to
@@ -140,7 +140,7 @@ def _mark_text_ranges(
140140
child.end_lineno, child.end_col_offset = child.lineno, child.col_offset+2
141141
return root.body
142142

143-
# %% ../nbs/09_API/02_maker.ipynb 29
143+
# %% ../nbs/09_API/02_maker.ipynb 28
144144
def update_import(source, tree, libname, f=relative_import):
145145
if not tree: return
146146
if sys.version_info < (3,8): tree = _mark_text_ranges(source)
@@ -160,7 +160,7 @@ def import2relative(cell:NbCell, libname):
160160
src = update_import(cell.source, cell.parsed_(), libname)
161161
if src: cell.set_source(src)
162162

163-
# %% ../nbs/09_API/02_maker.ipynb 31
163+
# %% ../nbs/09_API/02_maker.ipynb 30
164164
@patch
165165
def _last_future(self:ModuleMaker, cells):
166166
"Returns the location of a `__future__` in `cells`"
@@ -169,13 +169,13 @@ def _last_future(self:ModuleMaker, cells):
169169
isinstance(t,ast.ImportFrom) and t.module=='__future__' for t in tree))+1
170170
except ValueError: return 0
171171

172-
# %% ../nbs/09_API/02_maker.ipynb 32
172+
# %% ../nbs/09_API/02_maker.ipynb 31
173173
def _import2relative(cells, lib_name=None):
174174
"Converts `cells` to use `import2relative` based on `lib_name`"
175175
if lib_name is None: lib_name = get_config().lib_name
176176
for cell in cells: cell.import2relative(lib_name)
177177

178-
# %% ../nbs/09_API/02_maker.ipynb 33
178+
# %% ../nbs/09_API/02_maker.ipynb 32
179179
@patch
180180
def make(self:ModuleMaker, cells, all_cells=None, lib_path=None):
181181
"Write module containing `cells` with `__all__` generated from `all_cells`"
@@ -198,10 +198,10 @@ def make(self:ModuleMaker, cells, all_cells=None, lib_path=None):
198198
f.write(f"# AUTOGENERATED! DO NOT EDIT! File to edit: {self.dest2nb}.")
199199
if last_future > 0: write_cells(cells[:last_future], self.hdr, f)
200200
if self.parse: f.write(f"\n\n# %% auto 0\n__all__ = {all_str}")
201-
write_cells(cells[last_future:], self.hdr, f, 1 if last_future>0 else 0)
201+
write_cells(cells[last_future:], self.hdr, f)
202202
f.write('\n')
203203

204-
# %% ../nbs/09_API/02_maker.ipynb 38
204+
# %% ../nbs/09_API/02_maker.ipynb 37
205205
@patch
206206
def _update_all(self:ModuleMaker, all_cells, alls):
207207
return pformat(alls + self.make_all(all_cells), width=160)
@@ -212,7 +212,7 @@ def _make_exists(self:ModuleMaker, cells, all_cells=None):
212212
if all_cells and self.parse: update_var('__all__', partial(self._update_all, all_cells), fn=self.fname)
213213
with self.fname.open('a') as f: write_cells(cells, self.hdr, f)
214214

215-
# %% ../nbs/09_API/02_maker.ipynb 44
215+
# %% ../nbs/09_API/02_maker.ipynb 43
216216
def _basic_export_nb2(fname, name, dest=None):
217217
"A basic exporter to bootstrap nbdev using `ModuleMaker`"
218218
if dest is None: dest = get_config().path('lib_path')

nbdev/qmd.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
# %% auto 0
1111
__all__ = ['setup', 'meta', 'div', 'img', 'btn']
1212

13-
# %% ../nbs/09_API/14_qmd.ipynb 5
13+
# %% ../nbs/09_API/14_qmd.ipynb 4
1414
def setup():
1515
mod = inspect.getmodule(inspect.currentframe().f_back)
1616
path = Path(mod.__file__)
1717
os.chdir(path.parent)
1818
sys.stdout = open(path.with_suffix('.qmd'), 'w')
1919
print(mod.__doc__)
2020

21-
# %% ../nbs/09_API/14_qmd.ipynb 6
21+
# %% ../nbs/09_API/14_qmd.ipynb 5
2222
def meta(md, # Markdown to add meta to
2323
classes=None, # List of CSS classes to add
2424
style=None, # Dict of CSS styles to add
@@ -33,15 +33,15 @@ def meta(md, # Markdown to add meta to
3333
meta = ' '.join(meta)
3434
return md + ("{" + meta + "}" if meta else "")
3535

36-
# %% ../nbs/09_API/14_qmd.ipynb 7
36+
# %% ../nbs/09_API/14_qmd.ipynb 6
3737
def div(txt, # Markdown to add meta to
3838
classes=None, # List of CSS classes to add
3939
style=None, # Dict of CSS styles to add
4040
**kwargs):
4141
"A qmd div with optional metadata section"
4242
return meta("::: ", classes=classes, style=style, **kwargs) + f"\n\n{txt}\n\n:::\n\n"
4343

44-
# %% ../nbs/09_API/14_qmd.ipynb 8
44+
# %% ../nbs/09_API/14_qmd.ipynb 7
4545
def img(fname, # Image to link to
4646
classes=None, # List of CSS classes to add
4747
style=None, # Dict of CSS styles to add
@@ -59,7 +59,7 @@ def img(fname, # Image to link to
5959
res = meta(f'![]({fname})', classes=classes, style=style, **kwargs)
6060
return f'[{res}]({fname})' if link else res
6161

62-
# %% ../nbs/09_API/14_qmd.ipynb 9
62+
# %% ../nbs/09_API/14_qmd.ipynb 8
6363
def btn(txt, # Button text
6464
link, # Button link URL
6565
classes=None, # List of CSS classes to add

0 commit comments

Comments
 (0)