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.
Files changed (42) hide show
  1. {fastcore-2.0.4/fastcore.egg-info → fastcore-2.0.6}/PKG-INFO +1 -1
  2. fastcore-2.0.6/fastcore/__init__.py +1 -0
  3. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/_modidx.py +1 -2
  4. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/docments.py +4 -1
  5. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/nbio.py +13 -20
  6. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/xtras.py +6 -2
  7. {fastcore-2.0.4 → fastcore-2.0.6/fastcore.egg-info}/PKG-INFO +1 -1
  8. fastcore-2.0.4/fastcore/__init__.py +0 -1
  9. {fastcore-2.0.4 → fastcore-2.0.6}/CONTRIBUTING.md +0 -0
  10. {fastcore-2.0.4 → fastcore-2.0.6}/LICENSE +0 -0
  11. {fastcore-2.0.4 → fastcore-2.0.6}/MANIFEST.in +0 -0
  12. {fastcore-2.0.4 → fastcore-2.0.6}/README.md +0 -0
  13. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/aio.py +0 -0
  14. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/all.py +0 -0
  15. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/ansi.py +0 -0
  16. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/basics.py +0 -0
  17. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/dispatch.py +0 -0
  18. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/docscrape.py +0 -0
  19. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/foundation.py +0 -0
  20. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/imghdr.py +0 -0
  21. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/imports.py +0 -0
  22. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/meta.py +0 -0
  23. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/nb_imports.py +0 -0
  24. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/net.py +0 -0
  25. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/parallel.py +0 -0
  26. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/py2pyi.py +0 -0
  27. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/script.py +0 -0
  28. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/shutil.py +0 -0
  29. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/style.py +0 -0
  30. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/test.py +0 -0
  31. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/tools.py +0 -0
  32. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/transform.py +0 -0
  33. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/utils.py +0 -0
  34. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/xdg.py +0 -0
  35. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore/xml.py +0 -0
  36. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore.egg-info/SOURCES.txt +0 -0
  37. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore.egg-info/dependency_links.txt +0 -0
  38. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore.egg-info/entry_points.txt +0 -0
  39. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore.egg-info/requires.txt +0 -0
  40. {fastcore-2.0.4 → fastcore-2.0.6}/fastcore.egg-info/top_level.txt +0 -0
  41. {fastcore-2.0.4 → fastcore-2.0.6}/pyproject.toml +0 -0
  42. {fastcore-2.0.4 → fastcore-2.0.6}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastcore
3
- Version: 2.0.4
3
+ Version: 2.0.6
4
4
  Summary: Python supercharged for fastai development
5
5
  Author-email: Jeremy Howard and Sylvain Gugger <infos@fast.ai>
6
6
  License: Apache-2.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
- 'apply_controls', 'mk_stream', 'mk_result', 'mk_display', 'mk_error', 'concat_streams', 'render_output',
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, text = out['name'], _join(out['text'])
202
- streams[name] = apply_controls(streams.get(name, '') + text)
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
- if 'stdout' in streams: res.append(mk_stream('stdout', streams['stdout']))
206
- if 'stderr' in streams: res.append(mk_stream('stderr', streams['stderr']))
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
- def _preferred_msg_out(out, **kwargs):
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 = _preferred_msg_out(out, html1st=True, include_imgs=True)
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 = _preferred_msg_out(out, html1st=html1st, include_imgs=False)
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
- "Clean CLI output by handling alternate screen, carriage returns, and ANSI escapes"
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
- res = '\n'.join(l.rsplit('\r', 1)[-1] for l in txt.split('\n'))
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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastcore
3
- Version: 2.0.4
3
+ Version: 2.0.6
4
4
  Summary: Python supercharged for fastai development
5
5
  Author-email: Jeremy Howard and Sylvain Gugger <infos@fast.ai>
6
6
  License: Apache-2.0
@@ -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