How do I ensure that changed Cython code is recompiled when a module that imports it is reloaded into a Python session?
For example in utils.pyx I have something like
def func(int x):
return x**2
while in test.py I have, for example something like
def test_cython():
import pyximport; pyximport.install()
import utils
return utils.func(5)
I would like to work in IPython and have any changes to utils.pyx cause a recompilation whenever I reload test.py there, but
import test
seems to do nothing if test.py has already been imported and
reload(test)
loads from the already compiled test.pyc, so that even if utils.pyx has been changed
test.test_cython()
uses the "old" version of utils.func.
It seems the only way to achieve this is to make an edit to test.py after each change to utils.pyx. Is there any other way to do this?
Note: I believe this is a slightly different issue from this one; in particular, this promising answer, does not solve the problem for me, even when I take the import and pyximport.install statements out of test_cython and place them at the top level of test.py.