Skip to content

Commit a10eab9

Browse files
committed
fixes #37
1 parent 516faed commit a10eab9

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

execnb/shell.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
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
3636
class _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)
5858
def _out_exc(ename, evalue, traceback): return dict(ename=str(ename), evalue=str(evalue), output_type='error', traceback=traceback)
5959
def _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
6262
def _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
7171
class 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
129129
def 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
147147
def 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
158158
def _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
179179
def 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
200200
def 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
212212
def exec_nb(
213213
src:str, # Notebook path to read from

nbs/02_shell.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
" \"Add `path` to python path, or `path.parent` if it's a file\"\n",
162162
" path = Path(path)\n",
163163
" if path.is_file(): path = path.parent\n",
164-
" self.run_cell(f\"import sys; sys.path.insert(0, '{path}')\")\n",
164+
" self.run_cell(f\"import sys; sys.path.insert(0, '{path.as_posix()}')\")\n",
165165
"\n",
166166
" def enable_gui(self, gui=None):\n",
167167
" \"Disable GUI (over-ridden; called by IPython)\"\n",

nbs/_quarto.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ website:
2020
description: "A description of your project"
2121
twitter-card: true
2222
open-graph: true
23-
reader-mode: true
2423
repo-branch: master
2524
repo-url: "https://github.com/fastai/execnb/tree/master/"
2625
repo-actions: [issue]

0 commit comments

Comments
 (0)