Skip to content

Commit 5c0ee8c

Browse files
committed
fixes #1440
1 parent e1ab054 commit 5c0ee8c

22 files changed

+104
-86
lines changed

nbdev/_modidx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
'nbdev.doclinks.nbglob_cli': ('api/doclinks.html#nbglob_cli', 'nbdev/doclinks.py'),
7272
'nbdev.doclinks.patch_name': ('api/doclinks.html#patch_name', 'nbdev/doclinks.py')},
7373
'nbdev.export': { 'nbdev.export.ExportModuleProc': ('api/export.html#exportmoduleproc', 'nbdev/export.py'),
74+
'nbdev.export.ExportModuleProc.__call__': ('api/export.html#exportmoduleproc.__call__', 'nbdev/export.py'),
7475
'nbdev.export.ExportModuleProc._default_exp_': ( 'api/export.html#exportmoduleproc._default_exp_',
7576
'nbdev/export.py'),
7677
'nbdev.export.ExportModuleProc._export_': ('api/export.html#exportmoduleproc._export_', 'nbdev/export.py'),

nbdev/clean.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Strip superfluous metadata from notebooks"""
2+
13
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/11_clean.ipynb.
24

35
# %% auto 0

nbdev/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""CLI commands"""
2+
13
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/13_cli.ipynb.
24

35
# %% ../nbs/api/13_cli.ipynb 2

nbdev/config.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
"""Read and write nbdev's `settings.ini` file.
2-
`get_config` is the main function for reading settings."""
1+
"""Configuring nbdev and bootstrapping notebook export"""
32

43
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/01_config.ipynb.
54

65
# %% auto 0
76
__all__ = ['nbdev_create_config', 'get_config', 'config_key', 'create_output', 'show_src', 'update_version', 'add_init',
87
'write_cells']
98

10-
# %% ../nbs/api/01_config.ipynb
11-
_doc_ = """Read and write nbdev's `settings.ini` file.
12-
`get_config` is the main function for reading settings."""
13-
149
# %% ../nbs/api/01_config.ipynb
1510
from datetime import datetime
1611
from fastcore.docments import *
@@ -255,7 +250,7 @@ def add_init(path=None):
255250
def write_cells(cells, hdr, file, offset=0, cell_number=True):
256251
"Write `cells` to `file` along with header `hdr` starting at index `offset` (mainly for nbdev internal use)."
257252
for cell in cells:
258-
if cell.source.strip():
253+
if cell.cell_type=='code' and cell.source.strip():
259254
idx = f" {cell.idx_+offset}" if cell_number else ""
260255
file.write(f'\n\n{hdr}{idx}\n{cell.source}')
261256

nbdev/doclinks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Generating a documentation index from a module"""
2+
13
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/05_doclinks.ipynb.
24

35
# %% auto 0

nbdev/export.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Exporting a notebook to a library"""
2+
13
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/04_export.ipynb.
24

35
# %% auto 0
@@ -24,6 +26,10 @@ def _exporti_(self, cell, exp_to=None): self.modules[ifnone(exp_to, '#')].append
2426
def _export_(self, cell, exp_to=None):
2527
self._exporti_(cell, exp_to)
2628
self.in_all[ifnone(exp_to, '#')].append(cell)
29+
def __call__(self, cell):
30+
src = cell.source
31+
if not src: return
32+
if cell.cell_type=='markdown' and src.startswith('# '): self.modules['#'].append(cell)
2733
_exports_=_export_
2834

2935
# %% ../nbs/api/04_export.ipynb
@@ -67,12 +73,13 @@ def nb_export(nbname, lib_path=None, procs=None, debug=False, mod_maker=ModuleMa
6773
nb = NBProcessor(nbname, [exp]+L(procs), debug=debug)
6874
nb.process()
6975
for mod,cells in exp.modules.items():
70-
all_cells = exp.in_all[mod]
71-
nm = ifnone(name, getattr(exp, 'default_exp', None) if mod=='#' else mod)
72-
if not nm:
73-
warn(f"Notebook '{nbname}' uses `#|export` without `#|default_exp` cell.\n"
74-
"Note nbdev2 no longer supports nbdev1 syntax. Run `nbdev_migrate` to upgrade.\n"
75-
"See https://nbdev.fast.ai/getting_started.html for more information.")
76-
return
77-
mm = mod_maker(dest=lib_path, name=nm, nb_path=nbname, is_new=bool(name) or mod=='#')
78-
mm.make(cells, all_cells, lib_path=lib_path)
76+
if first(1 for o in cells if o.cell_type=='code'):
77+
all_cells = exp.in_all[mod]
78+
nm = ifnone(name, getattr(exp, 'default_exp', None) if mod=='#' else mod)
79+
if not nm:
80+
warn(f"Notebook '{nbname}' uses `#|export` without `#|default_exp` cell.\n"
81+
"Note nbdev2 no longer supports nbdev1 syntax. Run `nbdev_migrate` to upgrade.\n"
82+
"See https://nbdev.fast.ai/getting_started.html for more information.")
83+
return
84+
mm = mod_maker(dest=lib_path, name=nm, nb_path=nbname, is_new=bool(name) or mod=='#')
85+
mm.make(cells, all_cells, lib_path=lib_path)

nbdev/frontmatter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""A YAML and formatted-markdown frontmatter processor"""
2+
13
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/09_frontmatter.ipynb.
24

35
# %% auto 0

nbdev/maker.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Create one or more modules from selected notebook cells"""
2+
13
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/02_maker.ipynb.
24

35
# %% ../nbs/api/02_maker.ipynb 1
@@ -175,13 +177,13 @@ def _import2relative(cells, lib_name=None):
175177

176178
# %% ../nbs/api/02_maker.ipynb
177179
def _retr_mdoc(cells):
178-
"Search for `_doc_` variable, used to create module docstring"
179-
trees = L(cells).map(NbCell.parsed_).concat()
180-
for o in trees:
181-
if isinstance(o, _assign_types) and getattr(_targets(o)[0],'id',None)=='_doc_':
182-
v = try_attrs(o.value, 'value', 's') # py37 uses `ast.Str.s`
183-
return f'"""{v}"""\n\n'
184-
return ""
180+
"Search for md meta quote line, used to create module docstring"
181+
md1 = first(o for o in cells if o.cell_type=='markdown' and o.source.startswith('# '))
182+
if not md1: return ''
183+
summ = first(o for o in md1.source.splitlines() if o.startswith('> '))
184+
if not summ: return ''
185+
summ = summ.lstrip('> ').strip()
186+
return f'"""{summ}"""\n\n' if summ else ''
185187

186188
# %% ../nbs/api/02_maker.ipynb
187189
@patch

nbdev/merge.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Fix merge conflicts in jupyter notebooks"""
2+
13
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/07_merge.ipynb.
24

35
# %% auto 0

nbdev/migrate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Utilities for migrating to nbdev"""
2+
13
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/16_migrate.ipynb.
24

35
# %% auto 0

0 commit comments

Comments
 (0)