How to write Plots/Makie recipes for a module without having it precompile

I’m trying to create a Julia modules for simple mathematical functions, but I want to separate code which calculates from code which show stuff on the screen (plot recipes).

I want each mathematical domain to be in their own module (QuadraticFunctions, CubicFunctions) because I want to learn about precompilation. This way, if I change one module, I don’t have to precompile all my work environment.

The problem is that in order to create a recipe, like plot(some_data, color=:green) (code may be wrong, but focusing on having a specific color to a specific Module), I need to either mention my block uses Plots/Makie or imports Plots/Makie.

This means that I suddenly added this huge dependency on my calculation package just because I want to make a few plotting recipes available.

Plots/Makie will be imported and used on a main.jl like

using QuadraticFunctions
using CubicFunctions
using Plots

##### plots and calls to functions exported by both modules #####

Is there any better solution I’m not thinking about? Or do I just have to separate one module into two modules so I have QuadraticFunctions and QuadraticFunctionsRecipes, which depends on the calculations module? This way, changes to the internals of the modules which calculate will only trigger recompilation of their own things, not including any graphical package.

Only using RecipesBase should be required (to later use your package with Plots.jl).

See this post for more info.

1 Like

Thank you, I’ll check it out and reply once I get to test it in the following days!

After experimenting and researching my problem, I found that your solution is great for Plots, but Makie still requires the use of Requires.jl until MakieCore is sorted.

A working example of this is:

@require Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" begin
        export my_extra_plot_function

Where my-extra-plots.jl contains explicit references to Makie, like Makie.plot or Makie.stem!.