execnb 0.1.11__tar.gz → 0.1.13__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
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: execnb
3
- Version: 0.1.11
3
+ Version: 0.1.13
4
4
  Summary: A description of your project
5
5
  Home-page: https://github.com/AnswerDotAI/execnb/
6
6
  Author: Jeremy Howard
@@ -22,6 +22,19 @@ Provides-Extra: dev
22
22
  Requires-Dist: matplotlib; extra == "dev"
23
23
  Requires-Dist: Pillow; extra == "dev"
24
24
  Requires-Dist: mistletoe; extra == "dev"
25
+ Dynamic: author
26
+ Dynamic: author-email
27
+ Dynamic: classifier
28
+ Dynamic: description
29
+ Dynamic: description-content-type
30
+ Dynamic: home-page
31
+ Dynamic: keywords
32
+ Dynamic: license
33
+ Dynamic: license-file
34
+ Dynamic: provides-extra
35
+ Dynamic: requires-dist
36
+ Dynamic: requires-python
37
+ Dynamic: summary
25
38
 
26
39
  # execnb
27
40
 
@@ -0,0 +1 @@
1
+ __version__ = "0.1.13"
@@ -1,6 +1,6 @@
1
1
  # Autogenerated by nbdev
2
2
 
3
- d = { 'settings': { 'branch': 'master',
3
+ d = { 'settings': { 'branch': 'main',
4
4
  'doc_baseurl': '/execnb/',
5
5
  'doc_host': 'https://AnswerDotAI.github.io',
6
6
  'git_url': 'https://github.com/AnswerDotAI/execnb/',
@@ -35,6 +35,7 @@ d = { 'settings': { 'branch': 'master',
35
35
  'execnb.shell.CaptureShell.set_path': ('shell.html#captureshell.set_path', 'execnb/shell.py'),
36
36
  'execnb.shell.ExecutionInfo.__repr__': ('shell.html#executioninfo.__repr__', 'execnb/shell.py'),
37
37
  'execnb.shell.ExecutionResult.__repr__': ('shell.html#executionresult.__repr__', 'execnb/shell.py'),
38
+ 'execnb.shell.NbResult': ('shell.html#nbresult', 'execnb/shell.py'),
38
39
  'execnb.shell.SmartCompleter': ('shell.html#smartcompleter', 'execnb/shell.py'),
39
40
  'execnb.shell.SmartCompleter.__call__': ('shell.html#smartcompleter.__call__', 'execnb/shell.py'),
40
41
  'execnb.shell.SmartCompleter.__init__': ('shell.html#smartcompleter.__init__', 'execnb/shell.py'),
@@ -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,9 +32,10 @@ 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
- __all__ = ['CaptureShell', 'format_exc', 'render_outputs', 'find_output', 'out_exec', 'out_stream', 'out_error', 'exec_nb',
38
- 'SmartCompleter']
37
+ __all__ = ['CaptureShell', 'format_exc', 'NbResult', 'render_outputs', 'find_output', 'out_exec', 'out_stream', 'out_error',
38
+ 'exec_nb', 'SmartCompleter']
39
39
 
40
40
  # %% ../nbs/02_shell.ipynb
41
41
  class _CustDisplayHook(DisplayHook):
@@ -102,6 +102,9 @@ def format_exc(e):
102
102
  "Format exception `e` as a string list"
103
103
  return traceback.format_exception(type(e), e, e.__traceback__)
104
104
 
105
+ # %% ../nbs/02_shell.ipynb
106
+ class NbResult(list): pass
107
+
105
108
  # %% ../nbs/02_shell.ipynb
106
109
  def _out_stream(text, name): return dict(name=name, output_type='stream', text=text.splitlines(True))
107
110
  def _out_exc(e):
@@ -122,13 +125,15 @@ def _mk_out(data, meta, output_type='display_data'):
122
125
  return dict(data=fd, metadata=meta, output_type=output_type)
123
126
 
124
127
  def _out_nb(o, fmt):
125
- res = []
128
+ res = NbResult()
126
129
  if o.stdout: res.append(_out_stream(o.stdout, 'stdout'))
127
130
  if o.stderr: res.append(_out_stream(o.stderr, 'stderr'))
128
131
  if o.exception: res.append(_out_exc(o.exception))
129
132
  r = o.result.result
133
+ if hasattr(r, '__ft__'): r = r.__ft__()
134
+ res.result = r
130
135
  for x in o.display_objects: res.append(_mk_out(x.data, x.metadata))
131
- if r is not None and not o.quiet:
136
+ if r is not None and not o.quiet and not isinstance_str(r, 'FT'):
132
137
  res.append(_mk_out(*fmt.format(r), 'execute_result'))
133
138
  if 'execution_count' not in o: o['execution_count']=None
134
139
  for p in res:
@@ -161,33 +166,35 @@ async def run_async(self:CaptureShell,
161
166
  def _pre(s, xtra=''): return f"<pre {xtra}><code>{escape(s)}</code></pre>"
162
167
  def _strip(s): return strip_ansi(escape(s))
163
168
 
164
- def render_outputs(outputs, ansi_renderer=_strip, include_imgs=True, pygments=False):
169
+ def render_outputs(outputs, ansi_renderer=_strip, include_imgs=True, pygments=False, md_tfm=noop, html_tfm=noop):
165
170
  try:
166
171
  from mistletoe import markdown, HTMLRenderer
167
172
  from mistletoe.contrib.pygments_renderer import PygmentsRenderer
168
- except ImportError: return print('mistletoe not found -- please install it')
173
+ except ImportError: return print('mistletoe not found -- please install it for execnb.shell.render_output')
169
174
  renderer = PygmentsRenderer if pygments else HTMLRenderer
175
+
170
176
  def render_output(out):
171
177
  otype = out['output_type']
172
178
  if otype == 'stream':
173
- txt = ansi_renderer(''.join(out['text']))
179
+ txt = ansi_renderer(''.join(out["text"]))
174
180
  xtra = '' if out['name']=='stdout' else "class='stderr'"
175
- return f"<pre {xtra}><code>{txt}</code></pre>"
181
+ is_err = '<span class' in txt
182
+ return f"<pre {xtra}><code class='{'nohighlight hljs' if is_err else ''}'>{txt}</code></pre>"
176
183
  elif otype in ('display_data','execute_result'):
177
184
  data = out['data']
178
185
  _g = lambda t: ''.join(data[t]) if t in data else None
179
- if d := _g('text/html'): return d
186
+ if d := _g('text/html'): return html_tfm(d)
180
187
  if d := _g('application/javascript'): return f'<script>{d}</script>'
181
- if d := _g('text/markdown'): return markdown(d, renderer=renderer)
188
+ if d := _g('text/markdown'): return md_tfm(markdown(d, renderer=renderer))
182
189
  if d := _g('text/latex'): return f'<div class="math">${d}$</div>'
183
190
  if include_imgs:
184
191
  if d := _g('image/jpeg'): return f'<img src="data:image/jpeg;base64,{d}"/>'
185
192
  if d := _g('image/png'): return f'<img src="data:image/png;base64,{d}"/>'
193
+ if d := _g('image/svg+xml'): return d
186
194
  if d := _g('text/plain'): return _pre(d)
187
- if d := _g('image/svg+xml'): return d
188
195
 
189
196
  return ''
190
-
197
+
191
198
  return '\n'.join(map(render_output, outputs))
192
199
 
193
200
  # %% ../nbs/02_shell.ipynb
@@ -273,7 +280,7 @@ def prettytb(self:CaptureShell,
273
280
  fname = fname if fname else self._fname
274
281
  _fence = '='*75
275
282
  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)}"
283
+ cell_str = f"\n{cell_intro_str}\n{''.join(format_exc(self.exc))}"
277
284
  fname_str = f' in {fname}' if fname else ''
278
285
  return f"{type(self.exc).__name__}{fname_str}:\n{_fence}\n{cell_str}\n"
279
286
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: execnb
3
- Version: 0.1.11
3
+ Version: 0.1.13
4
4
  Summary: A description of your project
5
5
  Home-page: https://github.com/AnswerDotAI/execnb/
6
6
  Author: Jeremy Howard
@@ -22,6 +22,19 @@ Provides-Extra: dev
22
22
  Requires-Dist: matplotlib; extra == "dev"
23
23
  Requires-Dist: Pillow; extra == "dev"
24
24
  Requires-Dist: mistletoe; extra == "dev"
25
+ Dynamic: author
26
+ Dynamic: author-email
27
+ Dynamic: classifier
28
+ Dynamic: description
29
+ Dynamic: description-content-type
30
+ Dynamic: home-page
31
+ Dynamic: keywords
32
+ Dynamic: license
33
+ Dynamic: license-file
34
+ Dynamic: provides-extra
35
+ Dynamic: requires-dist
36
+ Dynamic: requires-python
37
+ Dynamic: summary
25
38
 
26
39
  # execnb
27
40
 
@@ -0,0 +1,11 @@
1
+ [build-system]
2
+ requires = ["setuptools>=64.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name="execnb"
7
+ requires-python=">=3.7"
8
+ dynamic = [ "keywords", "description", "version", "dependencies", "optional-dependencies", "readme", "license", "authors", "classifiers", "entry-points", "scripts", "urls"]
9
+
10
+ [tool.uv]
11
+ cache-keys = [{ file = "pyproject.toml" }, { file = "settings.ini" }, { file = "setup.py" }]
@@ -8,8 +8,8 @@ keywords = some keywords
8
8
  user = AnswerDotAI
9
9
  author = Jeremy Howard
10
10
  author_email = j@fast.ai
11
- branch = master
12
- version = 0.1.11
11
+ branch = main
12
+ version = 0.1.13
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"
@@ -1,3 +0,0 @@
1
- [build-system]
2
- requires = ["setuptools>=64.0"]
3
- build-backend = "setuptools.build_meta"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes