Skip to content

Commit

Permalink
Merge pull request #1448 from fastai/is_nbdev
Browse files Browse the repository at this point in the history
test if in nbdev_repo & improve `nbdev_export` err message
  • Loading branch information
jph00 authored Sep 17, 2024
2 parents 906a467 + 1468008 commit b95cd3e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 16 deletions.
1 change: 1 addition & 0 deletions nbdev/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'nbdev.config.config_key': ('api/config.html#config_key', 'nbdev/config.py'),
'nbdev.config.create_output': ('api/config.html#create_output', 'nbdev/config.py'),
'nbdev.config.get_config': ('api/config.html#get_config', 'nbdev/config.py'),
'nbdev.config.is_nbdev': ('api/config.html#is_nbdev', 'nbdev/config.py'),
'nbdev.config.nbdev_create_config': ('api/config.html#nbdev_create_config', 'nbdev/config.py'),
'nbdev.config.show_src': ('api/config.html#show_src', 'nbdev/config.py'),
'nbdev.config.update_version': ('api/config.html#update_version', 'nbdev/config.py'),
Expand Down
7 changes: 5 additions & 2 deletions nbdev/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/01_config.ipynb.

# %% auto 0
__all__ = ['nbdev_create_config', 'get_config', 'config_key', 'create_output', 'show_src', 'update_version', 'add_init',
'write_cells']
__all__ = ['nbdev_create_config', 'get_config', 'config_key', 'is_nbdev', 'create_output', 'show_src', 'update_version',
'add_init', 'write_cells']

# %% ../nbs/api/01_config.ipynb
from datetime import datetime
Expand Down Expand Up @@ -209,6 +209,9 @@ def config_key(c, default=None, path=True, missing_ok=None):
warn("`config_key` is deprecated. Use `get_config().get` or `get_config().path` instead.", DeprecationWarning)
return get_config().path(c, default) if path else get_config().get(c, default)

# %% ../nbs/api/01_config.ipynb
def is_nbdev(): return _nbdev_config_file().exists()

# %% ../nbs/api/01_config.ipynb
def create_output(txt, mime):
"Add a cell output containing `txt` of the `mime` text MIME sub-type"
Expand Down
5 changes: 3 additions & 2 deletions nbdev/doclinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ def nbdev_export(
**kwargs):
"Export notebooks in `path` to Python modules"
if os.environ.get('IN_TEST',0): return
if not is_nbdev(): raise Exception('`nbdev_export` must be called from a directory within a nbdev project.')
if procs:
import nbdev.export
procs = [getattr(nbdev.export, p) for p in L(procs)]
import nbdev.export
procs = [getattr(nbdev.export, p) for p in L(procs)]
files = nbglob(path=path, as_path=True, **kwargs).sorted('name')
for f in files: nb_export(f, procs=procs)
add_init(get_config().lib_path)
Expand Down
20 changes: 20 additions & 0 deletions nbs/api/01_config.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,26 @@
"## Helpers"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#|export\n",
"def is_nbdev(): return _nbdev_config_file().exists()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#|hide\n",
"test_eq(is_nbdev(), True)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
25 changes: 13 additions & 12 deletions nbs/api/05_doclinks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,10 @@
" **kwargs):\n",
" \"Export notebooks in `path` to Python modules\"\n",
" if os.environ.get('IN_TEST',0): return\n",
" if not is_nbdev(): raise Exception('`nbdev_export` must be called from a directory within a nbdev project.')\n",
" if procs:\n",
" import nbdev.export\n",
" procs = [getattr(nbdev.export, p) for p in L(procs)]\n",
" import nbdev.export\n",
" procs = [getattr(nbdev.export, p) for p in L(procs)]\n",
" files = nbglob(path=path, as_path=True, **kwargs).sorted('name')\n",
" for f in files: nb_export(f, procs=procs)\n",
" add_init(get_config().lib_path)\n",
Expand Down Expand Up @@ -576,24 +577,24 @@
"text/markdown": [
"---\n",
"\n",
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L216){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L226){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"\n",
"### NbdevLookup.doc\n",
"\n",
"> NbdevLookup.doc (sym)\n",
"\n",
"Link to docs for `sym`"
"*Link to docs for `sym`*"
],
"text/plain": [
"---\n",
"\n",
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L216){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L226){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"\n",
"### NbdevLookup.doc\n",
"\n",
"> NbdevLookup.doc (sym)\n",
"\n",
"Link to docs for `sym`"
"*Link to docs for `sym`*"
]
},
"execution_count": null,
Expand Down Expand Up @@ -670,24 +671,24 @@
"text/markdown": [
"---\n",
"\n",
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L221){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.code\n",
"\n",
"> NbdevLookup.code (sym)\n",
"\n",
"Link to source code for `sym`"
"*Link to source code for `sym`*"
],
"text/plain": [
"---\n",
"\n",
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L221){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.code\n",
"\n",
"> NbdevLookup.code (sym)\n",
"\n",
"Link to source code for `sym`"
"*Link to source code for `sym`*"
]
},
"execution_count": null,
Expand Down Expand Up @@ -729,7 +730,7 @@
"text/markdown": [
"---\n",
"\n",
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L238){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L248){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"\n",
"### NbdevLookup.linkify\n",
"\n",
Expand All @@ -738,7 +739,7 @@
"text/plain": [
"---\n",
"\n",
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L238){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L248){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
"\n",
"### NbdevLookup.linkify\n",
"\n",
Expand Down

0 comments on commit b95cd3e

Please sign in to comment.