Conditional package dependency to avoid build errors

I’ve created a package called anyMOD.jl that uses the Gurobi package as a dependency. However, Gurobi is only required for one special but quite useful feature and apart from that not used anywhere in the package. Building the Gurobi package successfully requires to have installed some additional software. This also prevents a package with a Gurobi dependency from being tested via Travis. As a result, I want Gurobi only to be a dependency, if some specific files exists in a specific directory.

Is there any way to achieve such a condition on package dependency? I looked into Requires.jl, but only found a way to make parts of the module dependant on dependencies.

Usually you put the special feature that depends on Gurobi in some file filerequiringgurobi.l in anyMod.jl and load this using Requires.jl as follows:

function __init__()
    @require Gurobi="uuid of Gurobi" include("filerequiringgurobi.jl")
end

Then once one does using Gurobi (which implies hopefully a proper installation of Gurobi and the additional software), then the additional feature is loaded.

Probably I misunderstood the question, but isn’t this what you want?

1 Like

Thanks. That actually worked. I misunderstood how the package actually works before.