Skip to content

Commit

Permalink
fixes #939
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Aug 26, 2022
1 parent c09b077 commit 5dbb3f7
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 33 deletions.
17 changes: 8 additions & 9 deletions nbdev/doclinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@ def _build_modidx(dest=None, nbs_path=None, skip_exists=False):

# %% ../nbs/09_API/04b_doclinks.ipynb 15
@delegates(globtastic, but=('file_glob', 'skip_folder_re', 'skip_file_re'))
def nbglob(path=None, skip_folder_re = '^[_.]', file_glob='*.ipynb', skip_file_re='^[_.]',
recursive=None, key='nbs_path', as_path=False, **kwargs):
def nbglob(path=None, skip_folder_re = '^[_.]', file_glob='*.ipynb', skip_file_re='^[_.]', key='nbs_path', as_path=False, **kwargs):
"Find all files in a directory matching an extension given a config key."
path = Path(path or get_config().path(key))
if recursive is None: recursive=str2bool(get_config().recursive)
recursive=str2bool(get_config().recursive)
res = globtastic(path, file_glob=file_glob, skip_folder_re=skip_folder_re,
skip_file_re=skip_file_re, recursive=recursive, **kwargs)
return res.map(Path) if as_path else res
Expand All @@ -106,8 +105,7 @@ def nbglob_cli(
folder_re:str=None, # Only enter folders matching regex
skip_file_glob:str=None, # Skip files matching glob
skip_file_re:str='^[_.]', # Skip files matching regex
skip_folder_re:str = '^[_.]', # Skip folders matching regex
recursive:bool=None): # Search subfolders too
skip_folder_re:str = '^[_.]'): # Skip folders matching regex
"Find all files in a directory matching an extension given a config key."
return nbglob(path, symlinks=symlinks, file_glob=file_glob, file_re=file_re, folder_re=folder_re,
skip_file_glob=skip_file_glob, skip_file_re=skip_file_re, skip_folder_re=skip_folder_re)
Expand All @@ -129,7 +127,7 @@ def nbdev_export(
import importlib,ast
from functools import lru_cache

# %% ../nbs/09_API/04b_doclinks.ipynb 20
# %% ../nbs/09_API/04b_doclinks.ipynb 22
def _find_mod(mod):
mp,_,mr = mod.partition('/')
loc = Path(importlib.util.find_spec(mp).origin).parent
Expand All @@ -146,9 +144,9 @@ def _get_exps(mod):
if isinstance(tree, ast.ClassDef): d.update({tree.name+"."+t2.name: t2.lineno for t2 in tree.body if isinstance(t2, _def_types)})
return d

def _lineno(sym, fname): return _get_exps(fname).get(sym.rpartition('.')[2], None) if fname else None
def _lineno(sym, fname): return _get_exps(fname).get(sym, None) if fname else None

# %% ../nbs/09_API/04b_doclinks.ipynb 22
# %% ../nbs/09_API/04b_doclinks.ipynb 24
def _qual_sym(s, settings):
if not isinstance(s,tuple): return s
nb,py = s
Expand All @@ -163,9 +161,10 @@ def _qual_syms(entries):
if 'doc_host' not in settings: return entries
return {'syms': {mod:_qual_mod(d, settings) for mod,d in entries['syms'].items()}, 'settings':settings}

# %% ../nbs/09_API/04b_doclinks.ipynb 23
# %% ../nbs/09_API/04b_doclinks.ipynb 25
_re_backticks = re.compile(r'`([^`\s]+)`')

# %% ../nbs/09_API/04b_doclinks.ipynb 26
@lru_cache(None)
class NbdevLookup:
"Mapping from symbol names to docs and source URLs"
Expand Down
82 changes: 59 additions & 23 deletions nbs/09_API/04b_doclinks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,25 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"Path('/home/jhoward/git/nbdev')"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#|export\n",
"@delegates(globtastic, but=('file_glob', 'skip_folder_re', 'skip_file_re'))\n",
"def nbglob(path=None, skip_folder_re = '^[_.]', file_glob='*.ipynb', skip_file_re='^[_.]',\n",
" recursive=None, key='nbs_path', as_path=False, **kwargs):\n",
"def nbglob(path=None, skip_folder_re = '^[_.]', file_glob='*.ipynb', skip_file_re='^[_.]', key='nbs_path', as_path=False, **kwargs):\n",
" \"Find all files in a directory matching an extension given a config key.\"\n",
" path = Path(path or get_config().path(key))\n",
" if recursive is None: recursive=str2bool(get_config().recursive)\n",
" recursive=str2bool(get_config().recursive)\n",
" res = globtastic(path, file_glob=file_glob, skip_folder_re=skip_folder_re,\n",
" skip_file_re=skip_file_re, recursive=recursive, **kwargs)\n",
" return res.map(Path) if as_path else res"
Expand All @@ -272,8 +282,7 @@
" folder_re:str=None, # Only enter folders matching regex\n",
" skip_file_glob:str=None, # Skip files matching glob\n",
" skip_file_re:str='^[_.]', # Skip files matching regex\n",
" skip_folder_re:str = '^[_.]', # Skip folders matching regex\n",
" recursive:bool=None): # Search subfolders too\n",
" skip_folder_re:str = '^[_.]'): # Skip folders matching regex\n",
" \"Find all files in a directory matching an extension given a config key.\"\n",
" return nbglob(path, symlinks=symlinks, file_glob=file_glob, file_re=file_re, folder_re=folder_re,\n",
" skip_file_glob=skip_file_glob, skip_file_re=skip_file_re, skip_folder_re=skip_folder_re)"
Expand Down Expand Up @@ -317,6 +326,35 @@
"from functools import lru_cache"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"a = Path('a/b.c')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"('a', 'b.c')"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a.parts"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -340,28 +378,18 @@
" if isinstance(tree, ast.ClassDef): d.update({tree.name+\".\"+t2.name: t2.lineno for t2 in tree.body if isinstance(t2, _def_types)})\n",
" return d\n",
"\n",
"def _lineno(sym, fname): return _get_exps(fname).get(sym.rpartition('.')[2], None) if fname else None"
"def _lineno(sym, fname): return _get_exps(fname).get(sym, None) if fname else None"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"205"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"#|hide\n",
"_lineno('urlsend', 'fastcore/net.py')"
"assert _lineno('urlsend', 'fastcore/net.py')\n",
"assert _lineno('ModuleMaker.make', 'nbdev/maker.py')"
]
},
{
Expand Down Expand Up @@ -393,8 +421,16 @@
"outputs": [],
"source": [
"#|export\n",
"_re_backticks = re.compile(r'`([^`\\s]+)`')\n",
"\n",
"_re_backticks = re.compile(r'`([^`\\s]+)`')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#|export\n",
"@lru_cache(None)\n",
"class NbdevLookup:\n",
" \"Mapping from symbol names to docs and source URLs\"\n",
Expand Down Expand Up @@ -624,7 +660,7 @@
{
"data": {
"text/plain": [
"'https:/fastai/fastcore/blob/master/fastcore/net.py#L205'"
"'https:/fastai/fastcore/blob/master/fastcore/net.py#LNone'"
]
},
"execution_count": null,
Expand Down
2 changes: 1 addition & 1 deletion nbs/09_API/13_quarto.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
"metadata": {},
"outputs": [],
"source": [
"# nbdev_sidebar(printit=True, force=True)"
"# nbdev_sidebar(printit=True)"
]
},
{
Expand Down

0 comments on commit 5dbb3f7

Please sign in to comment.