diff --git a/Project.toml b/Project.toml index a6ca72d..53fd368 100644 --- a/Project.toml +++ b/Project.toml @@ -1,19 +1,25 @@ name = "StaticGraphs" uuid = "4c8beaf5-199b-59a0-a7f2-21d17de635b6" -version = "0.3.1" +version = "0.4.0" [deps] Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" -JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" +[weakdeps] +JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" + +[extensions] +StaticGraphsJLD2Ext = "JLD2" + [compat] Graphs = "1.4" JLD2 = "0.1 - 0.6" -julia = "1" +julia = "1.10" [extras] +JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test"] +test = ["JLD2", "Test"] diff --git a/ext/StaticGraphsJLD2Ext.jl b/ext/StaticGraphsJLD2Ext.jl new file mode 100644 index 0000000..e011427 --- /dev/null +++ b/ext/StaticGraphsJLD2Ext.jl @@ -0,0 +1,32 @@ +module StaticGraphsJLD2Ext + +using JLD2 +using StaticGraphs + +function StaticGraphs.savesg(fn::AbstractString, g::StaticGraph) + f_ind = g.f_ind + f_vec = g.f_vec + @save fn f_vec f_ind + return 1 +end + +function StaticGraphs.savesg(fn::AbstractString, g::StaticDiGraph) + f_ind = g.f_ind + f_vec = g.f_vec + b_ind = g.b_ind + b_vec = g.b_vec + @save fn f_vec f_ind b_vec b_ind + return 1 +end + +function StaticGraphs.loadsg(fn::AbstractString, ::SGFormat) + @load fn f_vec f_ind + return StaticGraph(f_vec, f_ind) +end + +function StaticGraphs.loadsg(fn::AbstractString, ::SDGFormat) + @load fn f_vec f_ind b_vec b_ind + return StaticDiGraph(f_vec, f_ind, b_vec, b_ind) +end + +end \ No newline at end of file diff --git a/src/StaticGraphs.jl b/src/StaticGraphs.jl index d01d0cf..9c7261d 100644 --- a/src/StaticGraphs.jl +++ b/src/StaticGraphs.jl @@ -1,7 +1,6 @@ module StaticGraphs using Graphs -using JLD2 using SparseArrays import Base: @@ -115,4 +114,19 @@ eltype(::Type{StaticEdgeIter{StaticDiGraph{T, U}}}) where T where U = StaticDiGr include("overrides.jl") +function __init__() + # Register error hint for the `loadsg` and `savesg` functions + if isdefined(Base.Experimental, :register_error_hint) + Base.Experimental.register_error_hint(MethodError) do io, exc, _, _ + if exc.f === loadsg + print(io, "\n\nIn order to load static graphs from binary files, you need \ + to load the JLD2.jl package.") + elseif exc.f === savesg + print(io,"\n\nIn order to save static graphs to binary files, you need to \ + load the JLD2.jl package.") + end + end + end +end + end # module diff --git a/src/persistence.jl b/src/persistence.jl index 7ca59db..b918796 100644 --- a/src/persistence.jl +++ b/src/persistence.jl @@ -7,31 +7,8 @@ abstract type StaticGraphFormat <: AbstractGraphFormat end struct SGFormat <: StaticGraphFormat end struct SDGFormat <: StaticGraphFormat end -function savesg(fn::AbstractString, g::StaticGraph) - f_ind = g.f_ind - f_vec = g.f_vec - @save fn f_vec f_ind - return 1 -end - -function savesg(fn::AbstractString, g::StaticDiGraph) - f_ind = g.f_ind - f_vec = g.f_vec - b_ind = g.b_ind - b_vec = g.b_vec - @save fn f_vec f_ind b_vec b_ind - return 1 -end - -function loadsg(fn::AbstractString, ::SGFormat) - @load fn f_vec f_ind - return StaticGraph(f_vec, f_ind) -end - -function loadsg(fn::AbstractString, ::SDGFormat) - @load fn f_vec f_ind b_vec b_ind - return StaticDiGraph(f_vec, f_ind, b_vec, b_ind) -end +function loadsg end +function savesg end loadgraph(fn::AbstractString, gname::String, s::StaticGraphFormat) = loadsg(fn, s) -savegraph(fn::AbstractString, g::AbstractStaticGraph) = savesg(fn, g) \ No newline at end of file +savegraph(fn::AbstractString, g::AbstractStaticGraph) = savesg(fn, g) \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index d770e89..df69e00 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,7 @@ using StaticGraphs using Graphs using Graphs.SimpleGraphs +using JLD2 using Test const testdir = dirname(@__FILE__)