fastcore 2.2.4__tar.gz → 2.2.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 (44) hide show
  1. {fastcore-2.2.4/fastcore.egg-info → fastcore-2.2.6}/PKG-INFO +1 -1
  2. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/__init__.py +1 -1
  3. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/_modidx.py +3 -2
  4. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/nbio.py +21 -37
  5. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/parallel.py +29 -14
  6. {fastcore-2.2.4 → fastcore-2.2.6/fastcore.egg-info}/PKG-INFO +1 -1
  7. {fastcore-2.2.4 → fastcore-2.2.6}/CONTRIBUTING.md +0 -0
  8. {fastcore-2.2.4 → fastcore-2.2.6}/LICENSE +0 -0
  9. {fastcore-2.2.4 → fastcore-2.2.6}/MANIFEST.in +0 -0
  10. {fastcore-2.2.4 → fastcore-2.2.6}/README.md +0 -0
  11. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/aio.py +0 -0
  12. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/all.py +0 -0
  13. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/ansi.py +0 -0
  14. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/apisurface.py +0 -0
  15. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/basics.py +0 -0
  16. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/dispatch.py +0 -0
  17. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/docments.py +0 -0
  18. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/docscrape.py +0 -0
  19. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/editskill.py +0 -0
  20. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/foundation.py +0 -0
  21. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/funccall.py +0 -0
  22. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/imghdr.py +0 -0
  23. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/imports.py +0 -0
  24. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/meta.py +0 -0
  25. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/nb_imports.py +0 -0
  26. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/net.py +0 -0
  27. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/py2pyi.py +0 -0
  28. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/script.py +0 -0
  29. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/shutil.py +0 -0
  30. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/style.py +0 -0
  31. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/test.py +0 -0
  32. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/tools.py +0 -0
  33. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/transform.py +0 -0
  34. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/utils.py +0 -0
  35. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/xdg.py +0 -0
  36. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/xml.py +0 -0
  37. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore/xtras.py +0 -0
  38. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore.egg-info/SOURCES.txt +0 -0
  39. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore.egg-info/dependency_links.txt +0 -0
  40. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore.egg-info/entry_points.txt +0 -0
  41. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore.egg-info/requires.txt +0 -0
  42. {fastcore-2.2.4 → fastcore-2.2.6}/fastcore.egg-info/top_level.txt +0 -0
  43. {fastcore-2.2.4 → fastcore-2.2.6}/pyproject.toml +0 -0
  44. {fastcore-2.2.4 → fastcore-2.2.6}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastcore
3
- Version: 2.2.4
3
+ Version: 2.2.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
@@ -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.4"
58
+ __version__ = "2.2.6"
@@ -611,7 +611,6 @@ d = { 'settings': { 'branch': 'main',
611
611
  'fastcore.nbio.deep_merge': ('nbio.html#deep_merge', 'fastcore/nbio.py'),
612
612
  'fastcore.nbio.dict2nb': ('nbio.html#dict2nb', 'fastcore/nbio.py'),
613
613
  'fastcore.nbio.dir_tag': ('nbio.html#dir_tag', 'fastcore/nbio.py'),
614
- 'fastcore.nbio.exec_cell': ('nbio.html#exec_cell', 'fastcore/nbio.py'),
615
614
  'fastcore.nbio.find_cells': ('nbio.html#find_cells', 'fastcore/nbio.py'),
616
615
  'fastcore.nbio.find_id': ('nbio.html#find_id', 'fastcore/nbio.py'),
617
616
  'fastcore.nbio.first_code_ln': ('nbio.html#first_code_ln', 'fastcore/nbio.py'),
@@ -638,8 +637,8 @@ d = { 'settings': { 'branch': 'main',
638
637
  'fastcore.nbio.render_text': ('nbio.html#render_text', 'fastcore/nbio.py'),
639
638
  'fastcore.nbio.repair_cell': ('nbio.html#repair_cell', 'fastcore/nbio.py'),
640
639
  'fastcore.nbio.repair_nb': ('nbio.html#repair_nb', 'fastcore/nbio.py'),
640
+ 'fastcore.nbio.run_cell': ('nbio.html#run_cell', 'fastcore/nbio.py'),
641
641
  'fastcore.nbio.select_cells': ('nbio.html#select_cells', 'fastcore/nbio.py'),
642
- 'fastcore.nbio.show_cell': ('nbio.html#show_cell', 'fastcore/nbio.py'),
643
642
  'fastcore.nbio.summary_nb': ('nbio.html#summary_nb', 'fastcore/nbio.py'),
644
643
  'fastcore.nbio.update_cell': ('nbio.html#update_cell', 'fastcore/nbio.py'),
645
644
  'fastcore.nbio.validate_cell': ('nbio.html#validate_cell', 'fastcore/nbio.py'),
@@ -689,6 +688,8 @@ d = { 'settings': { 'branch': 'main',
689
688
  'fastcore.parallel.bg_task': ('parallel.html#bg_task', 'fastcore/parallel.py'),
690
689
  'fastcore.parallel.parallel': ('parallel.html#parallel', 'fastcore/parallel.py'),
691
690
  'fastcore.parallel.parallel_async': ('parallel.html#parallel_async', 'fastcore/parallel.py'),
691
+ 'fastcore.parallel.parallel_async_dict': ('parallel.html#parallel_async_dict', 'fastcore/parallel.py'),
692
+ 'fastcore.parallel.parallel_async_gen': ('parallel.html#parallel_async_gen', 'fastcore/parallel.py'),
692
693
  'fastcore.parallel.parallelable': ('parallel.html#parallelable', 'fastcore/parallel.py'),
693
694
  'fastcore.parallel.startproc': ('parallel.html#startproc', 'fastcore/parallel.py'),
694
695
  'fastcore.parallel.startthread': ('parallel.html#startthread', 'fastcore/parallel.py'),
@@ -16,7 +16,7 @@ __all__ = ['langs', 'cell_insert_line', 'cell_str_replace', 'cell_strs_replace',
16
16
  'preferred_out', 'join_out', 'mk_stream', 'mk_result', 'mk_display', 'mk_error', 'concat_streams',
17
17
  'preferred_msg_out', 'render_output', 'render_outputs', 'render_text', 'item2xml', 'cell2xml', 'cells2xml',
18
18
  'Notebook', 'CellRow', 'CellRows', 'summary_nb', 'Found', 'FoundCells', 'find_cells', 'deep_merge',
19
- 'update_cell', 'select_cells', 'exec_cell', 'show_cell', 'msg2out', 'msgs2outs']
19
+ 'update_cell', 'select_cells', 'run_cell', 'msg2out', 'msgs2outs']
20
20
 
21
21
  # %% ../nbs/13_nbio.ipynb #954ca1aa
22
22
  from .basics import *
@@ -866,44 +866,28 @@ def select_cells(
866
866
  if skip_noeval: sel = [o for o in sel if not _is_noeval(o)]
867
867
  return sel
868
868
 
869
- # %% ../nbs/13_nbio.ipynb #b30755db
870
- async def exec_cell(
871
- shell, # An IPython `InteractiveShell` (or compatible: `transform_cell`, `compile`, `user_ns`, `events`)
872
- src:str, # Cell source: magics, `!` commands, and top-level `await` all work
873
- ): # The final bare expression's value (None if there is none, or a trailing `;` suppresses it)
874
- "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"
875
- __tracebackhide__ = True
876
- xsrc = shell.transform_cell(src)
877
- tree,cfname = ast.parse(xsrc),shell.compile.cache(xsrc)
878
- expr = tree.body.pop().value if tree.body and isinstance(tree.body[-1], ast.Expr) else None
879
- async def _go(node, mode):
880
- __tracebackhide__ = "__ipython_bottom__" # to the debugger: all frames above are host machinery
881
- co = compile(ast.fix_missing_locations(node), cfname, mode, flags=ast.PyCF_ALLOW_TOP_LEVEL_AWAIT)
882
- r = eval(co, shell.user_global_ns, shell.user_ns)
883
- return await r if co.co_flags & inspect.CO_COROUTINE else r
884
- shell.events.trigger('pre_execute')
885
- r = None
886
- try:
887
- if tree.body: await _go(tree, 'exec')
888
- if expr is not None: r = await _go(ast.Expression(body=expr), 'eval')
889
- finally: shell.events.trigger('post_execute')
890
- if src.rstrip().endswith(';') and not src.lstrip().startswith('%%'): return
891
- return r
892
-
893
- # %% ../nbs/13_nbio.ipynb #6b39aa5b
894
- async def show_cell(
895
- shell, # An IPython `InteractiveShell` (or compatible), as `exec_cell`
896
- src:str, # Cell source, as `exec_cell`
897
- 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`
898
877
  ):
899
- "Run cell `src` in `shell` and display its result, notebook-style"
900
- from IPython.display import display
901
- 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)
902
881
  except Exception:
903
- if raise_exc: raise
904
- traceback.print_exc()
905
- return
906
- 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
907
891
 
908
892
  # %% ../nbs/13_nbio.ipynb #ec976147
909
893
  def _msg_type(msg): return msg.get('msg_type') or msg['header']['msg_type']
@@ -8,7 +8,7 @@ Docs: https://fastcore.fast.ai/parallel.html.md"""
8
8
 
9
9
  # %% auto #0
10
10
  __all__ = ['threaded', 'startthread', 'startproc', 'parallelable', 'ThreadPoolExecutor', 'ProcessPoolExecutor', 'parallel',
11
- 'parallel_async', 'bg_task']
11
+ 'parallel_async_gen', 'parallel_async_dict', 'parallel_async', 'bg_task']
12
12
 
13
13
  # %% ../nbs/03a_parallel.ipynb #569d18c6
14
14
  from .imports import *
@@ -19,7 +19,7 @@ from .xtras import *
19
19
  from functools import wraps
20
20
 
21
21
  import concurrent.futures,time
22
- from multiprocessing import Process,Queue,Manager,set_start_method,get_all_start_methods,get_context
22
+ from multiprocessing import Process,Manager,set_start_method,get_context
23
23
  from threading import Thread,Lock
24
24
  try:
25
25
  if sys.platform == 'darwin' and IN_NOTEBOOK: set_start_method("fork")
@@ -127,7 +127,7 @@ class ProcessPoolExecutor(concurrent.futures.ProcessPoolExecutor):
127
127
 
128
128
  # %% ../nbs/03a_parallel.ipynb #529e1bb1
129
129
  def parallel(f, items, *args, n_workers=defaults.cpus, total=None, progress=None, pause=0,
130
- method=None, threadpool=False, timeout=None, chunksize=1, return_exceptions=False, **kwargs):
130
+ method=None, threadpool=False, timeout=None, chunksize=1, return_exceptions=False, **kwargs):
131
131
  "Applies `func` in parallel to `items`, using `n_workers`"
132
132
  kwpool = {}
133
133
  if threadpool: pool = ThreadPoolExecutor
@@ -150,25 +150,40 @@ def _add_one(x, a=1):
150
150
  time.sleep(random.random()/80)
151
151
  return x+a
152
152
 
153
- # %% ../nbs/03a_parallel.ipynb #87a80e04
154
- async def parallel_async(f, items, *args, n_workers=16, pause=0,
155
- timeout=None, chunksize=1, cancel_on_error=False, return_exceptions=False, **kwargs):
156
- "Applies `f` to `items` in parallel using asyncio and a semaphore to limit concurrency."
153
+ # %% ../nbs/03a_parallel.ipynb #9a6e2f26
154
+ async def parallel_async_gen(f, items, *args, n_workers=16, pause=0,
155
+ timeout=None, return_exceptions=False, cancel_on_exit=True, **kwargs):
156
+ "Yield `(index,result)` pairs as `f` applied to each of `items` completes, in completion order"
157
157
  import asyncio
158
158
  semaphore = asyncio.Semaphore(n_workers)
159
159
  async def limited_task(i, item):
160
160
  if pause: await asyncio.sleep(i * pause)
161
161
  async with semaphore:
162
162
  coro = f(item, *args, **kwargs) if asyncio.iscoroutinefunction(f) else asyncio.to_thread(f, item, *args, **kwargs)
163
- return await asyncio.wait_for(coro, timeout) if timeout else await coro
164
- if cancel_on_error:
165
- tasks = [asyncio.ensure_future(limited_task(i, item)) for i,item in enumerate(items)]
166
- try: return await asyncio.gather(*tasks)
167
- except BaseException:
163
+ try: return i, (await asyncio.wait_for(coro, timeout) if timeout else await coro)
164
+ except Exception as e:
165
+ if return_exceptions: return i, e
166
+ raise
167
+ tasks = [asyncio.ensure_future(limited_task(i, o)) for i,o in enumerate(items)]
168
+ try:
169
+ for t in asyncio.as_completed(tasks): yield await t
170
+ finally:
171
+ if cancel_on_exit:
168
172
  for t in tasks: t.cancel()
169
173
  await asyncio.gather(*tasks, return_exceptions=True)
170
- raise
171
- return await asyncio.gather(*[limited_task(i, item) for i,item in enumerate(items)], return_exceptions=return_exceptions)
174
+
175
+ # %% ../nbs/03a_parallel.ipynb #7406c085
176
+ @delegates(parallel_async_gen)
177
+ async def parallel_async_dict(f, items, *args, **kwargs):
178
+ "Apply `f` to `items` in parallel, returning `{index: result}` in completion order"
179
+ return {i:r async for i,r in parallel_async_gen(f, items, *args, **kwargs)}
180
+
181
+ # %% ../nbs/03a_parallel.ipynb #87a80e04
182
+ @delegates(parallel_async_dict, but=['cancel_on_exit'])
183
+ async def parallel_async(f, items, *args, cancel_on_error=False, **kwargs):
184
+ "Applies `f` to `items` in parallel using asyncio and a semaphore to limit concurrency."
185
+ res = await parallel_async_dict(f, items, *args, cancel_on_exit=cancel_on_error, **kwargs)
186
+ return L(res[i] for i in range(len(res)))
172
187
 
173
188
  # %% ../nbs/03a_parallel.ipynb #6748aa27
174
189
  def bg_task(coro):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastcore
3
- Version: 2.2.4
3
+ Version: 2.2.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
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