Skip to content

Commit

Permalink
Import notebooks in the init
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfast committed May 13, 2018
1 parent 94527e2 commit 0955033
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
29 changes: 17 additions & 12 deletions pidgin/__init__.ipynb
Expand Up @@ -2,26 +2,30 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
" def load_ipython_extension(ip):\n",
" %reload_ext importnb\n",
" from pidgin.config import alias\n",
" if __name__ == '__main__':\n",
" %reload_ext config\n",
" else:\n",
" %reload_ext pidgin.config"
" with __import__('importnb').Notebook():\n",
" try:\n",
" from . import config, conventions, markdown, recall, template\n",
" except:\n",
" import config, conventions, markdown, recall, template"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
" from IPython.core.inputsplitter import IPythonInputSplitter"
" def load_ipython_extension(ip):\n",
" %reload_ext importnb\n",
" from pidgin.config import alias\n",
" if __name__ == '__main__':\n",
" %reload_ext config\n",
" else:\n",
" %reload_ext pidgin.config"
]
},
{
Expand All @@ -31,6 +35,7 @@
"outputs": [],
"source": [
" def unload_ipython_extension(ip):\n",
" from IPython.core.inputsplitter import IPythonInputSplitter\n",
" ip.input_transformer_manager = IPythonInputSplitter()"
]
},
Expand All @@ -44,14 +49,14 @@
"output_type": "stream",
"text": [
"[NbConvertApp] Converting notebook __init__.ipynb to python\n",
"[NbConvertApp] Writing 678 bytes to __init__.py\n"
"[NbConvertApp] Writing 886 bytes to __init__.py\n"
]
}
],
"source": [
" if __name__ == '__main__':\n",
" !jupyter nbconvert --to python __init__.ipynb\n",
" load_ipython_extension(__import__('IPython').get_ipython())"
"# load_ipython_extension(__import__('IPython').get_ipython())"
]
}
],
Expand Down
25 changes: 15 additions & 10 deletions pidgin/__init__.py
@@ -1,7 +1,17 @@

# coding: utf-8

# In[1]:
# In[4]:


with __import__('importnb').Notebook():
try:
from . import config, conventions, markdown, recall, template
except:
import config, conventions, markdown, recall, template


# In[ ]:


def load_ipython_extension(ip):
Expand All @@ -13,23 +23,18 @@ def load_ipython_extension(ip):
get_ipython().run_line_magic('reload_ext', 'pidgin.config')


# In[6]:


from IPython.core.inputsplitter import IPythonInputSplitter


# In[7]:
# In[ ]:


def unload_ipython_extension(ip):
from IPython.core.inputsplitter import IPythonInputSplitter
ip.input_transformer_manager = IPythonInputSplitter()


# In[2]:
# In[ ]:


if __name__ == '__main__':
get_ipython().system('jupyter nbconvert --to python __init__.ipynb')
load_ipython_extension(__import__('IPython').get_ipython())
# load_ipython_extension(__import__('IPython').get_ipython())

4 changes: 2 additions & 2 deletions pidgin/recall.ipynb
Expand Up @@ -105,8 +105,8 @@
" from inspect import Parameter, Signature\n",
" return Signature([Parameter(str, Parameter.KEYWORD_ONLY, default = vars[str]) for str in vars])\n",
" \n",
" try: from importnb import AST\n",
" except: from importnb import AST"
" try: from importnb.loader import AST\n",
" except: from importnb.loader import AST"
]
},
{
Expand Down

0 comments on commit 0955033

Please sign in to comment.