I ran into an interesting problem today that I am trying to figure out (along with @Wikunia and @arsh). Basically, it stems from the idea of trying to load specific packages by user demand. The specific issue we are working on is this: https://github.com/Wikunia/Javis.jl/pull/236
Here is what we are trying to achieve:
Package
A
has functionmain()
which can call functionextra()
which resides in scriptextra_file.jl
. The functions that are inextra_file.jl
rely on packageB
. PackageB
however, is quite large and we desire to not use it each time a user runsA.main()
as they may not always needmain()
to call functionextra()
.
Some pseudo code could be thought of as follows (NOTE: ignore the fact that each time the user executes main(true)
it uses B
and includes extra_file.jl
repeatedly. In practice, we only want to execute these commands once):
module A
...
function main(call_extra = false)
...
if call_extra == true
using B
include("extra_file.jl")
extra()
end
end
...
end
We attempted to use Requires.jl to handle this problem but, to carry from the example, extra()
was not able to be called. Then, we tried the exact same solution in the preceding example and ran into the notorious “world age” problem.
We feel like we are getting close to a solution but are not sure of how to move forward. We looked at Base.invokelatest()
to address the problem, but not sure whether that is the solution nor to exactly implement it. Any thoughts? Thank you! ~tcp