fastcore 2.2.37__tar.gz → 2.2.39__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.37/fastcore.egg-info → fastcore-2.2.39}/PKG-INFO +1 -1
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/__init__.py +1 -1
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/_modidx.py +1 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/docments.py +15 -4
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/parallel.py +5 -2
- {fastcore-2.2.37 → fastcore-2.2.39/fastcore.egg-info}/PKG-INFO +1 -1
- {fastcore-2.2.37 → fastcore-2.2.39}/CONTRIBUTING.md +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/LICENSE +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/README.md +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/aio.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/all.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/ansi.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/apisurface.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/basics.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/dispatch.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/docscrape.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/editskill.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/foundation.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/funccall.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/imghdr.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/imports.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/meta.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/nb_imports.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/nbio.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/net.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/py2pyi.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/script.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/shutil.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/style.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/test.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/tools.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/transform.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/utils.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/xdg.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/xml.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore/xtras.py +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore.egg-info/SOURCES.txt +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore.egg-info/dependency_links.txt +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore.egg-info/entry_points.txt +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore.egg-info/requires.txt +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/fastcore.egg-info/top_level.txt +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/pyproject.toml +0 -0
- {fastcore-2.2.37 → fastcore-2.2.39}/setup.cfg +0 -0
|
@@ -375,6 +375,7 @@ d = { 'settings': { 'branch': 'main',
|
|
|
375
375
|
'fastcore.docments._merge_docs': ('docments.html#_merge_docs', 'fastcore/docments.py'),
|
|
376
376
|
'fastcore.docments._param_locs': ('docments.html#_param_locs', 'fastcore/docments.py'),
|
|
377
377
|
'fastcore.docments._parses': ('docments.html#_parses', 'fastcore/docments.py'),
|
|
378
|
+
'fastcore.docments._relocated_source': ('docments.html#_relocated_source', 'fastcore/docments.py'),
|
|
378
379
|
'fastcore.docments._tokens': ('docments.html#_tokens', 'fastcore/docments.py'),
|
|
379
380
|
'fastcore.docments._type_str': ('docments.html#_type_str', 'fastcore/docments.py'),
|
|
380
381
|
'fastcore.docments._unwrap_sym': ('docments.html#_unwrap_sym', 'fastcore/docments.py'),
|
|
@@ -24,7 +24,7 @@ __all__ = ['empty', 'docstring', 'parse_docstring', 'isdataclass', 'get_dataclas
|
|
|
24
24
|
'sig2str', 'can_render', 'ShowDocRenderer', 'MarkdownRenderer']
|
|
25
25
|
|
|
26
26
|
# %% ../nbs/04_docments.ipynb #4c662acc
|
|
27
|
-
import re,ast,inspect
|
|
27
|
+
import re,ast,inspect,linecache
|
|
28
28
|
from tokenize import tokenize,COMMENT
|
|
29
29
|
from ast import parse,FunctionDef,AsyncFunctionDef,AnnAssign
|
|
30
30
|
from io import BytesIO
|
|
@@ -72,6 +72,16 @@ def _defines(src, f):
|
|
|
72
72
|
d = re.search(r'^\s*(?:async\s+)?def\s+(\w+)', src, re.M)
|
|
73
73
|
return bool(re.match(r'\s*(@|(async\s+)?def\s)', src)) and bool(d) and d[1]==nm
|
|
74
74
|
|
|
75
|
+
def _relocated_source(f):
|
|
76
|
+
src = ''.join(linecache.getlines(inspect.getfile(f), f.__globals__))
|
|
77
|
+
node = parse(src)
|
|
78
|
+
for name in f.__qualname__.replace('.<locals>', '').split('.'):
|
|
79
|
+
nodes = [o for o in node.body if isinstance(o, (FunctionDef,AsyncFunctionDef,ast.ClassDef)) and o.name==name]
|
|
80
|
+
if len(nodes)!=1: raise OSError(f"Could not locate source for {f.__qualname__}")
|
|
81
|
+
node = nodes[0]
|
|
82
|
+
start = min([node.lineno, *(d.lineno for d in node.decorator_list)])-1
|
|
83
|
+
return ''.join(src.splitlines(keepends=True)[start:node.end_lineno])
|
|
84
|
+
|
|
75
85
|
def get_source(s):
|
|
76
86
|
"Get source for a function, callable implementation, dataclass, or source string"
|
|
77
87
|
if isinstance(s,str): return s
|
|
@@ -79,9 +89,10 @@ def get_source(s):
|
|
|
79
89
|
if isinstance(s, partial): s = s.func
|
|
80
90
|
if _callable_instance(s): s = s.__call__
|
|
81
91
|
if not (isfunction(s) or ismethod(s)): return get_dataclass_source(s) if isdataclass(s) else None
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return
|
|
92
|
+
f = getattr(s, '__func__', s)
|
|
93
|
+
try: src = getsource(s)
|
|
94
|
+
except OSError: return _relocated_source(f)
|
|
95
|
+
return src if _defines(src, f) else _relocated_source(f)
|
|
85
96
|
|
|
86
97
|
# %% ../nbs/04_docments.ipynb #40e3f274
|
|
87
98
|
def _get_property_name(p):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""Threading and multiprocessing functions
|
|
2
2
|
|
|
3
|
-
`parallel(f, items)` applies `f` to each item using a process pool. Set `threadpool=True` to use threads. Set `n_workers` to control concurrency, or to 0 for serial execution when debugging. Optional arguments include a `progress` bar, a `pause` between starts,
|
|
3
|
+
`parallel(f, items)` applies `f` to each item using a process pool. Set `threadpool=True` to use threads. Set `n_workers` to control concurrency, or to 0 for serial execution when debugging. Optional arguments include a `progress` bar, a `pause` between starts, `return_exceptions` to collect errors, and `max_tasks_per_child=1` to run each item in a new process (Python 3.11 and later, with `f` importable from a module rather than defined in `__main__`). `parallel_async` runs work concurrently with asyncio.
|
|
4
4
|
|
|
5
5
|
`@threaded` runs a function in a background thread and returns the thread. Read its `result` attribute after it finishes. Set `process=True` to run in a process. `startthread` and `startproc` start their decorated functions immediately.
|
|
6
6
|
|
|
@@ -129,11 +129,14 @@ class ProcessPoolExecutor(concurrent.futures.ProcessPoolExecutor):
|
|
|
129
129
|
|
|
130
130
|
# %% ../nbs/03a_parallel.ipynb #529e1bb1
|
|
131
131
|
def parallel(f, items, *args, n_workers=defaults.cpus, total=None, progress=None, pause=0,
|
|
132
|
-
method=None, threadpool=False, timeout=None, chunksize=1, return_exceptions=False, **kwargs):
|
|
132
|
+
method=None, threadpool=False, timeout=None, chunksize=1, return_exceptions=False, max_tasks_per_child=None, **kwargs):
|
|
133
133
|
"Applies `func` in parallel to `items`, using `n_workers`"
|
|
134
134
|
kwpool = {}
|
|
135
135
|
if threadpool: pool = ThreadPoolExecutor
|
|
136
136
|
else:
|
|
137
|
+
if max_tasks_per_child:
|
|
138
|
+
kwpool['max_tasks_per_child'] = max_tasks_per_child
|
|
139
|
+
if not method: method = 'spawn' if sys.platform == 'win32' else 'forkserver'
|
|
137
140
|
if not method and sys.platform == 'darwin': method='fork'
|
|
138
141
|
if method: kwpool['mp_context'] = get_context(method)
|
|
139
142
|
pool = ProcessPoolExecutor
|
|
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
|