Skip to content

Commit

Permalink
fixes #67
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Dec 4, 2024
1 parent dbc7cfe commit 68fae7e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
8 changes: 4 additions & 4 deletions execnb/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from IPython.core.displayhook import DisplayHook
from IPython.utils.capture import capture_output
from IPython.utils.text import strip_ansi
from IPython.core.completer import IPCompleter,provisionalcompleter
from IPython.core.completer import IPCompleter,provisionalcompleter,Completer
from IPython.core.hooks import CommandChainDispatcher
from IPython.core.completerlib import module_completer
from IPython.utils.strdispatch import StrDispatch
Expand Down Expand Up @@ -307,9 +307,9 @@ def __init__(self, shell, namespace=None, jedi=False):
def __call__(self, c):
if not c: return []
with provisionalcompleter():
return [o.text.rpartition('.')[-1]
for o in self.completions(c, len(c))
if o.type not in ('magic', 'path')]
res = [o.text.rpartition('.')[-1] for o in self.completions(c, len(c)) if o.type!='magic']
if res and res[0][-1]=='=': res = [o for o in res if o[-1]=='=']
return res

# %% ../nbs/02_shell.ipynb
@patch
Expand Down
42 changes: 33 additions & 9 deletions nbs/02_shell.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"from IPython.core.displayhook import DisplayHook\n",
"from IPython.utils.capture import capture_output\n",
"from IPython.utils.text import strip_ansi\n",
"from IPython.core.completer import IPCompleter,provisionalcompleter\n",
"from IPython.core.completer import IPCompleter,provisionalcompleter,Completer\n",
"from IPython.core.hooks import CommandChainDispatcher\n",
"from IPython.core.completerlib import module_completer\n",
"from IPython.utils.strdispatch import StrDispatch\n",
Expand Down Expand Up @@ -779,8 +779,8 @@
"text/plain": [
"[{'name': 'stdout',\n",
" 'output_type': 'stream',\n",
" 'text': ['CPU times: user 4 us, sys: 1 us, total: 5 us\\n',\n",
" 'Wall time: 9.06 us\\n']},\n",
" 'text': ['CPU times: user 1e+03 ns, sys: 1 us, total: 2 us\\n',\n",
" 'Wall time: 2.15 us\\n']},\n",
" {'data': {'text/plain': ['2']},\n",
" 'metadata': {},\n",
" 'output_type': 'execute_result',\n",
Expand Down Expand Up @@ -1020,7 +1020,7 @@
"File <ipython-input-1-a5c3817716b6>:1\n",
"----> 1 import time; time.sleep(1.1)\n",
"\n",
"Cell In[58], line 7, in run_cell.<locals>.handler(*args)\n",
"Cell In[6], line 7, in run_cell.<locals>.handler(*args)\n",
"----> 7 def handler(*args): raise TimeoutError()\n",
"\n",
"TimeoutError: \n",
Expand Down Expand Up @@ -1059,7 +1059,7 @@
"File <span class=\"ansi-green-fg\">&lt;ipython-input-1-a5c3817716b6&gt;:1</span>\n",
"<span class=\"ansi-green-fg\">----&gt; 1</span> <span class=\"ansi-bold\" style=\"color: rgb(0,135,0)\">import</span> <span class=\"ansi-bold\" style=\"color: rgb(0,0,255)\">time</span>; time<span style=\"color: rgb(98,98,98)\">.</span>sleep(<span style=\"color: rgb(98,98,98)\">1.1</span>)\n",
"\n",
"Cell <span class=\"ansi-green-fg\">In[58], line 7</span>, in <span class=\"ansi-cyan-fg\">run_cell.&lt;locals&gt;.handler</span><span class=\"ansi-blue-fg\">(*args)</span>\n",
"Cell <span class=\"ansi-green-fg\">In[6], line 7</span>, in <span class=\"ansi-cyan-fg\">run_cell.&lt;locals&gt;.handler</span><span class=\"ansi-blue-fg\">(*args)</span>\n",
"<span class=\"ansi-green-fg\">----&gt; 7</span> <span class=\"ansi-bold\" style=\"color: rgb(0,135,0)\">def</span> <span style=\"color: rgb(0,0,255)\">handler</span>(<span style=\"color: rgb(98,98,98)\">*</span>args): <span class=\"ansi-bold\" style=\"color: rgb(0,135,0)\">raise</span> <span class=\"ansi-bold\" style=\"color: rgb(215,95,95)\">TimeoutError</span>()\n",
"\n",
"<span class=\"ansi-red-fg\">TimeoutError</span>: \n",
Expand Down Expand Up @@ -1738,7 +1738,7 @@
"===========================================================================\n",
"\n",
"While Executing Cell #2:\n",
"['Traceback (most recent call last):\\n', ' File \"/var/folders/ss/34z569j921v58v8n1n_8z7h40000gn/T/ipykernel_23644/1421292703.py\", line 3, in <module>\\n s.execute(\\'../tests/error.ipynb\\', exc_stop=True)\\n', ' File \"/var/folders/ss/34z569j921v58v8n1n_8z7h40000gn/T/ipykernel_23644/3609882568.py\", line 18, in execute\\n self.run_all(nb, exc_stop=exc_stop, preproc=preproc, postproc=postproc,\\n', ' File \"/var/folders/ss/34z569j921v58v8n1n_8z7h40000gn/T/ipykernel_23644/3068237356.py\", line 19, in run_all\\n if self.exc and exc_stop: raise self.exc from None\\n ^^^^^^^^^^^^^^^^^^^^^^^^\\n', ' File \"/Users/jhoward/miniconda3/lib/python3.11/site-packages/IPython/core/interactiveshell.py\", line 3577, in run_code\\n exec(code_obj, self.user_global_ns, self.user_ns)\\n', ' File \"<ipython-input-1-b968a57a586e>\", line 3, in <module>\\n foo()\\n', ' File \"/Users/jhoward/subs_aai/execnb/tests/err.py\", line 2, in foo\\n assert 13 == 98\\n ^^^^^^^^\\n', 'AssertionError\\n']\n",
"['Traceback (most recent call last):\\n', ' File \"/var/folders/ss/34z569j921v58v8n1n_8z7h40000gn/T/ipykernel_37071/1421292703.py\", line 3, in <module>\\n s.execute(\\'../tests/error.ipynb\\', exc_stop=True)\\n', ' File \"/var/folders/ss/34z569j921v58v8n1n_8z7h40000gn/T/ipykernel_37071/3609882568.py\", line 18, in execute\\n self.run_all(nb, exc_stop=exc_stop, preproc=preproc, postproc=postproc,\\n', ' File \"/var/folders/ss/34z569j921v58v8n1n_8z7h40000gn/T/ipykernel_37071/3068237356.py\", line 19, in run_all\\n if self.exc and exc_stop: raise self.exc from None\\n ^^^^^^^^^^^^^^^^^^^^^^^^\\n', ' File \"/Users/jhoward/miniconda3/lib/python3.11/site-packages/IPython/core/interactiveshell.py\", line 3577, in run_code\\n exec(code_obj, self.user_global_ns, self.user_ns)\\n', ' File \"<ipython-input-1-b968a57a586e>\", line 3, in <module>\\n foo()\\n', ' File \"/Users/jhoward/subs_aai/execnb/tests/err.py\", line 2, in foo\\n assert 13 == 98\\n ^^^^^^^^\\n', 'AssertionError\\n']\n",
"\n"
]
}
Expand Down Expand Up @@ -2016,9 +2016,9 @@
" def __call__(self, c):\n",
" if not c: return []\n",
" with provisionalcompleter():\n",
" return [o.text.rpartition('.')[-1]\n",
" for o in self.completions(c, len(c))\n",
" if o.type not in ('magic', 'path')]"
" res = [o.text.rpartition('.')[-1] for o in self.completions(c, len(c)) if o.type!='magic']\n",
" if res and res[0][-1]=='=': res = [o for o in res if o[-1]=='=']\n",
" return res"
]
},
{
Expand Down Expand Up @@ -2049,6 +2049,30 @@
"test_set(cc(\"from abc import AB\"), ['ABC', 'ABCMeta'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['n=', 'pat=', 's=']"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s = CaptureShell()\n",
"cc = SmartCompleter(s)\n",
"s.run('''def captures(pat, s, n, **kw):\n",
" return 1''')\n",
"cc('captures(')"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit 68fae7e

Please sign in to comment.