Skip to content
Open
12 changes: 8 additions & 4 deletions nbdev/doclinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .maker import *
from .export import *
from .imports import *
from .process import plaintext_file_formats

from fastcore.script import *
from fastcore.utils import *
Expand Down Expand Up @@ -116,15 +117,18 @@ def nbglob(path=None, skip_folder_re = '^[_.]', file_glob='*.ipynb', skip_file_r
"Find all files in a directory matching an extension given a config key."
path = Path(path or get_config()[key])
recursive=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)
if type(file_glob) != list: file_glob = [file_glob]
res = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a list comprehension.

for _file_glob in file_glob:
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

# %% ../nbs/api/05_doclinks.ipynb
def nbglob_cli(
path:str=None, # Path to notebooks
symlinks:bool=False, # Follow symlinks?
file_glob:str='*.ipynb', # Only include files matching glob
file_glob:str|List[str]=['*.ipynb'] + [f"*.{ext}" for ext in plaintext_file_formats], # Only include files matching glob
file_re:str=None, # Only include files matching regex
folder_re:str=None, # Only enter folders matching regex
skip_file_glob:str=None, # Skip files matching glob
Expand All @@ -138,7 +142,7 @@ def nbglob_cli(
@call_parse
@delegates(nbglob_cli)
def nbdev_export(
path:str=None, # Path or filename
path:str=None, # Path or filename,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a mistake?

procs:Param("tokens naming the export processors to use.", nargs="*", choices=optional_procs())="black_format",
**kwargs):
"Export notebooks in `path` to Python modules"
Expand Down
30 changes: 23 additions & 7 deletions nbs/api/05_doclinks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"from nbdev.maker import *\n",
"from nbdev.export import *\n",
"from nbdev.imports import *\n",
"from nbdev.process import plaintext_file_formats\n",
"\n",
"from fastcore.script import *\n",
"from fastcore.utils import *\n",
Expand Down Expand Up @@ -320,8 +321,11 @@
" \"Find all files in a directory matching an extension given a config key.\"\n",
" path = Path(path or get_config()[key])\n",
" recursive=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",
" if type(file_glob) != list: file_glob = [file_glob]\n",
" res = []\n",
" for _file_glob in file_glob:\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 @@ -335,7 +339,7 @@
"def nbglob_cli(\n",
" path:str=None, # Path to notebooks\n",
" symlinks:bool=False, # Follow symlinks?\n",
" file_glob:str='*.ipynb', # Only include files matching glob\n",
" file_glob:str|List[str]=['*.ipynb'] + [f\"*.{ext}\" for ext in plaintext_file_formats], # Only include files matching glob\n",
" file_re:str=None, # Only include files matching regex\n",
" folder_re:str=None, # Only enter folders matching regex\n",
" skip_file_glob:str=None, # Skip files matching glob\n",
Expand All @@ -357,7 +361,7 @@
"@call_parse\n",
"@delegates(nbglob_cli)\n",
"def nbdev_export(\n",
" path:str=None, # Path or filename\n",
" path:str=None, # Path or filename,\n",
" procs:Param(\"tokens naming the export processors to use.\", nargs=\"*\", choices=optional_procs())=\"black_format\",\n",
" **kwargs):\n",
" \"Export notebooks in `path` to Python modules\"\n",
Expand Down Expand Up @@ -577,7 +581,7 @@
"text/markdown": [
"---\n",
"\n",
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L226){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L231){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"\n",
"### NbdevLookup.doc\n",
"\n",
Expand All @@ -588,7 +592,7 @@
"text/plain": [
"---\n",
"\n",
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L226){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L231){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"\n",
"### NbdevLookup.doc\n",
"\n",
Expand Down Expand Up @@ -637,7 +641,19 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "AttributeError",
"evalue": "'NoneType' object has no attribute 'startswith'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[30], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[43mc\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdoc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mnumpy.array\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstartswith\u001b[49m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mhttp\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m c\u001b[38;5;241m.\u001b[39mdoc(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mNbdevLookup\u001b[39m\u001b[38;5;124m'\u001b[39m)\u001b[38;5;241m.\u001b[39mendswith(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m#nbdevlookup\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m c\u001b[38;5;241m.\u001b[39mdoc(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124marray\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
"\u001b[0;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'startswith'"
]
}
],
"source": [
"assert c.doc('numpy.array').startswith('http')\n",
"assert c.doc('NbdevLookup').endswith('#nbdevlookup')\n",
Expand Down