3030# %% auto 0
3131__all__ = ['CaptureShell' , 'exec_nb' ]
3232
33- # %% ../nbs/02_shell.ipynb 5
33+ # %% ../nbs/02_shell.ipynb 4
3434# IPython requires a DisplayHook and DisplayPublisher
3535# We override `__call__` and `publish` to save outputs instead of printing them
3636class _CaptureHook (DisplayHook ):
@@ -53,12 +53,12 @@ class _CapturePub(DisplayPublisher):
5353 "Called when adding an output"
5454 def publish (self , data , metadata = None , ** kwargs ): self .shell ._add_out (data , metadata , typ = 'display_data' )
5555
56- # %% ../nbs/02_shell.ipynb 6
56+ # %% ../nbs/02_shell.ipynb 5
5757# These are the standard notebook formats for exception and stream data (e.g stdout)
5858def _out_exc (ename , evalue , traceback ): return dict (ename = str (ename ), evalue = str (evalue ), output_type = 'error' , traceback = traceback )
5959def _out_stream (text , name ): return dict (name = name , output_type = 'stream' , text = text .splitlines (True ))
6060
61- # %% ../nbs/02_shell.ipynb 7
61+ # %% ../nbs/02_shell.ipynb 6
6262def _format_mimedata (k , v ):
6363 "Format mime-type keyed data consistently with Jupyter"
6464 if k .startswith ('text/' ): return v .splitlines (True )
@@ -67,7 +67,7 @@ def _format_mimedata(k, v):
6767 return v + '\n ' if not v .endswith ('\n ' ) else v
6868 return v
6969
70- # %% ../nbs/02_shell.ipynb 9
70+ # %% ../nbs/02_shell.ipynb 8
7171class CaptureShell (FastInteractiveShell ):
7272 "Execute the IPython/Jupyter source code"
7373 def __init__ (self ,
@@ -91,7 +91,7 @@ def set_path(self, path):
9191 "Add `path` to python path, or `path.parent` if it's a file"
9292 path = Path (path )
9393 if path .is_file (): path = path .parent
94- self .run_cell (f"import sys; sys.path.insert(0, '{ path } ')" )
94+ self .run_cell (f"import sys; sys.path.insert(0, '{ path . as_posix () } ')" )
9595
9696 def enable_gui (self , gui = None ):
9797 "Disable GUI (over-ridden; called by IPython)"
@@ -124,7 +124,7 @@ def _stream(self):
124124 self .out .append (_out_stream (text , nm ))
125125 setattr (self , attr , StringIO ())
126126
127- # %% ../nbs/02_shell.ipynb 12
127+ # %% ../nbs/02_shell.ipynb 11
128128@patch
129129def run (self :CaptureShell ,
130130 code :str , # Python/IPython code to run
@@ -142,7 +142,7 @@ def run(self:CaptureShell,
142142 self ._stream ()
143143 return [* self .out ]
144144
145- # %% ../nbs/02_shell.ipynb 25
145+ # %% ../nbs/02_shell.ipynb 24
146146@patch
147147def cell (self :CaptureShell , cell , stdout = True , stderr = True ):
148148 "Run `cell`, skipping if not code, and store outputs back in cell"
@@ -154,7 +154,7 @@ def cell(self:CaptureShell, cell, stdout=True, stderr=True):
154154 for o in outs :
155155 if 'execution_count' in o : cell ['execution_count' ] = o ['execution_count' ]
156156
157- # %% ../nbs/02_shell.ipynb 29
157+ # %% ../nbs/02_shell.ipynb 28
158158def _false (o ): return False
159159
160160@patch
@@ -174,7 +174,7 @@ def run_all(self:CaptureShell,
174174 postproc (cell )
175175 if self .exc and exc_stop : raise self .exc [1 ] from None
176176
177- # %% ../nbs/02_shell.ipynb 43
177+ # %% ../nbs/02_shell.ipynb 42
178178@patch
179179def execute (self :CaptureShell ,
180180 src :str | Path , # Notebook path to read from
@@ -195,7 +195,7 @@ def execute(self:CaptureShell,
195195 inject_code = inject_code , inject_idx = inject_idx )
196196 if dest : write_nb (nb , dest )
197197
198- # %% ../nbs/02_shell.ipynb 47
198+ # %% ../nbs/02_shell.ipynb 46
199199@patch
200200def prettytb (self :CaptureShell ,
201201 fname :str | Path = None ): # filename to print alongside the traceback
@@ -207,7 +207,7 @@ def prettytb(self:CaptureShell,
207207 fname_str = f' in { fname } ' if fname else ''
208208 return f"{ type (self .exc [1 ]).__name__ } { fname_str } :\n { _fence } \n { cell_str } \n "
209209
210- # %% ../nbs/02_shell.ipynb 66
210+ # %% ../nbs/02_shell.ipynb 65
211211@call_parse
212212def exec_nb (
213213 src :str , # Notebook path to read from
0 commit comments