execnb 0.2.2__py3-none-any.whl → 0.2.3__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.
- execnb/__init__.py +1 -1
- execnb/_modidx.py +5 -1
- execnb/shell.py +66 -12
- {execnb-0.2.2.dist-info → execnb-0.2.3.dist-info}/METADATA +1 -1
- execnb-0.2.3.dist-info/RECORD +9 -0
- execnb-0.2.2.dist-info/RECORD +0 -9
- {execnb-0.2.2.dist-info → execnb-0.2.3.dist-info}/WHEEL +0 -0
- {execnb-0.2.2.dist-info → execnb-0.2.3.dist-info}/entry_points.txt +0 -0
- {execnb-0.2.2.dist-info → execnb-0.2.3.dist-info}/licenses/LICENSE +0 -0
- {execnb-0.2.2.dist-info → execnb-0.2.3.dist-info}/top_level.txt +0 -0
execnb/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.2.
|
|
1
|
+
__version__ = "0.2.3"
|
execnb/_modidx.py
CHANGED
|
@@ -12,6 +12,8 @@ d = { 'settings': { 'branch': 'main',
|
|
|
12
12
|
'execnb.shell.CaptureShell.complete': ('shell.html#captureshell.complete', 'execnb/shell.py'),
|
|
13
13
|
'execnb.shell.CaptureShell.enable_gui': ('shell.html#captureshell.enable_gui', 'execnb/shell.py'),
|
|
14
14
|
'execnb.shell.CaptureShell.execute': ('shell.html#captureshell.execute', 'execnb/shell.py'),
|
|
15
|
+
'execnb.shell.CaptureShell.nbopen': ('shell.html#captureshell.nbopen', 'execnb/shell.py'),
|
|
16
|
+
'execnb.shell.CaptureShell.nbrun': ('shell.html#captureshell.nbrun', 'execnb/shell.py'),
|
|
15
17
|
'execnb.shell.CaptureShell.prettytb': ('shell.html#captureshell.prettytb', 'execnb/shell.py'),
|
|
16
18
|
'execnb.shell.CaptureShell.run': ('shell.html#captureshell.run', 'execnb/shell.py'),
|
|
17
19
|
'execnb.shell.CaptureShell.run_all': ('shell.html#captureshell.run_all', 'execnb/shell.py'),
|
|
@@ -32,6 +34,7 @@ d = { 'settings': { 'branch': 'main',
|
|
|
32
34
|
'execnb/shell.py'),
|
|
33
35
|
'execnb.shell._false': ('shell.html#_false', 'execnb/shell.py'),
|
|
34
36
|
'execnb.shell._format_mimedata': ('shell.html#_format_mimedata', 'execnb/shell.py'),
|
|
37
|
+
'execnb.shell._is_exported': ('shell.html#_is_exported', 'execnb/shell.py'),
|
|
35
38
|
'execnb.shell._mk_out': ('shell.html#_mk_out', 'execnb/shell.py'),
|
|
36
39
|
'execnb.shell._out_exc': ('shell.html#_out_exc', 'execnb/shell.py'),
|
|
37
40
|
'execnb.shell._out_nb': ('shell.html#_out_nb', 'execnb/shell.py'),
|
|
@@ -44,4 +47,5 @@ d = { 'settings': { 'branch': 'main',
|
|
|
44
47
|
'execnb.shell.out_error': ('shell.html#out_error', 'execnb/shell.py'),
|
|
45
48
|
'execnb.shell.out_exec': ('shell.html#out_exec', 'execnb/shell.py'),
|
|
46
49
|
'execnb.shell.out_stream': ('shell.html#out_stream', 'execnb/shell.py'),
|
|
47
|
-
'execnb.shell.render_outputs': ('shell.html#render_outputs', 'execnb/shell.py')
|
|
50
|
+
'execnb.shell.render_outputs': ('shell.html#render_outputs', 'execnb/shell.py'),
|
|
51
|
+
'execnb.shell.select_cells': ('shell.html#select_cells', 'execnb/shell.py')}}}
|
execnb/shell.py
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
"""A shell for running notebook code without a notebook server
|
|
1
|
+
"""A shell for running notebook code without a notebook server
|
|
2
|
+
|
|
3
|
+
Docs: https://AnswerDotAI.github.io/execnbshell.html.md"""
|
|
2
4
|
|
|
3
5
|
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_shell.ipynb.
|
|
4
6
|
|
|
5
7
|
# %% auto #0
|
|
6
8
|
__all__ = ['CaptureShell', 'format_exc', 'NbResult', 'render_outputs', 'find_output', 'out_exec', 'out_stream', 'out_error',
|
|
7
|
-
'exec_nb', 'SmartCompleter']
|
|
9
|
+
'select_cells', 'exec_nb', 'SmartCompleter']
|
|
8
10
|
|
|
9
11
|
# %% ../nbs/00_shell.ipynb #535003cf
|
|
10
12
|
from fastcore.utils import *
|
|
@@ -55,7 +57,7 @@ class CaptureShell(InteractiveShell):
|
|
|
55
57
|
self.result,self.exc = None,None
|
|
56
58
|
if path: self.set_path(path)
|
|
57
59
|
self.display_formatter.active = True
|
|
58
|
-
if not
|
|
60
|
+
if not in_notebook(): InteractiveShell._instance = self
|
|
59
61
|
if mpl_format:
|
|
60
62
|
try: from matplotlib_inline.backend_inline import set_matplotlib_formats
|
|
61
63
|
except ImportError: set_matplotlib_formats = None
|
|
@@ -234,15 +236,16 @@ def out_error(outp):
|
|
|
234
236
|
def _false(o): return False
|
|
235
237
|
|
|
236
238
|
@patch
|
|
237
|
-
def run_all(
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
239
|
+
def run_all(
|
|
240
|
+
self:CaptureShell,
|
|
241
|
+
nb, # A notebook read with `nbclient` or `read_nb`
|
|
242
|
+
exc_stop:bool=False, # Stop on exceptions?
|
|
243
|
+
preproc:callable=_false, # Called before each cell is executed
|
|
244
|
+
postproc:callable=_false, # Called after each cell is executed
|
|
245
|
+
inject_code:str|None=None, # Code to inject into a cell
|
|
246
|
+
inject_idx:int=0, # Cell to replace with `inject_code`
|
|
247
|
+
verbose:bool=False # Show stdout/stderr during execution
|
|
248
|
+
):
|
|
246
249
|
"Run all cells in `nb`, stopping at first exception if `exc_stop`"
|
|
247
250
|
if inject_code is not None: nb.cells[inject_idx].source = inject_code
|
|
248
251
|
for cell in nb.cells:
|
|
@@ -285,6 +288,57 @@ def prettytb(self:CaptureShell,
|
|
|
285
288
|
fname_str = f' in {fname}' if fname else ''
|
|
286
289
|
return f"{type(self.exc).__name__}{fname_str}:\n{_fence}\n{cell_str}\n"
|
|
287
290
|
|
|
291
|
+
# %% ../nbs/00_shell.ipynb #de6bd9f6
|
|
292
|
+
def _is_exported(src): return bool(re.search(r'^\s*#\|\s*exports?\b', src, flags=re.M))
|
|
293
|
+
|
|
294
|
+
def select_cells(
|
|
295
|
+
nb, # A notebook read with `read_nb`
|
|
296
|
+
msgid:str=None, # Cell id prefix to match
|
|
297
|
+
above:bool=False, # Include the matched cell and all cells above it?
|
|
298
|
+
below:bool=False, # Include the matched cell and all cells below it?
|
|
299
|
+
all:bool=False, # Include all code cells (ignores `msgid`)?
|
|
300
|
+
exported:bool=False # Only cells with `#| export` or `#| exports`?
|
|
301
|
+
):
|
|
302
|
+
"Select code cells from `nb` by cell id prefix"
|
|
303
|
+
cells = [o for o in nb.cells if o.cell_type=='code']
|
|
304
|
+
if not all:
|
|
305
|
+
if not msgid: raise ValueError('`msgid` required unless `all=True`')
|
|
306
|
+
idx = first(i for i,o in enumerate(cells) if str(o.id).startswith(msgid))
|
|
307
|
+
if idx is None: raise ValueError(f'No code cell id starting with {msgid!r}')
|
|
308
|
+
if above: cells = cells[:idx+1]
|
|
309
|
+
elif below: cells = cells[idx:]
|
|
310
|
+
else: cells = [cells[idx]]
|
|
311
|
+
if exported: cells = [o for o in cells if _is_exported(o.source)]
|
|
312
|
+
return cells
|
|
313
|
+
|
|
314
|
+
# %% ../nbs/00_shell.ipynb #9c16e245
|
|
315
|
+
from fastcore.nbio import render_text
|
|
316
|
+
|
|
317
|
+
# %% ../nbs/00_shell.ipynb #ec223d10
|
|
318
|
+
@patch
|
|
319
|
+
def nbopen(self:CaptureShell, fname:str|Path):
|
|
320
|
+
"Set the default notebook for `nbrun`"
|
|
321
|
+
self._nbrun_fname = Path(fname)
|
|
322
|
+
|
|
323
|
+
@patch
|
|
324
|
+
def nbrun(
|
|
325
|
+
self:CaptureShell,
|
|
326
|
+
msgid:str=None, # Cell id prefix to run
|
|
327
|
+
fname:str|Path=None, # Notebook path (defaults to last `nbopen`)
|
|
328
|
+
above:bool=False, # Also run all cells above the match?
|
|
329
|
+
below:bool=False, # Also run all cells below the match?
|
|
330
|
+
all:bool=False, # Run all code cells?
|
|
331
|
+
exported:bool=False # Only cells with `#| export` or `#| exports`?
|
|
332
|
+
):
|
|
333
|
+
"Run cell(s) from a notebook by id prefix, printing rendered outputs"
|
|
334
|
+
fname = ifnone(fname, getattr(self,'_nbrun_fname',None))
|
|
335
|
+
if not fname: raise ValueError('No `fname` passed and no notebook opened with `nbopen`')
|
|
336
|
+
self.nbopen(fname)
|
|
337
|
+
nb = read_nb(fname)
|
|
338
|
+
for cell in select_cells(nb, msgid, above=above, below=below, all=all, exported=exported):
|
|
339
|
+
res = render_text(self.run(cell.source))
|
|
340
|
+
if res: print(f'--- {cell.id} ---\n{res}')
|
|
341
|
+
|
|
288
342
|
# %% ../nbs/00_shell.ipynb #1227c8b1
|
|
289
343
|
@call_parse
|
|
290
344
|
def exec_nb(
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
execnb/__init__.py,sha256=PNiDER4qM19h9zdsdfgKt2_dT4WgYK7EguJ8RU2qA_g,22
|
|
2
|
+
execnb/_modidx.py,sha256=1X5wgXhlgj9-9iG5SRHERvBj1S9mzvKbBPNPynQmu8g,5280
|
|
3
|
+
execnb/shell.py,sha256=RX8DcZEzc5uaMk899EVIE4wVxIBMTJETz5PP5iahxi8,16690
|
|
4
|
+
execnb-0.2.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
5
|
+
execnb-0.2.3.dist-info/METADATA,sha256=-nqjhTTrQ_vEqOcejq0Y2JwaLbfRWGSWXJwqV1kUJLk,3461
|
|
6
|
+
execnb-0.2.3.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
7
|
+
execnb-0.2.3.dist-info/entry_points.txt,sha256=jZ8LPZCqnu4hXN_AgQpm05hVnTE-C25YK_4aiVX4i78,84
|
|
8
|
+
execnb-0.2.3.dist-info/top_level.txt,sha256=VGWmzsw8FOlT1r5TdOxaTWIAyRdclcxNdJ2r1hojf5U,7
|
|
9
|
+
execnb-0.2.3.dist-info/RECORD,,
|
execnb-0.2.2.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
execnb/__init__.py,sha256=m6kyaNpwBcP1XYcqrelX2oS3PJuOnElOcRdBa9pEb8c,22
|
|
2
|
-
execnb/_modidx.py,sha256=aCCCo-JWXL9co-Zrpp3UJvIVGzf_hYYv7DvklFBzQP4,4826
|
|
3
|
-
execnb/shell.py,sha256=RtnB_-1S2fJ2-EJb3QG3snmaPksa77ok0WFrbz2jOsU,14482
|
|
4
|
-
execnb-0.2.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
5
|
-
execnb-0.2.2.dist-info/METADATA,sha256=2UsDr6Nmi1yO4mLQkF9wLCKkbI_ff-jmn0C0Ym_cr9U,3461
|
|
6
|
-
execnb-0.2.2.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
7
|
-
execnb-0.2.2.dist-info/entry_points.txt,sha256=jZ8LPZCqnu4hXN_AgQpm05hVnTE-C25YK_4aiVX4i78,84
|
|
8
|
-
execnb-0.2.2.dist-info/top_level.txt,sha256=VGWmzsw8FOlT1r5TdOxaTWIAyRdclcxNdJ2r1hojf5U,7
|
|
9
|
-
execnb-0.2.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|