deathbeds / importnb

notebook files as source

Home Page:https://importnb.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Autoreload functionality

davidleejy opened this issue · comments

commented

Does anyone know how to engage autoreload functionality while using importnb package?

Autoreload is the automatic reloading of imported content when that content is altered. This functionality is available in Jupyter. For example, to use autoreload in Jupyter, enter the following in a Jupyter cell:

%load_ext autoreload
%autoreload 2
import abc

abc.foo()

When content in abc.py is changed, abc is re-imported and the changes are effected in the Jupyter notebook.

I understand that importnb is compatible with importlib's reload (see README). Disappointingly, I've tried pairing it with autoreload in a Jupyter notebook to observe that notebooks imported via importnb are not affected.

Autoreload has no effect on importnb's import of abc.ipynb.

%load_ext autoreload          # No effect on the import of abc.ipynb
%autoreload 2                      # No effect on the import of abc.ipynb
from importnb import Notebook
from importlib import reload
with Notebook(): 
    import abc
    assert abc.__file__.endswith('.ipynb')
    reload(abc)
import abc

abc.foo()