fastcore 2.2.33__tar.gz → 2.2.34__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.33/fastcore.egg-info → fastcore-2.2.34}/PKG-INFO +1 -1
  2. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/__init__.py +1 -1
  3. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/ansi.py +5 -4
  4. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/basics.py +1 -0
  5. fastcore-2.2.34/fastcore/editskill.py +62 -0
  6. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/funccall.py +6 -12
  7. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/nbio.py +7 -4
  8. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/xml.py +1 -0
  9. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/xtras.py +1 -1
  10. {fastcore-2.2.33 → fastcore-2.2.34/fastcore.egg-info}/PKG-INFO +1 -1
  11. fastcore-2.2.33/fastcore/editskill.py +0 -64
  12. {fastcore-2.2.33 → fastcore-2.2.34}/CONTRIBUTING.md +0 -0
  13. {fastcore-2.2.33 → fastcore-2.2.34}/LICENSE +0 -0
  14. {fastcore-2.2.33 → fastcore-2.2.34}/README.md +0 -0
  15. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/_modidx.py +0 -0
  16. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/aio.py +0 -0
  17. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/all.py +0 -0
  18. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/apisurface.py +0 -0
  19. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/dispatch.py +0 -0
  20. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/docments.py +0 -0
  21. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/docscrape.py +0 -0
  22. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/foundation.py +0 -0
  23. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/imghdr.py +0 -0
  24. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/imports.py +0 -0
  25. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/meta.py +0 -0
  26. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/nb_imports.py +0 -0
  27. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/net.py +0 -0
  28. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/parallel.py +0 -0
  29. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/py2pyi.py +0 -0
  30. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/script.py +0 -0
  31. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/shutil.py +0 -0
  32. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/style.py +0 -0
  33. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/test.py +0 -0
  34. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/tools.py +0 -0
  35. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/transform.py +0 -0
  36. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/utils.py +0 -0
  37. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore/xdg.py +0 -0
  38. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore.egg-info/SOURCES.txt +0 -0
  39. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore.egg-info/dependency_links.txt +0 -0
  40. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore.egg-info/entry_points.txt +0 -0
  41. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore.egg-info/requires.txt +0 -0
  42. {fastcore-2.2.33 → fastcore-2.2.34}/fastcore.egg-info/top_level.txt +0 -0
  43. {fastcore-2.2.33 → fastcore-2.2.34}/pyproject.toml +0 -0
  44. {fastcore-2.2.33 → fastcore-2.2.34}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastcore
3
- Version: 2.2.33
3
+ Version: 2.2.34
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.33"
58
+ __version__ = "2.2.34"
@@ -9,20 +9,21 @@ from html import escape
9
9
  __all__ = ["strip_ansi", "ansi2html", "ansi2latex"]
10
10
 
11
11
  _ANSI_RE = re.compile("\x1b\\[(.*?)([@-~])")
12
+ _OSC_RE = re.compile(r'\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)')
12
13
  _ANSI_COLORS = ( "ansi-black", "ansi-red", "ansi-green", "ansi-yellow", "ansi-blue", "ansi-magenta", "ansi-cyan", "ansi-white", "ansi-black-intense",
13
14
  "ansi-red-intense", "ansi-green-intense", "ansi-yellow-intense", "ansi-blue-intense", "ansi-magenta-intense", "ansi-cyan-intense", "ansi-white-intense")
14
15
 
15
16
  def strip_terminal_queries(text):
16
- # Remove OSC sequences (like background color queries)
17
- text = re.sub('\x1b\\][^\x07]*\x07', '', text)
17
+ # Remove OSC sequences, such as hyperlinks and background color queries
18
+ text = _OSC_RE.sub('', text)
18
19
  # Remove DSR sequences (device status reports)
19
20
  return re.sub(r'\x1b\[[0-9]*n', '', text)
20
21
 
21
22
 
22
23
  def strip_ansi(source, term_queries:bool=False):
23
- "Remove ANSI escape codes from text."
24
+ "Remove ANSI escape codes, including OSC sequences such as hyperlinks, from text."
24
25
  if term_queries: source = strip_terminal_queries(source)
25
- return _ANSI_RE.sub("", source)
26
+ return _ANSI_RE.sub("", _OSC_RE.sub("", source))
26
27
 
27
28
 
28
29
  def _htmlconverter(fg, bg, bold, underline, inverse):
@@ -1314,6 +1314,7 @@ class NotStr(GetAttr):
1314
1314
  class PrettyString(str):
1315
1315
  "Little hack to get strings to show properly in Jupyter."
1316
1316
  def __repr__(self): return self
1317
+ full = True # Tools that truncate long strings show this whole
1317
1318
 
1318
1319
  # %% ../nbs/01_basics.ipynb #a5138103
1319
1320
  def even_mults(start, stop, n):
@@ -0,0 +1,62 @@
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')}
@@ -219,10 +219,9 @@ def _nm_map(nms):
219
219
  return py2orig
220
220
 
221
221
  # %% ../nbs/14_funccall.ipynb #47b49644
222
- def call_func(fc_name, fc_inputs, ns, raise_on_err=True):
223
- "Call the function `fc_name` with the given `fc_inputs` using namespace `ns`."
224
- if not isinstance(ns, abc.Mapping): ns = mk_ns(ns)
225
- func = resolve_nm(fc_name, ns)
222
+ def call_func(fc_name, fc_inputs, ns=None, raise_on_err=True):
223
+ "Call `fc_name`, a function or its name in namespace `ns`, with the given `fc_inputs`."
224
+ func = resolve_nm(fc_name, mk_ns(ns)) if isinstance(fc_name, str) else fc_name
226
225
  inps = {_norm_nm(k):v for k,v in fc_inputs.items()}
227
226
  inps = coerce_inputs(func, inps)
228
227
  try: return func(**inps)
@@ -231,17 +230,12 @@ def call_func(fc_name, fc_inputs, ns, raise_on_err=True):
231
230
  else: return traceback.format_exc()
232
231
 
233
232
  # %% ../nbs/14_funccall.ipynb #73bca085
234
- async def call_func_async(fc_name, fc_inputs, ns, raise_on_err=True):
235
- "Awaits the function `fc_name` with the given `fc_inputs` using namespace `ns`."
236
- if not isinstance(ns, abc.Mapping): ns = mk_ns(ns)
237
- func = resolve_nm(fc_name, ns)
238
- try:
239
- res = call_func(fc_name, fc_inputs, ns, raise_on_err=raise_on_err)
240
- res = await maybe_await(res)
233
+ async def call_func_async(fc_name, fc_inputs, ns=None, raise_on_err=True):
234
+ "Awaits `fc_name`, a function or its name in namespace `ns`, with the given `fc_inputs`."
235
+ try: return await maybe_await(call_func(fc_name, fc_inputs, ns, raise_on_err=raise_on_err))
241
236
  except Exception as e:
242
237
  if raise_on_err: raise e from None
243
238
  else: return traceback.format_exc()
244
- return res
245
239
 
246
240
  # %% ../nbs/14_funccall.ipynb #5a2588d5
247
241
  type_map = dict(string=str, boolean=bool, integer=int, number=float, array=list, object=dict)
@@ -799,9 +799,10 @@ def to_dict(self:Notebook):
799
799
  class Found:
800
800
  "Mixin for find-result containers: `matched` ids, id-only indexing, and match/context kinds"
801
801
  _unit = 'item'
802
- def __init__(self, items=None, matched=None):
802
+ def __init__(self, items=None, matched=None, maxlen=MAXLEN):
803
803
  super().__init__(items if items is not None else [])
804
804
  self.matched = set(matched) if matched is not None else {o.id for o in self}
805
+ self.maxlen = maxlen
805
806
  def kind(self, o): return 'match' if o.id in self.matched else 'context'
806
807
  def __getitem__(self, k):
807
808
  if not isinstance(k, str): raise TypeError(
@@ -814,7 +815,7 @@ class FoundCells(Found, list):
814
815
  "Find results: cells indexed by id (exact or unique prefix), shown as `CellRow` lines with context rows marked"
815
816
  _unit = 'cell'
816
817
  def __repr__(self):
817
- rows = [c if isinstance(c, CellRow) else CellRow(c) for c in self]
818
+ rows = [c if isinstance(c, CellRow) else CellRow(c, self.maxlen) for c in self]
818
819
  for r in rows: r.kind = self.kind(r)
819
820
  return '\n'.join(repr(r) for r in rows)
820
821
 
@@ -825,6 +826,7 @@ def find_cells(self:Notebook,
825
826
  cell_type:str=None, # Optional limit by type ('code', 'markdown', or 'raw')
826
827
  ids='', # Optional limit by cell ids (comma-separated str, or list); exact or unique prefixes
827
828
  context:int=None, # Cells of context around matches (default 1)
829
+ maxlen:int=MAXLEN, # Maximum source characters per displayed cell
828
830
  ):
829
831
  "Find live cells matching all the given criteria, plus `context` neighbouring cells"
830
832
  if context is None: context = 1
@@ -832,7 +834,7 @@ def find_cells(self:Notebook,
832
834
  cs = self.cells
833
835
  idxs = [i for i,c in enumerate(cs) if (not pat or re.search(pat, c.source)) and (not cell_type or c.cell_type==cell_type) and (not ids or c.id in ids)]
834
836
  keep = sorted({j for i in idxs for j in range(max(0,i-context), min(len(cs),i+context+1))})
835
- return FoundCells([cs[j] for j in keep], matched={cs[i].id for i in idxs})
837
+ return FoundCells([cs[j] for j in keep], matched={cs[i].id for i in idxs}, maxlen=maxlen)
836
838
 
837
839
  # %% ../nbs/13_nbio.ipynb #cb639e77
838
840
  def find_cells(
@@ -841,10 +843,11 @@ def find_cells(
841
843
  cell_type:str=None, # Optional limit by type ('code', 'markdown', or 'raw')
842
844
  ids='', # Optional limit by cell ids (comma-separated str, or list); exact or unique prefixes
843
845
  context:int=None, # Cells of context around matches (default 1)
846
+ maxlen:int=MAXLEN, # Maximum source characters per displayed cell
844
847
  ):
845
848
  "Snapshot `FoundCells` for matching cells in the notebook at `path`"
846
849
  fc = Notebook.open(path).find_cells(pat, cell_type, ids=ids, context=context)
847
- return FoundCells([CellRow(c) for c in fc], matched=fc.matched)
850
+ return FoundCells([CellRow(c, maxlen) for c in fc], matched=fc.matched)
848
851
 
849
852
  # %% ../nbs/13_nbio.ipynb #202a29f1
850
853
  def deep_merge(
@@ -158,6 +158,7 @@ def Html(*c, doctype=True, **kwargs)->FT:
158
158
  # %% ../nbs/09_xml.ipynb #116c886e
159
159
  class Safe(str):
160
160
  def __html__(self): return self
161
+ full = True # Tools that truncate long strings show this whole
161
162
 
162
163
  # %% ../nbs/09_xml.ipynb #254c8ff3
163
164
  def _escape(s):
@@ -258,7 +258,7 @@ def detect_mime(data):
258
258
  import mimetypes
259
259
  from fastcore import imghdr
260
260
  for (sig,pos),mime in _sigs.items():
261
- if data[pos:pos+len(sig)]==sig: return mime(data) if callable(mime) else mime
261
+ if data[pos:pos+len(sig)]==sig and (res := mime(data) if callable(mime) else mime): return res
262
262
  return mimetypes.types_map.get(f'.{imghdr.what(None, h=data)}')
263
263
 
264
264
  # %% ../nbs/03_xtras.ipynb #f856746a
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastcore
3
- Version: 2.2.33
3
+ Version: 2.2.34
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,64 +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` (text primitives, file tools) and `fastcore.nbio` (notebook I/O, cell editors). Where installed, prefer `exhash` for hash-verified editing, `rgapi` for search, and `aidialog`/`dialoghelper` for dialogs.
4
-
5
- ## Places
6
-
7
- Targets: strings in memory, files (a path), notebook cells (`path, cell_id`; edits that cell's source), and in-memory `Notebook`/`NbCell`. A Solveit dialog is an `.ipynb` whose cells are notes, runnable code, and prompt/reply pairs; cell tools work with notebook structure whatever produced the file, while `aidialog.dlgskill`/`dialoghelper` read and edit dialog messages. exhash's `open_doc` outlines Markdown, code, and notebooks (`doc(open_doc)`: inputs, navigation, llms.txt workflow); a section is a span of lines or a run of cells, changed with the file and cell tools.
8
-
9
- Open a `Notebook` with `Notebook.open(path)` and save it with `nb.save()`. Index it by position or cell id (exact or unique prefix): `nb[k]` returns a cell, `nb[k] = src` sets its source, and `del nb[k]` removes it. `nb.add(src, cell_type)` and `nb.md(src)` insert a cell at `idx`, or `after` or `before` a cell id. `nb.move(ids, after=, before=)` reorders cells.
10
-
11
- ## Naming
12
-
13
- - Operations on files, notebooks, cells, and messages: `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 rows for notebook cells.
14
- - Text primitives (`insert_line`, `del_lines`, `replace_lines`, `str_replace`) get `file_`/`cell_`/`msg_` versions (`file_del_lines`, `cell_del_lines`, `msg_del_lines`) that take the primitive's arguments after their address arguments. `str_replace` keeps the name and argument order of Anthropic's text editor tool. `ast_replace` (AST patterns) and `exhash` (hash-verified line addresses) use the same prefixes: `file_ast_replace`, `msg_ast_replace`, `file_exhash`, `cell_exhash`.
15
- - Converters: `x2y` (`nb2dict`, `cell2xml`, aidialog's `dlg2md`); converter methods: `to_y` (`nb.to_dict()`).
16
- - Plural names take several items: `view_cell` one cell, `lnhashview_cells` several, `del_msgs` many.
17
-
18
- ## Parameters (one vocabulary wherever it appears)
19
-
20
- - Order: the place's address (`text`; `path`; `path, cell_id`; a message `id`), then the new text, then ambient context as keyword-only (how message tools name their dialog).
21
- - `start_line`/`end_line`: 1-based, inclusive, `None` = first/last line; a negative `end_line` counts from the end. `del_lines` has no defaults: state the range.
22
- - `re_filter`/`invert_filter`: restrict an edit to lines (not) matching a regex, like ex `g//`/`g!//`; combines with the range.
23
- - Searches read patterns as regex by default; editors read them as literal text unless `use_regex=True`.
24
- - Views: `nums` (line numbers), `lnhashs` (`lineno|hash|` addresses); `maxlen` caps summary lines; `trunc_out`/`trunc_in` truncate outputs/sources in dialog views.
25
- - Search tools (`fd`, `ls`, `rg`, `nbrg`): `pattern` first, `root='.'`, one include/exclude/ext/hidden/ignore block; variants differ by defaults, not API (`ls` is `fd` with listing defaults).
26
- - Boolean filters narrow as `only_*` (`only_err`, `only_exp`, `only_errors`) and widen as `incl_*` (`incl_out`).
27
- - `context=` counts the place's units: lines (blocks in summary mode) for files, cells for notebooks, messages for dialogs.
28
- - Editors return a diff, which is the verification: read it rather than re-viewing. No change: fastcore editors and exhash return `none: No changes.`
29
-
30
- ## Functions and methods
31
-
32
- Functions take a path, save, and return a diff; methods change an object in memory, saved explicitly. Methods drop the address arguments and the object's part of the name: `cell_str_replace(path, cell_id, ...)` -> `c.str_replace(...)` on an `NbCell`; `find_cells(path, pat)` -> `nb.find_cells(pat)` on a `Notebook`. Read functions return snapshot rows (addresses, source, metadata); read methods return the objects. One style per file at a time: save before switching to functions, reopen before returning to methods.
33
-
34
- ## Addresses
35
-
36
- Edits take plain line numbers or lnhash addresses, got while reading: `nums=True`/`lnhashs=True` views, `rg(lnhashs=True)`. Prefer lnhash addresses where exhash is installed; stale ones are rejected. Plain line numbers are unverified and shift, so re-view after each such edit and apply several bottom-to-top. `exhash.skill` covers address forms and the verified edit loop.
37
-
38
- Not sure where to edit? Start with a summary: rgapi's `rg(summary=True)` and `nbrg`, aidialog's `summary_dlg`, and exhash's `open_doc` outlines give one addressed row per block, cell, message, or section. A section token such as `1.6.|12|Py|,45|HD|` is the section number plus the lnhash range of the section's first and last lines; that range works as an exhash address.
39
-
40
- ## What's where
41
-
42
- - `fastcore.tools`: text primitives, file tools, and `line_hash`/`lnhash`/`lnhash_at` for creating addresses without exhash installed.
43
- - `fastcore.nbio`: notebook read/write/validate/repair, cell construction, cell editors, and the `Notebook`/`NbCell` session objects with their snapshot queries (`find_cells`, `summary_nb`).
44
- - `exhash.skill`: hash-verified editing for files and cells, plus `open_doc` section outlines for Markdown, code, and notebooks; prefer it for edits where installed.
45
- - `rgapi.skill`: `rg`/`fd`/`ls`/`nbrg` search with lnhash output, and `rgstr` to search text already in hand.
46
- - `remold`: structural search and rewrite for Python source (declarative ast-grep rules, LibCST matcher transforms, symbol queries); the engine behind `ast_replace`.
47
- - `aidialog.dlgskill`, `dialoghelper`: the dialog layer, including its own theory of dialogs and projections.
48
-
49
- Docs: https://fastcore.fast.ai/tools.html.md and https://fastcore.fast.ai/nbio.html.md
50
- """
51
-
52
- from fastcore.tools import (insert_line, str_replace, strs_replace, replace_lines, del_lines, ast_replace,
53
- file_insert_line, file_str_replace, file_strs_replace, file_replace_lines, file_del_lines, file_ast_replace,
54
- view_file, create_file, line_hash, lnhash, lnhash_at)
55
- from fastcore.nbio import (read_nb, write_nb, new_nb, mk_cell, validate_nb, validate_cell, repair_nb, repair_cell,
56
- 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)
57
-
58
- __all__ = ['insert_line', 'str_replace', 'strs_replace', 'replace_lines', 'del_lines', 'ast_replace',
59
- 'file_insert_line', 'file_str_replace', 'file_strs_replace', 'file_replace_lines', 'file_del_lines', 'file_ast_replace',
60
- 'view_file', 'create_file', 'line_hash', 'lnhash', 'lnhash_at',
61
- 'read_nb', 'write_nb', 'new_nb', 'mk_cell', 'validate_nb', 'validate_cell', 'repair_nb', 'repair_cell',
62
- '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']
63
-
64
- __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