22
33# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/12_tools.ipynb.
44
5- # %% auto 0
5+ # %% auto # 0
66__all__ = ['explain_exc' , 'ensure' , 'valid_path' , 'run_cmd' , 'rg' , 'sed' , 'view' , 'create' , 'insert' , 'str_replace' ,
77 'strs_replace' , 'replace_lines' , 'move_lines' , 'get_callable' ]
88
1212from shlex import split
1313from subprocess import run , DEVNULL
1414
15- # %% ../nbs/12_tools.ipynb
15+ # %% ../nbs/12_tools.ipynb #7603dedb
1616def explain_exc (task = '' ):
1717 """Convert an current exception to an LLM friendly error message."""
1818 try : raise sys .exc_info ()[1 ]
@@ -21,20 +21,20 @@ def explain_exc(task=''):
2121 except Exception as e : return f"Error { task } : { repr (e )} "
2222
2323
24- # %% ../nbs/12_tools.ipynb
24+ # %% ../nbs/12_tools.ipynb #b8823d07
2525def ensure (b : bool , msg :str = "" ):
2626 "Works like assert b, msg but raise ValueError and is not disabled when run with python -O"
2727 if not b : raise ValueError (msg )
2828
2929
30- # %% ../nbs/12_tools.ipynb
30+ # %% ../nbs/12_tools.ipynb #e4288129
3131def valid_path (path :str , must_exist :bool = True ) -> Path :
3232 'Return expanded/resolved Path, raising FileNotFoundError if must_exist and missing'
3333 p = Path (path ).expanduser ().resolve ()
3434 if must_exist and not p .exists (): raise FileNotFoundError (f'File not found: { p } ' )
3535 return p
3636
37- # %% ../nbs/12_tools.ipynb
37+ # %% ../nbs/12_tools.ipynb #1182336d
3838def run_cmd (
3939 cmd :str , # The command name to run
4040 argstr :str = '' , # All args to the command, will be split with shlex
@@ -69,8 +69,8 @@ def sed(
6969 "Run the `sed` command with the args in `argstr` (e.g for reading a section of a file)"
7070 return run_cmd ('sed' , argstr , allow_re = allow_re , disallow_re = disallow_re )
7171
72- # %% ../nbs/12_tools.ipynb
73- def _fmt_path (f , p ):
72+ # %% ../nbs/12_tools.ipynb #864b213a
73+ def _fmt_path (f , p , skip_folders = () ):
7474 'Format path with emoji for dirs/symlinks or size for files'
7575 parts = f .relative_to (p ).parts
7676 if any (part .startswith ('.' ) for part in parts ): return None
@@ -79,7 +79,7 @@ def _fmt_path(f, p):
7979 if f .is_dir (): return f'{ f } 📁'
8080 return f'{ f } ({ f .stat ().st_size / 1024 :.1f} k)'
8181
82- # %% ../nbs/12_tools.ipynb #f2e2f69c
82+ # %% ../nbs/12_tools.ipynb #5dd1aaf3
8383def view (
8484 path :str , # Path to directory or file to view
8585 view_range :tuple [int ,int ]= None , # Optional 1-indexed (start, end) line range for files, end=-1 for EOF. Do NOT use unless it's known that the file is too big to keep in context—simply view the WHOLE file when possible
0 commit comments