diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7d41252..e9a4317 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: - version: '1' os: ubuntu-latest arch: x64 - - version: '1.5' + - version: '1.10' os: ubuntu-latest arch: x64 - version: 'nightly' diff --git a/Project.toml b/Project.toml index 656bea6..eedf346 100644 --- a/Project.toml +++ b/Project.toml @@ -1,20 +1,26 @@ name = "MetaGraphs" uuid = "626554b9-1ddb-594c-aa3c-2596fe9399a5" -version = "0.8.1" +version = "0.9.0" [deps] Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" -JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +[weakdeps] +JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" + +[extensions] +MetaGraphsJLD2Ext = ["Graphs", "JLD2"] + [compat] Graphs = "1.4" JLD2 = "0.1.11, 0.2, 0.3, 0.4, 0.5, 0.6" -julia = "1" +julia = "1.10" [extras] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" +JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test", "Base64"] +test = ["Test", "Base64", "JLD2"] diff --git a/ext/MetaGraphsJLD2Ext.jl b/ext/MetaGraphsJLD2Ext.jl new file mode 100644 index 0000000..f8b5fd2 --- /dev/null +++ b/ext/MetaGraphsJLD2Ext.jl @@ -0,0 +1,17 @@ +module MetaGraphsJLD2Ext + +using Graphs +using JLD2 +using MetaGraphs + +function MetaGraphs.loadmg(fn::AbstractString) + @load fn g + return g +end + +function MetaGraphs.savemg(fn::AbstractString, g::AbstractMetaGraph) + @save fn g + return 1 +end + +end \ No newline at end of file diff --git a/src/MetaGraphs.jl b/src/MetaGraphs.jl index 06c3b3a..8a88435 100644 --- a/src/MetaGraphs.jl +++ b/src/MetaGraphs.jl @@ -1,6 +1,5 @@ module MetaGraphs using Graphs -using JLD2 import Base: eltype, show, ==, Pair, @@ -582,4 +581,20 @@ include("metadigraph.jl") include("metagraph.jl") include("persistence.jl") include("overrides.jl") + +function __init__() + # Register error hint for the `loadmg` and `savemg` + if isdefined(Base.Experimental, :register_error_hint) + Base.Experimental.register_error_hint(MethodError) do io, exc, _, _ + if exc.f === loadmg + print(io, "\n\nIn order to load meta graphs from binary files, you need \ + to load the JLD2.jl package.") + elseif exc.f === savemg + print(io,"\n\nIn order to save meta 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 7f25788..c3f0825 100644 --- a/src/persistence.jl +++ b/src/persistence.jl @@ -3,18 +3,17 @@ struct MGFormat <: AbstractGraphFormat end struct DOTFormat <: AbstractGraphFormat end -function loadmg(fn::AbstractString) - @load fn g - return g -end +function loadmg end +function savemg end -function savemg(fn::AbstractString, g::AbstractMetaGraph) - @save fn g - return 1 -end +loadgraph(fn::AbstractString, ::String, ::MGFormat) = loadmg(fn) +savegraph(fn::AbstractString, g::AbstractMetaGraph) = savemg(fn, g) -loadgraph(fn::AbstractString, gname::String, ::MGFormat) = loadmg(fn) -savegraph(fn::AbstractString, g::AbstractMetaGraph) = savemg(fn, g) +function savegraph(fn::AbstractString, g::AbstractMetaGraph, ::DOTFormat) + open(fn, "w") do fp + savedot(fp, g) + end +end # escaping unescaped quotation marks # i.e. replacing `"`` with `\"` while leaving `\"` as is @@ -37,7 +36,6 @@ quote_prop(p::Any) = "\"" * escape_quotes(string(p)) * "\"" # That will break if someone uses a DOT keyword as a property name, as they must be quoted. function savedot(io::IO, g::AbstractMetaGraph) - if is_directed(g) write(io, "digraph G {\n") dash = "->" @@ -73,9 +71,3 @@ function savedot(io::IO, g::AbstractMetaGraph) end write(io, "}\n") end - -function savegraph(fn::AbstractString, g::AbstractMetaGraph, ::DOTFormat) - open(fn, "w") do fp - savedot(fp, g) - end -end diff --git a/test/runtests.jl b/test/runtests.jl index d562e53..2afed68 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,7 @@ using Graphs using MetaGraphs + +using JLD2 using Test import Graphs.SimpleGraphs: SimpleGraph, SimpleDiGraph