nbdev 3.0.7__py3-none-any.whl → 3.0.9__py3-none-any.whl

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/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "3.0.7"
1
+ __version__ = "3.0.9"
2
2
 
3
3
  from .doclinks import nbdev_export
4
4
  from .showdoc import show_doc
nbdev/_modidx.py CHANGED
@@ -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.black_format': ('api/export.html#black_format', 'nbdev/export.py'),
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')},
nbdev/cli.py CHANGED
@@ -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(f'nbdev_export')
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'nb_export --lib_path {lib} "{p}"')
193
+ try: run(f'nb-export --lib_path {lib} "{p}"')
194
194
  except IOError:
195
195
  time.sleep(0.3)
196
- run(f'nb_export --lib_path {lib} "{p}"')
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
 
nbdev/config.py CHANGED
@@ -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 bool(_load_toml(p).get('tool', {}).get('nbdev', {}))
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, black_formatting=False, branch='main')
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)."
nbdev/doclinks.py CHANGED
@@ -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:Param("tokens naming the export processors to use.", nargs="*", choices=optional_procs())="black_format",
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
- if procs:
152
- import nbdev.export
153
- procs = [getattr(nbdev.export, p) for p in L(procs)]
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(get_config().lib_path)
156
+ add_init(cfg.lib_path)
157
157
  _build_modidx()
158
158
 
159
159
  # %% ../nbs/api/05_doclinks.ipynb #3134c22b
nbdev/export.py CHANGED
@@ -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', 'black_format', 'scrub_magics', 'optional_procs', 'nb_export']
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.
nbdev/processors.py CHANGED
@@ -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('procs', '').split()
275
- return [_import_obj(o) for o in imps]
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,
nbdev/scrubmagics.py ADDED
@@ -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
nbdev/test.py CHANGED
@@ -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): # path to add to sys.path
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:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nbdev
3
- Version: 3.0.7
3
+ Version: 3.0.9
4
4
  Summary: Create delightful software with Jupyter Notebooks
5
5
  Author-email: "Jeremy Howard and the fast.ai community" <j@fast.ai>
6
6
  License: Apache-2.0
@@ -1,11 +1,11 @@
1
- nbdev/__init__.py,sha256=R0jqAgtza_duNsesrGsCQEtjZAcArXUUOpzBmf9Ps4g,89
2
- nbdev/_modidx.py,sha256=7jB1wx0EmQtah_L-jwRW360KwP02VB-TOuK9qY2o3ZI,40082
1
+ nbdev/__init__.py,sha256=a21H1qIzdDiM7kLL551O4AKTkJVlIRK_AH5rWOCjG_Y,89
2
+ nbdev/_modidx.py,sha256=Y1-yq_wlSkARimmnPO4eJ9DZX-1fortFw63a3G8OOZs,39761
3
3
  nbdev/clean.py,sha256=Ai83xeFJuhYva_BRGm00PhQsQtUv4_Lnp_pxSMfd4n8,9665
4
- nbdev/cli.py,sha256=ZYJdR5npjv1kbyJrsWLycgzaAES8tR41mCHhDqdoY54,7772
5
- nbdev/config.py,sha256=N2SjU3Clm_IVfjUfzJIqFsyeE1v_cS3epQD4L-UEzug,14773
4
+ nbdev/cli.py,sha256=bCLV3JCfNRBZRwVfLX3kw25p7iEetMzow3_zX2-nxDo,7771
5
+ nbdev/config.py,sha256=iLDTEeFu10zbwbd4oZhsiiO9lQtobpUw07HVUXQtTX8,15024
6
6
  nbdev/diff.py,sha256=8vzFbmk8jmn4LW66wXEDJVxsJTf4eegNMbBVV4jI708,3794
7
- nbdev/doclinks.py,sha256=oSvmFibewmC3vNOrNLNzcOU7Fv6ZaJPTcQx0h9AMWeM,12829
8
- nbdev/export.py,sha256=7Lg9MZXlp2YVxpODpe8EuNtDJcz7B_8U0lxEGbq1B3k,4040
7
+ nbdev/doclinks.py,sha256=x4HFqPdONrwAEg2fcRqz2uNJIHWC-G0t0AYWMmP4eqA,12864
8
+ nbdev/export.py,sha256=MJZqR8GlWXbK7vDwxWtZys9LgZXdyOrRIfv8jLq_q8M,2646
9
9
  nbdev/extract_attachments.py,sha256=O4mS4EFIOXL_yQ3jmsnBStrWxGR_nPNvxLYXHtLeimw,2208
10
10
  nbdev/frontmatter.py,sha256=CdJj6B1NyodH--uOCfWhGK0vI7gnKp-i2EzKce47kQQ,2820
11
11
  nbdev/imports.py,sha256=f5Ynco14hsJyFCf43-uP_YARMhHADe6lM-20Mc_vXhw,95
@@ -13,18 +13,19 @@ nbdev/maker.py,sha256=OG0l-L-_zzErA5boWpt-0Ozi8eZU_2SSbY_-peo13_E,10011
13
13
  nbdev/merge.py,sha256=WOjbqKwDfNK16L9P-eZ-IPUTgC1brOWg6jaKfDziDIc,4432
14
14
  nbdev/migrate.py,sha256=kjfYEigg9yMCERrblWM8xV_igpMPTXCSk1yo5k_N-LQ,12888
15
15
  nbdev/process.py,sha256=cSKAdQ-KDPv6UNLqii61SnmFsw8qmcY-YwBPUbwRd18,6163
16
- nbdev/processors.py,sha256=SL4Y4ha1ZQU-dV1nZyyb68viq0X2tE2PfBX26_LEzYY,12364
16
+ nbdev/processors.py,sha256=tVpUIvEQT1S-2TfVGQ_5ReWeSHtvL3F_uncOl3gCZ60,12221
17
17
  nbdev/qmd.py,sha256=4_paV81SjRh2TmDS5tyu8Y2TW1X_yg0PYGAi6fOw3ek,3129
18
18
  nbdev/quarto.py,sha256=2uxekOFtFJ47NalegwLoZw6Jd-C3gf5BJWhHsraf2J0,14126
19
19
  nbdev/release.py,sha256=KbnwAeNer9zVCFXR6C3ZmO-Ggb8PTOMcNazzbGLDkIk,14632
20
+ nbdev/scrubmagics.py,sha256=vDPd71vEAc9S3SeKCKHnCGb7lv1NmatQU9U3mv5DPoA,376
20
21
  nbdev/serve.py,sha256=UQD30QsO3KFhN95kcLTwXyXcg6GrrpFP8Ek5OCcKIRs,3191
21
22
  nbdev/serve_drv.py,sha256=IZ2acem_KKsXYYe0iUECiR_orkYLBkT1ZG_258ZS7SQ,657
22
23
  nbdev/showdoc.py,sha256=rgVpHGVQi14RBdLYnh3ukPPG9EEKGyTMW_zGAH7HM7o,2657
23
24
  nbdev/sync.py,sha256=eMYZYzu3RMDWjY-apr2TyzB7cTEB9v5-svF_Z--xyj8,3391
24
- nbdev/test.py,sha256=KBJL4dJjxaGGqKqaQONnLP-ugX79RV4B0TDUG3MnHnw,4579
25
- nbdev-3.0.7.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
26
- nbdev-3.0.7.dist-info/METADATA,sha256=MkFbPB0p2s5Qtcpm4JFCNzmaWeOBNxCx7OCmWikPcB0,11775
27
- nbdev-3.0.7.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
28
- nbdev-3.0.7.dist-info/entry_points.txt,sha256=xA-m1VqUYaBAfOtq_zYrGQQ_0C7k0004LbTpg1gQcZA,1511
29
- nbdev-3.0.7.dist-info/top_level.txt,sha256=3cWYLMuaXsZjz3TQRGEkWGs9Z8ieEDmYcq8TZS3y3vU,6
30
- nbdev-3.0.7.dist-info/RECORD,,
25
+ nbdev/test.py,sha256=LU5j59xrfh5fxYRpZs9KtIAz0OJUKR7Wm5l-pkPNXm8,4754
26
+ nbdev-3.0.9.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
27
+ nbdev-3.0.9.dist-info/METADATA,sha256=Ifopg6am89RVqHVVht9GVkUGwl6mg49eEgH5YlqXQng,11775
28
+ nbdev-3.0.9.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
29
+ nbdev-3.0.9.dist-info/entry_points.txt,sha256=xA-m1VqUYaBAfOtq_zYrGQQ_0C7k0004LbTpg1gQcZA,1511
30
+ nbdev-3.0.9.dist-info/top_level.txt,sha256=3cWYLMuaXsZjz3TQRGEkWGs9Z8ieEDmYcq8TZS3y3vU,6
31
+ nbdev-3.0.9.dist-info/RECORD,,
File without changes