There are a number of questions on SO about reloading Cython files in IPython (I'm using Spyder). Here's my implementation that appears to check all the boxes from other questions:
from importlib import reload
import pyximport
import sys
pyximport.install(reload_support=True)
try:
del sys.modules['cython_test.ctest']
del ctest
except:
pass
import cython_test.ctest as ctest
ctest = reload(ctest)
ctest.test()
However, it doesn't work and I have to restart the kernel to get an updated version of the file.
In case it's relevant, here's how I'm generating the .so
file:
from setuptools import setup
from Cython.Build import cythonize
import os
file = os.environ.get("CYTHONIZE_FILE", "")
setup(ext_modules=cythonize(f"{file}.pyx"))
And I would call this in the command line:
CYTHONIZE_FILE=ctest python setup.py build_ext --inplace
Any ideas?