execnb 0.3.2__py3-none-any.whl → 0.3.4__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/shell.py +7 -0
- {execnb-0.3.2.dist-info → execnb-0.3.4.dist-info}/METADATA +22 -19
- execnb-0.3.4.dist-info/RECORD +9 -0
- {execnb-0.3.2.dist-info → execnb-0.3.4.dist-info}/WHEEL +1 -1
- execnb-0.3.2.dist-info/RECORD +0 -9
- {execnb-0.3.2.dist-info → execnb-0.3.4.dist-info}/entry_points.txt +0 -0
- {execnb-0.3.2.dist-info → execnb-0.3.4.dist-info}/licenses/LICENSE +0 -0
- {execnb-0.3.2.dist-info → execnb-0.3.4.dist-info}/top_level.txt +0 -0
execnb/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.3.
|
|
1
|
+
__version__ = "0.3.4"
|
execnb/shell.py
CHANGED
|
@@ -13,9 +13,12 @@ from fastcore.utils import *
|
|
|
13
13
|
from fastcore.meta import delegates
|
|
14
14
|
from fastcore.script import call_parse
|
|
15
15
|
from fastcore.ansi import strip_ansi
|
|
16
|
+
from fastcore.aio import enable_async_magics
|
|
16
17
|
|
|
17
18
|
import asyncio,io,multiprocessing,threading,types,traceback,builtins
|
|
18
19
|
from contextlib import contextmanager,suppress
|
|
20
|
+
from datetime import datetime,timezone
|
|
21
|
+
from time import perf_counter
|
|
19
22
|
try:
|
|
20
23
|
if sys.platform == 'darwin': multiprocessing.set_start_method("fork")
|
|
21
24
|
except RuntimeError: pass # if re-running cell
|
|
@@ -78,6 +81,7 @@ class CaptureShell(InteractiveShell):
|
|
|
78
81
|
cfg = _profile_cfg()[0] if profile else Config()
|
|
79
82
|
if not history: cfg.HistoryManager.hist_file = ':memory:'
|
|
80
83
|
super().__init__(config=cfg)
|
|
84
|
+
enable_async_magics(self)
|
|
81
85
|
self.input_transformers_cleanup.append(leading_comment_lines)
|
|
82
86
|
self.history_manager.enabled = history
|
|
83
87
|
self.timeout = timeout
|
|
@@ -286,7 +290,10 @@ def cell(self:CaptureShell, cell, stdout=True, stderr=True, verbose=False, timeo
|
|
|
286
290
|
"Run `cell`, skipping if not code, and store outputs (and the execution count) back in cell"
|
|
287
291
|
if cell.cell_type!='code': return
|
|
288
292
|
self._cell_idx = cell.idx_ + 1
|
|
293
|
+
st,t0 = datetime.now(timezone.utc),perf_counter()
|
|
289
294
|
outs = self.run(cell.source, stdout=stdout, stderr=stderr, verbose=verbose, timeout=timeout)
|
|
295
|
+
cell.metadata['execution'] = {'iopub.execute_input': st.isoformat(),
|
|
296
|
+
'shell.execute_reply': datetime.now(timezone.utc).isoformat(), 'total': perf_counter()-t0}
|
|
290
297
|
cell.outputs = _dict2obj(outs) if outs else []
|
|
291
298
|
cell.execution_count = self.execution_count-1 # the count this run used: the shell has already advanced
|
|
292
299
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: execnb
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.4
|
|
4
4
|
Summary: A description of your project
|
|
5
5
|
Author-email: Jeremy Howard <j@fast.ai>
|
|
6
|
-
License: Apache-2.0
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
7
|
Project-URL: Repository, https://github.com/AnswerDotAI/execnb/
|
|
8
8
|
Project-URL: Documentation, https://AnswerDotAI.github.io/execnb/
|
|
9
9
|
Keywords: some,keywords
|
|
@@ -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>=2.2.
|
|
18
|
+
Requires-Dist: fastcore>=2.2.34
|
|
19
19
|
Requires-Dist: ipython
|
|
20
20
|
Provides-Extra: dev
|
|
21
21
|
Requires-Dist: matplotlib; extra == "dev"
|
|
@@ -42,7 +42,7 @@ or if you use conda:
|
|
|
42
42
|
|
|
43
43
|
## How to use
|
|
44
44
|
|
|
45
|
-
Use [`CaptureShell`](https://AnswerDotAI.github.io/execnb/shell.html#captureshell) to run Jupyter code and capture notebook outputs, without running a Jupyter server (or even having it installed). The API is
|
|
45
|
+
Use [`CaptureShell`](https://AnswerDotAI.github.io/execnb/shell.html#captureshell) to run Jupyter code and capture notebook outputs, without running a Jupyter server (or even having it installed). The API is sync – each shell runs cells on its own private event loop in a background thread, so it works the same from a script, a notebook, or an async server, and cells may use top-level `await`:
|
|
46
46
|
|
|
47
47
|
``` python
|
|
48
48
|
from execnb.shell import *
|
|
@@ -52,24 +52,24 @@ from fastcore.nbio import *
|
|
|
52
52
|
|
|
53
53
|
``` python
|
|
54
54
|
s = CaptureShell()
|
|
55
|
-
|
|
55
|
+
s.run('1+1')
|
|
56
56
|
```
|
|
57
57
|
|
|
58
58
|
[{'data': {'text/plain': ['2']},
|
|
59
59
|
'metadata': {},
|
|
60
60
|
'output_type': 'execute_result',
|
|
61
|
-
'execution_count':
|
|
61
|
+
'execution_count': 1}]
|
|
62
62
|
|
|
63
63
|
To execute a notebook and save it with outputs filled in, use [`CaptureShell.execute`](https://AnswerDotAI.github.io/execnb/shell.html#captureshell.execute):
|
|
64
64
|
|
|
65
65
|
``` python
|
|
66
66
|
try:
|
|
67
|
-
|
|
67
|
+
s.execute('../tests/clean.ipynb', 'tmp.ipynb')
|
|
68
68
|
print(read_nb('tmp.ipynb').cells[1].outputs)
|
|
69
69
|
finally: Path('tmp.ipynb').unlink()
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
-
[{'name': 'stdout', 'output_type': 'stream', 'text': '1\n'}, {'data': {'text/plain': '2'}, 'execution_count':
|
|
72
|
+
[{'name': 'stdout', 'output_type': 'stream', 'text': '1\n'}, {'data': {'text/plain': '2'}, 'execution_count': 3, 'metadata': {}, 'output_type': 'execute_result'}]
|
|
73
73
|
|
|
74
74
|
You can also execute notebooks from the command line with [`exec_nb`](https://AnswerDotAI.github.io/execnb/shell.html#exec_nb):
|
|
75
75
|
|
|
@@ -77,21 +77,24 @@ You can also execute notebooks from the command line with [`exec_nb`](https://An
|
|
|
77
77
|
!exec_nb --help
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
usage: exec_nb [-h] [--dest
|
|
81
|
-
[--
|
|
80
|
+
usage: exec_nb [-h] [--dest (str)] [--exc-stop] [--inject-code (str)]
|
|
81
|
+
[--inject-path (str)] [--inject-idx (int)] [--verbose]
|
|
82
|
+
[--cell-timeout (int)]
|
|
82
83
|
src
|
|
83
84
|
|
|
84
85
|
Execute notebook from `src` and save with outputs to `dest`
|
|
85
86
|
|
|
86
87
|
positional arguments:
|
|
87
|
-
src
|
|
88
|
+
src Notebook path to read from
|
|
88
89
|
|
|
89
90
|
options:
|
|
90
|
-
-h, --help
|
|
91
|
-
--dest
|
|
92
|
-
--
|
|
93
|
-
--
|
|
94
|
-
--
|
|
95
|
-
--
|
|
96
|
-
--verbose
|
|
97
|
-
|
|
91
|
+
-h, --help show this help message and exit
|
|
92
|
+
--dest (str) Notebook path to write to (default: '')
|
|
93
|
+
--exc-stop Stop on exceptions? (default: False)
|
|
94
|
+
--inject-code (str) Code to inject into a cell
|
|
95
|
+
--inject-path (str) Path to file containing code to inject into a cell
|
|
96
|
+
--inject-idx (int) Cell to replace with `inject_code` (default: 0)
|
|
97
|
+
--verbose Show stdout/stderr during execution (default: False)
|
|
98
|
+
--cell-timeout (int) Seconds before each cell times out (None: no limit)
|
|
99
|
+
|
|
100
|
+
execnb 0.3.4
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
execnb/__init__.py,sha256=oYLGMpySamd16KLiaBTfRyrAS7_oyp-TOEHmzmeumwg,22
|
|
2
|
+
execnb/_modidx.py,sha256=MjNuUL_bi4wfGKPaqwskCCqi4at5zy9Ju2YxO5qv6L0,6165
|
|
3
|
+
execnb/shell.py,sha256=kS2Jef3OBe6d6b76L8da9MT0UpoLn64rF8HcqdGHJtc,20462
|
|
4
|
+
execnb-0.3.4.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
5
|
+
execnb-0.3.4.dist-info/METADATA,sha256=rZEey22FbjMTGnL63L0HCn7Cze8PKYfj3srM7Cnb1Rk,3407
|
|
6
|
+
execnb-0.3.4.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
7
|
+
execnb-0.3.4.dist-info/entry_points.txt,sha256=jZ8LPZCqnu4hXN_AgQpm05hVnTE-C25YK_4aiVX4i78,84
|
|
8
|
+
execnb-0.3.4.dist-info/top_level.txt,sha256=VGWmzsw8FOlT1r5TdOxaTWIAyRdclcxNdJ2r1hojf5U,7
|
|
9
|
+
execnb-0.3.4.dist-info/RECORD,,
|
execnb-0.3.2.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
execnb/__init__.py,sha256=vNiWJ14r_cw5t_7UDqDQIVZvladKFGyHH2avsLpN7Vg,22
|
|
2
|
-
execnb/_modidx.py,sha256=MjNuUL_bi4wfGKPaqwskCCqi4at5zy9Ju2YxO5qv6L0,6165
|
|
3
|
-
execnb/shell.py,sha256=RAs7b6khhpdvRe8RdaVWqiFG6_5CGFXLs7l8whfY1E4,20088
|
|
4
|
-
execnb-0.3.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
5
|
-
execnb-0.3.2.dist-info/METADATA,sha256=zjIJtSSLwiCLjiN_gfxt_sQ69ZI8xdJt1pJAoLZ8fd8,3347
|
|
6
|
-
execnb-0.3.2.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
7
|
-
execnb-0.3.2.dist-info/entry_points.txt,sha256=jZ8LPZCqnu4hXN_AgQpm05hVnTE-C25YK_4aiVX4i78,84
|
|
8
|
-
execnb-0.3.2.dist-info/top_level.txt,sha256=VGWmzsw8FOlT1r5TdOxaTWIAyRdclcxNdJ2r1hojf5U,7
|
|
9
|
-
execnb-0.3.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|