fastcore 2.2.3__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.
Files changed (44) hide show
  1. {fastcore-2.2.3/fastcore.egg-info → fastcore-2.2.4}/PKG-INFO +1 -1
  2. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/__init__.py +1 -1
  3. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/_modidx.py +2 -0
  4. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/nbio.py +32 -10
  5. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/xtras.py +2 -3
  6. {fastcore-2.2.3 → fastcore-2.2.4/fastcore.egg-info}/PKG-INFO +1 -1
  7. {fastcore-2.2.3 → fastcore-2.2.4}/CONTRIBUTING.md +0 -0
  8. {fastcore-2.2.3 → fastcore-2.2.4}/LICENSE +0 -0
  9. {fastcore-2.2.3 → fastcore-2.2.4}/MANIFEST.in +0 -0
  10. {fastcore-2.2.3 → fastcore-2.2.4}/README.md +0 -0
  11. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/aio.py +0 -0
  12. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/all.py +0 -0
  13. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/ansi.py +0 -0
  14. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/apisurface.py +0 -0
  15. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/basics.py +0 -0
  16. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/dispatch.py +0 -0
  17. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/docments.py +0 -0
  18. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/docscrape.py +0 -0
  19. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/editskill.py +0 -0
  20. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/foundation.py +0 -0
  21. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/funccall.py +0 -0
  22. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/imghdr.py +0 -0
  23. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/imports.py +0 -0
  24. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/meta.py +0 -0
  25. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/nb_imports.py +0 -0
  26. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/net.py +0 -0
  27. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/parallel.py +0 -0
  28. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/py2pyi.py +0 -0
  29. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/script.py +0 -0
  30. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/shutil.py +0 -0
  31. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/style.py +0 -0
  32. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/test.py +0 -0
  33. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/tools.py +0 -0
  34. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/transform.py +0 -0
  35. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/utils.py +0 -0
  36. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/xdg.py +0 -0
  37. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore/xml.py +0 -0
  38. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore.egg-info/SOURCES.txt +0 -0
  39. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore.egg-info/dependency_links.txt +0 -0
  40. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore.egg-info/entry_points.txt +0 -0
  41. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore.egg-info/requires.txt +0 -0
  42. {fastcore-2.2.3 → fastcore-2.2.4}/fastcore.egg-info/top_level.txt +0 -0
  43. {fastcore-2.2.3 → fastcore-2.2.4}/pyproject.toml +0 -0
  44. {fastcore-2.2.3 → fastcore-2.2.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastcore
3
- Version: 2.2.3
3
+ Version: 2.2.4
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
@@ -55,4 +55,4 @@ Modules:
55
55
  - `fastcore.xml`: Concise generation of XML.
56
56
  - `fastcore.xtras`: Utility functions used in the fastai library"""
57
57
 
58
- __version__ = "2.2.3"
58
+ __version__ = "2.2.4"
@@ -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
- 'nb_frontmatter', 'first_code_ln', 'dir_tag', 'nb2dict', 'nb2str', 'write_nb', 'find_id', 'cell_edit',
15
- 'view_cell', 'validate_cell', 'validate_nb', 'repair_cell', 'repair_nb', 'preferred_out', 'join_out',
16
- 'mk_stream', 'mk_result', 'mk_display', 'mk_error', 'concat_streams', 'preferred_msg_out', 'render_output',
17
- 'render_outputs', 'render_text', 'item2xml', 'cell2xml', 'cells2xml', 'Notebook', 'CellRow', 'CellRows',
18
- 'summary_nb', 'Found', 'FoundCells', 'find_cells', 'deep_merge', 'update_cell', 'select_cells', 'exec_cell',
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 mapping from `nb`'s first cell (raw or markdown opening with `---`)"
146
- c = first(nb.cells)
147
- if c is None or c.cell_type not in ('raw','markdown'): return {}
148
- return frontmatter(c.source, strvals=strvals)[0]
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*\|"
@@ -737,15 +737,14 @@ def asave_iter(g):
737
737
 
738
738
  # %% ../nbs/03_xtras.ipynb #d2757e2a
739
739
  def frontmatter(txt:str, strvals:bool=False)->tuple:
740
- "Tuple of (dict, body) from frontmatter in `txt`; invalid/missing frontmatter returns ({}, txt)"
740
+ "Tuple of (dict, body) from frontmatter in `txt`; missing frontmatter returns ({}, txt), malformed YAML raises"
741
741
  import yaml
742
742
  if not txt.startswith('---\n'): return {},txt
743
743
  end = min((i for i in (txt.find(f'\n{c}\n', 3) for c in ('---','...')) if i >= 0), default=-1)
744
744
  if end < 0:
745
745
  if not txt.endswith(('\n---','\n...')): return {},txt
746
746
  end = len(txt) - 4
747
- try: res = yaml.load(txt[4:end], Loader=yaml.BaseLoader if strvals else yaml.SafeLoader)
748
- except yaml.YAMLError: return {},txt
747
+ res = yaml.load(txt[4:end], Loader=yaml.BaseLoader if strvals else yaml.SafeLoader)
749
748
  return (res,txt[end+5:]) if isinstance(res,dict) else ({},txt)
750
749
 
751
750
  # %% ../nbs/03_xtras.ipynb #45eb5141
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastcore
3
- Version: 2.2.3
3
+ Version: 2.2.4
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
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