fastcore 2.0.4__tar.gz → 2.0.6__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.
- {fastcore-2.0.4/fastcore.egg-info → fastcore-2.0.6}/PKG-INFO +1 -1
- fastcore-2.0.6/fastcore/__init__.py +1 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/_modidx.py +1 -2
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/docments.py +4 -1
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/nbio.py +13 -20
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/xtras.py +6 -2
- {fastcore-2.0.4 → fastcore-2.0.6/fastcore.egg-info}/PKG-INFO +1 -1
- fastcore-2.0.4/fastcore/__init__.py +0 -1
- {fastcore-2.0.4 → fastcore-2.0.6}/CONTRIBUTING.md +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/LICENSE +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/MANIFEST.in +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/README.md +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/aio.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/all.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/ansi.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/basics.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/dispatch.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/docscrape.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/foundation.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/imghdr.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/imports.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/meta.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/nb_imports.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/net.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/parallel.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/py2pyi.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/script.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/shutil.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/style.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/test.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/tools.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/transform.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/utils.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/xdg.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/xml.py +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore.egg-info/SOURCES.txt +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore.egg-info/dependency_links.txt +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore.egg-info/entry_points.txt +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore.egg-info/requires.txt +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/fastcore.egg-info/top_level.txt +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/pyproject.toml +0 -0
- {fastcore-2.0.4 → fastcore-2.0.6}/setup.cfg +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.0.6"
|
|
@@ -505,14 +505,12 @@ d = { 'settings': { 'branch': 'main',
|
|
|
505
505
|
'fastcore.nbio._is_json_mime': ('nbio.html#_is_json_mime', 'fastcore/nbio.py'),
|
|
506
506
|
'fastcore.nbio._join': ('nbio.html#_join', 'fastcore/nbio.py'),
|
|
507
507
|
'fastcore.nbio._mkout': ('nbio.html#_mkout', 'fastcore/nbio.py'),
|
|
508
|
-
'fastcore.nbio._preferred_msg_out': ('nbio.html#_preferred_msg_out', 'fastcore/nbio.py'),
|
|
509
508
|
'fastcore.nbio._read_json': ('nbio.html#_read_json', 'fastcore/nbio.py'),
|
|
510
509
|
'fastcore.nbio._rejoin_cell': ('nbio.html#_rejoin_cell', 'fastcore/nbio.py'),
|
|
511
510
|
'fastcore.nbio._rejoin_mime': ('nbio.html#_rejoin_mime', 'fastcore/nbio.py'),
|
|
512
511
|
'fastcore.nbio._render_text': ('nbio.html#_render_text', 'fastcore/nbio.py'),
|
|
513
512
|
'fastcore.nbio._split_cell': ('nbio.html#_split_cell', 'fastcore/nbio.py'),
|
|
514
513
|
'fastcore.nbio._split_mime': ('nbio.html#_split_mime', 'fastcore/nbio.py'),
|
|
515
|
-
'fastcore.nbio.apply_controls': ('nbio.html#apply_controls', 'fastcore/nbio.py'),
|
|
516
514
|
'fastcore.nbio.cell2xml': ('nbio.html#cell2xml', 'fastcore/nbio.py'),
|
|
517
515
|
'fastcore.nbio.cells2xml': ('nbio.html#cells2xml', 'fastcore/nbio.py'),
|
|
518
516
|
'fastcore.nbio.concat_streams': ('nbio.html#concat_streams', 'fastcore/nbio.py'),
|
|
@@ -525,6 +523,7 @@ d = { 'settings': { 'branch': 'main',
|
|
|
525
523
|
'fastcore.nbio.nb2dict': ('nbio.html#nb2dict', 'fastcore/nbio.py'),
|
|
526
524
|
'fastcore.nbio.nb2str': ('nbio.html#nb2str', 'fastcore/nbio.py'),
|
|
527
525
|
'fastcore.nbio.new_nb': ('nbio.html#new_nb', 'fastcore/nbio.py'),
|
|
526
|
+
'fastcore.nbio.preferred_msg_out': ('nbio.html#preferred_msg_out', 'fastcore/nbio.py'),
|
|
528
527
|
'fastcore.nbio.preferred_out': ('nbio.html#preferred_out', 'fastcore/nbio.py'),
|
|
529
528
|
'fastcore.nbio.read_nb': ('nbio.html#read_nb', 'fastcore/nbio.py'),
|
|
530
529
|
'fastcore.nbio.render_output': ('nbio.html#render_output', 'fastcore/nbio.py'),
|
|
@@ -57,7 +57,10 @@ def get_source(s):
|
|
|
57
57
|
# %% ../nbs/04_docments.ipynb #91c0d15f
|
|
58
58
|
def _parses(s):
|
|
59
59
|
"Parse source of function, method, or dataclass `s`"
|
|
60
|
-
return parse(dedent(get_source(s) or ''))
|
|
60
|
+
try: return parse(dedent(get_source(s) or ''))
|
|
61
|
+
except SyntaxError:
|
|
62
|
+
if isinstance(s,str): raise
|
|
63
|
+
return parse('') # live object whose file changed on disk since import: degrade to no docments
|
|
61
64
|
|
|
62
65
|
def _tokens(s):
|
|
63
66
|
"Tokenize Python code in string or function object `s`"
|
|
@@ -5,15 +5,16 @@ Docs: https://fastcore.fast.ai/nbio.html.md"""
|
|
|
5
5
|
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/13_nbio.ipynb.
|
|
6
6
|
|
|
7
7
|
# %% auto #0
|
|
8
|
-
__all__ = ['NbCell', 'dict2nb', 'read_nb', 'mk_cell', 'new_nb', 'nb2dict', 'nb2str', 'write_nb', 'preferred_out',
|
|
9
|
-
'
|
|
8
|
+
__all__ = ['NbCell', 'dict2nb', 'read_nb', 'mk_cell', 'new_nb', 'nb2dict', 'nb2str', 'write_nb', 'preferred_out', 'mk_stream',
|
|
9
|
+
'mk_result', 'mk_display', 'mk_error', 'concat_streams', 'preferred_msg_out', 'render_output',
|
|
10
10
|
'render_outputs', 'render_text', 'cell2xml', 'cells2xml', 'Notebook']
|
|
11
11
|
|
|
12
12
|
# %% ../nbs/13_nbio.ipynb #954ca1aa
|
|
13
13
|
from .basics import *
|
|
14
|
-
from .xtras import rtoken_hex
|
|
14
|
+
from .xtras import rtoken_hex,clean_cli_output
|
|
15
15
|
from .imports import *
|
|
16
16
|
from .ansi import ansi2html
|
|
17
|
+
from .meta import delegates
|
|
17
18
|
|
|
18
19
|
import ast,functools
|
|
19
20
|
from pprint import pformat,pprint
|
|
@@ -159,16 +160,6 @@ def preferred_out(data, html1st=True, include_imgs=False):
|
|
|
159
160
|
if (text := data.get(mt)): return mt,text
|
|
160
161
|
return 'text/plain',''
|
|
161
162
|
|
|
162
|
-
# %% ../nbs/13_nbio.ipynb #efec6078
|
|
163
|
-
def apply_controls(text):
|
|
164
|
-
r"Apply \r and \b to text, returning processed result"
|
|
165
|
-
lines = text.split('\n')
|
|
166
|
-
for i, line in enumerate(lines):
|
|
167
|
-
if 0<(rpos := line.rfind('\r'))<len(line)-1: lines[i] = line[rpos+1:]
|
|
168
|
-
text = '\n'.join(lines)
|
|
169
|
-
while (pos := text.find('\b')) >= 0: text = text[:max(0, pos-1)] + text[pos+1:]
|
|
170
|
-
return text
|
|
171
|
-
|
|
172
163
|
# %% ../nbs/13_nbio.ipynb #24a47a87
|
|
173
164
|
def _join(d): return ''.join(d) if isinstance(d, list) else d
|
|
174
165
|
|
|
@@ -198,17 +189,19 @@ def concat_streams(outputs):
|
|
|
198
189
|
streams, res, execute_results = {}, [], []
|
|
199
190
|
for out in outputs:
|
|
200
191
|
if out['output_type'] == 'stream':
|
|
201
|
-
name
|
|
202
|
-
streams[name] =
|
|
192
|
+
name = out['name']
|
|
193
|
+
streams[name] = streams.get(name, '') + _join(out['text'])
|
|
203
194
|
elif out['output_type'] in ('error','execute_result'): execute_results.append(out)
|
|
204
195
|
else: res.append(out)
|
|
205
|
-
|
|
206
|
-
|
|
196
|
+
for name in ('stdout','stderr'):
|
|
197
|
+
if name in streams: res.append(mk_stream(name, clean_cli_output(streams[name], strip=False)))
|
|
207
198
|
res.extend(execute_results)
|
|
208
199
|
return res
|
|
209
200
|
|
|
210
201
|
# %% ../nbs/13_nbio.ipynb #a3deacac
|
|
211
|
-
|
|
202
|
+
@delegates(preferred_out)
|
|
203
|
+
def preferred_msg_out(out, **kwargs):
|
|
204
|
+
"Preferred mime type and content for any Jupyter output dict (stream, error, or data-bearing)"
|
|
212
205
|
typ = out['output_type']
|
|
213
206
|
if typ == 'stream': return 'text/plain', _join(out.get('text', ""))
|
|
214
207
|
elif typ == 'error': return 'text/plain', '\n'.join(out.get('traceback', []))
|
|
@@ -221,7 +214,7 @@ def render_output(out):
|
|
|
221
214
|
def _fmt(text):
|
|
222
215
|
res = ansi2html(str(text))
|
|
223
216
|
return f'<pre class="!border-0 !rounded-none !my-0 !p-0"><code class="nohighlight">{res}</code></pre>'
|
|
224
|
-
ptyp,d =
|
|
217
|
+
ptyp,d = preferred_msg_out(out, html1st=True, include_imgs=True)
|
|
225
218
|
d = _join(d)
|
|
226
219
|
if ptyp=='text/plain': return _fmt(d)
|
|
227
220
|
elif ptyp=='text/html': return d
|
|
@@ -242,7 +235,7 @@ def render_outputs(outputs):
|
|
|
242
235
|
# %% ../nbs/13_nbio.ipynb #88b0018a
|
|
243
236
|
def _render_text(out, html1st=False):
|
|
244
237
|
typ = out['output_type']
|
|
245
|
-
mime,d =
|
|
238
|
+
mime,d = preferred_msg_out(out, html1st=html1st, include_imgs=False)
|
|
246
239
|
d = _join(d)
|
|
247
240
|
if not d: return None
|
|
248
241
|
attrs = {}
|
|
@@ -713,12 +713,16 @@ def frontmatter(txt:str)->tuple:
|
|
|
713
713
|
|
|
714
714
|
# %% ../nbs/03_xtras.ipynb #45eb5141
|
|
715
715
|
def clean_cli_output(txt:str, strip:bool=True):
|
|
716
|
-
"
|
|
716
|
+
r"Render CLI output as it appears on screen: alternate screen, `\r` overwrites, `\b` backspaces, and ANSI escapes"
|
|
717
717
|
if '\x1b[?1049h' in txt:
|
|
718
718
|
if '\x1b[?1049l' not in txt: return ''
|
|
719
719
|
txt = txt.rsplit('\x1b[?1049l', 1)[-1]
|
|
720
720
|
txt = txt.replace('\r\n', '\n')
|
|
721
|
-
|
|
721
|
+
def _line(l):
|
|
722
|
+
l = l.rstrip('\r').rsplit('\r', 1)[-1] # trailing \r overwrites nothing; else keep last overwrite
|
|
723
|
+
while (i := l.find('\b')) != -1: l = l[:i] if i==len(l)-1 else l[:max(0,i-1)] + l[i+1:]
|
|
724
|
+
return l
|
|
725
|
+
res = '\n'.join(_line(l) for l in txt.split('\n'))
|
|
722
726
|
return strip_ansi(res, term_queries=True) if strip else res
|
|
723
727
|
|
|
724
728
|
# %% ../nbs/03_xtras.ipynb #35368de5
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "2.0.4"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|