execnb 0.2.0__tar.gz → 0.2.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: execnb
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: A description of your project
5
5
  Author-email: Jeremy Howard <j@fast.ai>
6
6
  License: Apache-2.0
@@ -53,9 +53,9 @@ to run Jupyter code and capture notebook outputs, without running a
53
53
  Jupyter server (or even having it installed):
54
54
 
55
55
  ``` python
56
- from execnb.nbio import *
57
56
  from execnb.shell import *
58
57
  from fastcore.utils import *
58
+ from fastcore.nbio import *
59
59
  ```
60
60
 
61
61
  ``` python
@@ -66,7 +66,7 @@ s.run('1+1')
66
66
  [{'data': {'text/plain': ['2']},
67
67
  'metadata': {},
68
68
  'output_type': 'execute_result',
69
- 'execution_count': 1}]
69
+ 'execution_count': None}]
70
70
 
71
71
  To execute a notebook and save it with outputs filled in, use
72
72
  [`CaptureShell.execute`](https://AnswerDotAI.github.io/execnb/shell.html#captureshell.execute):
@@ -78,7 +78,7 @@ try:
78
78
  finally: Path('tmp.ipynb').unlink()
79
79
  ```
80
80
 
81
- [{'name': 'stdout', 'output_type': 'stream', 'text': ['1\n']}, {'data': {'text/plain': ['2']}, 'execution_count': 3, 'metadata': {}, 'output_type': 'execute_result'}]
81
+ [{'name': 'stdout', 'output_type': 'stream', 'text': ['1\n']}, {'data': {'text/plain': ['2']}, 'execution_count': None, 'metadata': {}, 'output_type': 'execute_result'}]
82
82
 
83
83
  You can also execute notebooks from the command line with
84
84
  [`exec_nb`](https://AnswerDotAI.github.io/execnb/shell.html#exec_nb):
@@ -88,8 +88,7 @@ You can also execute notebooks from the command line with
88
88
  ```
89
89
 
90
90
  usage: exec_nb [-h] [--dest DEST] [--exc_stop] [--inject_code INJECT_CODE]
91
- [--inject_path INJECT_PATH] [--inject_idx INJECT_IDX]
92
- [--verbose]
91
+ [--inject_path INJECT_PATH] [--inject_idx INJECT_IDX] [--verbose]
93
92
  src
94
93
 
95
94
  Execute notebook from `src` and save with outputs to `dest`
@@ -97,11 +96,12 @@ You can also execute notebooks from the command line with
97
96
  positional arguments:
98
97
  src Notebook path to read from
99
98
 
100
- optional arguments:
99
+ options:
101
100
  -h, --help show this help message and exit
102
101
  --dest DEST Notebook path to write to (default: )
103
102
  --exc_stop Stop on exceptions? (default: False)
104
103
  --inject_code INJECT_CODE Code to inject into a cell
105
104
  --inject_path INJECT_PATH Path to file containing code to inject into a cell
106
105
  --inject_idx INJECT_IDX Cell to replace with `inject_code` (default: 0)
107
- --verbose Show stdout/stderr during execution (default: False)
106
+ --verbose Show stdout/stderr during execution (default:
107
+ False)
@@ -28,9 +28,9 @@ to run Jupyter code and capture notebook outputs, without running a
28
28
  Jupyter server (or even having it installed):
29
29
 
30
30
  ``` python
31
- from execnb.nbio import *
32
31
  from execnb.shell import *
33
32
  from fastcore.utils import *
33
+ from fastcore.nbio import *
34
34
  ```
35
35
 
36
36
  ``` python
@@ -41,7 +41,7 @@ s.run('1+1')
41
41
  [{'data': {'text/plain': ['2']},
42
42
  'metadata': {},
43
43
  'output_type': 'execute_result',
44
- 'execution_count': 1}]
44
+ 'execution_count': None}]
45
45
 
46
46
  To execute a notebook and save it with outputs filled in, use
47
47
  [`CaptureShell.execute`](https://AnswerDotAI.github.io/execnb/shell.html#captureshell.execute):
@@ -53,7 +53,7 @@ try:
53
53
  finally: Path('tmp.ipynb').unlink()
54
54
  ```
55
55
 
56
- [{'name': 'stdout', 'output_type': 'stream', 'text': ['1\n']}, {'data': {'text/plain': ['2']}, 'execution_count': 3, 'metadata': {}, 'output_type': 'execute_result'}]
56
+ [{'name': 'stdout', 'output_type': 'stream', 'text': ['1\n']}, {'data': {'text/plain': ['2']}, 'execution_count': None, 'metadata': {}, 'output_type': 'execute_result'}]
57
57
 
58
58
  You can also execute notebooks from the command line with
59
59
  [`exec_nb`](https://AnswerDotAI.github.io/execnb/shell.html#exec_nb):
@@ -63,8 +63,7 @@ You can also execute notebooks from the command line with
63
63
  ```
64
64
 
65
65
  usage: exec_nb [-h] [--dest DEST] [--exc_stop] [--inject_code INJECT_CODE]
66
- [--inject_path INJECT_PATH] [--inject_idx INJECT_IDX]
67
- [--verbose]
66
+ [--inject_path INJECT_PATH] [--inject_idx INJECT_IDX] [--verbose]
68
67
  src
69
68
 
70
69
  Execute notebook from `src` and save with outputs to `dest`
@@ -72,11 +71,12 @@ You can also execute notebooks from the command line with
72
71
  positional arguments:
73
72
  src Notebook path to read from
74
73
 
75
- optional arguments:
74
+ options:
76
75
  -h, --help show this help message and exit
77
76
  --dest DEST Notebook path to write to (default: )
78
77
  --exc_stop Stop on exceptions? (default: False)
79
78
  --inject_code INJECT_CODE Code to inject into a cell
80
79
  --inject_path INJECT_PATH Path to file containing code to inject into a cell
81
80
  --inject_idx INJECT_IDX Cell to replace with `inject_code` (default: 0)
82
- --verbose Show stdout/stderr during execution (default: False)
81
+ --verbose Show stdout/stderr during execution (default:
82
+ False)
@@ -0,0 +1 @@
1
+ __version__ = "0.2.1"
@@ -1,12 +1,12 @@
1
1
  """A shell for running notebook code without a notebook server"""
2
2
 
3
- # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/02_shell.ipynb.
3
+ # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_shell.ipynb.
4
4
 
5
5
  # %% auto #0
6
6
  __all__ = ['CaptureShell', 'format_exc', 'NbResult', 'render_outputs', 'find_output', 'out_exec', 'out_stream', 'out_error',
7
7
  'exec_nb', 'SmartCompleter']
8
8
 
9
- # %% ../nbs/02_shell.ipynb #535003cf
9
+ # %% ../nbs/00_shell.ipynb #535003cf
10
10
  from fastcore.utils import *
11
11
  from fastcore.script import call_parse
12
12
  from fastcore.ansi import ansi2html, strip_ansi
@@ -35,7 +35,7 @@ from fastcore.nbio import *
35
35
  from fastcore.nbio import _dict2obj
36
36
 
37
37
 
38
- # %% ../nbs/02_shell.ipynb #6913382c
38
+ # %% ../nbs/00_shell.ipynb #6913382c
39
39
  class _CustDisplayHook(DisplayHook):
40
40
  def write_output_prompt(self): pass
41
41
  def write_format_data(self, data, md_dict): pass
@@ -47,7 +47,7 @@ def __repr__(self: ExecutionInfo): return f'cell: {self.raw_cell}; id: {self.cel
47
47
  @patch
48
48
  def __repr__(self: ExecutionResult): return f'result: {self.result}; err: {self.error_in_exec}; info: <{self.info}>'
49
49
 
50
- # %% ../nbs/02_shell.ipynb #e3fb2bee
50
+ # %% ../nbs/00_shell.ipynb #e3fb2bee
51
51
  class CaptureShell(InteractiveShell):
52
52
  displayhook_class = _CustDisplayHook
53
53
 
@@ -82,7 +82,7 @@ class CaptureShell(InteractiveShell):
82
82
 
83
83
  def enable_gui(self, gui=None): pass
84
84
 
85
- # %% ../nbs/02_shell.ipynb #93adf867
85
+ # %% ../nbs/00_shell.ipynb #93adf867
86
86
  @patch
87
87
  def run_cell(self:CaptureShell, raw_cell, store_history=False, silent=False, shell_futures=True, cell_id=None,
88
88
  stdout=True, stderr=True, display=True, timeout=None, verbose=False):
@@ -96,15 +96,15 @@ def run_cell(self:CaptureShell, raw_cell, store_history=False, silent=False, she
96
96
  finally:
97
97
  if timeout: signal.alarm(0)
98
98
 
99
- # %% ../nbs/02_shell.ipynb #a1eb7703
99
+ # %% ../nbs/00_shell.ipynb #a1eb7703
100
100
  def format_exc(e):
101
101
  "Format exception `e` as a string list"
102
102
  return traceback.format_exception(type(e), e, e.__traceback__)
103
103
 
104
- # %% ../nbs/02_shell.ipynb #8ba0ae59
104
+ # %% ../nbs/00_shell.ipynb #8ba0ae59
105
105
  class NbResult(list): pass
106
106
 
107
- # %% ../nbs/02_shell.ipynb #26bf9161
107
+ # %% ../nbs/00_shell.ipynb #26bf9161
108
108
  def _out_stream(text, name): return dict(name=name, output_type='stream', text=text.splitlines(True))
109
109
  def _out_exc(e):
110
110
  ename = type(e).__name__
@@ -137,7 +137,7 @@ def _out_nb(o, fmt):
137
137
  if p["output_type"]=="execute_result": p['execution_count'] = o['execution_count']
138
138
  return res
139
139
 
140
- # %% ../nbs/02_shell.ipynb #242f732f
140
+ # %% ../nbs/00_shell.ipynb #242f732f
141
141
  @patch
142
142
  def run(self:CaptureShell,
143
143
  code:str, # Python/IPython code to run
@@ -151,7 +151,7 @@ def run(self:CaptureShell,
151
151
  self.exc = res.exception
152
152
  return _out_nb(res, self.display_formatter)
153
153
 
154
- # %% ../nbs/02_shell.ipynb #eaa11df9
154
+ # %% ../nbs/00_shell.ipynb #eaa11df9
155
155
  @patch
156
156
  async def run_async(self:CaptureShell,
157
157
  code: str, # Python/IPython code to run
@@ -161,7 +161,7 @@ async def run_async(self:CaptureShell,
161
161
  verbose:bool=False): # Show stdout/stderr during execution
162
162
  return self.run(code, stdout=stdout, stderr=stderr, timeout=timeout, verbose=verbose)
163
163
 
164
- # %% ../nbs/02_shell.ipynb #f698a432
164
+ # %% ../nbs/00_shell.ipynb #f698a432
165
165
  def _pre(s, xtra=''): return f"<pre {xtra}><code>{escape(s)}</code></pre>"
166
166
  def _strip(s): return strip_ansi(escape(s))
167
167
 
@@ -196,7 +196,7 @@ def render_outputs(outputs, ansi_renderer=_strip, include_imgs=True, pygments=Fa
196
196
 
197
197
  return '\n'.join(map(render_output, outputs))
198
198
 
199
- # %% ../nbs/02_shell.ipynb #c6176b9e
199
+ # %% ../nbs/00_shell.ipynb #c6176b9e
200
200
  @patch
201
201
  def cell(self:CaptureShell, cell, stdout=True, stderr=True, verbose=False):
202
202
  "Run `cell`, skipping if not code, and store outputs back in cell"
@@ -205,32 +205,32 @@ def cell(self:CaptureShell, cell, stdout=True, stderr=True, verbose=False):
205
205
  outs = self.run(cell.source, verbose=verbose)
206
206
  if outs: cell.outputs = _dict2obj(outs)
207
207
 
208
- # %% ../nbs/02_shell.ipynb #008c0cef
208
+ # %% ../nbs/00_shell.ipynb #008c0cef
209
209
  def find_output(outp, # Output from `run`
210
210
  ot='execute_result' # Output_type to find
211
211
  ):
212
212
  "Find first output of type `ot` in `CaptureShell.run` output"
213
213
  return first(o for o in outp if o['output_type']==ot)
214
214
 
215
- # %% ../nbs/02_shell.ipynb #6e677414
215
+ # %% ../nbs/00_shell.ipynb #6e677414
216
216
  def out_exec(outp):
217
217
  "Get data from execution result in `outp`."
218
218
  out = find_output(outp)
219
219
  if out: return '\n'.join(first(out['data'].values()))
220
220
 
221
- # %% ../nbs/02_shell.ipynb #c7352a2b
221
+ # %% ../nbs/00_shell.ipynb #c7352a2b
222
222
  def out_stream(outp):
223
223
  "Get text from stream in `outp`."
224
224
  out = find_output(outp, 'stream')
225
225
  if out: return ('\n'.join(out['text'])).strip()
226
226
 
227
- # %% ../nbs/02_shell.ipynb #7d52326c
227
+ # %% ../nbs/00_shell.ipynb #7d52326c
228
228
  def out_error(outp):
229
229
  "Get traceback from error in `outp`."
230
230
  out = find_output(outp, 'error')
231
231
  if out: return '\n'.join(out['traceback'])
232
232
 
233
- # %% ../nbs/02_shell.ipynb #60a25f27
233
+ # %% ../nbs/00_shell.ipynb #60a25f27
234
234
  def _false(o): return False
235
235
 
236
236
  @patch
@@ -251,7 +251,7 @@ def run_all(self:CaptureShell,
251
251
  postproc(cell)
252
252
  if self.exc and exc_stop: raise self.exc from None
253
253
 
254
- # %% ../nbs/02_shell.ipynb #70808010
254
+ # %% ../nbs/00_shell.ipynb #70808010
255
255
  @patch
256
256
  def execute(self:CaptureShell,
257
257
  src:str|Path, # Notebook path to read from
@@ -273,7 +273,7 @@ def execute(self:CaptureShell,
273
273
  inject_code=inject_code, inject_idx=inject_idx, verbose=verbose)
274
274
  if dest: write_nb(nb, dest)
275
275
 
276
- # %% ../nbs/02_shell.ipynb #694161cb
276
+ # %% ../nbs/00_shell.ipynb #694161cb
277
277
  @patch
278
278
  def prettytb(self:CaptureShell,
279
279
  fname:str|Path=None): # filename to print alongside the traceback
@@ -285,7 +285,7 @@ def prettytb(self:CaptureShell,
285
285
  fname_str = f' in {fname}' if fname else ''
286
286
  return f"{type(self.exc).__name__}{fname_str}:\n{_fence}\n{cell_str}\n"
287
287
 
288
- # %% ../nbs/02_shell.ipynb #1227c8b1
288
+ # %% ../nbs/00_shell.ipynb #1227c8b1
289
289
  @call_parse
290
290
  def exec_nb(
291
291
  src:str, # Notebook path to read from
@@ -300,7 +300,7 @@ def exec_nb(
300
300
  CaptureShell().execute(src, dest, exc_stop=exc_stop, inject_code=inject_code,
301
301
  inject_path=inject_path, inject_idx=inject_idx, verbose=verbose)
302
302
 
303
- # %% ../nbs/02_shell.ipynb #c44963a0
303
+ # %% ../nbs/00_shell.ipynb #c44963a0
304
304
  class SmartCompleter(IPCompleter):
305
305
  def __init__(self, shell, namespace=None, jedi=False):
306
306
  if namespace is None: namespace = shell.user_ns
@@ -320,7 +320,7 @@ class SmartCompleter(IPCompleter):
320
320
  if res and res[0][-1]=='=': res = [o for o in res if o[-1]=='=']
321
321
  return res
322
322
 
323
- # %% ../nbs/02_shell.ipynb #7d7c852c
323
+ # %% ../nbs/00_shell.ipynb #7d7c852c
324
324
  @patch
325
325
  def complete(self:CaptureShell, c):
326
326
  if not hasattr(self, '_completer'): self._completer = SmartCompleter(self)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: execnb
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: A description of your project
5
5
  Author-email: Jeremy Howard <j@fast.ai>
6
6
  License: Apache-2.0
@@ -53,9 +53,9 @@ to run Jupyter code and capture notebook outputs, without running a
53
53
  Jupyter server (or even having it installed):
54
54
 
55
55
  ``` python
56
- from execnb.nbio import *
57
56
  from execnb.shell import *
58
57
  from fastcore.utils import *
58
+ from fastcore.nbio import *
59
59
  ```
60
60
 
61
61
  ``` python
@@ -66,7 +66,7 @@ s.run('1+1')
66
66
  [{'data': {'text/plain': ['2']},
67
67
  'metadata': {},
68
68
  'output_type': 'execute_result',
69
- 'execution_count': 1}]
69
+ 'execution_count': None}]
70
70
 
71
71
  To execute a notebook and save it with outputs filled in, use
72
72
  [`CaptureShell.execute`](https://AnswerDotAI.github.io/execnb/shell.html#captureshell.execute):
@@ -78,7 +78,7 @@ try:
78
78
  finally: Path('tmp.ipynb').unlink()
79
79
  ```
80
80
 
81
- [{'name': 'stdout', 'output_type': 'stream', 'text': ['1\n']}, {'data': {'text/plain': ['2']}, 'execution_count': 3, 'metadata': {}, 'output_type': 'execute_result'}]
81
+ [{'name': 'stdout', 'output_type': 'stream', 'text': ['1\n']}, {'data': {'text/plain': ['2']}, 'execution_count': None, 'metadata': {}, 'output_type': 'execute_result'}]
82
82
 
83
83
  You can also execute notebooks from the command line with
84
84
  [`exec_nb`](https://AnswerDotAI.github.io/execnb/shell.html#exec_nb):
@@ -88,8 +88,7 @@ You can also execute notebooks from the command line with
88
88
  ```
89
89
 
90
90
  usage: exec_nb [-h] [--dest DEST] [--exc_stop] [--inject_code INJECT_CODE]
91
- [--inject_path INJECT_PATH] [--inject_idx INJECT_IDX]
92
- [--verbose]
91
+ [--inject_path INJECT_PATH] [--inject_idx INJECT_IDX] [--verbose]
93
92
  src
94
93
 
95
94
  Execute notebook from `src` and save with outputs to `dest`
@@ -97,11 +96,12 @@ You can also execute notebooks from the command line with
97
96
  positional arguments:
98
97
  src Notebook path to read from
99
98
 
100
- optional arguments:
99
+ options:
101
100
  -h, --help show this help message and exit
102
101
  --dest DEST Notebook path to write to (default: )
103
102
  --exc_stop Stop on exceptions? (default: False)
104
103
  --inject_code INJECT_CODE Code to inject into a cell
105
104
  --inject_path INJECT_PATH Path to file containing code to inject into a cell
106
105
  --inject_idx INJECT_IDX Cell to replace with `inject_code` (default: 0)
107
- --verbose Show stdout/stderr during execution (default: False)
106
+ --verbose Show stdout/stderr during execution (default:
107
+ False)
@@ -1 +0,0 @@
1
- __version__ = "0.2.0"
File without changes
File without changes
File without changes
File without changes
File without changes