Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia: create a package with optional dependencies

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.

like image 839
mattu Avatar asked Jan 01 '23 15:01

mattu


2 Answers

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.

like image 184
fredrikekre Avatar answered Feb 19 '23 13:02

fredrikekre


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.

like image 23
Cameron Bieganek Avatar answered Feb 19 '23 13:02

Cameron Bieganek