Reloading by re-executing include() doesn't seem to work

Hey all,
I’m trying to run a reloading workflow just one step in complexity above the basic workflow as described in the manual. :slight_smile:

I have a MWE which I believe fits the same pattern as given in the manual, but still does not seem to work. Can anyone tell me why?

My workflow

julia --project=@. -i reloader.jl 
> reload()
"Hello world"
> # now edit JuliaIncludeTest to say "Goodbye world"
> reload()
WARNING: replacing module JuliaIncludeTest.
"Hello world" # wtf? it said it was replaced!

Project structure (or see https://github.com/akdor1154/jl-include-test)

+ src
  - JuliaIncludeTest.jl
- Project.toml
- reloader.jl

src/JuliaIncludeTest.jl

module JuliaIncludeTest
greet() = print("Hello World!")
end # module

reloader.jl

include("src/JuliaIncludeTest.jl")

function reload()
    include("src/JuliaIncludeTest.jl");
    JuliaIncludeTest.greet()
end

It sounds like you are looking for Revise.jl.
This will automatically reload code that changes in files and packages.

2 Likes

Thanks for the suggestion, but I started down this track (of working back to an MWE) because Revise wasn’t working for me either (for different reasons, some weird behaviour with Requires I think). So I started down the path of “reproduce as simply as possible”. Now I’m intrigued why this method doesn’t work, as it seems to contradict the manual saying that include() should redefine included modules!

The reason why your reload function doesn’t work the way you expect it to is that it is compiled before it runs. At compile-time JuliaIncludeTest.greet() refers to a different function, because the include has not happened yet.

If you’re having problems getting the right version of Revise.jl, it might the issue described in this thread.

3 Likes