fastcore 2.2.41__tar.gz → 2.2.43__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.41/fastcore.egg-info → fastcore-2.2.43}/PKG-INFO +1 -1
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/__init__.py +1 -1
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/_modidx.py +1 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/docments.py +1 -1
- fastcore-2.2.43/fastcore/editskill.py +54 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/parallel.py +12 -6
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/xtras.py +2 -3
- {fastcore-2.2.41 → fastcore-2.2.43/fastcore.egg-info}/PKG-INFO +1 -1
- fastcore-2.2.41/fastcore/editskill.py +0 -62
- {fastcore-2.2.41 → fastcore-2.2.43}/CONTRIBUTING.md +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/LICENSE +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/README.md +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/aio.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/all.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/ansi.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/apisurface.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/basics.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/dispatch.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/docscrape.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/foundation.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/funccall.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/imghdr.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/imports.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/meta.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/nb_imports.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/nbio.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/net.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/py2pyi.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/script.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/shutil.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/style.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/test.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/tools.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/transform.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/utils.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/xdg.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore/xml.py +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore.egg-info/SOURCES.txt +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore.egg-info/dependency_links.txt +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore.egg-info/entry_points.txt +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore.egg-info/requires.txt +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/fastcore.egg-info/top_level.txt +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/pyproject.toml +0 -0
- {fastcore-2.2.41 → fastcore-2.2.43}/setup.cfg +0 -0
|
@@ -696,6 +696,7 @@ d = { 'settings': { 'branch': 'main',
|
|
|
696
696
|
'fastcore/parallel.py'),
|
|
697
697
|
'fastcore.parallel._add_one': ('parallel.html#_add_one', 'fastcore/parallel.py'),
|
|
698
698
|
'fastcore.parallel._call': ('parallel.html#_call', 'fastcore/parallel.py'),
|
|
699
|
+
'fastcore.parallel._report_exc': ('parallel.html#_report_exc', 'fastcore/parallel.py'),
|
|
699
700
|
'fastcore.parallel.bg_task': ('parallel.html#bg_task', 'fastcore/parallel.py'),
|
|
700
701
|
'fastcore.parallel.parallel': ('parallel.html#parallel', 'fastcore/parallel.py'),
|
|
701
702
|
'fastcore.parallel.parallel_async': ('parallel.html#parallel_async', 'fastcore/parallel.py'),
|
|
@@ -206,7 +206,7 @@ def docments(s, full=False, eval_str=False, returns=True, args_kwargs=False):
|
|
|
206
206
|
docs = {}
|
|
207
207
|
while s is not None:
|
|
208
208
|
p = _param_locs(s, returns=returns, args_kwargs=args_kwargs) or {}
|
|
209
|
-
c = {o.start[0]:_clean_comment(o.string) for o in _tokens(s) if o.type==COMMENT}
|
|
209
|
+
c = {o.start[0]:_clean_comment(o.string) for o in _tokens(s) if o.type==COMMENT} if p else {}
|
|
210
210
|
for k,v in p.items():
|
|
211
211
|
if v not in docs: docs[v] = _get_comment(k, v, c, p)
|
|
212
212
|
s = getattr(s, '__delwrap__', None)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# NB: this file is designed for an LLM reader, not a human. Add it to your LLM's context and ask it to explain.
|
|
2
|
+
"""Text, file, cell, and notebook editing from `fastcore.tools` and `fastcore.nbio`, plus the conventions the whole fastai editing toolkit follows. Read this before working with the editing tools in any package that shares them.
|
|
3
|
+
|
|
4
|
+
- `import *`: fastcore.tools (text, file editors; `lnhash` addresses without exhash), fastcore.nbio (notebooks, cells; `Notebook`, `NbCell` session objects)
|
|
5
|
+
- notation: /why
|
|
6
|
+
- prefer, where installed: exhash.skill: verified edits; rgapi.skill: search; aidialog.dlgskill or dialoghelper: Solveit dialogs (.ipynb of notes, code, prompt/reply pairs); cell tools here still handle any notebook's structure, dialogs too
|
|
7
|
+
- remold: engine behind `ast_replace`
|
|
8
|
+
- `Notebook` `nb[k]`: k = position, cell id or unique id prefix; get cell, assign source, `del`
|
|
9
|
+
|
|
10
|
+
## Names, parameters: same across the toolkit
|
|
11
|
+
|
|
12
|
+
- text primitives (`str_replace`, `del_lines`, `ast_replace`, `exhash`, ...) act on a str; `file_`, `cell_`, `msg_` prefix: same op on that target, address args first
|
|
13
|
+
- other ops: verb_target (`view_file`, `read_nb`, `summary_nb`, `lnhashview_cell`); no extra dialog or notebook part: `find_msgs`, `add_msg`, `del_msgs`, `find_cells`
|
|
14
|
+
- msg: dialog message; cell: notebook cell; plural: several (`lnhashview_cells`); converter `x2y`, method `to_y`; `str_replace`: Anthropic text editor's name, argument order
|
|
15
|
+
- argument order: address (text; path; path, cell_id; message id), new text, keyword-only context (dialog)
|
|
16
|
+
- search patterns: regex by default; editors: literal unless `use_regex=True`
|
|
17
|
+
- `only_*` narrows, `incl_*` widens; `context=`: file lines (summary mode: blocks), cells or messages
|
|
18
|
+
- editors return a diff: read it, don't re-view
|
|
19
|
+
|
|
20
|
+
## Functions, methods
|
|
21
|
+
|
|
22
|
+
| |function|method
|
|
23
|
+
-|-|-
|
|
24
|
+
target|path|held object
|
|
25
|
+
saving|each call; returns diff|explicit `save()`
|
|
26
|
+
`NbCell`|`cell_str_replace(path, cell_id, ...)`|`c.str_replace(...)`
|
|
27
|
+
`Notebook`|`find_cells(path, pat)`|`nb.find_cells(pat)`
|
|
28
|
+
reads return|snapshot rows: addresses, source, metadata|objects
|
|
29
|
+
|
|
30
|
+
- method: the function's name and arguments, minus its target part and address
|
|
31
|
+
- one style per file: save before switching to functions; reopen before methods
|
|
32
|
+
|
|
33
|
+
## Addresses
|
|
34
|
+
|
|
35
|
+
- unsure where: summary first: `rg(summary=True)`, `nbrg`, `summary_dlg`, `open_doc` outline /an addressed row per block, cell, message or section
|
|
36
|
+
- copy from a view (`nums=True`, `lnhashs=True`, `rg(lnhashs=True)`); prefer lnhash where exhash is installed /stale ones rejected
|
|
37
|
+
- plain line numbers: unverified, shift: re-view after each edit; several: bottom-to-top
|
|
38
|
+
|
|
39
|
+
Docs: https://fastcore.fast.ai/tools.html.md and https://fastcore.fast.ai/nbio.html.md
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
from fastcore.tools import (insert_line, str_replace, strs_replace, replace_lines, del_lines, ast_replace,
|
|
43
|
+
file_insert_line, file_str_replace, file_strs_replace, file_replace_lines, file_del_lines, file_ast_replace,
|
|
44
|
+
view_file, create_file, line_hash, lnhash, lnhash_at)
|
|
45
|
+
from fastcore.nbio import (read_nb, write_nb, new_nb, mk_cell, validate_nb, validate_cell, repair_nb, repair_cell,
|
|
46
|
+
view_cell, cell_insert_line, cell_str_replace, cell_strs_replace, cell_replace_lines, cell_del_lines, cell_ast_replace, Notebook, NbCell, find_cells, summary_nb)
|
|
47
|
+
|
|
48
|
+
__all__ = ['insert_line', 'str_replace', 'strs_replace', 'replace_lines', 'del_lines', 'ast_replace',
|
|
49
|
+
'file_insert_line', 'file_str_replace', 'file_strs_replace', 'file_replace_lines', 'file_del_lines', 'file_ast_replace',
|
|
50
|
+
'view_file', 'create_file', 'line_hash', 'lnhash', 'lnhash_at',
|
|
51
|
+
'read_nb', 'write_nb', 'new_nb', 'mk_cell', 'validate_nb', 'validate_cell', 'repair_nb', 'repair_cell',
|
|
52
|
+
'view_cell', 'cell_insert_line', 'cell_str_replace', 'cell_strs_replace', 'cell_replace_lines', 'cell_del_lines', 'cell_ast_replace', 'Notebook', 'NbCell', 'find_cells', 'summary_nb']
|
|
53
|
+
|
|
54
|
+
__pyskill_params__ = {'replace_params': ('start_line', 'end_line', 'n_matches', 're_filter', 'invert_filter', 'use_regex')}
|
|
@@ -156,6 +156,13 @@ def _add_one(x, a=1):
|
|
|
156
156
|
return x+a
|
|
157
157
|
|
|
158
158
|
# %% ../nbs/03a_parallel.ipynb #9a6e2f26
|
|
159
|
+
def _report_exc(t, on_err=None, skip=None):
|
|
160
|
+
"Pass finished task `t`'s exception to `on_err`, or print its traceback; nothing if `t` was cancelled, succeeded, or raised `skip`"
|
|
161
|
+
import traceback
|
|
162
|
+
if t.cancelled() or (exc := t.exception()) is None or exc is skip: return
|
|
163
|
+
if on_err: on_err(exc)
|
|
164
|
+
else: traceback.print_exception(exc)
|
|
165
|
+
|
|
159
166
|
async def parallel_async_gen(f, items, *args, n_workers=16, pause=0,
|
|
160
167
|
timeout=None, return_exceptions=False, cancel_on_exit=True, **kwargs):
|
|
161
168
|
"Yield `(index,result)` pairs as `f` applied to each of `items` completes, in completion order"
|
|
@@ -176,6 +183,9 @@ async def parallel_async_gen(f, items, *args, n_workers=16, pause=0,
|
|
|
176
183
|
if cancel_on_exit:
|
|
177
184
|
for t in tasks: t.cancel()
|
|
178
185
|
await asyncio.gather(*tasks, return_exceptions=True)
|
|
186
|
+
else:
|
|
187
|
+
raised = sys.exc_info()[1]
|
|
188
|
+
for t in tasks: t.add_done_callback(partial(_report_exc, skip=raised))
|
|
179
189
|
|
|
180
190
|
# %% ../nbs/03a_parallel.ipynb #7406c085
|
|
181
191
|
@delegates(parallel_async_gen)
|
|
@@ -198,13 +208,9 @@ def bg_task(
|
|
|
198
208
|
on_err=None, # Called with the exception when the task fails; default prints the traceback
|
|
199
209
|
):
|
|
200
210
|
"Like `asyncio.create_task`, but keeps the task alive and reports exceptions, for fire-and-forget tasks"
|
|
201
|
-
import
|
|
202
|
-
def _done(t):
|
|
203
|
-
if not t.cancelled() and (exc := t.exception()):
|
|
204
|
-
if on_err: on_err(exc)
|
|
205
|
-
else: traceback.print_exception(exc)
|
|
211
|
+
import asyncio
|
|
206
212
|
task = asyncio.create_task(coro)
|
|
207
213
|
_bg_tasks.add(task)
|
|
208
214
|
task.add_done_callback(_bg_tasks.discard)
|
|
209
|
-
task.add_done_callback(
|
|
215
|
+
task.add_done_callback(partial(_report_exc, on_err=on_err))
|
|
210
216
|
return task
|
|
@@ -681,11 +681,10 @@ def __repr__(self:Path):
|
|
|
681
681
|
@patch
|
|
682
682
|
def delete(self:Path):
|
|
683
683
|
"Delete a file, symlink, or directory tree"
|
|
684
|
-
if not self.
|
|
685
|
-
if self.is_dir():
|
|
684
|
+
if not self.is_symlink() and self.is_dir():
|
|
686
685
|
import shutil
|
|
687
686
|
shutil.rmtree(self)
|
|
688
|
-
else: self.unlink()
|
|
687
|
+
else: self.unlink(missing_ok=True)
|
|
689
688
|
|
|
690
689
|
# %% ../nbs/03_xtras.ipynb #f2bb033e
|
|
691
690
|
class IterLen:
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"""Text, file, cell, and notebook editing from `fastcore.tools` and `fastcore.nbio`, plus the conventions the whole fastai editing toolkit follows. Read this before working with the editing tools in any package that shares them.
|
|
2
|
-
|
|
3
|
-
`from fastcore.editskill import *` loads `fastcore.tools` and `fastcore.nbio`.
|
|
4
|
-
|
|
5
|
-
## Targets and tools
|
|
6
|
-
|
|
7
|
-
Targets: in-memory strings, file paths, notebook cell sources (`path, cell_id`), and held `Notebook`/`NbCell` objects.
|
|
8
|
-
|
|
9
|
-
- `fastcore.tools`: text primitives, file tools, and `line_hash`/`lnhash`/`lnhash_at` address creation without exhash installed.
|
|
10
|
-
- `fastcore.nbio`: notebook read/write/validate/repair, cell construction/editing, and `Notebook`/`NbCell` session objects with snapshot queries (`find_cells`, `summary_nb`).
|
|
11
|
-
- `exhash.skill`: preferred hash-verified file/cell editing where installed; covers address forms and the verified edit loop.
|
|
12
|
-
- `rgapi.skill`: preferred search where installed: `rg`/`fd`/`ls`/`nbrg` with lnhash output, `rgstr` for text already held.
|
|
13
|
-
- `remold`: structural Python search/rewrite with declarative ast-grep rules, LibCST matcher transforms and symbol queries; the engine behind `ast_replace`.
|
|
14
|
-
- `aidialog.dlgskill`, `dialoghelper`: preferred dialog layer where installed, including its own theory of dialogs and projections. A Solveit dialog is an `.ipynb` with notes, runnable code and prompt/reply pairs. Cell tools handle notebook structure regardless of origin; this layer reads/edits dialog messages.
|
|
15
|
-
|
|
16
|
-
Open/save: `Notebook.open(path)`, `nb.save()`. Index by position or cell id (exact/unique prefix): `nb[k]` returns a cell, `nb[k] = src` sets its source, `del nb[k]` removes it. `nb.add(src, cell_type)`/`nb.md(src)` insert at `idx`, `after` or `before` a cell id; `nb.move(ids, after=, before=)` reorders cells.
|
|
17
|
-
|
|
18
|
-
## Naming
|
|
19
|
-
|
|
20
|
-
- File/notebook/cell/message operations: `verb_target` (`view_file`, `create_file`, `read_nb`, `write_nb`, `view_cell`, `validate_nb`, `view_msg`, `view_dlg`, `lnhashview_cell`). `find_msgs`, `add_msg`, `del_msgs`, `find_cells` need no extra dialog/notebook prefix. `msg` = dialog message; `cell` = notebook cell; `summary_nb` returns notebook-cell rows.
|
|
21
|
-
- Text primitives (`insert_line`, `del_lines`, `replace_lines`, `str_replace`) gain `file_`/`cell_`/`msg_` prefixes (`file_del_lines`, `cell_del_lines`, `msg_del_lines`); address arguments precede the primitive's arguments. `str_replace` retains Anthropic's text editor name/argument order. `ast_replace` (AST patterns) and `exhash` (hash-verified line addresses) use these prefixes too: `file_ast_replace`, `msg_ast_replace`, `file_exhash`, `cell_exhash`.
|
|
22
|
-
- Converters: `x2y` (`nb2dict`, `cell2xml`); methods: `to_y` (`nb.to_dict()`).
|
|
23
|
-
- Plurals accept several items: `view_cell` one cell, `lnhashview_cells` several, `del_msgs` many.
|
|
24
|
-
|
|
25
|
-
## Parameters: shared vocabulary
|
|
26
|
-
|
|
27
|
-
- Order: address (`text`; `path`; `path, cell_id`; message `id`), new text, then keyword-only ambient context (message tools' dialog).
|
|
28
|
-
- `start_line`/`end_line`: 1-based, inclusive; `None` = first/last line; negative `end_line` counts from the end. `del_lines` has no defaults: state the range.
|
|
29
|
-
- `re_filter`/`invert_filter`: lines (not) matching a regex, like ex `g//`/`g!//`; combines with the range.
|
|
30
|
-
- Search patterns default to regex; editors default to literal unless `use_regex=True`.
|
|
31
|
-
- Views: `nums` line numbers; `lnhashs` `lineno|hash|` addresses; `maxlen` caps summary lines; `trunc_out`/`trunc_in` truncate dialog outputs/sources.
|
|
32
|
-
- `fd`/`ls`/`rg`/`nbrg` share one include/exclude/ext/hidden/ignore block. `fd`/`rg`/`nbrg`: `pattern` first, `root='.'` second. `ls` is `fd` with listing defaults, but `root` first, like shell `ls DIR`.
|
|
33
|
-
- Filters narrow with `only_*` (`only_err`, `only_exp`, `only_errors`), widen with `incl_*` (`incl_out`).
|
|
34
|
-
- `context=` units: file lines (blocks in summary mode), notebook cells, dialog messages.
|
|
35
|
-
- Editors return a diff: read it as verification rather than re-viewing. No change: fastcore editors and exhash return `none: No changes.`
|
|
36
|
-
|
|
37
|
-
## Functions and methods
|
|
38
|
-
|
|
39
|
-
Functions take a path, save and return a diff; methods change held objects, saved explicitly. Methods drop address arguments and the object's part of the name: `cell_str_replace(path, cell_id, ...)` -> `c.str_replace(...)` on `NbCell`; `find_cells(path, pat)` -> `nb.find_cells(pat)` on `Notebook`. Read functions return snapshot rows (addresses, source, metadata); read methods return objects. One style per file: save before switching to functions; reopen before returning to methods.
|
|
40
|
-
|
|
41
|
-
## Navigation and addresses
|
|
42
|
-
|
|
43
|
-
When unsure where to edit, start with summaries: rgapi's `rg(summary=True)`/`nbrg`, aidialog's `summary_dlg`, exhash's `open_doc` outlines. They give one addressed row per block/cell/message/section. `open_doc` outlines Markdown, code and notebooks; `doc(open_doc)` covers inputs, navigation and llms.txt. A section is a span of lines or a run of cells, edited through file/cell tools. Token `1.6.|12|Py|,45|HD|` combines section number and first/last-line lnhash range; the range is an exhash address.
|
|
44
|
-
|
|
45
|
-
Edits take plain line numbers or lnhash addresses obtained while reading: `nums=True`/`lnhashs=True` views, `rg(lnhashs=True)`. Prefer lnhash addresses where exhash is installed; stale ones are rejected. Plain numbers are unverified and shift: re-view after each such edit; apply several bottom-to-top.
|
|
46
|
-
|
|
47
|
-
Docs: https://fastcore.fast.ai/tools.html.md and https://fastcore.fast.ai/nbio.html.md
|
|
48
|
-
"""
|
|
49
|
-
|
|
50
|
-
from fastcore.tools import (insert_line, str_replace, strs_replace, replace_lines, del_lines, ast_replace,
|
|
51
|
-
file_insert_line, file_str_replace, file_strs_replace, file_replace_lines, file_del_lines, file_ast_replace,
|
|
52
|
-
view_file, create_file, line_hash, lnhash, lnhash_at)
|
|
53
|
-
from fastcore.nbio import (read_nb, write_nb, new_nb, mk_cell, validate_nb, validate_cell, repair_nb, repair_cell,
|
|
54
|
-
view_cell, cell_insert_line, cell_str_replace, cell_strs_replace, cell_replace_lines, cell_del_lines, cell_ast_replace, Notebook, NbCell, find_cells, summary_nb)
|
|
55
|
-
|
|
56
|
-
__all__ = ['insert_line', 'str_replace', 'strs_replace', 'replace_lines', 'del_lines', 'ast_replace',
|
|
57
|
-
'file_insert_line', 'file_str_replace', 'file_strs_replace', 'file_replace_lines', 'file_del_lines', 'file_ast_replace',
|
|
58
|
-
'view_file', 'create_file', 'line_hash', 'lnhash', 'lnhash_at',
|
|
59
|
-
'read_nb', 'write_nb', 'new_nb', 'mk_cell', 'validate_nb', 'validate_cell', 'repair_nb', 'repair_cell',
|
|
60
|
-
'view_cell', 'cell_insert_line', 'cell_str_replace', 'cell_strs_replace', 'cell_replace_lines', 'cell_del_lines', 'cell_ast_replace', 'Notebook', 'NbCell', 'find_cells', 'summary_nb']
|
|
61
|
-
|
|
62
|
-
__pyskill_params__ = {'replace_params': ('start_line', 'end_line', 'n_matches', 're_filter', 'invert_filter', 'use_regex')}
|
|
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
|