fastcore 2.2.2__tar.gz → 2.2.4__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.2.2/fastcore.egg-info → fastcore-2.2.4}/PKG-INFO +1 -1
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/__init__.py +1 -1
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/_modidx.py +2 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/nbio.py +32 -10
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/xml.py +3 -4
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/xtras.py +4 -10
- {fastcore-2.2.2 → fastcore-2.2.4/fastcore.egg-info}/PKG-INFO +1 -1
- {fastcore-2.2.2 → fastcore-2.2.4}/CONTRIBUTING.md +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/LICENSE +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/MANIFEST.in +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/README.md +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/aio.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/all.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/ansi.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/apisurface.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/basics.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/dispatch.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/docments.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/docscrape.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/editskill.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/foundation.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/funccall.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/imghdr.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/imports.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/meta.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/nb_imports.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/net.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/parallel.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/py2pyi.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/script.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/shutil.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/style.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/test.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/tools.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/transform.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/utils.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore/xdg.py +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore.egg-info/SOURCES.txt +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore.egg-info/dependency_links.txt +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore.egg-info/entry_points.txt +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore.egg-info/requires.txt +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/fastcore.egg-info/top_level.txt +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/pyproject.toml +0 -0
- {fastcore-2.2.2 → fastcore-2.2.4}/setup.cfg +0 -0
|
@@ -605,6 +605,7 @@ d = { 'settings': { 'branch': 'main',
|
|
|
605
605
|
'fastcore.nbio._unparse_dir': ('nbio.html#_unparse_dir', 'fastcore/nbio.py'),
|
|
606
606
|
'fastcore.nbio.cell2xml': ('nbio.html#cell2xml', 'fastcore/nbio.py'),
|
|
607
607
|
'fastcore.nbio.cell_edit': ('nbio.html#cell_edit', 'fastcore/nbio.py'),
|
|
608
|
+
'fastcore.nbio.cell_frontmatter': ('nbio.html#cell_frontmatter', 'fastcore/nbio.py'),
|
|
608
609
|
'fastcore.nbio.cells2xml': ('nbio.html#cells2xml', 'fastcore/nbio.py'),
|
|
609
610
|
'fastcore.nbio.concat_streams': ('nbio.html#concat_streams', 'fastcore/nbio.py'),
|
|
610
611
|
'fastcore.nbio.deep_merge': ('nbio.html#deep_merge', 'fastcore/nbio.py'),
|
|
@@ -616,6 +617,7 @@ d = { 'settings': { 'branch': 'main',
|
|
|
616
617
|
'fastcore.nbio.first_code_ln': ('nbio.html#first_code_ln', 'fastcore/nbio.py'),
|
|
617
618
|
'fastcore.nbio.item2xml': ('nbio.html#item2xml', 'fastcore/nbio.py'),
|
|
618
619
|
'fastcore.nbio.join_out': ('nbio.html#join_out', 'fastcore/nbio.py'),
|
|
620
|
+
'fastcore.nbio.md_frontmatter': ('nbio.html#md_frontmatter', 'fastcore/nbio.py'),
|
|
619
621
|
'fastcore.nbio.mk_cell': ('nbio.html#mk_cell', 'fastcore/nbio.py'),
|
|
620
622
|
'fastcore.nbio.mk_display': ('nbio.html#mk_display', 'fastcore/nbio.py'),
|
|
621
623
|
'fastcore.nbio.mk_error': ('nbio.html#mk_error', 'fastcore/nbio.py'),
|
|
@@ -11,12 +11,12 @@ Docs: https://fastcore.fast.ai/nbio.html.md"""
|
|
|
11
11
|
# %% auto #0
|
|
12
12
|
__all__ = ['langs', 'cell_insert_line', 'cell_str_replace', 'cell_strs_replace', 'cell_replace_lines', 'cell_del_lines',
|
|
13
13
|
'cell_ast_replace', 'IMG_MIMES', 'nb_lang', 'NbCell', 'dict2nb', 'read_nb', 'mk_cell', 'new_nb',
|
|
14
|
-
'
|
|
15
|
-
'
|
|
16
|
-
'
|
|
17
|
-
'
|
|
18
|
-
'
|
|
19
|
-
'show_cell', 'msg2out', 'msgs2outs']
|
|
14
|
+
'cell_frontmatter', 'md_frontmatter', 'nb_frontmatter', 'first_code_ln', 'dir_tag', 'nb2dict', 'nb2str',
|
|
15
|
+
'write_nb', 'find_id', 'cell_edit', 'view_cell', 'validate_cell', 'validate_nb', 'repair_cell', 'repair_nb',
|
|
16
|
+
'preferred_out', 'join_out', 'mk_stream', 'mk_result', 'mk_display', 'mk_error', 'concat_streams',
|
|
17
|
+
'preferred_msg_out', 'render_output', 'render_outputs', 'render_text', 'item2xml', 'cell2xml', 'cells2xml',
|
|
18
|
+
'Notebook', 'CellRow', 'CellRows', 'summary_nb', 'Found', 'FoundCells', 'find_cells', 'deep_merge',
|
|
19
|
+
'update_cell', 'select_cells', 'exec_cell', 'show_cell', 'msg2out', 'msgs2outs']
|
|
20
20
|
|
|
21
21
|
# %% ../nbs/13_nbio.ipynb #954ca1aa
|
|
22
22
|
from .basics import *
|
|
@@ -141,11 +141,33 @@ def new_nb(cells=None, meta=None, nbformat=4, nbformat_minor=5):
|
|
|
141
141
|
return dict2nb(cells=cells or [],metadata=meta or {},nbformat=nbformat,nbformat_minor=nbformat_minor)
|
|
142
142
|
|
|
143
143
|
# %% ../nbs/13_nbio.ipynb #af62e5ef
|
|
144
|
+
def cell_frontmatter(s:str, strvals:bool=False):
|
|
145
|
+
"Frontmatter mapping from a cell source that is entirely a literal `---` block, else {}"
|
|
146
|
+
d,body = frontmatter(s.strip(), strvals=strvals)
|
|
147
|
+
return d if not body.strip() else {}
|
|
148
|
+
|
|
149
|
+
def md_frontmatter(s:str):
|
|
150
|
+
"Frontmatter synthesized from an H1-formatted markdown cell: `# title`, `> description`, and `- key: value` lines"
|
|
151
|
+
import yaml
|
|
152
|
+
m = re.search(r'^#\s+(\S.*?)\s*$', s, flags=re.MULTILINE)
|
|
153
|
+
if not m: return {}
|
|
154
|
+
res = dict(title=m.group(1))
|
|
155
|
+
m = re.search(r'^>\s+(\S.*?)\s*$', s, flags=re.MULTILINE)
|
|
156
|
+
if m: res['description'] = m.group(1)
|
|
157
|
+
r = re.findall(r'^-\s+(\S.*:.*\S)\s*$', s, flags=re.MULTILINE)
|
|
158
|
+
if r:
|
|
159
|
+
try: res.update(yaml.safe_load('\n'.join(r)))
|
|
160
|
+
except yaml.YAMLError as e: warn(f'Failed to create YAML dict for:\n{r}\n\n{e}\n')
|
|
161
|
+
return res
|
|
162
|
+
|
|
144
163
|
def nb_frontmatter(nb, strvals:bool=False):
|
|
145
|
-
"Frontmatter
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
164
|
+
"Frontmatter from `nb`: its first raw cell plus first markdown cell (literal `---` block, or `# title` synthesis), raw keys winning"
|
|
165
|
+
raw = first(c for c in nb.cells if c.cell_type=='raw')
|
|
166
|
+
md = first(c for c in nb.cells if c.cell_type=='markdown')
|
|
167
|
+
res = (cell_frontmatter(md.source, strvals=strvals) or md_frontmatter(md.source)) if md else {}
|
|
168
|
+
if raw: res.update(cell_frontmatter(raw.source, strvals=strvals))
|
|
169
|
+
return res
|
|
170
|
+
|
|
149
171
|
|
|
150
172
|
# %% ../nbs/13_nbio.ipynb #c2ed0d5e
|
|
151
173
|
def _dir_pre(lang=None): return fr"\s*{langs[lang]}\s*\|"
|
|
@@ -182,7 +182,7 @@ def _to_xml(elm, lvl=0, indent=True, do_escape=True):
|
|
|
182
182
|
esc_fn = _escape if do_escape else _noescape
|
|
183
183
|
if elm is None: return ''
|
|
184
184
|
if hasattr(elm, '__ft__'): elm = elm.__ft__()
|
|
185
|
-
if isinstance(elm, tuple): return ''.join(_to_xml(o, lvl=lvl, indent=indent, do_escape=do_escape) for o in elm)
|
|
185
|
+
if isinstance(elm, (tuple, L)): return ''.join(_to_xml(o, lvl=lvl, indent=indent, do_escape=do_escape) for o in elm)
|
|
186
186
|
if isinstance(elm, bytes): return elm.decode('utf-8')
|
|
187
187
|
if not isinstance(elm, FT): return f'{esc_fn(elm)}'
|
|
188
188
|
|
|
@@ -204,7 +204,7 @@ def _to_xml(elm, lvl=0, indent=True, do_escape=True):
|
|
|
204
204
|
if not cs:
|
|
205
205
|
if is_void: return f'{sp}{stag_}{nl_end}'
|
|
206
206
|
else: return f'{sp}{stag_}{cltag}{nl_end}'
|
|
207
|
-
if len(cs) == 1 and not isinstance(cs[0], (list, tuple, FT)) and not hasattr(cs[0], '__ft__'):
|
|
207
|
+
if len(cs) == 1 and not isinstance(cs[0], (list, tuple, L, FT)) and not hasattr(cs[0], '__ft__'):
|
|
208
208
|
content = esc_fn(cs[0])
|
|
209
209
|
return f'{sp}{stag_}{content}{cltag}{nl_end}'
|
|
210
210
|
|
|
@@ -217,13 +217,12 @@ def _to_xml(elm, lvl=0, indent=True, do_escape=True):
|
|
|
217
217
|
def to_xml(*elms, lvl=0, indent=True, do_escape=True):
|
|
218
218
|
"Convert `ft` element tree into an XML string"
|
|
219
219
|
def _f(elm):
|
|
220
|
-
if isinstance(elm, (list,tuple,FT)) or hasattr(elm, '__ft__'):
|
|
220
|
+
if isinstance(elm, (list,tuple,L,FT)) or hasattr(elm, '__ft__'):
|
|
221
221
|
return _to_xml(elm, lvl, indent, do_escape=do_escape)
|
|
222
222
|
if isinstance(elm, bytes): return elm.decode('utf-8')
|
|
223
223
|
return elm or ''
|
|
224
224
|
return Safe('\n'.join(map(_f, elms)))
|
|
225
225
|
|
|
226
|
-
|
|
227
226
|
# %% ../nbs/09_xml.ipynb #dd054392
|
|
228
227
|
@patch
|
|
229
228
|
def __html__(self:FT): return to_xml(self, indent=False)
|
|
@@ -43,7 +43,7 @@ from .ansi import strip_ansi
|
|
|
43
43
|
|
|
44
44
|
from importlib import import_module
|
|
45
45
|
from functools import wraps
|
|
46
|
-
import string,time,dataclasses,difflib
|
|
46
|
+
import string,time,dataclasses,difflib,json
|
|
47
47
|
from enum import Enum
|
|
48
48
|
from contextlib import contextmanager,ExitStack
|
|
49
49
|
from configparser import ConfigParser
|
|
@@ -250,8 +250,6 @@ def bunzip(fn):
|
|
|
250
250
|
def loads(s, **kw):
|
|
251
251
|
"Same as `json.loads`, but handles `None`"
|
|
252
252
|
if not s: return {}
|
|
253
|
-
try: import ujson as json
|
|
254
|
-
except ModuleNotFoundError: import json
|
|
255
253
|
return json.loads(s, **kw)
|
|
256
254
|
|
|
257
255
|
# %% ../nbs/03_xtras.ipynb #131170f7
|
|
@@ -268,10 +266,7 @@ def loads_multi(s:str):
|
|
|
268
266
|
|
|
269
267
|
# %% ../nbs/03_xtras.ipynb #ed688ac4
|
|
270
268
|
def dumps(obj, **kw):
|
|
271
|
-
"Same as `json.dumps
|
|
272
|
-
try: import ujson as json
|
|
273
|
-
except ModuleNotFoundError: import json
|
|
274
|
-
else: kw['escape_forward_slashes']=False
|
|
269
|
+
"Same as `json.dumps`"
|
|
275
270
|
return json.dumps(obj, **kw)
|
|
276
271
|
|
|
277
272
|
# %% ../nbs/03_xtras.ipynb #ac84300c
|
|
@@ -742,15 +737,14 @@ def asave_iter(g):
|
|
|
742
737
|
|
|
743
738
|
# %% ../nbs/03_xtras.ipynb #d2757e2a
|
|
744
739
|
def frontmatter(txt:str, strvals:bool=False)->tuple:
|
|
745
|
-
"Tuple of (dict, body) from frontmatter in `txt`;
|
|
740
|
+
"Tuple of (dict, body) from frontmatter in `txt`; missing frontmatter returns ({}, txt), malformed YAML raises"
|
|
746
741
|
import yaml
|
|
747
742
|
if not txt.startswith('---\n'): return {},txt
|
|
748
743
|
end = min((i for i in (txt.find(f'\n{c}\n', 3) for c in ('---','...')) if i >= 0), default=-1)
|
|
749
744
|
if end < 0:
|
|
750
745
|
if not txt.endswith(('\n---','\n...')): return {},txt
|
|
751
746
|
end = len(txt) - 4
|
|
752
|
-
|
|
753
|
-
except yaml.YAMLError: return {},txt
|
|
747
|
+
res = yaml.load(txt[4:end], Loader=yaml.BaseLoader if strvals else yaml.SafeLoader)
|
|
754
748
|
return (res,txt[end+5:]) if isinstance(res,dict) else ({},txt)
|
|
755
749
|
|
|
756
750
|
# %% ../nbs/03_xtras.ipynb #45eb5141
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|