Re-importing modules with changes in the code

I am writing some functions into an additional file, which I am including in the jupyter notebook. The file looks like this:

module pivPlotting

using PyPlot

export vectorPlot

function vectorPlot(frame1, u, v, searchArea, ...
...
end

Runing the following initially works:

include("pivPlotting.jl")

using pivPlotting

vectorPlot()...

As soon as I change something in the file “pivPlotting.jl” and run the above cells again (including the “include” and “using” commands, I end up with the error:

WARNING: using pivPlotting.vectorPlot in module Main conflicts with an existing identifier.

vectorPlot() does not contain the change in code, whereas pivPlotting.vectorPlot() does. So the “Main” instance, previously imported, is not overwritten by re-including and re-importing the module.

How to import changes introduced into modules?

Revise.jl does a great job at keeping your REPL and now even your workers up to date with code changing on disk. With the .juliarc code snippet, it keeps Modules updated that you are using and can also be asked to track scripts or other files that are included.

Not sure how it works on Jupyter though?

5 Likes

Thanks for the suggestion. I am adding it now and will have a closer look.

I am surprised that there is no simple overwrite while running the include and using commands again. I mean, after my include(“pivPlotting.jl”) it says:

WARNING: replacing module pivPlotting

But there is no effect seen while running the function from the module.

So I have to restart the kernel of the notebook to use the change in my file :confused:

Instead of using pivPlotting, you can just include the module file and then refer to the functions in it as pivPlotting.foo(). It’s a bit less convenient, but should allow you to repeatedly include the same module without restarting your kernel.

2 Likes

Thanks, works too!

Coming from Python, so it is a common thing for me to reference it like that :blush:

Revise.jl works on Jupyter too.

Have to be sure to run Revise.track(“customModuleFile.jl”) and it tracks it pretty good for what I have seen now. Onces the file is saved, the changes can be seen directly by calling the e.g. functions in the main workspace.

Thanks again!

1 Like