fastcore 2.2.3__tar.gz → 2.2.5__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.5}/PKG-INFO +1 -1
  2. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/__init__.py +1 -1
  3. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/_modidx.py +3 -2
  4. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/nbio.py +52 -46
  5. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/xtras.py +2 -3
  6. {fastcore-2.2.3 → fastcore-2.2.5/fastcore.egg-info}/PKG-INFO +1 -1
  7. {fastcore-2.2.3 → fastcore-2.2.5}/CONTRIBUTING.md +0 -0
  8. {fastcore-2.2.3 → fastcore-2.2.5}/LICENSE +0 -0
  9. {fastcore-2.2.3 → fastcore-2.2.5}/MANIFEST.in +0 -0
  10. {fastcore-2.2.3 → fastcore-2.2.5}/README.md +0 -0
  11. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/aio.py +0 -0
  12. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/all.py +0 -0
  13. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/ansi.py +0 -0
  14. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/apisurface.py +0 -0
  15. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/basics.py +0 -0
  16. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/dispatch.py +0 -0
  17. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/docments.py +0 -0
  18. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/docscrape.py +0 -0
  19. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/editskill.py +0 -0
  20. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/foundation.py +0 -0
  21. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/funccall.py +0 -0
  22. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/imghdr.py +0 -0
  23. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/imports.py +0 -0
  24. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/meta.py +0 -0
  25. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/nb_imports.py +0 -0
  26. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/net.py +0 -0
  27. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/parallel.py +0 -0
  28. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/py2pyi.py +0 -0
  29. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/script.py +0 -0
  30. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/shutil.py +0 -0
  31. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/style.py +0 -0
  32. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/test.py +0 -0
  33. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/tools.py +0 -0
  34. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/transform.py +0 -0
  35. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/utils.py +0 -0
  36. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/xdg.py +0 -0
  37. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore/xml.py +0 -0
  38. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore.egg-info/SOURCES.txt +0 -0
  39. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore.egg-info/dependency_links.txt +0 -0
  40. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore.egg-info/entry_points.txt +0 -0
  41. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore.egg-info/requires.txt +0 -0
  42. {fastcore-2.2.3 → fastcore-2.2.5}/fastcore.egg-info/top_level.txt +0 -0
  43. {fastcore-2.2.3 → fastcore-2.2.5}/pyproject.toml +0 -0
  44. {fastcore-2.2.3 → fastcore-2.2.5}/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.5
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.5"
@@ -605,17 +605,18 @@ 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'),
611
612
  'fastcore.nbio.dict2nb': ('nbio.html#dict2nb', 'fastcore/nbio.py'),
612
613
  'fastcore.nbio.dir_tag': ('nbio.html#dir_tag', 'fastcore/nbio.py'),
613
- 'fastcore.nbio.exec_cell': ('nbio.html#exec_cell', 'fastcore/nbio.py'),
614
614
  'fastcore.nbio.find_cells': ('nbio.html#find_cells', 'fastcore/nbio.py'),
615
615
  'fastcore.nbio.find_id': ('nbio.html#find_id', 'fastcore/nbio.py'),
616
616
  'fastcore.nbio.first_code_ln': ('nbio.html#first_code_ln', 'fastcore/nbio.py'),
617
617
  'fastcore.nbio.item2xml': ('nbio.html#item2xml', 'fastcore/nbio.py'),
618
618
  'fastcore.nbio.join_out': ('nbio.html#join_out', 'fastcore/nbio.py'),
619
+ 'fastcore.nbio.md_frontmatter': ('nbio.html#md_frontmatter', 'fastcore/nbio.py'),
619
620
  'fastcore.nbio.mk_cell': ('nbio.html#mk_cell', 'fastcore/nbio.py'),
620
621
  'fastcore.nbio.mk_display': ('nbio.html#mk_display', 'fastcore/nbio.py'),
621
622
  'fastcore.nbio.mk_error': ('nbio.html#mk_error', 'fastcore/nbio.py'),
@@ -636,8 +637,8 @@ d = { 'settings': { 'branch': 'main',
636
637
  'fastcore.nbio.render_text': ('nbio.html#render_text', 'fastcore/nbio.py'),
637
638
  'fastcore.nbio.repair_cell': ('nbio.html#repair_cell', 'fastcore/nbio.py'),
638
639
  'fastcore.nbio.repair_nb': ('nbio.html#repair_nb', 'fastcore/nbio.py'),
640
+ 'fastcore.nbio.run_cell': ('nbio.html#run_cell', 'fastcore/nbio.py'),
639
641
  'fastcore.nbio.select_cells': ('nbio.html#select_cells', 'fastcore/nbio.py'),
640
- 'fastcore.nbio.show_cell': ('nbio.html#show_cell', 'fastcore/nbio.py'),
641
642
  'fastcore.nbio.summary_nb': ('nbio.html#summary_nb', 'fastcore/nbio.py'),
642
643
  'fastcore.nbio.update_cell': ('nbio.html#update_cell', 'fastcore/nbio.py'),
643
644
  'fastcore.nbio.validate_cell': ('nbio.html#validate_cell', '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', 'run_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*\|"
@@ -844,44 +866,28 @@ def select_cells(
844
866
  if skip_noeval: sel = [o for o in sel if not _is_noeval(o)]
845
867
  return sel
846
868
 
847
- # %% ../nbs/13_nbio.ipynb #b30755db
848
- async def exec_cell(
849
- shell, # An IPython `InteractiveShell` (or compatible: `transform_cell`, `compile`, `user_ns`, `events`)
850
- src:str, # Cell source: magics, `!` commands, and top-level `await` all work
851
- ): # The final bare expression's value (None if there is none, or a trailing `;` suppresses it)
852
- "Run cell `src` in `shell` as a library call: the value and any exception go to the caller, and only the code's own output is shown"
853
- __tracebackhide__ = True
854
- xsrc = shell.transform_cell(src)
855
- tree,cfname = ast.parse(xsrc),shell.compile.cache(xsrc)
856
- expr = tree.body.pop().value if tree.body and isinstance(tree.body[-1], ast.Expr) else None
857
- async def _go(node, mode):
858
- __tracebackhide__ = "__ipython_bottom__" # to the debugger: all frames above are host machinery
859
- co = compile(ast.fix_missing_locations(node), cfname, mode, flags=ast.PyCF_ALLOW_TOP_LEVEL_AWAIT)
860
- r = eval(co, shell.user_global_ns, shell.user_ns)
861
- return await r if co.co_flags & inspect.CO_COROUTINE else r
862
- shell.events.trigger('pre_execute')
863
- r = None
864
- try:
865
- if tree.body: await _go(tree, 'exec')
866
- if expr is not None: r = await _go(ast.Expression(body=expr), 'eval')
867
- finally: shell.events.trigger('post_execute')
868
- if src.rstrip().endswith(';') and not src.lstrip().startswith('%%'): return
869
- return r
870
-
871
- # %% ../nbs/13_nbio.ipynb #6b39aa5b
872
- async def show_cell(
873
- shell, # An IPython `InteractiveShell` (or compatible), as `exec_cell`
874
- src:str, # Cell source, as `exec_cell`
875
- raise_exc:bool=True, # Raise a failing cell's exception? Else display its traceback as the outcome
869
+ # %% ../nbs/13_nbio.ipynb #4c71f592
870
+ async def run_cell(
871
+ shell, # An `InteractiveShell`-compatible object: `transform_cell`, `run_cell_async`, `events`
872
+ raw_cell:str, # Python/IPython source for one cell: magics, `!` commands, and top-level `await` all work
873
+ store_history:bool=False, # Store the cell in the shell's history? (enables native `;` suppression and execution counts)
874
+ silent:bool=False, # Suppress displayhook and `post_run_cell` event? (the result value stays unset)
875
+ shell_futures:bool=True, # Share `__future__` imports with the shell?
876
+ cell_id=None, # Optional cell id, passed through to `run_cell_async`
876
877
  ):
877
- "Run cell `src` in `shell` and display its result, notebook-style"
878
- from IPython.display import display
879
- try: r = await exec_cell(shell, src)
878
+ "Run one cell on `shell`: transform, await `run_cell_async` on the calling loop, and fire the post events; returns the `ExecutionResult`"
879
+ preprocessing_exc_tuple = None
880
+ try: transformed_cell = shell.transform_cell(raw_cell)
880
881
  except Exception:
881
- if raise_exc: raise
882
- traceback.print_exc()
883
- return
884
- if r is not None: display(r)
882
+ transformed_cell = raw_cell
883
+ preprocessing_exc_tuple = sys.exc_info()
884
+ result = None
885
+ try: result = await shell.run_cell_async(raw_cell, store_history, silent, shell_futures=shell_futures,
886
+ transformed_cell=transformed_cell, preprocessing_exc_tuple=preprocessing_exc_tuple, cell_id=cell_id)
887
+ finally:
888
+ shell.events.trigger('post_execute')
889
+ if not silent: shell.events.trigger('post_run_cell', result)
890
+ return result
885
891
 
886
892
  # %% ../nbs/13_nbio.ipynb #ec976147
887
893
  def _msg_type(msg): return msg.get('msg_type') or msg['header']['msg_type']
@@ -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.5
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