deathbeds / importnb

notebook files as source
https://importnb.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
68 stars 5 forks source link

Autoreload functionality #117

Open davidleejy opened 2 years ago

davidleejy commented 2 years ago

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()