Skip to content

Commit b95cd3e

Browse files
authored
Merge pull request #1448 from fastai/is_nbdev
test if in nbdev_repo & improve `nbdev_export` err message
2 parents 906a467 + 1468008 commit b95cd3e

File tree

5 files changed

+42
-16
lines changed

5 files changed

+42
-16
lines changed

nbdev/_modidx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
'nbdev.config.config_key': ('api/config.html#config_key', 'nbdev/config.py'),
4242
'nbdev.config.create_output': ('api/config.html#create_output', 'nbdev/config.py'),
4343
'nbdev.config.get_config': ('api/config.html#get_config', 'nbdev/config.py'),
44+
'nbdev.config.is_nbdev': ('api/config.html#is_nbdev', 'nbdev/config.py'),
4445
'nbdev.config.nbdev_create_config': ('api/config.html#nbdev_create_config', 'nbdev/config.py'),
4546
'nbdev.config.show_src': ('api/config.html#show_src', 'nbdev/config.py'),
4647
'nbdev.config.update_version': ('api/config.html#update_version', 'nbdev/config.py'),

nbdev/config.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/01_config.ipynb.
44

55
# %% auto 0
6-
__all__ = ['nbdev_create_config', 'get_config', 'config_key', 'create_output', 'show_src', 'update_version', 'add_init',
7-
'write_cells']
6+
__all__ = ['nbdev_create_config', 'get_config', 'config_key', 'is_nbdev', 'create_output', 'show_src', 'update_version',
7+
'add_init', 'write_cells']
88

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

212+
# %% ../nbs/api/01_config.ipynb
213+
def is_nbdev(): return _nbdev_config_file().exists()
214+
212215
# %% ../nbs/api/01_config.ipynb
213216
def create_output(txt, mime):
214217
"Add a cell output containing `txt` of the `mime` text MIME sub-type"

nbdev/doclinks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ def nbdev_export(
143143
**kwargs):
144144
"Export notebooks in `path` to Python modules"
145145
if os.environ.get('IN_TEST',0): return
146+
if not is_nbdev(): raise Exception('`nbdev_export` must be called from a directory within a nbdev project.')
146147
if procs:
147-
import nbdev.export
148-
procs = [getattr(nbdev.export, p) for p in L(procs)]
148+
import nbdev.export
149+
procs = [getattr(nbdev.export, p) for p in L(procs)]
149150
files = nbglob(path=path, as_path=True, **kwargs).sorted('name')
150151
for f in files: nb_export(f, procs=procs)
151152
add_init(get_config().lib_path)

nbs/api/01_config.ipynb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,26 @@
596596
"## Helpers"
597597
]
598598
},
599+
{
600+
"cell_type": "code",
601+
"execution_count": null,
602+
"metadata": {},
603+
"outputs": [],
604+
"source": [
605+
"#|export\n",
606+
"def is_nbdev(): return _nbdev_config_file().exists()"
607+
]
608+
},
609+
{
610+
"cell_type": "code",
611+
"execution_count": null,
612+
"metadata": {},
613+
"outputs": [],
614+
"source": [
615+
"#|hide\n",
616+
"test_eq(is_nbdev(), True)"
617+
]
618+
},
599619
{
600620
"cell_type": "code",
601621
"execution_count": null,

nbs/api/05_doclinks.ipynb

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,10 @@
362362
" **kwargs):\n",
363363
" \"Export notebooks in `path` to Python modules\"\n",
364364
" if os.environ.get('IN_TEST',0): return\n",
365+
" if not is_nbdev(): raise Exception('`nbdev_export` must be called from a directory within a nbdev project.')\n",
365366
" if procs:\n",
366-
" import nbdev.export\n",
367-
" procs = [getattr(nbdev.export, p) for p in L(procs)]\n",
367+
" import nbdev.export\n",
368+
" procs = [getattr(nbdev.export, p) for p in L(procs)]\n",
368369
" files = nbglob(path=path, as_path=True, **kwargs).sorted('name')\n",
369370
" for f in files: nb_export(f, procs=procs)\n",
370371
" add_init(get_config().lib_path)\n",
@@ -576,24 +577,24 @@
576577
"text/markdown": [
577578
"---\n",
578579
"\n",
579-
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L216){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
580+
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L226){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
580581
"\n",
581582
"### NbdevLookup.doc\n",
582583
"\n",
583584
"> NbdevLookup.doc (sym)\n",
584585
"\n",
585-
"Link to docs for `sym`"
586+
"*Link to docs for `sym`*"
586587
],
587588
"text/plain": [
588589
"---\n",
589590
"\n",
590-
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L216){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
591+
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L226){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
591592
"\n",
592593
"### NbdevLookup.doc\n",
593594
"\n",
594595
"> NbdevLookup.doc (sym)\n",
595596
"\n",
596-
"Link to docs for `sym`"
597+
"*Link to docs for `sym`*"
597598
]
598599
},
599600
"execution_count": null,
@@ -670,24 +671,24 @@
670671
"text/markdown": [
671672
"---\n",
672673
"\n",
673-
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L221){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
674+
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L231){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
674675
"\n",
675676
"### NbdevLookup.code\n",
676677
"\n",
677678
"> NbdevLookup.code (sym)\n",
678679
"\n",
679-
"Link to source code for `sym`"
680+
"*Link to source code for `sym`*"
680681
],
681682
"text/plain": [
682683
"---\n",
683684
"\n",
684-
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L221){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
685+
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L231){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
685686
"\n",
686687
"### NbdevLookup.code\n",
687688
"\n",
688689
"> NbdevLookup.code (sym)\n",
689690
"\n",
690-
"Link to source code for `sym`"
691+
"*Link to source code for `sym`*"
691692
]
692693
},
693694
"execution_count": null,
@@ -729,7 +730,7 @@
729730
"text/markdown": [
730731
"---\n",
731732
"\n",
732-
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L238){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
733+
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L248){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
733734
"\n",
734735
"### NbdevLookup.linkify\n",
735736
"\n",
@@ -738,7 +739,7 @@
738739
"text/plain": [
739740
"---\n",
740741
"\n",
741-
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L238){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
742+
"[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L248){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
742743
"\n",
743744
"### NbdevLookup.linkify\n",
744745
"\n",

0 commit comments

Comments
 (0)