Skip to content

Commit 5ed5ad5

Browse files
committed
implemented suggested change
1 parent fd9103c commit 5ed5ad5

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

nbdev/doclinks.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def nbglob(path=None, skip_folder_re = '^[_.]', file_glob='*.ipynb', skip_file_r
109109
res = res.map(Path) if as_path else res
110110
return res
111111

112-
# %% ../nbs/api/doclinks.ipynb 22
112+
# %% ../nbs/api/doclinks.ipynb 21
113113
def nbglob_cli(
114114
path:str=None, # Path to notebooks
115115
symlinks:bool=False, # Follow symlinks?
@@ -123,24 +123,24 @@ def nbglob_cli(
123123
return nbglob(path, symlinks=symlinks, file_glob=file_glob, file_re=file_re, folder_re=folder_re,
124124
skip_file_glob=skip_file_glob, skip_file_re=skip_file_re, skip_folder_re=skip_folder_re)
125125

126-
# %% ../nbs/api/doclinks.ipynb 23
126+
# %% ../nbs/api/doclinks.ipynb 22
127127
@call_parse
128128
@delegates(nbglob_cli)
129129
def nbdev_export(
130130
path:str=None, # Path or filename
131131
**kwargs):
132132
"Export notebooks in `path` to Python modules"
133133
if os.environ.get('IN_TEST',0): return
134-
files = nbglob(path=path, **kwargs)#.sorted(lambda path_str: Path(path_str).name)
134+
files = nbglob(path=path, as_path=True, **kwargs).sorted('name')
135135
for f in files: nb_export(f)
136136
add_init(get_config().lib_path)
137137
_build_modidx()
138138

139-
# %% ../nbs/api/doclinks.ipynb 27
139+
# %% ../nbs/api/doclinks.ipynb 26
140140
import importlib,ast
141141
from functools import lru_cache
142142

143-
# %% ../nbs/api/doclinks.ipynb 28
143+
# %% ../nbs/api/doclinks.ipynb 27
144144
def _find_mod(mod):
145145
mp,_,mr = mod.partition('/')
146146
spec = importlib.util.find_spec(mp)
@@ -163,7 +163,7 @@ def _get_exps(mod):
163163

164164
def _lineno(sym, fname): return _get_exps(fname).get(sym, None) if fname else None
165165

166-
# %% ../nbs/api/doclinks.ipynb 30
166+
# %% ../nbs/api/doclinks.ipynb 29
167167
def _qual_sym(s, settings):
168168
if not isinstance(s,tuple): return s
169169
nb,py = s
@@ -178,10 +178,10 @@ def _qual_syms(entries):
178178
if 'doc_host' not in settings: return entries
179179
return {'syms': {mod:_qual_mod(d, settings) for mod,d in entries['syms'].items()}, 'settings':settings}
180180

181-
# %% ../nbs/api/doclinks.ipynb 31
181+
# %% ../nbs/api/doclinks.ipynb 30
182182
_re_backticks = re.compile(r'`([^`\s]+)`')
183183

184-
# %% ../nbs/api/doclinks.ipynb 32
184+
# %% ../nbs/api/doclinks.ipynb 31
185185
@lru_cache(None)
186186
class NbdevLookup:
187187
"Mapping from symbol names to docs and source URLs"

nbs/api/doclinks.ipynb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@
351351
" **kwargs):\n",
352352
" \"Export notebooks in `path` to Python modules\"\n",
353353
" if os.environ.get('IN_TEST',0): return\n",
354-
" files = sorted(nbglob(path=path, **kwargs), key=lambda path_str: Path(path_str).name)\n",
354+
" files = nbglob(path=path, as_path=True, **kwargs).sorted('name')\n",
355355
" for f in files: nb_export(f)\n",
356356
" add_init(get_config().lib_path)\n",
357357
" _build_modidx()"
@@ -377,27 +377,29 @@
377377
" pass\n",
378378
"\n",
379379
"def nb_export_mock(nb_path: str):\n",
380-
" assert nb_path==expected_order.pop()\n",
380+
" expected = expected_order.pop()\n",
381+
" assert nb_path==expected, f'Expected {expected}, got {nb_path}'\n",
381382
" \n",
382383
" # escape from the outer function as the tests are done\n",
383384
" if not expected_order:\n",
384385
" raise EscapeException()\n",
385386
" \n",
386-
"\n",
387+
"# replace those functions by mocks, saving the original objects\n",
387388
"nbglob_save = copy(nbglob)\n",
388389
"nb_export_save = copy(nb_export)\n",
389390
"\n",
390-
"nbglob = lambda *args, **kwargs: ['../../8.ipynb', 'api/3.ipynb', '4.ipynb']\n",
391+
"nbglob = lambda *args, **kwargs: L(['../../8.ipynb', 'api/3.ipynb', '4.ipynb']).map(Path)\n",
391392
"\n",
392-
"expected_order = ['api/3.ipynb', '4.ipynb', '../../8.ipynb']\n",
393-
"expected_order.reverse()\n",
393+
"expected_order = reversed(L(['api/3.ipynb', '4.ipynb', '../../8.ipynb']).map(Path))\n",
394+
"#expected_order.reverse()\n",
394395
"nb_export = nb_export_mock\n",
395396
"\n",
396397
"try:\n",
397398
" nbdev_export()\n",
398399
"except EscapeException:\n",
399400
" pass # this silences the exception used to end nbdev_export early\n",
400401
"\n",
402+
"# restore original objects to make sure the notebook runs as intended\n",
401403
"nbglob = nbglob_save\n",
402404
"nb_export = nb_export_save"
403405
]

0 commit comments

Comments
 (0)