Revise and import

Hi folks,

a fairly basic question on Revise.jl usage: how should I use revise with packages (mine) that import other packages? For example:

julia> using Revise
julia> import MyPackage
<edit code in package imported by MyPackage>
julia> MyPackage.function()
<old code is run>

I tried adding ‘using Revise’ to MyPackage, but that didn’t seem to have any effect either. Thanks,

Dara

Your approach should work. However, note that using Revise must come before the package that you’re editing is loaded. Perhaps you already did using OtherPackageThatMyPackageImports in this Julia session?

I find it most convenient to just load Revise automatically, which ensures that it is always loaded first: https://timholy.github.io/Revise.jl/stable/config/#Using-Revise-by-default-1

1 Like

I think my question is a suitable follow-up question:

When using Revise and importing a module , Revise does its magic.
More specifically I can redefine the struct in the imported module and Revise reloads it.

But when importing a specific struct/function from the module, I get a LoadError: MethodError.
Is there some syntactic difference to what Revise can reload and what not?

Example:

# Both files Human.jl and Main.jl are in the same directory

# Human.jl

module Human

export Person, printastring

struct Person
    name::String
    age::Int64
    zip::Int64
    partner::Bool
    child::Bool
end
end

# Main.jl

using Revise
include("Human.jl")
import .Human: Person

Bob = Human.Person("Robert", 16, 12345, true, false) -> Revise works
Bob = Person("Robert", 16, 12345, true, false) -> Revise doesnt work
println(Bob)

Specifically, my question is how Revise interacts with importing functions/structs from modules and what the best practices are for Revise and importing specific functions/structs from other modules.

There is actually an entire paragraph on how to use Revise with import and all in the official Julia docs:

https://docs.julialang.org/en/v1/manual/workflow-tips/#Browser-based-workflow-1

1 Like