I have read Julia’s documentation about package extensions as well as this GitHub example and though I first thought it was suitable for my use case, it seems it isn’t.
I have in my package a mutable struct SolveParameters that is used by the user so he can declare what he wants to do.
i.e., he could run the following in the REPL:
julia> import RingStarProblems as RSP
julia> using JuMP
julia> pars = RSP.SolverParameters(
solve_mod = RSP.BranchBendersCut(), # ILP or B&BC
[...] Some other parameters
do_plot = false, # plot_results (to debug)
[...] Some other parameters
)
When using the paramter do_plot = false
, everything is fine. However, I would like that the user could run do_plot = true
and only when he does so:
module PlottingSol #
if pars.do_plot
using RingStarProblems, GraphPlots, Compose
# Do some plotting and saving to .pdf
end
end ### /!\ this generates errors as you can't have `using` inside a function!
I tried to put the module PlottingSol
into an extension as mentioned in Julia documentation, i.e., my Project.toml contains, among other dependencies removed for brevity:
[weakdeps]
Compose = "a81c6b42-2e10-5240-aca2-a61377ecd94b"
GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
[extensions]
PlottingSol = ["Compose", "GraphPlot"]
[compat]
Compose = "0.8, 0.9"
GraphPlot = "0.4.1, 0.5, 0.6"
[test] # For testing
Compose = "a81c6b42-2e10-5240-aca2-a61377ecd94b"
GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
However, at this point, I do not understand how the user is supposed to ask for package PlottingSol with do_plot = true
.