Skip to content

Commit 3b922e3

Browse files
committed
fixes #77
1 parent d45487a commit 3b922e3

4 files changed

Lines changed: 158 additions & 24 deletions

File tree

dialoghelper/_modidx.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
'dialoghelper.core.ast_grep': ('core.html#ast_grep', 'dialoghelper/core.py'),
2323
'dialoghelper.core.ast_py': ('core.html#ast_py', 'dialoghelper/core.py'),
2424
'dialoghelper.core.call_endp': ('core.html#call_endp', 'dialoghelper/core.py'),
25+
'dialoghelper.core.ctx_folder': ('core.html#ctx_folder', 'dialoghelper/core.py'),
26+
'dialoghelper.core.ctx_repo': ('core.html#ctx_repo', 'dialoghelper/core.py'),
27+
'dialoghelper.core.ctx_symfile': ('core.html#ctx_symfile', 'dialoghelper/core.py'),
28+
'dialoghelper.core.ctx_symfolder': ('core.html#ctx_symfolder', 'dialoghelper/core.py'),
29+
'dialoghelper.core.ctx_sympkg': ('core.html#ctx_sympkg', 'dialoghelper/core.py'),
2530
'dialoghelper.core.curr_dialog': ('core.html#curr_dialog', 'dialoghelper/core.py'),
2631
'dialoghelper.core.del_msg': ('core.html#del_msg', 'dialoghelper/core.py'),
2732
'dialoghelper.core.event_get': ('core.html#event_get', 'dialoghelper/core.py'),
@@ -31,8 +36,6 @@
3136
'dialoghelper.core.find_msgs': ('core.html#find_msgs', 'dialoghelper/core.py'),
3237
'dialoghelper.core.find_var': ('core.html#find_var', 'dialoghelper/core.py'),
3338
'dialoghelper.core.fire_event': ('core.html#fire_event', 'dialoghelper/core.py'),
34-
'dialoghelper.core.get_folder': ('core.html#get_folder', 'dialoghelper/core.py'),
35-
'dialoghelper.core.get_repo': ('core.html#get_repo', 'dialoghelper/core.py'),
3639
'dialoghelper.core.gist_file': ('core.html#gist_file', 'dialoghelper/core.py'),
3740
'dialoghelper.core.iife': ('core.html#iife', 'dialoghelper/core.py'),
3841
'dialoghelper.core.import_gist': ('core.html#import_gist', 'dialoghelper/core.py'),

dialoghelper/core.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
__all__ = ['md_cls_d', 'dh_settings', 'Placements', 'empty', 'add_styles', 'find_var', 'set_var', 'find_dname', 'find_msg_id',
55
'call_endp', 'curr_dialog', 'msg_idx', 'add_scr', 'iife', 'pop_data', 'fire_event', 'event_get', 'find_msgs',
66
'add_html', 'read_msg', 'read_msgid', 'add_msg', 'del_msg', 'update_msg', 'run_msg', 'url2note', 'ast_py',
7-
'ast_grep', 'get_folder', 'get_repo', 'msg_insert_line', 'msg_str_replace', 'msg_strs_replace',
8-
'msg_replace_lines', 'msg_del_lines', 'load_gist', 'gist_file', 'import_string', 'is_usable_tool',
9-
'mk_toollist', 'import_gist', 'tool_info', 'fc_tool_info', 'is_tool']
7+
'ast_grep', 'ctx_folder', 'ctx_repo', 'ctx_symfile', 'ctx_symfolder', 'ctx_sympkg', 'msg_insert_line',
8+
'msg_str_replace', 'msg_strs_replace', 'msg_replace_lines', 'msg_del_lines', 'load_gist', 'gist_file',
9+
'import_string', 'is_usable_tool', 'mk_toollist', 'import_gist', 'tool_info', 'fc_tool_info', 'is_tool']
1010

1111
# %% ../nbs/00_core.ipynb
1212
import json,importlib,linecache,re,inspect,uuid
@@ -26,7 +26,7 @@
2626
from IPython.display import display,Markdown
2727
from monsterui.all import franken_class_map,apply_classes
2828
from fasthtml.common import Safe,Script,Div
29-
from toolslm.xml import repo2ctx,folder2ctx
29+
from toolslm.xml import *
3030

3131
# %% ../nbs/00_core.ipynb
3232
md_cls_d = {
@@ -329,19 +329,19 @@ def ast_grep(
329329

330330
# %% ../nbs/00_core.ipynb
331331
@delegates(folder2ctx)
332-
def get_folder(
332+
def ctx_folder(
333333
path:Path='.', # Path to collect
334334
types:str|list='py,doc', # list or comma-separated str of ext types from: py, js, java, c, cpp, rb, r, ex, sh, web, doc, cfg
335335
out=False, # Include notebook cell outputs?
336336
**kwargs
337337
):
338338
"Convert folder to XML context and place in a new message"
339339
res = folder2ctx(path, types=types, out=out, **kwargs)
340-
return add_msg(res, msg_type='raw');
340+
return add_msg(res, msg_type='raw')
341341

342342
# %% ../nbs/00_core.ipynb
343343
@delegates(repo2ctx)
344-
def get_repo(
344+
def ctx_repo(
345345
owner:str, # GitHub repo owner
346346
repo:str, # GitHub repo name
347347
types:str|list='py,doc', # list or comma-separated str of ext types from: py, js, java, c, cpp, rb, r, ex, sh, web, doc, cfg
@@ -350,7 +350,29 @@ def get_repo(
350350
):
351351
"Convert GitHub repo to XML context and place in a new message"
352352
res = repo2ctx(owner, repo, out=out, **kwargs)
353-
return add_msg(res, msg_type='raw');
353+
return add_msg(res, msg_type='raw')
354+
355+
# %% ../nbs/00_core.ipynb
356+
@delegates(sym2file)
357+
def ctx_symfile(sym):
358+
"Add note with filepath and contents for a symbol's source file"
359+
return add_msg(sym2file(sym), msg_type='note');
360+
361+
# %% ../nbs/00_core.ipynb
362+
@delegates(sym2folderctx)
363+
def ctx_symfolder(
364+
sym, # Symbol to get folder context from
365+
**kwargs):
366+
"Add raw message with folder context for a symbol's source file location"
367+
return add_msg(sym2folderctx(sym, **kwargs), msg_type='raw');
368+
369+
# %% ../nbs/00_core.ipynb
370+
@delegates(sym2folderctx)
371+
def ctx_sympkg(
372+
sym, # Symbol to get folder context from
373+
**kwargs):
374+
"Add raw message with repo context for a symbol's root package"
375+
return add_msg(sym2pkgctx(sym, **kwargs), msg_type='raw');
354376

355377
# %% ../nbs/00_core.ipynb
356378
def msg_insert_line(

nbs/00_core.ipynb

Lines changed: 122 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"from IPython.display import display,Markdown\n",
5454
"from monsterui.all import franken_class_map,apply_classes\n",
5555
"from fasthtml.common import Safe,Script,Div\n",
56-
"from toolslm.xml import repo2ctx,folder2ctx"
56+
"from toolslm.xml import *"
5757
]
5858
},
5959
{
@@ -551,7 +551,7 @@
551551
{
552552
"data": {
553553
"text/plain": [
554-
"'import json,importlib,linecache,re,inspect,uuid\\nfrom typing import Dict\\nfrom tempfile import TemporaryDirectory\\nfrom ipykernel_helper import *\\nfrom dataclasses import dataclass\\nfrom fastcore.xml import to_xml\\n\\nfrom fastcore.utils import *\\nfrom fastcore.meta import delegates\\nfrom ghapi.all import *\\nfrom fastlite import *\\nfrom fastcore.xtras import asdict\\nfrom inspect import currentframe,Parameter,signature\\nfrom httpx import get as xget, post as xpost\\nfrom IPython.display import display,Markdown\\nfrom monsterui.all import franken_class_map,apply_classes\\nfrom fasthtml.common import Safe,Script,Div\\nfrom toolslm.xml import repo2ctx'"
554+
"'import json,importlib,linecache,re,inspect,uuid\\nfrom typing import Dict\\nfrom tempfile import TemporaryDirectory\\nfrom ipykernel_helper import *\\nfrom dataclasses import dataclass\\nfrom fastcore.xml import to_xml\\n\\nfrom fastcore.utils import *\\nfrom fastcore.meta import delegates\\nfrom ghapi.all import *\\nfrom fastlite import *\\nfrom fastcore.xtras import asdict\\nfrom inspect import currentframe,Parameter,signature\\nfrom httpx import get as xget, post as xpost\\nfrom IPython.display import display,Markdown\\nfrom monsterui.all import franken_class_map,apply_classes\\nfrom fasthtml.common import Safe,Script,Div\\nfrom toolslm.xml import repo2ctx,folder2ctx'"
555555
]
556556
},
557557
"execution_count": null,
@@ -713,7 +713,7 @@
713713
"output_type": "stream",
714714
"text": [
715715
"_9c544573\n",
716-
"_2a6c39e8\n"
716+
"_87a4343f\n"
717717
]
718718
}
719719
],
@@ -989,7 +989,7 @@
989989
{
990990
"data": {
991991
"text/plain": [
992-
"'_675a14d7'"
992+
"'_996622fa'"
993993
]
994994
},
995995
"execution_count": null,
@@ -1314,15 +1314,15 @@
13141314
"source": [
13151315
"#| export\n",
13161316
"@delegates(folder2ctx)\n",
1317-
"def get_folder(\n",
1317+
"def ctx_folder(\n",
13181318
" path:Path='.', # Path to collect\n",
13191319
" types:str|list='py,doc', # list or comma-separated str of ext types from: py, js, java, c, cpp, rb, r, ex, sh, web, doc, cfg\n",
13201320
" out=False, # Include notebook cell outputs?\n",
13211321
" **kwargs\n",
13221322
"):\n",
13231323
" \"Convert folder to XML context and place in a new message\"\n",
13241324
" res = folder2ctx(path, types=types, out=out, **kwargs)\n",
1325-
" return add_msg(res, msg_type='raw');"
1325+
" return add_msg(res, msg_type='raw')"
13261326
]
13271327
},
13281328
{
@@ -1366,7 +1366,7 @@
13661366
"source": [
13671367
"#| export\n",
13681368
"@delegates(repo2ctx)\n",
1369-
"def get_repo(\n",
1369+
"def ctx_repo(\n",
13701370
" owner:str, # GitHub repo owner\n",
13711371
" repo:str, # GitHub repo name\n",
13721372
" types:str|list='py,doc', # list or comma-separated str of ext types from: py, js, java, c, cpp, rb, r, ex, sh, web, doc, cfg\n",
@@ -1375,7 +1375,7 @@
13751375
"):\n",
13761376
" \"Convert GitHub repo to XML context and place in a new message\"\n",
13771377
" res = repo2ctx(owner, repo, out=out, **kwargs)\n",
1378-
" return add_msg(res, msg_type='raw');"
1378+
" return add_msg(res, msg_type='raw')"
13791379
]
13801380
},
13811381
{
@@ -1419,6 +1419,115 @@
14191419
"[TRUNCATED: output size 123364 exceeded max size 500 bytes]"
14201420
]
14211421
},
1422+
{
1423+
"cell_type": "code",
1424+
"execution_count": null,
1425+
"id": "5bd8915b",
1426+
"metadata": {},
1427+
"outputs": [],
1428+
"source": [
1429+
"#| export\n",
1430+
"@delegates(sym2file)\n",
1431+
"def ctx_symfile(sym):\n",
1432+
" \"Add note with filepath and contents for a symbol's source file\"\n",
1433+
" return add_msg(sym2file(sym), msg_type='note');"
1434+
]
1435+
},
1436+
{
1437+
"cell_type": "code",
1438+
"execution_count": null,
1439+
"id": "6180d2a3",
1440+
"metadata": {},
1441+
"outputs": [
1442+
{
1443+
"data": {
1444+
"text/plain": [
1445+
"'_030ef334'"
1446+
]
1447+
},
1448+
"execution_count": null,
1449+
"metadata": {},
1450+
"output_type": "execute_result"
1451+
}
1452+
],
1453+
"source": [
1454+
"# ctx_symfile(TemporaryDirectory)"
1455+
]
1456+
},
1457+
{
1458+
"cell_type": "code",
1459+
"execution_count": null,
1460+
"id": "bbc9bd0c",
1461+
"metadata": {},
1462+
"outputs": [],
1463+
"source": [
1464+
"#| export\n",
1465+
"@delegates(sym2folderctx)\n",
1466+
"def ctx_symfolder(\n",
1467+
" sym, # Symbol to get folder context from\n",
1468+
" **kwargs):\n",
1469+
" \"Add raw message with folder context for a symbol's source file location\"\n",
1470+
" return add_msg(sym2folderctx(sym, **kwargs), msg_type='raw');"
1471+
]
1472+
},
1473+
{
1474+
"cell_type": "code",
1475+
"execution_count": null,
1476+
"id": "7a308942",
1477+
"metadata": {},
1478+
"outputs": [
1479+
{
1480+
"data": {
1481+
"text/plain": [
1482+
"'_b4d835be'"
1483+
]
1484+
},
1485+
"execution_count": null,
1486+
"metadata": {},
1487+
"output_type": "execute_result"
1488+
}
1489+
],
1490+
"source": [
1491+
"# ctx_symfolder(folder2ctx)"
1492+
]
1493+
},
1494+
{
1495+
"cell_type": "code",
1496+
"execution_count": null,
1497+
"id": "9d8d83b5",
1498+
"metadata": {},
1499+
"outputs": [],
1500+
"source": [
1501+
"#| export\n",
1502+
"@delegates(sym2folderctx)\n",
1503+
"def ctx_sympkg(\n",
1504+
" sym, # Symbol to get folder context from\n",
1505+
" **kwargs):\n",
1506+
" \"Add raw message with repo context for a symbol's root package\"\n",
1507+
" return add_msg(sym2pkgctx(sym, **kwargs), msg_type='raw');"
1508+
]
1509+
},
1510+
{
1511+
"cell_type": "code",
1512+
"execution_count": null,
1513+
"id": "11c8b385",
1514+
"metadata": {},
1515+
"outputs": [
1516+
{
1517+
"data": {
1518+
"text/plain": [
1519+
"'_c6181f90'"
1520+
]
1521+
},
1522+
"execution_count": null,
1523+
"metadata": {},
1524+
"output_type": "execute_result"
1525+
}
1526+
],
1527+
"source": [
1528+
"# ctx_sympkg(folder2ctx)"
1529+
]
1530+
},
14221531
{
14231532
"cell_type": "markdown",
14241533
"id": "4cfd0bc5",
@@ -1459,7 +1568,7 @@
14591568
{
14601569
"data": {
14611570
"text/plain": [
1462-
"{'success': 'Inserted text after line 5 in message _0f6c9b92'}"
1571+
"{'success': 'Inserted text after line 5 in message _70e14974'}"
14631572
]
14641573
},
14651574
"execution_count": null,
@@ -1528,7 +1637,7 @@
15281637
{
15291638
"data": {
15301639
"text/plain": [
1531-
"{'success': 'Replaced text in message _0f6c9b92'}"
1640+
"{'success': 'Replaced text in message _70e14974'}"
15321641
]
15331642
},
15341643
"execution_count": null,
@@ -1600,7 +1709,7 @@
16001709
{
16011710
"data": {
16021711
"text/plain": [
1603-
"{'success': 'Successfully replaced all the strings in message _0f6c9b92'}"
1712+
"{'success': 'Successfully replaced all the strings in message _70e14974'}"
16041713
]
16051714
},
16061715
"execution_count": null,
@@ -1689,7 +1798,7 @@
16891798
{
16901799
"data": {
16911800
"text/plain": [
1692-
"{'success': 'Replaced lines 2 to 4 in message _0f6c9b92'}"
1801+
"{'success': 'Replaced lines 2 to 4 in message _70e14974'}"
16931802
]
16941803
},
16951804
"execution_count": null,
@@ -1758,7 +1867,7 @@
17581867
{
17591868
"data": {
17601869
"text/plain": [
1761-
"{'success': 'Deleted lines 2 to 4 in message _0f6c9b92'}"
1870+
"{'success': 'Deleted lines 2 to 4 in message _70e14974'}"
17621871
]
17631872
},
17641873
"execution_count": null,

settings.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ version = 0.0.58
55
min_python = 3.9
66
license = apache2
77
black_formatting = False
8-
requirements = fastcore>=1.8.10 fastlite ghapi ipykernel-helper>=0.0.15 claudette ast-grep-cli ast-grep-py MonsterUI lisette>=0.0.13 pillow toolslm>=0.3.9
8+
requirements = fastcore>=1.8.10 fastlite ghapi ipykernel-helper>=0.0.15 claudette ast-grep-cli ast-grep-py MonsterUI lisette>=0.0.13 pillow toolslm>=0.3.14
99
dev_requirements = python-fasthtml
1010
doc_path = _docs
1111
lib_path = dialoghelper

0 commit comments

Comments
 (0)