Skip to content

Commit

Permalink
Fixes ipython#11 by adding get_ipython to the module by default for p…
Browse files Browse the repository at this point in the history
…ortability
  • Loading branch information
tonyfast committed Apr 25, 2018
1 parent fc6ba78 commit d5c86ce
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
15 changes: 13 additions & 2 deletions importnb/__init__.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
" from importlib.machinery import SourceFileLoader\n",
" from importlib._bootstrap_external import FileFinder\n",
" from importlib import reload\n",
" from traceback import print_exc\n",
" "
" from traceback import print_exc"
]
},
{
Expand Down Expand Up @@ -78,6 +77,11 @@
" super().__init__(fullname, path)\n",
" \n",
" def exec_module(Loader, module):\n",
" try:\n",
" from IPython import get_ipython\n",
" module.get_ipython = get_ipython\n",
" except: ...\n",
"\n",
" module.__output__ = None\n",
" if Loader.capture: return Loader.exec_module_capture(module)\n",
" else: return super().exec_module(module)\n",
Expand Down Expand Up @@ -155,6 +159,13 @@
" Path('__init__.py').write_text(ScriptExporter().from_filename('__init__.ipynb')[0])\n",
" __import__('doctest').testmod()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
7 changes: 7 additions & 0 deletions importnb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ def __init__(self, fullname=None, path=None, *, capture=True):
super().__init__(fullname, path)

def exec_module(Loader, module):
try:
from IPython import get_ipython

module.get_ipython = get_ipython
except:
...

module.__output__ = None
if Loader.capture:
return Loader.exec_module_capture(module)
Expand Down

0 comments on commit d5c86ce

Please sign in to comment.