toolslm 0.3.16__tar.gz → 0.3.17__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.
- {toolslm-0.3.16/toolslm.egg-info → toolslm-0.3.17}/PKG-INFO +1 -1
- {toolslm-0.3.16 → toolslm-0.3.17}/settings.ini +1 -1
- toolslm-0.3.17/toolslm/__init__.py +1 -0
- {toolslm-0.3.16 → toolslm-0.3.17}/toolslm/xml.py +12 -9
- {toolslm-0.3.16 → toolslm-0.3.17/toolslm.egg-info}/PKG-INFO +1 -1
- toolslm-0.3.16/toolslm/__init__.py +0 -1
- {toolslm-0.3.16 → toolslm-0.3.17}/LICENSE +0 -0
- {toolslm-0.3.16 → toolslm-0.3.17}/MANIFEST.in +0 -0
- {toolslm-0.3.16 → toolslm-0.3.17}/README.md +0 -0
- {toolslm-0.3.16 → toolslm-0.3.17}/pyproject.toml +0 -0
- {toolslm-0.3.16 → toolslm-0.3.17}/setup.cfg +0 -0
- {toolslm-0.3.16 → toolslm-0.3.17}/setup.py +0 -0
- {toolslm-0.3.16 → toolslm-0.3.17}/toolslm/_modidx.py +0 -0
- {toolslm-0.3.16 → toolslm-0.3.17}/toolslm/download.py +0 -0
- {toolslm-0.3.16 → toolslm-0.3.17}/toolslm/funccall.py +0 -0
- {toolslm-0.3.16 → toolslm-0.3.17}/toolslm/md_hier.py +0 -0
- {toolslm-0.3.16 → toolslm-0.3.17}/toolslm/shell.py +0 -0
- {toolslm-0.3.16 → toolslm-0.3.17}/toolslm.egg-info/SOURCES.txt +0 -0
- {toolslm-0.3.16 → toolslm-0.3.17}/toolslm.egg-info/dependency_links.txt +0 -0
- {toolslm-0.3.16 → toolslm-0.3.17}/toolslm.egg-info/entry_points.txt +0 -0
- {toolslm-0.3.16 → toolslm-0.3.17}/toolslm.egg-info/not-zip-safe +0 -0
- {toolslm-0.3.16 → toolslm-0.3.17}/toolslm.egg-info/requires.txt +0 -0
- {toolslm-0.3.16 → toolslm-0.3.17}/toolslm.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.3.17"
|
|
@@ -50,22 +50,23 @@ def cell2out(o):
|
|
|
50
50
|
if hasattr(o, 'ename'): return Out(f"{o.ename}: {o.evalue}", type='error')
|
|
51
51
|
|
|
52
52
|
# %% ../00_xml.ipynb
|
|
53
|
-
def cell2xml(cell, out=True):
|
|
53
|
+
def cell2xml(cell, out=True, ids=True):
|
|
54
54
|
"Convert notebook cell to concise XML format"
|
|
55
55
|
src = ''.join(getattr(cell, 'source', ''))
|
|
56
56
|
f = Code if cell.cell_type=='code' else Md
|
|
57
|
-
if
|
|
57
|
+
kw = dict(id=cell.id) if ids and hasattr(cell, 'id') else {}
|
|
58
|
+
if not out: return f(src, **kw)
|
|
58
59
|
parts = [Source(src)]
|
|
59
60
|
out_items = L(getattr(cell,'outputs',[])).map(cell2out).filter()
|
|
60
61
|
if out_items: parts.append(Outs(*out_items))
|
|
61
|
-
return f(*parts)
|
|
62
|
+
return f(*parts, **kw)
|
|
62
63
|
|
|
63
64
|
# %% ../00_xml.ipynb
|
|
64
|
-
def nb2xml(fname=None, nb=None, out=True):
|
|
65
|
+
def nb2xml(fname=None, nb=None, out=True, ids=True):
|
|
65
66
|
"Convert notebook to XML format"
|
|
66
67
|
assert bool(fname)^bool(nb), "Pass either `fname` or `nb`"
|
|
67
68
|
if not nb: nb = dict2obj(fname.read_json())
|
|
68
|
-
cells_xml = [to_xml(cell2xml(c, out=out), do_escape=False) for c in nb.cells if c.cell_type in ('code','markdown')]
|
|
69
|
+
cells_xml = [to_xml(cell2xml(c, out=out, ids=ids), do_escape=False) for c in nb.cells if c.cell_type in ('code','markdown')]
|
|
69
70
|
return to_xml(Notebook(*cells_xml), do_escape=False)
|
|
70
71
|
|
|
71
72
|
# %% ../00_xml.ipynb
|
|
@@ -115,10 +116,10 @@ def docs_xml(docs:list[str], # The content of each document
|
|
|
115
116
|
return pre + to_xml(Documents(*docs, **kw), do_escape=False)
|
|
116
117
|
|
|
117
118
|
# %% ../00_xml.ipynb
|
|
118
|
-
def read_file(fname, out=True, max_size=None):
|
|
119
|
+
def read_file(fname, out=True, max_size=None, ids=True):
|
|
119
120
|
"Read file content, converting notebooks to XML if needed"
|
|
120
121
|
fname = Path(fname)
|
|
121
|
-
if fname.suffix == '.ipynb': res = nb2xml(fname, out=out)
|
|
122
|
+
if fname.suffix == '.ipynb': res = nb2xml(fname, out=out, ids=ids)
|
|
122
123
|
else: res = fname.read_text()
|
|
123
124
|
if max_size and len(res)>max_size: return f"[Skipped: {fname.name} exceeds {max_size} bytes]"
|
|
124
125
|
return res
|
|
@@ -130,11 +131,12 @@ def files2ctx(
|
|
|
130
131
|
out:bool=True, # Include notebook cell outputs?
|
|
131
132
|
srcs:Optional[list]=None, # Use the labels instead of `fnames`
|
|
132
133
|
max_size:int=None, # Skip files larger than this (bytes)
|
|
134
|
+
ids:bool=True, # Include cell ids in notebooks?
|
|
133
135
|
**kwargs
|
|
134
136
|
)->str: # XML for LM context
|
|
135
137
|
"Convert files to XML context, handling notebooks"
|
|
136
138
|
fnames = [Path(o) for o in fnames]
|
|
137
|
-
contents = [read_file(o, out=out, max_size=max_size) for o in fnames]
|
|
139
|
+
contents = [read_file(o, out=out, max_size=max_size, ids=ids) for o in fnames]
|
|
138
140
|
return docs_xml(contents, srcs or fnames, **kwargs)
|
|
139
141
|
|
|
140
142
|
# %% ../00_xml.ipynb
|
|
@@ -149,6 +151,7 @@ def folder2ctx(
|
|
|
149
151
|
max_total:int=10_000_000, # Max total output size in bytes
|
|
150
152
|
readme_first:bool=False, # Prioritize README files at start of context?
|
|
151
153
|
files_only:bool=False, # Return dict of {filename: size} instead of context?
|
|
154
|
+
ids:bool=True, # Include cell ids in notebooks?
|
|
152
155
|
**kwargs
|
|
153
156
|
)->Union[str,dict]:
|
|
154
157
|
"Convert folder contents to XML context, handling notebooks"
|
|
@@ -157,7 +160,7 @@ def folder2ctx(
|
|
|
157
160
|
if files_only: return {str(f.relative_to(folder)): f.stat().st_size for f in fnames}
|
|
158
161
|
if readme_first: fnames = sorted(fnames, key=lambda f: (0 if 'readme' in f.name.lower() else 1, f))
|
|
159
162
|
srcs = fnames if include_base else [f.relative_to(folder) for f in fnames]
|
|
160
|
-
res = files2ctx(fnames, prefix=prefix, out=out, srcs=srcs, title=title, max_size=max_size)
|
|
163
|
+
res = files2ctx(fnames, prefix=prefix, out=out, srcs=srcs, title=title, max_size=max_size, ids=ids)
|
|
161
164
|
suf = f"\n\n[TRUNCATED: output size {{_outsz_}} exceeded max size {max_total} bytes]"
|
|
162
165
|
if max_total and len(res) > max_total: res = truncstr(res, max_total, suf=suf, sizevar='_outsz_')
|
|
163
166
|
return res
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.3.16"
|
|
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
|