nbdev 3.0.7__tar.gz → 3.0.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {nbdev-3.0.7/nbdev.egg-info → nbdev-3.0.9}/PKG-INFO +1 -1
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/__init__.py +1 -1
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/_modidx.py +3 -5
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/cli.py +3 -3
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/config.py +12 -4
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/doclinks.py +5 -5
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/export.py +1 -32
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/processors.py +3 -9
- nbdev-3.0.9/nbdev/scrubmagics.py +13 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/test.py +5 -3
- {nbdev-3.0.7 → nbdev-3.0.9/nbdev.egg-info}/PKG-INFO +1 -1
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev.egg-info/SOURCES.txt +1 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/CONTRIBUTING.md +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/LICENSE +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/MANIFEST.in +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/README.md +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/clean.py +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/diff.py +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/extract_attachments.py +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/frontmatter.py +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/imports.py +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/maker.py +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/merge.py +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/migrate.py +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/process.py +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/qmd.py +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/quarto.py +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/release.py +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/serve.py +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/serve_drv.py +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/showdoc.py +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev/sync.py +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev.egg-info/dependency_links.txt +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev.egg-info/entry_points.txt +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev.egg-info/requires.txt +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/nbdev.egg-info/top_level.txt +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/pyproject.toml +0 -0
- {nbdev-3.0.7 → nbdev-3.0.9}/setup.cfg +0 -0
|
@@ -49,6 +49,7 @@ d = { 'settings': { 'branch': 'main',
|
|
|
49
49
|
'nbdev.config.bump_version': ('api/config.html#bump_version', 'nbdev/config.py'),
|
|
50
50
|
'nbdev.config.create_output': ('api/config.html#create_output', 'nbdev/config.py'),
|
|
51
51
|
'nbdev.config.get_config': ('api/config.html#get_config', 'nbdev/config.py'),
|
|
52
|
+
'nbdev.config.import_obj': ('api/config.html#import_obj', 'nbdev/config.py'),
|
|
52
53
|
'nbdev.config.is_nbdev': ('api/config.html#is_nbdev', 'nbdev/config.py'),
|
|
53
54
|
'nbdev.config.nbdev_create_config': ('api/config.html#nbdev_create_config', 'nbdev/config.py'),
|
|
54
55
|
'nbdev.config.read_version': ('api/config.html#read_version', 'nbdev/config.py'),
|
|
@@ -98,10 +99,7 @@ d = { 'settings': { 'branch': 'main',
|
|
|
98
99
|
'nbdev.export.ExportModuleProc._export_': ('api/export.html#exportmoduleproc._export_', 'nbdev/export.py'),
|
|
99
100
|
'nbdev.export.ExportModuleProc._exporti_': ('api/export.html#exportmoduleproc._exporti_', 'nbdev/export.py'),
|
|
100
101
|
'nbdev.export.ExportModuleProc.begin': ('api/export.html#exportmoduleproc.begin', 'nbdev/export.py'),
|
|
101
|
-
'nbdev.export.
|
|
102
|
-
'nbdev.export.nb_export': ('api/export.html#nb_export', 'nbdev/export.py'),
|
|
103
|
-
'nbdev.export.optional_procs': ('api/export.html#optional_procs', 'nbdev/export.py'),
|
|
104
|
-
'nbdev.export.scrub_magics': ('api/export.html#scrub_magics', 'nbdev/export.py')},
|
|
102
|
+
'nbdev.export.nb_export': ('api/export.html#nb_export', 'nbdev/export.py')},
|
|
105
103
|
'nbdev.extract_attachments': {},
|
|
106
104
|
'nbdev.frontmatter': { 'nbdev.frontmatter.FrontmatterProc': ('api/frontmatter.html#frontmatterproc', 'nbdev/frontmatter.py'),
|
|
107
105
|
'nbdev.frontmatter.FrontmatterProc._update': ( 'api/frontmatter.html#frontmatterproc._update',
|
|
@@ -222,7 +220,6 @@ d = { 'settings': { 'branch': 'main',
|
|
|
222
220
|
'nbdev.processors._default_exp': ('api/processors.html#_default_exp', 'nbdev/processors.py'),
|
|
223
221
|
'nbdev.processors._do_eval': ('api/processors.html#_do_eval', 'nbdev/processors.py'),
|
|
224
222
|
'nbdev.processors._get_nm': ('api/processors.html#_get_nm', 'nbdev/processors.py'),
|
|
225
|
-
'nbdev.processors._import_obj': ('api/processors.html#_import_obj', 'nbdev/processors.py'),
|
|
226
223
|
'nbdev.processors._is_showdoc': ('api/processors.html#_is_showdoc', 'nbdev/processors.py'),
|
|
227
224
|
'nbdev.processors._re_hideline': ('api/processors.html#_re_hideline', 'nbdev/processors.py'),
|
|
228
225
|
'nbdev.processors._show_docs': ('api/processors.html#_show_docs', 'nbdev/processors.py'),
|
|
@@ -333,6 +330,7 @@ d = { 'settings': { 'branch': 'main',
|
|
|
333
330
|
'nbdev.release.release_pypi': ('api/release.html#release_pypi', 'nbdev/release.py'),
|
|
334
331
|
'nbdev.release.write_conda_meta': ('api/release.html#write_conda_meta', 'nbdev/release.py'),
|
|
335
332
|
'nbdev.release.write_requirements': ('api/release.html#write_requirements', 'nbdev/release.py')},
|
|
333
|
+
'nbdev.scrubmagics': {},
|
|
336
334
|
'nbdev.serve': { 'nbdev.serve._is_qpy': ('api/serve.html#_is_qpy', 'nbdev/serve.py'),
|
|
337
335
|
'nbdev.serve._proc_file': ('api/serve.html#_proc_file', 'nbdev/serve.py'),
|
|
338
336
|
'nbdev.serve.proc_nbs': ('api/serve.html#proc_nbs', 'nbdev/serve.py')},
|
|
@@ -184,16 +184,16 @@ def watch_export(nbs:str=None, # Nb directory to watch for changes
|
|
|
184
184
|
lib = lib or (cfg.lib_path if cfg else '.')
|
|
185
185
|
if cfg and (nbs != cfg.nbs_path or lib != cfg.lib_path) and not force:
|
|
186
186
|
raise ValueError("In nbdev project. Use --force to override config.")
|
|
187
|
-
run(
|
|
187
|
+
run('nbdev-export')
|
|
188
188
|
def _export(e,lib=lib):
|
|
189
189
|
p = e.src_path
|
|
190
190
|
if (not '.ipynb_checkpoints' in p and p.endswith('.ipynb') and not Path(p).name.startswith(('tmp','.~'))):
|
|
191
191
|
if e.event_type == 'modified':
|
|
192
192
|
time.sleep(0.1)
|
|
193
|
-
try: run(f'
|
|
193
|
+
try: run(f'nb-export --lib_path {lib} "{p}"')
|
|
194
194
|
except IOError:
|
|
195
195
|
time.sleep(0.3)
|
|
196
|
-
run(f'
|
|
196
|
+
run(f'nb-export --lib_path {lib} "{p}"')
|
|
197
197
|
with fs_watchdog(_export, nbs):
|
|
198
198
|
while True: time.sleep(1)
|
|
199
199
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# %% auto #0
|
|
6
6
|
__all__ = ['pyproject_nm', 'pyproject_tmpl', 'nbdev_defaults', 'pyproj_tmpl', 'nbdev_create_config', 'ConfigToml', 'get_config',
|
|
7
7
|
'is_nbdev', 'create_output', 'show_src', 'read_version', 'set_version', 'bump_version', 'update_version',
|
|
8
|
-
'update_proj', 'add_init', 'write_cells']
|
|
8
|
+
'update_proj', 'add_init', 'import_obj', 'write_cells']
|
|
9
9
|
|
|
10
10
|
# %% ../nbs/api/01_config.ipynb #6fd14ecd
|
|
11
11
|
from datetime import datetime
|
|
@@ -16,7 +16,7 @@ from fastcore.script import *
|
|
|
16
16
|
from fastcore.style import *
|
|
17
17
|
from fastcore.xdg import *
|
|
18
18
|
|
|
19
|
-
import ast,warnings
|
|
19
|
+
import ast,importlib,warnings
|
|
20
20
|
from IPython.display import Markdown
|
|
21
21
|
from execnb.nbio import read_nb,NbCell
|
|
22
22
|
from urllib.error import HTTPError
|
|
@@ -152,7 +152,7 @@ def _load_toml(p):
|
|
|
152
152
|
|
|
153
153
|
def _has_nbdev(p):
|
|
154
154
|
"True if pyproject.toml at `p` has [tool.nbdev]"
|
|
155
|
-
try: return
|
|
155
|
+
try: return _load_toml(p).get('tool', {}).get('nbdev') is not None
|
|
156
156
|
except Exception: return False
|
|
157
157
|
|
|
158
158
|
def _find_nbdev_pyproject(path=None):
|
|
@@ -167,7 +167,8 @@ def _find_nbdev_pyproject(path=None):
|
|
|
167
167
|
|
|
168
168
|
# %% ../nbs/api/01_config.ipynb #3dac70e0
|
|
169
169
|
nbdev_defaults = dict(nbs_path='nbs', doc_path='_docs', tst_flags='notest', recursive=True, readme_nb='index.ipynb',
|
|
170
|
-
clean_ids=True, clear_all=False, put_version_in_init=True, jupyter_hooks=False,
|
|
170
|
+
clean_ids=True, clear_all=False, put_version_in_init=True, jupyter_hooks=False, branch='main',
|
|
171
|
+
doc_procs=[], export_procs=[])
|
|
171
172
|
|
|
172
173
|
_path_keys = 'lib_path', 'nbs_path', 'doc_path'
|
|
173
174
|
|
|
@@ -337,6 +338,13 @@ def add_init(path=None):
|
|
|
337
338
|
if get_config().get('put_version_in_init', True): update_version(path)
|
|
338
339
|
if get_config().get('update_pyproject', True): update_proj(path.parent)
|
|
339
340
|
|
|
341
|
+
# %% ../nbs/api/01_config.ipynb #95cebda6
|
|
342
|
+
def import_obj(s):
|
|
343
|
+
"Import and return `module:obj` string"
|
|
344
|
+
mod_nm, obj_nm = s.split(':')
|
|
345
|
+
mod = importlib.import_module(mod_nm)
|
|
346
|
+
return getattr(mod, obj_nm)
|
|
347
|
+
|
|
340
348
|
# %% ../nbs/api/01_config.ipynb #cdd05b4c
|
|
341
349
|
def write_cells(cells, hdr, file, solo_nb=False):
|
|
342
350
|
"Write `cells` to `file` along with header `hdr` (mainly for nbdev internal use)."
|
|
@@ -143,17 +143,17 @@ def nbglob_cli(
|
|
|
143
143
|
@delegates(nbglob_cli)
|
|
144
144
|
def nbdev_export(
|
|
145
145
|
path:str=None, # Path or filename
|
|
146
|
-
procs:
|
|
146
|
+
procs:str='', # Space-separated `module:name` processors to use (or set `export_procs` in pyproject.toml)
|
|
147
147
|
**kwargs):
|
|
148
148
|
"Export notebooks in `path` to Python modules"
|
|
149
149
|
if os.environ.get('IN_TEST',0): return
|
|
150
150
|
if not is_nbdev(): raise Exception('`nbdev_export` must be called from a directory within a nbdev project.')
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
cfg = get_config()
|
|
152
|
+
procs = procs.split() if procs else cfg.get('export_procs', [])
|
|
153
|
+
procs = [import_obj(p) for p in procs] if procs else None
|
|
154
154
|
files = nbglob(path=path, as_path=True, **kwargs).sorted('name')
|
|
155
155
|
for f in files: nb_export(f, procs=procs)
|
|
156
|
-
add_init(
|
|
156
|
+
add_init(cfg.lib_path)
|
|
157
157
|
_build_modidx()
|
|
158
158
|
|
|
159
159
|
# %% ../nbs/api/05_doclinks.ipynb #3134c22b
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/04_export.ipynb.
|
|
4
4
|
|
|
5
5
|
# %% auto #0
|
|
6
|
-
__all__ = ['ExportModuleProc', '
|
|
6
|
+
__all__ = ['ExportModuleProc', 'nb_export']
|
|
7
7
|
|
|
8
8
|
# %% ../nbs/api/04_export.ipynb #3b932371
|
|
9
9
|
from .config import *
|
|
@@ -33,37 +33,6 @@ class ExportModuleProc:
|
|
|
33
33
|
if cell.cell_type=='markdown' and src.startswith('# '): self.modules['#'].append(cell)
|
|
34
34
|
_exports_=_export_
|
|
35
35
|
|
|
36
|
-
# %% ../nbs/api/04_export.ipynb #6f524839
|
|
37
|
-
def black_format(cell, # Cell to format
|
|
38
|
-
force=False): # Turn black formatting on regardless of pyproject.toml
|
|
39
|
-
"Processor to format code with `black`"
|
|
40
|
-
cfg = get_config()
|
|
41
|
-
if (not cfg.black_formatting and not force) or cell.cell_type != 'code': return
|
|
42
|
-
try: import black
|
|
43
|
-
except: raise ImportError("You must install black: `pip install black` if you wish to use black formatting with nbdev")
|
|
44
|
-
else:
|
|
45
|
-
_format_str = partial(black.format_str, mode = black.Mode())
|
|
46
|
-
try: cell.source = _format_str(cell.source).strip()
|
|
47
|
-
except: pass
|
|
48
|
-
|
|
49
|
-
# %% ../nbs/api/04_export.ipynb #aed6a875
|
|
50
|
-
# includes the newline, because calling .strip() would affect all cells.
|
|
51
|
-
_magics_pattern = re.compile(r'^\s*(%%|%).*\n?', re.MULTILINE)
|
|
52
|
-
|
|
53
|
-
def scrub_magics(cell): # Cell to format
|
|
54
|
-
"Processor to remove cell magics from exported code"
|
|
55
|
-
cfg = get_config()
|
|
56
|
-
if cell.cell_type != 'code': return
|
|
57
|
-
try: cell.source = _magics_pattern.sub('', cell.source)
|
|
58
|
-
except: pass
|
|
59
|
-
|
|
60
|
-
# %% ../nbs/api/04_export.ipynb #d4a5fd8c
|
|
61
|
-
import nbdev.export
|
|
62
|
-
def optional_procs():
|
|
63
|
-
"An explicit list of processors that could be used by `nb_export`"
|
|
64
|
-
return L([p for p in nbdev.export.__all__
|
|
65
|
-
if p not in ["nb_export", "nb_export_cli", "ExportModuleProc", "optional_procs"]])
|
|
66
|
-
|
|
67
36
|
# %% ../nbs/api/04_export.ipynb #76717e36
|
|
68
37
|
def nb_export(nbname:str, # Filename of notebook
|
|
69
38
|
lib_path:str=None, # Path to destination library. If not in a nbdev project, defaults to current directory.
|
|
@@ -9,7 +9,6 @@ __all__ = ['populate_language', 'insert_warning', 'cell_lang', 'add_show_docs',
|
|
|
9
9
|
|
|
10
10
|
# %% ../nbs/api/10_processors.ipynb #2398f5ef-06d3-4890-8a54-7cf4f81f3894
|
|
11
11
|
import ast
|
|
12
|
-
import importlib
|
|
13
12
|
|
|
14
13
|
from .config import *
|
|
15
14
|
from .imports import *
|
|
@@ -261,18 +260,13 @@ class exec_show_docs(Processor):
|
|
|
261
260
|
widgets = {**old, **new, 'state': {**old.get('state', {}), **new['state']}}
|
|
262
261
|
self.nb.metadata['widgets'] = {mimetype: widgets}
|
|
263
262
|
|
|
264
|
-
# %% ../nbs/api/10_processors.ipynb #a761e07c
|
|
265
|
-
def _import_obj(s):
|
|
266
|
-
mod_nm, obj_nm = s.split(':')
|
|
267
|
-
mod = importlib.import_module(mod_nm)
|
|
268
|
-
return getattr(mod, obj_nm)
|
|
269
|
-
|
|
270
263
|
# %% ../nbs/api/10_processors.ipynb #4b450cff
|
|
271
264
|
class FilterDefaults:
|
|
272
265
|
"Override `FilterDefaults` to change which notebook processors are used"
|
|
273
266
|
def xtra_procs(self):
|
|
274
|
-
imps = get_config().get('
|
|
275
|
-
|
|
267
|
+
imps = get_config().get('doc_procs', [])
|
|
268
|
+
if isinstance(imps, str): imps = imps.split()
|
|
269
|
+
return [import_obj(o) for o in imps]
|
|
276
270
|
|
|
277
271
|
def base_procs(self):
|
|
278
272
|
return [FrontmatterProc, populate_language, add_show_docs, insert_warning,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Scrub Jupyter magics from exported code"""
|
|
2
|
+
|
|
3
|
+
__all__ = ['scrub_magics']
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
_magics_pattern = re.compile(r'^\s*(%%|%).*\n?', re.MULTILINE)
|
|
8
|
+
|
|
9
|
+
def scrub_magics(cell):
|
|
10
|
+
"Remove Jupyter magic lines (e.g. %%time, %matplotlib) from exported code cells"
|
|
11
|
+
if cell.cell_type != 'code': return
|
|
12
|
+
try: cell.source = _magics_pattern.sub('', cell.source)
|
|
13
|
+
except: pass
|
|
@@ -28,7 +28,8 @@ def test_nb(fn, # file name of notebook to test
|
|
|
28
28
|
force_flags=None, # list of flags marking cells to always run
|
|
29
29
|
do_print=False, # print completion?
|
|
30
30
|
showerr=True, # print errors to stderr?
|
|
31
|
-
basepath=None
|
|
31
|
+
basepath=None, # path to add to sys.path
|
|
32
|
+
verbose=False): # stream stdout/stderr from cells to console?
|
|
32
33
|
"Execute tests in notebook in `fn` except those with `skip_flags`"
|
|
33
34
|
if basepath: sys.path.insert(0, str(basepath))
|
|
34
35
|
if not IN_NOTEBOOK: os.environ["IN_TEST"] = '1'
|
|
@@ -49,7 +50,7 @@ def test_nb(fn, # file name of notebook to test
|
|
|
49
50
|
if do_print: print(f'Starting {fn}')
|
|
50
51
|
try:
|
|
51
52
|
with working_directory(fn.parent):
|
|
52
|
-
k.run_all(nb, exc_stop=True, preproc=_no_eval)
|
|
53
|
+
k.run_all(nb, exc_stop=True, preproc=_no_eval, verbose=verbose)
|
|
53
54
|
res = True
|
|
54
55
|
except:
|
|
55
56
|
if showerr: sys.stderr.write(k.prettytb(fname=fn)+'\n')
|
|
@@ -76,6 +77,7 @@ def nbdev_test(
|
|
|
76
77
|
do_print:bool=False, # Print start and end of each notebook
|
|
77
78
|
pause:float=0.01, # Pause time (in seconds) between notebooks to avoid race conditions
|
|
78
79
|
ignore_fname:str='.notest', # Filename that will result in siblings being ignored
|
|
80
|
+
verbose:bool=False, # Print stdout/stderr from notebook cells?
|
|
79
81
|
**kwargs):
|
|
80
82
|
"Test in parallel notebooks matching `path`, passing along `flags`"
|
|
81
83
|
skip_flags = get_config().tst_flags
|
|
@@ -90,7 +92,7 @@ def nbdev_test(
|
|
|
90
92
|
wd_pth = get_config().nbs_path
|
|
91
93
|
with working_directory(wd_pth if (wd_pth and wd_pth.exists()) else os.getcwd()):
|
|
92
94
|
results = parallel(test_nb, files, skip_flags=skip_flags, force_flags=force_flags, n_workers=n_workers,
|
|
93
|
-
basepath=get_config().config_path, pause=pause, do_print=do_print, **kw)
|
|
95
|
+
basepath=get_config().config_path, pause=pause, do_print=do_print, verbose=verbose, **kw)
|
|
94
96
|
passed,times = zip(*results)
|
|
95
97
|
if all(passed): print("Success.")
|
|
96
98
|
else:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|