I want to build a numerical package that also has optional support for visualization. For simplicity, let's say the respective dependencies are NumPackage
for the heavy lifting
and VizPackage
for optional visualization.
In Julia, how can I build a module that has NumPackage
in its required dependencies, but VizPackage
only as an optional dependency, say for example for those users that want to run an example simulation and visualize it?
I saw the Requires.jl package but not sure if it's the right tool for what I'm trying to do.
The current best solution (2019-10-04) is to use Requires.jl
. However, there are a number of issues with Requires.jl
so there are plans for a better solution, see https://github.com/JuliaLang/Pkg.jl/issues/1285. Hopefully it will be ready in time for Julia version 1.4 or 1.5.
I don't know how to add optional dependencies to a package, but for the specific case of having a dependency on a visualization package, what you can do is create plot recipes. In order to have plot recipes in your package, you only need to depend on RecipesBase.jl, which is a very minimal package. If you create plot recipes for your types you will then be able to use Plots.jl to visualize the information contained in your types, without having an explicit dependency on Plots.jl in your package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With