fastcore 2.2.40__tar.gz → 2.2.42__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.40/fastcore.egg-info → fastcore-2.2.42}/PKG-INFO +1 -1
  2. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/__init__.py +1 -1
  3. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/_modidx.py +1 -0
  4. fastcore-2.2.42/fastcore/editskill.py +54 -0
  5. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/nbio.py +2 -1
  6. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/parallel.py +12 -6
  7. {fastcore-2.2.40 → fastcore-2.2.42/fastcore.egg-info}/PKG-INFO +1 -1
  8. fastcore-2.2.40/fastcore/editskill.py +0 -62
  9. {fastcore-2.2.40 → fastcore-2.2.42}/CONTRIBUTING.md +0 -0
  10. {fastcore-2.2.40 → fastcore-2.2.42}/LICENSE +0 -0
  11. {fastcore-2.2.40 → fastcore-2.2.42}/README.md +0 -0
  12. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/aio.py +0 -0
  13. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/all.py +0 -0
  14. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/ansi.py +0 -0
  15. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/apisurface.py +0 -0
  16. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/basics.py +0 -0
  17. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/dispatch.py +0 -0
  18. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/docments.py +0 -0
  19. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/docscrape.py +0 -0
  20. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/foundation.py +0 -0
  21. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/funccall.py +0 -0
  22. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/imghdr.py +0 -0
  23. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/imports.py +0 -0
  24. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/meta.py +0 -0
  25. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/nb_imports.py +0 -0
  26. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/net.py +0 -0
  27. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/py2pyi.py +0 -0
  28. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/script.py +0 -0
  29. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/shutil.py +0 -0
  30. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/style.py +0 -0
  31. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/test.py +0 -0
  32. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/tools.py +0 -0
  33. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/transform.py +0 -0
  34. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/utils.py +0 -0
  35. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/xdg.py +0 -0
  36. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/xml.py +0 -0
  37. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore/xtras.py +0 -0
  38. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore.egg-info/SOURCES.txt +0 -0
  39. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore.egg-info/dependency_links.txt +0 -0
  40. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore.egg-info/entry_points.txt +0 -0
  41. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore.egg-info/requires.txt +0 -0
  42. {fastcore-2.2.40 → fastcore-2.2.42}/fastcore.egg-info/top_level.txt +0 -0
  43. {fastcore-2.2.40 → fastcore-2.2.42}/pyproject.toml +0 -0
  44. {fastcore-2.2.40 → fastcore-2.2.42}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastcore
3
- Version: 2.2.40
3
+ Version: 2.2.42
4
4
  Summary: Python supercharged for fastai development
5
5
  Author-email: Jeremy Howard and Sylvain Gugger <infos@fast.ai>
6
6
  License-Expression: Apache-2.0
@@ -55,4 +55,4 @@ Modules:
55
55
  - `fastcore.xml`: Concise HTML generation and namespace-aware XML construction.
56
56
  - `fastcore.xtras`: Utility functions used in the fastai library"""
57
57
 
58
- __version__ = "2.2.40"
58
+ __version__ = "2.2.42"
@@ -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'),
@@ -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')}
@@ -563,7 +563,7 @@ def mk_error(traceback, ename='', evalue=''):
563
563
 
564
564
  # %% ../nbs/13_nbio.ipynb #493e36b0
565
565
  def concat_streams(outputs):
566
- "Concatenate stream outputs by name (stdout/stderr), preserving execute_result at end"
566
+ "Concatenate stdout/stderr and Markdown streams, preserving execute_result at end"
567
567
  streams, res, execute_results = {}, [], []
568
568
  for out in outputs:
569
569
  if out['output_type'] == 'stream':
@@ -573,6 +573,7 @@ def concat_streams(outputs):
573
573
  else: res.append(out)
574
574
  for name in ('stdout','stderr'):
575
575
  if name in streams: res.append(mk_stream(name, clean_cli_output(streams[name], strip=False)))
576
+ if 'markdown' in streams: res.append(mk_display(text_markdown=streams['markdown']))
576
577
  res.extend(execute_results)
577
578
  return res
578
579
 
@@ -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 traceback,asyncio
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(_done)
215
+ task.add_done_callback(partial(_report_exc, on_err=on_err))
210
216
  return task
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastcore
3
- Version: 2.2.40
3
+ Version: 2.2.42
4
4
  Summary: Python supercharged for fastai development
5
5
  Author-email: Jeremy Howard and Sylvain Gugger <infos@fast.ai>
6
6
  License-Expression: Apache-2.0
@@ -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