execnb 0.1.11__tar.gz → 0.1.12__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.1
2
2
  Name: execnb
3
- Version: 0.1.11
3
+ Version: 0.1.12
4
4
  Summary: A description of your project
5
5
  Home-page: https://github.com/AnswerDotAI/execnb/
6
6
  Author: Jeremy Howard
@@ -0,0 +1 @@
1
+ __version__ = "0.1.12"
@@ -7,7 +7,7 @@ from __future__ import annotations
7
7
 
8
8
  from fastcore.utils import *
9
9
  from fastcore.script import call_parse
10
- from fastcore.ansi import ansi2html
10
+ from fastcore.ansi import ansi2html, strip_ansi
11
11
 
12
12
  import multiprocessing,types,traceback,signal
13
13
  try:
@@ -17,7 +17,6 @@ except RuntimeError: pass # if re-running cell
17
17
  from IPython.core.interactiveshell import InteractiveShell, ExecutionInfo, ExecutionResult
18
18
  from IPython.core.displayhook import DisplayHook
19
19
  from IPython.utils.capture import capture_output
20
- from IPython.utils.text import strip_ansi
21
20
  from IPython.core.completer import IPCompleter,provisionalcompleter,Completer
22
21
  from IPython.core.hooks import CommandChainDispatcher
23
22
  from IPython.core.completerlib import module_completer
@@ -33,6 +32,7 @@ except ImportError: set_matplotlib_formats = None
33
32
  from .nbio import *
34
33
  from .nbio import _dict2obj
35
34
 
35
+
36
36
  # %% auto 0
37
37
  __all__ = ['CaptureShell', 'format_exc', 'render_outputs', 'find_output', 'out_exec', 'out_stream', 'out_error', 'exec_nb',
38
38
  'SmartCompleter']
@@ -161,24 +161,26 @@ async def run_async(self:CaptureShell,
161
161
  def _pre(s, xtra=''): return f"<pre {xtra}><code>{escape(s)}</code></pre>"
162
162
  def _strip(s): return strip_ansi(escape(s))
163
163
 
164
- def render_outputs(outputs, ansi_renderer=_strip, include_imgs=True, pygments=False):
164
+ def render_outputs(outputs, ansi_renderer=_strip, include_imgs=True, pygments=False, md_tfm=noop, html_tfm=noop):
165
165
  try:
166
166
  from mistletoe import markdown, HTMLRenderer
167
167
  from mistletoe.contrib.pygments_renderer import PygmentsRenderer
168
- except ImportError: return print('mistletoe not found -- please install it')
168
+ except ImportError: return print('mistletoe not found -- please install it for execnb.shell.render_output')
169
169
  renderer = PygmentsRenderer if pygments else HTMLRenderer
170
+
170
171
  def render_output(out):
171
172
  otype = out['output_type']
172
173
  if otype == 'stream':
173
- txt = ansi_renderer(''.join(out['text']))
174
+ txt = ansi_renderer(''.join(out["text"]))
174
175
  xtra = '' if out['name']=='stdout' else "class='stderr'"
175
- return f"<pre {xtra}><code>{txt}</code></pre>"
176
+ is_err = '<span class' in txt
177
+ return f"<pre {xtra}><code class='{'nohighlight hljs' if is_err else ''}'>{txt}</code></pre>"
176
178
  elif otype in ('display_data','execute_result'):
177
179
  data = out['data']
178
180
  _g = lambda t: ''.join(data[t]) if t in data else None
179
- if d := _g('text/html'): return d
181
+ if d := _g('text/html'): return html_tfm(d)
180
182
  if d := _g('application/javascript'): return f'<script>{d}</script>'
181
- if d := _g('text/markdown'): return markdown(d, renderer=renderer)
183
+ if d := _g('text/markdown'): return md_tfm(markdown(d, renderer=renderer))
182
184
  if d := _g('text/latex'): return f'<div class="math">${d}$</div>'
183
185
  if include_imgs:
184
186
  if d := _g('image/jpeg'): return f'<img src="data:image/jpeg;base64,{d}"/>'
@@ -187,7 +189,7 @@ def render_outputs(outputs, ansi_renderer=_strip, include_imgs=True, pygments=Fa
187
189
  if d := _g('image/svg+xml'): return d
188
190
 
189
191
  return ''
190
-
192
+
191
193
  return '\n'.join(map(render_output, outputs))
192
194
 
193
195
  # %% ../nbs/02_shell.ipynb
@@ -273,7 +275,7 @@ def prettytb(self:CaptureShell,
273
275
  fname = fname if fname else self._fname
274
276
  _fence = '='*75
275
277
  cell_intro_str = f"While Executing Cell #{self._cell_idx}:" if self._cell_idx else "While Executing:"
276
- cell_str = f"\n{cell_intro_str}\n{format_exc(self.exc)}"
278
+ cell_str = f"\n{cell_intro_str}\n{''.join(format_exc(self.exc))}"
277
279
  fname_str = f' in {fname}' if fname else ''
278
280
  return f"{type(self.exc).__name__}{fname_str}:\n{_fence}\n{cell_str}\n"
279
281
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: execnb
3
- Version: 0.1.11
3
+ Version: 0.1.12
4
4
  Summary: A description of your project
5
5
  Home-page: https://github.com/AnswerDotAI/execnb/
6
6
  Author: Jeremy Howard
@@ -9,7 +9,7 @@ user = AnswerDotAI
9
9
  author = Jeremy Howard
10
10
  author_email = j@fast.ai
11
11
  branch = master
12
- version = 0.1.11
12
+ version = 0.1.12
13
13
  min_python = 3.7
14
14
  requirements = fastcore>=1.5.5 ipython
15
15
  dev_requirements = matplotlib Pillow mistletoe
@@ -1 +0,0 @@
1
- __version__ = "0.1.11"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes