Automatic, persistent autoreload in iPython

howto ipython python

2024-10-02


I like that iPython can be configured to automatically reload modules. It's useful to be able to keep REPL context through development, without needing to constantly tear down and setup your context:

>>> %load_ext autoreload
>>> %autoreload 2

However, turning on the autoreload extension is also annoying to set each time you spawn a REPL, but thankfully this can also be automated:

c.InteractiveShellApp.extensions = ["autoreload"]
c.InteractiveShellApp.exec_lines = ["%autoreload 2"]
volumes:
  - .ipython_data_local:/root/.ipython/profile_default

Using .ipython_data_local/ipython_config.py seems quite strange, but it seems it's based on iPython's own profile system. It would be nice if this could be configured in pyproject.toml like everything else.