Skip to content

Commit

Permalink
Informative errors for Pkg extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarros committed Nov 12, 2023
1 parent 1463c50 commit d95a082
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Sunny.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,21 @@ export propose_uniform, propose_flip, propose_delta, @mix_proposals, LocalSample

include("deprecated.jl")

isloaded(pkg::String) = any(k -> k.name == pkg, keys(Base.loaded_modules))

### ext/PlottingExt.jl, dependent on Makie
function plot_spins end
function view_crystal end
function plot_spins(args...)
error(isloaded("Makie") ? "Invalid method call" : "Import GLMakie or GLMakie to enable plotting")
end
function view_crystal(args...)
error(isloaded("Makie") ? "Invalid method call" : "Import GLMakie or GLMakie to enable plotting")
end
export plot_spins, view_crystal

### ext/ExportVTKExt.jl, dependent on WriteVTK
function export_vtk end
function export_vtk(args...)
error(isloaded("WriteVTK") ? "Invalid method call" : "Import WriteVTK to enable exporting.")
end
export export_vtk

end

0 comments on commit d95a082

Please sign in to comment.