execnb 0.1.5__py3-none-any.whl → 0.1.6__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 CHANGED
@@ -1 +1 @@
1
- __version__ = "0.1.5"
1
+ __version__ = "0.1.6"
execnb/_modidx.py CHANGED
@@ -3,7 +3,7 @@
3
3
  d = { 'settings': { 'branch': 'master',
4
4
  'doc_baseurl': '/execnb/',
5
5
  'doc_host': 'https://fastai.github.io',
6
- 'git_url': 'https://github.com/fastai/execnb/tree/master/',
6
+ 'git_url': 'https://github.com/fastai/execnb/',
7
7
  'lib_path': 'execnb'},
8
8
  'syms': { 'execnb.fastshell': {},
9
9
  'execnb.nbio': { 'execnb.nbio.NbCell': ('nbio.html#nbcell', 'execnb/nbio.py'),
@@ -46,4 +46,8 @@ d = { 'settings': { 'branch': 'master',
46
46
  'execnb.shell._format_mimedata': ('shell.html#_format_mimedata', 'execnb/shell.py'),
47
47
  'execnb.shell._out_exc': ('shell.html#_out_exc', 'execnb/shell.py'),
48
48
  'execnb.shell._out_stream': ('shell.html#_out_stream', 'execnb/shell.py'),
49
- 'execnb.shell.exec_nb': ('shell.html#exec_nb', 'execnb/shell.py')}}}
49
+ 'execnb.shell.exec_nb': ('shell.html#exec_nb', 'execnb/shell.py'),
50
+ 'execnb.shell.find_output': ('shell.html#find_output', 'execnb/shell.py'),
51
+ 'execnb.shell.out_error': ('shell.html#out_error', 'execnb/shell.py'),
52
+ 'execnb.shell.out_exec': ('shell.html#out_exec', 'execnb/shell.py'),
53
+ 'execnb.shell.out_stream': ('shell.html#out_stream', 'execnb/shell.py')}}}
execnb/nbio.py CHANGED
@@ -28,7 +28,7 @@ class NbCell(AttrDict):
28
28
 
29
29
  def parsed_(self):
30
30
  if self.cell_type!='code' or self.source.strip()[:1] in ['%', '!']: return
31
- if '_parsed_' not in self:
31
+ if '_parsed_' not in self:
32
32
  try: self._parsed_ = ast.parse(self.source).body
33
33
  # you can assign the result of ! to a variable in a notebook cell
34
34
  # which will result in a syntax error if parsed with the ast module.
@@ -70,6 +70,9 @@ def mk_cell(text, # `source` attr in cell
70
70
  "Create an `NbCell` containing `text`"
71
71
  assert cell_type in {'code', 'markdown', 'raw'}
72
72
  if 'metadata' not in kwargs: kwargs['metadata']={}
73
+ if cell_type == 'code':
74
+ kwargs['outputs']=[]
75
+ kwargs['execution_count']=0
73
76
  return NbCell(0, dict(cell_type=cell_type, source=text, directives_={}, **kwargs))
74
77
 
75
78
  # %% ../nbs/01_nbio.ipynb 31
execnb/shell.py CHANGED
@@ -29,7 +29,7 @@ from .nbio import _dict2obj
29
29
  from collections.abc import Callable
30
30
 
31
31
  # %% auto 0
32
- __all__ = ['CaptureShell', 'exec_nb']
32
+ __all__ = ['CaptureShell', 'find_output', 'out_exec', 'out_stream', 'out_error', 'exec_nb']
33
33
 
34
34
  # %% ../nbs/02_shell.ipynb 4
35
35
  # IPython requires a DisplayHook and DisplayPublisher
@@ -155,7 +155,32 @@ def cell(self:CaptureShell, cell, stdout=True, stderr=True):
155
155
  for o in outs:
156
156
  if 'execution_count' in o: cell['execution_count'] = o['execution_count']
157
157
 
158
- # %% ../nbs/02_shell.ipynb 28
158
+ # %% ../nbs/02_shell.ipynb 27
159
+ def find_output(outp, # Output from `run`
160
+ ot='execute_result' # Output_type to find
161
+ ):
162
+ "Find first output of type `ot` in `CaptureShell.run` output"
163
+ return first(o for o in outp if o['output_type']==ot)
164
+
165
+ # %% ../nbs/02_shell.ipynb 30
166
+ def out_exec(outp):
167
+ "Get data from execution result in `outp`."
168
+ out = find_output(outp)
169
+ if out: return '\n'.join(first(out['data'].values()))
170
+
171
+ # %% ../nbs/02_shell.ipynb 32
172
+ def out_stream(outp):
173
+ "Get text from stream in `outp`."
174
+ out = find_output(outp, 'stream')
175
+ if out: return ('\n'.join(out['text'])).strip()
176
+
177
+ # %% ../nbs/02_shell.ipynb 34
178
+ def out_error(outp):
179
+ "Get traceback from error in `outp`."
180
+ out = find_output(outp, 'error')
181
+ if out: return '\n'.join(out['traceback'])
182
+
183
+ # %% ../nbs/02_shell.ipynb 37
159
184
  def _false(o): return False
160
185
 
161
186
  @patch
@@ -175,7 +200,7 @@ def run_all(self:CaptureShell,
175
200
  postproc(cell)
176
201
  if self.exc and exc_stop: raise self.exc[1] from None
177
202
 
178
- # %% ../nbs/02_shell.ipynb 42
203
+ # %% ../nbs/02_shell.ipynb 51
179
204
  @patch
180
205
  def execute(self:CaptureShell,
181
206
  src:str|Path, # Notebook path to read from
@@ -196,7 +221,7 @@ def execute(self:CaptureShell,
196
221
  inject_code=inject_code, inject_idx=inject_idx)
197
222
  if dest: write_nb(nb, dest)
198
223
 
199
- # %% ../nbs/02_shell.ipynb 46
224
+ # %% ../nbs/02_shell.ipynb 55
200
225
  @patch
201
226
  def prettytb(self:CaptureShell,
202
227
  fname:str|Path=None): # filename to print alongside the traceback
@@ -208,7 +233,7 @@ def prettytb(self:CaptureShell,
208
233
  fname_str = f' in {fname}' if fname else ''
209
234
  return f"{type(self.exc[1]).__name__}{fname_str}:\n{_fence}\n{cell_str}\n"
210
235
 
211
- # %% ../nbs/02_shell.ipynb 65
236
+ # %% ../nbs/02_shell.ipynb 74
212
237
  @call_parse
213
238
  def exec_nb(
214
239
  src:str, # Notebook path to read from
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: execnb
3
- Version: 0.1.5
3
+ Version: 0.1.6
4
4
  Summary: A description of your project
5
- Home-page: https://github.com/fastai/execnb/tree/master/
5
+ Home-page: https://github.com/fastai/execnb/
6
6
  Author: Jeremy Howard
7
7
  Author-email: j@fast.ai
8
8
  License: Apache Software License 2.0
@@ -16,14 +16,14 @@ Classifier: License :: OSI Approved :: Apache Software License
16
16
  Requires-Python: >=3.7
17
17
  Description-Content-Type: text/markdown
18
18
  License-File: LICENSE
19
- Requires-Dist: fastcore (>=1.5.5)
19
+ Requires-Dist: fastcore >=1.5.5
20
20
  Requires-Dist: ipython
21
21
  Provides-Extra: dev
22
22
  Requires-Dist: matplotlib ; extra == 'dev'
23
23
  Requires-Dist: Pillow ; extra == 'dev'
24
24
 
25
- execnb
26
- ================
25
+ # execnb
26
+
27
27
 
28
28
  <!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
29
29
 
@@ -0,0 +1,11 @@
1
+ execnb/__init__.py,sha256=n3oM6B_EMz93NsTI18NNZd-jKFcUPzUkbIKj5VFK5ok,22
2
+ execnb/_modidx.py,sha256=1OsF4WZ4cmkxB9wAj8kWjGMmVVhX4BbH73yWAYGBzCM,5229
3
+ execnb/fastshell.py,sha256=ODng8r7-b74lRiCR2nENHuIMubxnkfArh0Su2VMHMSs,4285
4
+ execnb/nbio.py,sha256=TOOsiO6VAduLfwbXWgCu4k_fXKEpJw6byBq69BCVXek,3660
5
+ execnb/shell.py,sha256=lL1rWX_iCPDPb0hK_UZIoqoRkY-plUL_RU6e4ujnjmE,9782
6
+ execnb-0.1.6.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
7
+ execnb-0.1.6.dist-info/METADATA,sha256=2FLEW9GK9faxUYwHN6g-43CI90xRcwvm2jQE8Pcm01o,3250
8
+ execnb-0.1.6.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
9
+ execnb-0.1.6.dist-info/entry_points.txt,sha256=jZ8LPZCqnu4hXN_AgQpm05hVnTE-C25YK_4aiVX4i78,84
10
+ execnb-0.1.6.dist-info/top_level.txt,sha256=VGWmzsw8FOlT1r5TdOxaTWIAyRdclcxNdJ2r1hojf5U,7
11
+ execnb-0.1.6.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.38.4)
2
+ Generator: bdist_wheel (0.41.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,11 +0,0 @@
1
- execnb/__init__.py,sha256=rPSfWgIeq2YWVPyESOAwCBt8vftsTpIkuLAGDEzyRQc,22
2
- execnb/_modidx.py,sha256=gpQj6i1HkFABwB73tBR5iaLqNDZNUY3wilOxlO7P5FQ,4833
3
- execnb/fastshell.py,sha256=ODng8r7-b74lRiCR2nENHuIMubxnkfArh0Su2VMHMSs,4285
4
- execnb/nbio.py,sha256=9k15675BTHIWDNVbbN_B93g6pCDECBDX4g7HgxHvyys,3568
5
- execnb/shell.py,sha256=se6sLSEql-zTbHWOH0P_fQ8Qg1WJCEv4s2HCfoaaOfE,8911
6
- execnb-0.1.5.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
7
- execnb-0.1.5.dist-info/METADATA,sha256=t5lJC6cUeocujmRxcvQ0nSnMUo4L3VJ8IfbB6lsyfxc,3278
8
- execnb-0.1.5.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
9
- execnb-0.1.5.dist-info/entry_points.txt,sha256=jZ8LPZCqnu4hXN_AgQpm05hVnTE-C25YK_4aiVX4i78,84
10
- execnb-0.1.5.dist-info/top_level.txt,sha256=VGWmzsw8FOlT1r5TdOxaTWIAyRdclcxNdJ2r1hojf5U,7
11
- execnb-0.1.5.dist-info/RECORD,,