execnb 0.2.7__py3-none-any.whl → 0.2.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.
- execnb/__init__.py +1 -1
- execnb/_modidx.py +1 -0
- execnb/shell.py +24 -11
- {execnb-0.2.7.dist-info → execnb-0.2.9.dist-info}/METADATA +2 -2
- execnb-0.2.9.dist-info/RECORD +9 -0
- execnb-0.2.7.dist-info/RECORD +0 -9
- {execnb-0.2.7.dist-info → execnb-0.2.9.dist-info}/WHEEL +0 -0
- {execnb-0.2.7.dist-info → execnb-0.2.9.dist-info}/entry_points.txt +0 -0
- {execnb-0.2.7.dist-info → execnb-0.2.9.dist-info}/licenses/LICENSE +0 -0
- {execnb-0.2.7.dist-info → execnb-0.2.9.dist-info}/top_level.txt +0 -0
execnb/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.2.
|
|
1
|
+
__version__ = "0.2.9"
|
execnb/_modidx.py
CHANGED
|
@@ -47,6 +47,7 @@ d = { 'settings': { 'branch': 'main',
|
|
|
47
47
|
'execnb.shell.exec_nb': ('shell.html#exec_nb', 'execnb/shell.py'),
|
|
48
48
|
'execnb.shell.find_output': ('shell.html#find_output', 'execnb/shell.py'),
|
|
49
49
|
'execnb.shell.format_exc': ('shell.html#format_exc', 'execnb/shell.py'),
|
|
50
|
+
'execnb.shell.leading_comment_lines': ('shell.html#leading_comment_lines', 'execnb/shell.py'),
|
|
50
51
|
'execnb.shell.out_error': ('shell.html#out_error', 'execnb/shell.py'),
|
|
51
52
|
'execnb.shell.out_exec': ('shell.html#out_exec', 'execnb/shell.py'),
|
|
52
53
|
'execnb.shell.out_stream': ('shell.html#out_stream', 'execnb/shell.py'),
|
execnb/shell.py
CHANGED
|
@@ -5,8 +5,8 @@ Docs: https://AnswerDotAI.github.io/execnb/shell.html.md"""
|
|
|
5
5
|
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_shell.ipynb.
|
|
6
6
|
|
|
7
7
|
# %% auto #0
|
|
8
|
-
__all__ = ['CaptureShell', 'format_exc', 'NbResult', 'render_outputs', 'find_output', 'out_exec',
|
|
9
|
-
'select_cells', 'exec_nb', 'SmartCompleter']
|
|
8
|
+
__all__ = ['leading_comment_lines', 'CaptureShell', 'format_exc', 'NbResult', 'render_outputs', 'find_output', 'out_exec',
|
|
9
|
+
'out_stream', 'out_error', 'select_cells', 'exec_nb', 'SmartCompleter']
|
|
10
10
|
|
|
11
11
|
# %% ../nbs/00_shell.ipynb #535003cf
|
|
12
12
|
from fastcore.utils import *
|
|
@@ -22,6 +22,7 @@ from traitlets.config import Config
|
|
|
22
22
|
from traitlets.config.loader import PyFileConfigLoader
|
|
23
23
|
from IPython.paths import get_ipython_dir
|
|
24
24
|
from IPython.core.interactiveshell import InteractiveShell, ExecutionInfo, ExecutionResult
|
|
25
|
+
from IPython.core.error import UsageError
|
|
25
26
|
from IPython.core.displayhook import DisplayHook
|
|
26
27
|
from IPython.utils.capture import capture_output
|
|
27
28
|
from IPython.core.completer import IPCompleter,provisionalcompleter
|
|
@@ -60,6 +61,12 @@ def _profile_cfg(name='default'):
|
|
|
60
61
|
cfg.merge(c)
|
|
61
62
|
return cfg,exts,pd
|
|
62
63
|
|
|
64
|
+
# %% ../nbs/00_shell.ipynb #62ece372
|
|
65
|
+
def leading_comment_lines(lines):
|
|
66
|
+
"Input cleanup transform: drop leading blank/comment lines when the first code line is a cell magic, which IPython otherwise misparses as a line magic"
|
|
67
|
+
i = next((i for i,l in enumerate(lines) if l.strip() and not l.lstrip().startswith('#')), 0)
|
|
68
|
+
return lines[i:] if i and lines[i].startswith('%%') else lines
|
|
69
|
+
|
|
63
70
|
# %% ../nbs/00_shell.ipynb #e3fb2bee
|
|
64
71
|
class CaptureShell(InteractiveShell):
|
|
65
72
|
displayhook_class = _CustDisplayHook
|
|
@@ -68,6 +75,7 @@ class CaptureShell(InteractiveShell):
|
|
|
68
75
|
cfg = _profile_cfg()[0] if profile else Config()
|
|
69
76
|
if not history: cfg.HistoryManager.hist_file = ':memory:'
|
|
70
77
|
super().__init__(config=cfg)
|
|
78
|
+
self.input_transformers_cleanup.append(leading_comment_lines)
|
|
71
79
|
self.history_manager.enabled = history
|
|
72
80
|
self.timeout = timeout
|
|
73
81
|
self.result,self.exc,self._cell_idx,self._fname,self._nested = None,None,None,None,False
|
|
@@ -100,8 +108,11 @@ class CaptureShell(InteractiveShell):
|
|
|
100
108
|
finally: self._nested = old
|
|
101
109
|
finally:
|
|
102
110
|
if timeout: signal.alarm(0)
|
|
111
|
+
e = result.error_in_exec or result.error_before_exec
|
|
112
|
+
if isinstance(e, UsageError) and str(e).startswith('Line magic function `%%'):
|
|
113
|
+
e.args = (f"{e} A cell magic (%%) must start the cell; remove or move the lines above it.",)
|
|
103
114
|
return AttrDict(result=result, stdout='' if semic else c.stdout, stderr=c.stderr, display_objects=c.outputs,
|
|
104
|
-
exception=
|
|
115
|
+
exception=e, quiet=semic)
|
|
105
116
|
|
|
106
117
|
def set_path(self, path):
|
|
107
118
|
"Add `path` to python path, or `path.parent` if it's a file"
|
|
@@ -334,9 +345,9 @@ def prettytb(self:CaptureShell,
|
|
|
334
345
|
return f"{type(self.exc).__name__}{fname_str}:\n{_fence}\n{cell_str}\n"
|
|
335
346
|
|
|
336
347
|
# %% ../nbs/00_shell.ipynb #de6bd9f6
|
|
337
|
-
def _is_exported(
|
|
338
|
-
def _is_noeval(
|
|
339
|
-
return 'nbdev_export'+'(' in
|
|
348
|
+
def _is_exported(cell): return cell.has_directive('export') or cell.has_directive('exports')
|
|
349
|
+
def _is_noeval(cell):
|
|
350
|
+
return 'nbdev_export'+'(' in cell.source or (cell.directive('eval') or '').lower()=='false'
|
|
340
351
|
|
|
341
352
|
def select_cells(
|
|
342
353
|
nb, # A notebook read with `read_nb`
|
|
@@ -358,8 +369,8 @@ def select_cells(
|
|
|
358
369
|
if above: cells = cells[:idx+1]
|
|
359
370
|
elif below: cells = cells[idx:]
|
|
360
371
|
else: cells = [cells[idx]]
|
|
361
|
-
if exported: cells = [o for o in cells if _is_exported(o
|
|
362
|
-
if skip_noeval: cells = [o for o in cells if not _is_noeval(o
|
|
372
|
+
if exported: cells = [o for o in cells if _is_exported(o)]
|
|
373
|
+
if skip_noeval: cells = [o for o in cells if not _is_noeval(o)]
|
|
363
374
|
return cells
|
|
364
375
|
|
|
365
376
|
# %% ../nbs/00_shell.ipynb #9c16e245
|
|
@@ -382,7 +393,8 @@ def nbrun(
|
|
|
382
393
|
below:bool=False, # Also run all cells below the match?
|
|
383
394
|
all:bool=False, # Run all code cells?
|
|
384
395
|
exported:bool=False, # Only cells with `#| export` or `#| exports`?
|
|
385
|
-
skip_noeval:bool=False # Skip `#| eval: false` and `nbdev_export` cells (like `nbdev-test`)?
|
|
396
|
+
skip_noeval:bool=False, # Skip `#| eval: false` and `nbdev_export` cells (like `nbdev-test`)?
|
|
397
|
+
stop_on_error:bool=True, # Stop after the first cell whose run errors?
|
|
386
398
|
):
|
|
387
399
|
"Run cell(s) from a notebook by id prefix, printing rendered outputs"
|
|
388
400
|
fname = ifnone(fname, getattr(self,'_nbrun_fname',None))
|
|
@@ -392,8 +404,9 @@ def nbrun(
|
|
|
392
404
|
if all or not msgids: msgids = (None,)
|
|
393
405
|
for msgid in msgids:
|
|
394
406
|
for cell in select_cells(nb, msgid, above=above, below=below, all=all, exported=exported, skip_noeval=skip_noeval):
|
|
395
|
-
|
|
396
|
-
if res: print(f'--- {cell.id} ---\n{res}')
|
|
407
|
+
outs = self.run(cell.source)
|
|
408
|
+
if res := render_text(outs): print(f'--- {cell.id} ---\n{res}')
|
|
409
|
+
if stop_on_error and any(o.get('output_type')=='error' for o in outs): return
|
|
397
410
|
|
|
398
411
|
# %% ../nbs/00_shell.ipynb #1227c8b1
|
|
399
412
|
@call_parse
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: execnb
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.9
|
|
4
4
|
Summary: A description of your project
|
|
5
5
|
Author-email: Jeremy Howard <j@fast.ai>
|
|
6
6
|
License: Apache-2.0
|
|
@@ -15,7 +15,7 @@ Classifier: Programming Language :: Python :: 3 :: Only
|
|
|
15
15
|
Requires-Python: >=3.7
|
|
16
16
|
Description-Content-Type: text/markdown
|
|
17
17
|
License-File: LICENSE
|
|
18
|
-
Requires-Dist: fastcore>=1.
|
|
18
|
+
Requires-Dist: fastcore>=2.1.2
|
|
19
19
|
Requires-Dist: ipython
|
|
20
20
|
Provides-Extra: dev
|
|
21
21
|
Requires-Dist: matplotlib; extra == "dev"
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
execnb/__init__.py,sha256=F8OVhAhMXSkvvXYgZtbPn2SG1AQC3joK4yu-FrHt81Y,22
|
|
2
|
+
execnb/_modidx.py,sha256=CGCE157AhQRJIdej9hutAZ-x6h0Y_yVA7GzkS2uC4o4,5748
|
|
3
|
+
execnb/shell.py,sha256=C3zkwwBZfRlyNHTxCBMEZbjz1jJiQlHiJoHNfU6k0OQ,20334
|
|
4
|
+
execnb-0.2.9.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
5
|
+
execnb-0.2.9.dist-info/METADATA,sha256=fcgTGT2uhXv7SudPWj-Tk-8qhCeR6vghXsOzjhzx6Ag,3456
|
|
6
|
+
execnb-0.2.9.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
7
|
+
execnb-0.2.9.dist-info/entry_points.txt,sha256=jZ8LPZCqnu4hXN_AgQpm05hVnTE-C25YK_4aiVX4i78,84
|
|
8
|
+
execnb-0.2.9.dist-info/top_level.txt,sha256=VGWmzsw8FOlT1r5TdOxaTWIAyRdclcxNdJ2r1hojf5U,7
|
|
9
|
+
execnb-0.2.9.dist-info/RECORD,,
|
execnb-0.2.7.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
execnb/__init__.py,sha256=XHypfHSPdgXFKmOdoewn7czU670gt8InhHhzlP5j_aA,22
|
|
2
|
-
execnb/_modidx.py,sha256=hpN6T1XnbTJKPSZM9ap1ovDJkLVFfUk7dBuvPkeowIY,5623
|
|
3
|
-
execnb/shell.py,sha256=lPUmDeOUO64axxYdEgYuzsxUxnIq3VtCUrxLsM2WJzY,19446
|
|
4
|
-
execnb-0.2.7.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
5
|
-
execnb-0.2.7.dist-info/METADATA,sha256=P8cCnC8W_ezWL3xcWjZSFAMuBr9VqJ6OPksy8iDmUE8,3458
|
|
6
|
-
execnb-0.2.7.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
7
|
-
execnb-0.2.7.dist-info/entry_points.txt,sha256=jZ8LPZCqnu4hXN_AgQpm05hVnTE-C25YK_4aiVX4i78,84
|
|
8
|
-
execnb-0.2.7.dist-info/top_level.txt,sha256=VGWmzsw8FOlT1r5TdOxaTWIAyRdclcxNdJ2r1hojf5U,7
|
|
9
|
-
execnb-0.2.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|