@@ -43,6 +43,9 @@ def patch_name(o):
4343 return _sym_nm (a ,o )
4444
4545# %% ../nbs/api/doclinks.ipynb 9
46+ def _nbpath2html (p ): return p .with_name (re .sub (r'\d+[a-zA-Z0-9]*_' , '' , p .name .lower ())).with_suffix ('.html' )
47+
48+ # %% ../nbs/api/doclinks.ipynb 11
4649def _get_modidx (pyfile , code_root , nbs_path ):
4750 "Get module symbol index for a Python source file"
4851 cfg = get_config ()
@@ -56,9 +59,8 @@ def _get_modidx(pyfile, code_root, nbs_path):
5659 top ,* rest = cell .splitlines () # First line is cell header
5760 nb = top .split ()[0 ]
5861 if nb != 'auto' :
59- nbpath = ((pyfile .parent )/ nb ).resolve () # NB paths are stored relative to .py file
60- nbpath = nbpath .with_name (re .sub (r'\d+[a-zA-Z0-9]*_' , '' , nbpath .name .lower ()))
61- loc = nbpath .relative_to (nbs_path ).with_suffix ('.html' )
62+ nbpath = (pyfile .parent / nb ).resolve () # NB paths are stored relative to .py file
63+ loc = _nbpath2html (nbpath .relative_to (nbs_path ))
6264
6365 def _stor (nm ):
6466 for n in L (nm ): d [f'{ mod_name } .{ n } ' ] = f'{ loc .as_posix ()} #{ n .lower ()} ' ,rel_name
@@ -69,7 +71,7 @@ def _stor(nm):
6971 if isinstance (t2 , _def_types ): _stor (f'{ tree .name } .{ t2 .name } ' )
7072 return {mod_name : d }
7173
72- # %% ../nbs/api/doclinks.ipynb 10
74+ # %% ../nbs/api/doclinks.ipynb 12
7375def _build_modidx (dest = None , nbs_path = None , skip_exists = False ):
7476 "Create _modidx.py"
7577 if dest is None : dest = get_config ().lib_path
@@ -87,7 +89,7 @@ def _build_modidx(dest=None, nbs_path=None, skip_exists=False):
8789 res ['syms' ].update (_get_modidx ((dest .parent / file ).resolve (), code_root , nbs_path = nbs_path ))
8890 idxfile .write_text ("# Autogenerated by nbdev\n \n d = " + pformat (res , width = 140 , indent = 2 , compact = True ))
8991
90- # %% ../nbs/api/doclinks.ipynb 15
92+ # %% ../nbs/api/doclinks.ipynb 17
9193@delegates (globtastic )
9294def nbglob (path = None , skip_folder_re = '^[_.]' , file_glob = '*.ipynb' , skip_file_re = '^[_.]' , key = 'nbs_path' , as_path = False , ** kwargs ):
9395 "Find all files in a directory matching an extension given a config key."
@@ -97,7 +99,7 @@ def nbglob(path=None, skip_folder_re = '^[_.]', file_glob='*.ipynb', skip_file_r
9799 skip_file_re = skip_file_re , recursive = recursive , ** kwargs )
98100 return res .map (Path ) if as_path else res
99101
100- # %% ../nbs/api/doclinks.ipynb 16
102+ # %% ../nbs/api/doclinks.ipynb 18
101103def nbglob_cli (
102104 path :str = None , # Path to notebooks
103105 symlinks :bool = False , # Follow symlinks?
@@ -111,7 +113,7 @@ def nbglob_cli(
111113 return nbglob (path , symlinks = symlinks , file_glob = file_glob , file_re = file_re , folder_re = folder_re ,
112114 skip_file_glob = skip_file_glob , skip_file_re = skip_file_re , skip_folder_re = skip_folder_re )
113115
114- # %% ../nbs/api/doclinks.ipynb 17
116+ # %% ../nbs/api/doclinks.ipynb 19
115117@call_parse
116118@delegates (nbglob_cli )
117119def nbdev_export (
@@ -124,11 +126,11 @@ def nbdev_export(
124126 add_init (get_config ().lib_path )
125127 _build_modidx ()
126128
127- # %% ../nbs/api/doclinks.ipynb 19
129+ # %% ../nbs/api/doclinks.ipynb 21
128130import importlib ,ast
129131from functools import lru_cache
130132
131- # %% ../nbs/api/doclinks.ipynb 20
133+ # %% ../nbs/api/doclinks.ipynb 22
132134def _find_mod (mod ):
133135 mp ,_ ,mr = mod .partition ('/' )
134136 spec = importlib .util .find_spec (mp )
@@ -151,7 +153,7 @@ def _get_exps(mod):
151153
152154def _lineno (sym , fname ): return _get_exps (fname ).get (sym , None ) if fname else None
153155
154- # %% ../nbs/api/doclinks.ipynb 22
156+ # %% ../nbs/api/doclinks.ipynb 24
155157def _qual_sym (s , settings ):
156158 if not isinstance (s ,tuple ): return s
157159 nb ,py = s
@@ -166,10 +168,10 @@ def _qual_syms(entries):
166168 if 'doc_host' not in settings : return entries
167169 return {'syms' : {mod :_qual_mod (d , settings ) for mod ,d in entries ['syms' ].items ()}, 'settings' :settings }
168170
169- # %% ../nbs/api/doclinks.ipynb 23
171+ # %% ../nbs/api/doclinks.ipynb 25
170172_re_backticks = re .compile (r'`([^`\s]+)`' )
171173
172- # %% ../nbs/api/doclinks.ipynb 24
174+ # %% ../nbs/api/doclinks.ipynb 26
173175@lru_cache (None )
174176class NbdevLookup :
175177 "Mapping from symbol names to docs and source URLs"
0 commit comments