Is there a way to replace a "top-level" module in a running session?

The way I usually use Juno for package development is that I open up the main Foo.jl file for my project Foo, select all, and evaluate. This gives me a Main.Foo module. I then go around to different files included from Foo.jl, do a “change module” to Main.Foo and edit / evaluate things inside of them.

I’m aware I could just do using Foo, and then edit / evaluate things in the various files with the module set to just Foo instead of Main.Foo (which is nice since the module is automatically detected in that case), but the problem is, what if I need to completely re-evaluate / replace the “top-level” module Foo, like I’d need to do if e.g. I changed the layout of a struct? Is there a way to do so with Juno that I’m not aware of?

https://github.com/JuliaLang/julia/issues/22562 for some comments and
https://github.com/JuliaLang/julia/pull/33102 for a PR.

1 Like

Thanks, although I may be missing something. Those look like a way to evaluate code in an arbitrary module, which Juno already does and I use a lot (and having that PR would be great to do it at the REPL easily too). My question was if you can swap out a top-level module, e.g. swap in a new version of Foo after you’ve already done a using Foo?

Maybe u r talking about Revise which is a God send

using Revise
using Foo

#just use Foo and every time u update it, all functions will be updated. So no need to select everything and run

Oh, I missunderstood then.

Juno doesn’t support that use case atm, but I think it could emulate the package loading mechanism (maybe even automatically if you eval a file which looks like it is a package’s entry point).

That said, just evaluating the module expression in the right context (aka whatever module you want to use the package in) will usually work just fine – the only complication is that you might need to pkg> activate the right environment first.

Thanks for the confirmation. And just to make sure I’m not missing anything, but another complication is that I have to “change module” to Main.Foo in all my included files, right? (since they’re autodetected as Foo, which is different than Main.Foo).

Ah, right, good point. That seems really annoying.
Wanna open an issue about replacing top-level modules just so we don’t forget about it?