execnb 0.1.13__py3-none-any.whl → 0.1.15__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.13"
1
+ __version__ = "0.1.15"
execnb/shell.py CHANGED
@@ -67,10 +67,10 @@ class CaptureShell(InteractiveShell):
67
67
  self._run(f"set_matplotlib_formats('{mpl_format}')")
68
68
 
69
69
  def _run(self, raw_cell, store_history=False, silent=False, shell_futures=True, cell_id=None,
70
- stdout=True, stderr=True, display=True):
70
+ stdout=True, stderr=True, display=True, verbose=False):
71
71
  # TODO what if there's a comment?
72
72
  semic = raw_cell.rstrip().endswith(';')
73
- with capture_output(display=display, stdout=stdout, stderr=stderr) as c:
73
+ with capture_output(display=display, stdout=stdout and not verbose, stderr=stderr and not verbose) as c:
74
74
  result = super().run_cell(raw_cell, store_history, silent, shell_futures=shell_futures, cell_id=cell_id)
75
75
  return AttrDict(result=result, stdout='' if semic else c.stdout, stderr=c.stderr,
76
76
  display_objects=c.outputs, exception=result.error_in_exec, quiet=semic)
@@ -86,14 +86,14 @@ class CaptureShell(InteractiveShell):
86
86
  # %% ../nbs/02_shell.ipynb
87
87
  @patch
88
88
  def run_cell(self:CaptureShell, raw_cell, store_history=False, silent=False, shell_futures=True, cell_id=None,
89
- stdout=True, stderr=True, display=True, timeout=None):
89
+ stdout=True, stderr=True, display=True, timeout=None, verbose=False):
90
90
  if not timeout: timeout = self.timeout
91
91
  if timeout:
92
92
  def handler(*args): raise TimeoutError()
93
93
  signal.signal(signal.SIGALRM, handler)
94
94
  signal.alarm(timeout)
95
95
  try: return self._run(raw_cell, store_history, silent, shell_futures, cell_id=cell_id,
96
- stdout=stdout, stderr=stderr, display=display)
96
+ stdout=stdout, stderr=stderr, display=display, verbose=verbose)
97
97
  finally:
98
98
  if timeout: signal.alarm(0)
99
99
 
@@ -129,12 +129,10 @@ def _out_nb(o, fmt):
129
129
  if o.stdout: res.append(_out_stream(o.stdout, 'stdout'))
130
130
  if o.stderr: res.append(_out_stream(o.stderr, 'stderr'))
131
131
  if o.exception: res.append(_out_exc(o.exception))
132
- r = o.result.result
133
- if hasattr(r, '__ft__'): r = r.__ft__()
134
- res.result = r
132
+ res.result = o.result.result
135
133
  for x in o.display_objects: res.append(_mk_out(x.data, x.metadata))
136
- if r is not None and not o.quiet and not isinstance_str(r, 'FT'):
137
- res.append(_mk_out(*fmt.format(r), 'execute_result'))
134
+ if res.result is not None and not o.quiet:
135
+ res.append(_mk_out(*fmt.format(res.result), 'execute_result'))
138
136
  if 'execution_count' not in o: o['execution_count']=None
139
137
  for p in res:
140
138
  if p["output_type"]=="execute_result": p['execution_count'] = o['execution_count']
@@ -146,9 +144,10 @@ def run(self:CaptureShell,
146
144
  code:str, # Python/IPython code to run
147
145
  stdout=True, # Capture stdout and save as output?
148
146
  stderr=True, # Capture stderr and save as output?
149
- timeout:Optional[int]=None): # Shell command will time out after {timeout} seconds
147
+ timeout:Optional[int]=None, # Shell command will time out after {timeout} seconds
148
+ verbose:bool=False): # Show stdout/stderr during execution
150
149
  "Run `code`, returning a list of all outputs in Jupyter notebook format"
151
- res = self.run_cell(code, stdout=stdout, stderr=stderr, timeout=timeout)
150
+ res = self.run_cell(code, stdout=stdout, stderr=stderr, timeout=timeout, verbose=verbose)
152
151
  self.result = res.result.result
153
152
  self.exc = res.exception
154
153
  return _out_nb(res, self.display_formatter)
@@ -159,8 +158,9 @@ async def run_async(self:CaptureShell,
159
158
  code: str, # Python/IPython code to run
160
159
  stdout=True, # Capture stdout and save as output?
161
160
  stderr=True, # Capture stderr and save as output?
162
- timeout:Optional[int]=None): # Shell command will time out after {timeout} seconds
163
- return self.run(code, stdout=stdout, stderr=stderr, timeout=timeout)
161
+ timeout:Optional[int]=None, # Shell command will time out after {timeout} seconds
162
+ verbose:bool=False): # Show stdout/stderr during execution
163
+ return self.run(code, stdout=stdout, stderr=stderr, timeout=timeout, verbose=verbose)
164
164
 
165
165
  # %% ../nbs/02_shell.ipynb
166
166
  def _pre(s, xtra=''): return f"<pre {xtra}><code>{escape(s)}</code></pre>"
@@ -199,11 +199,11 @@ def render_outputs(outputs, ansi_renderer=_strip, include_imgs=True, pygments=Fa
199
199
 
200
200
  # %% ../nbs/02_shell.ipynb
201
201
  @patch
202
- def cell(self:CaptureShell, cell, stdout=True, stderr=True):
202
+ def cell(self:CaptureShell, cell, stdout=True, stderr=True, verbose=False):
203
203
  "Run `cell`, skipping if not code, and store outputs back in cell"
204
204
  if cell.cell_type!='code': return
205
205
  self._cell_idx = cell.idx_ + 1
206
- outs = self.run(cell.source)
206
+ outs = self.run(cell.source, verbose=verbose)
207
207
  if outs: cell.outputs = _dict2obj(outs)
208
208
 
209
209
  # %% ../nbs/02_shell.ipynb
@@ -241,13 +241,14 @@ def run_all(self:CaptureShell,
241
241
  preproc:callable=_false, # Called before each cell is executed
242
242
  postproc:callable=_false, # Called after each cell is executed
243
243
  inject_code:str|None=None, # Code to inject into a cell
244
- inject_idx:int=0 # Cell to replace with `inject_code`
244
+ inject_idx:int=0, # Cell to replace with `inject_code`
245
+ verbose:bool=False # Show stdout/stderr during execution
245
246
  ):
246
247
  "Run all cells in `nb`, stopping at first exception if `exc_stop`"
247
248
  if inject_code is not None: nb.cells[inject_idx].source = inject_code
248
249
  for cell in nb.cells:
249
250
  if not preproc(cell):
250
- self.cell(cell)
251
+ self.cell(cell, verbose=verbose)
251
252
  postproc(cell)
252
253
  if self.exc and exc_stop: raise self.exc from None
253
254
 
@@ -261,7 +262,8 @@ def execute(self:CaptureShell,
261
262
  postproc:callable=_false, # Called after each cell is executed
262
263
  inject_code:str|None=None, # Code to inject into a cell
263
264
  inject_path:str|Path|None=None, # Path to file containing code to inject into a cell
264
- inject_idx:int=0 # Cell to replace with `inject_code`
265
+ inject_idx:int=0, # Cell to replace with `inject_code`
266
+ verbose:bool=False # Show stdout/stderr during execution
265
267
  ):
266
268
  "Execute notebook from `src` and save with outputs to `dest"
267
269
  nb = read_nb(src)
@@ -269,7 +271,7 @@ def execute(self:CaptureShell,
269
271
  self.set_path(Path(src).parent.resolve())
270
272
  if inject_path is not None: inject_code = Path(inject_path).read_text()
271
273
  self.run_all(nb, exc_stop=exc_stop, preproc=preproc, postproc=postproc,
272
- inject_code=inject_code, inject_idx=inject_idx)
274
+ inject_code=inject_code, inject_idx=inject_idx, verbose=verbose)
273
275
  if dest: write_nb(nb, dest)
274
276
 
275
277
  # %% ../nbs/02_shell.ipynb
@@ -292,11 +294,12 @@ def exec_nb(
292
294
  exc_stop:bool=False, # Stop on exceptions?
293
295
  inject_code:str=None, # Code to inject into a cell
294
296
  inject_path:str=None, # Path to file containing code to inject into a cell
295
- inject_idx:int=0 # Cell to replace with `inject_code`
297
+ inject_idx:int=0, # Cell to replace with `inject_code`
298
+ verbose:bool=False # Show stdout/stderr during execution
296
299
  ):
297
300
  "Execute notebook from `src` and save with outputs to `dest`"
298
301
  CaptureShell().execute(src, dest, exc_stop=exc_stop, inject_code=inject_code,
299
- inject_path=inject_path, inject_idx=inject_idx)
302
+ inject_path=inject_path, inject_idx=inject_idx, verbose=verbose)
300
303
 
301
304
  # %% ../nbs/02_shell.ipynb
302
305
  class SmartCompleter(IPCompleter):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: execnb
3
- Version: 0.1.13
3
+ Version: 0.1.15
4
4
  Summary: A description of your project
5
5
  Home-page: https://github.com/AnswerDotAI/execnb/
6
6
  Author: Jeremy Howard
@@ -102,6 +102,7 @@ You can also execute notebooks from the command line with
102
102
 
103
103
  usage: exec_nb [-h] [--dest DEST] [--exc_stop] [--inject_code INJECT_CODE]
104
104
  [--inject_path INJECT_PATH] [--inject_idx INJECT_IDX]
105
+ [--verbose]
105
106
  src
106
107
 
107
108
  Execute notebook from `src` and save with outputs to `dest`
@@ -116,3 +117,4 @@ You can also execute notebooks from the command line with
116
117
  --inject_code INJECT_CODE Code to inject into a cell
117
118
  --inject_path INJECT_PATH Path to file containing code to inject into a cell
118
119
  --inject_idx INJECT_IDX Cell to replace with `inject_code` (default: 0)
120
+ --verbose Show stdout/stderr during execution (default: False)
@@ -0,0 +1,10 @@
1
+ execnb/__init__.py,sha256=qb0TalpSt1CbprnFyeLUKqgrqNtmnk9IoQQ7umAoXVY,23
2
+ execnb/_modidx.py,sha256=5VB9uTJiRMiFNsXUWcd2J5p1jvvV36vsmQPUCWuqzrE,6308
3
+ execnb/nbio.py,sha256=gs3EGN0sP2j47XUH31rTn2KT57b3wWnBZsn9AoZm2JQ,3677
4
+ execnb/shell.py,sha256=x9qzwKQ4dGp-u96GDAbJb-nKiPAbAcv91BlXiH1Xlpw,14186
5
+ execnb-0.1.15.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
6
+ execnb-0.1.15.dist-info/METADATA,sha256=uVAHDOqtDORbwPOFxFRtrVpgP3JWA5IMVkDY1TtyLLg,3704
7
+ execnb-0.1.15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ execnb-0.1.15.dist-info/entry_points.txt,sha256=jZ8LPZCqnu4hXN_AgQpm05hVnTE-C25YK_4aiVX4i78,84
9
+ execnb-0.1.15.dist-info/top_level.txt,sha256=VGWmzsw8FOlT1r5TdOxaTWIAyRdclcxNdJ2r1hojf5U,7
10
+ execnb-0.1.15.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,10 +0,0 @@
1
- execnb/__init__.py,sha256=khDKUuWafURKVs5EAZkpOMiUHI2-V7axlqrWLPUpuZo,23
2
- execnb/_modidx.py,sha256=5VB9uTJiRMiFNsXUWcd2J5p1jvvV36vsmQPUCWuqzrE,6308
3
- execnb/nbio.py,sha256=gs3EGN0sP2j47XUH31rTn2KT57b3wWnBZsn9AoZm2JQ,3677
4
- execnb/shell.py,sha256=lL0I5vMYjhaeD3WFKwXekyAAAb-4kjosA1PFd-IrpKE,13723
5
- execnb-0.1.13.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
6
- execnb-0.1.13.dist-info/METADATA,sha256=Uotcx1EkHSBT6yFY6T4Qpg0gZ1X2SPnNBif6yZetQw8,3587
7
- execnb-0.1.13.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
- execnb-0.1.13.dist-info/entry_points.txt,sha256=jZ8LPZCqnu4hXN_AgQpm05hVnTE-C25YK_4aiVX4i78,84
9
- execnb-0.1.13.dist-info/top_level.txt,sha256=VGWmzsw8FOlT1r5TdOxaTWIAyRdclcxNdJ2r1hojf5U,7
10
- execnb-0.1.13.dist-info/RECORD,,