Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
version:
- '1.6'
- '1.10'
- '1'
steps:
- uses: actions/checkout@v6
Expand Down
11 changes: 8 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
name = "MetaGraphsNext"
uuid = "fa8bd995-216d-47f1-8a91-f3b68fbeb377"
version = "0.7.5"
version = "0.8.0"

[deps]
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
SimpleTraits = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"

[weakdeps]
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"

[extensions]
MetaGraphsNextJLD2Ext = ["Graphs", "JLD2"]

[compat]
Graphs = "1.4.1"
JLD2 = "0.1.11, 0.2, 0.3, 0.4, 0.5, 0.6"
SimpleTraits = "0.9"
julia = "1.6"
julia = "1.10"
2 changes: 2 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5"
MetaGraphsNext = "fa8bd995-216d-47f1-8a91-f3b68fbeb377"

[compat]
Documenter = "1"
Graphs = "1.13.3"
JLD2 = "0.6"
17 changes: 17 additions & 0 deletions ext/MetaGraphsNextJLD2Ext.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module MetaGraphsNextJLD2Ext

using Graphs
using JLD2
using MetaGraphsNext

function MetaGraphsNext.loadmg(file::AbstractString)
@load file meta_graph
return meta_graph
end

function MetaGraphsNext.savemg(file::AbstractString, meta_graph::MetaGraph)
@save file meta_graph
return 1
end

end
22 changes: 21 additions & 1 deletion src/MetaGraphsNext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ A package for graphs with vertex labels and metadata in Julia. Its main export i
"""
module MetaGraphsNext

using JLD2
using Graphs
using SimpleTraits

Expand All @@ -24,4 +23,25 @@ include("dict_utils.jl")
include("weights.jl")
include("persistence.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
21 changes: 6 additions & 15 deletions src/persistence.jl
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
# Metagraphs files are simply JLD2 files.

"""
struct MGFormat <: AbstractGraphFormat end

You can save `MetaGraph`s in a `MGFormat`, currently based on `JLD2`.
"""
struct MGFormat <: Graphs.AbstractGraphFormat end

function loadmg end
function savemg end

Graphs.loadgraph(file::AbstractString, ::String, ::MGFormat) = loadmg(file)
Graphs.savegraph(file::AbstractString, meta_graph::MetaGraph) = savemg(file, meta_graph)

"""
struct DOTFormat <: AbstractGraphFormat end

If all metadata types support `pairs` or are `Nothing`, you can save `MetaGraph`s in `DOTFormat`.
"""
struct DOTFormat <: Graphs.AbstractGraphFormat end

function loadmg(file::AbstractString)
@load file meta_graph
return meta_graph
end

function savemg(file::AbstractString, meta_graph::MetaGraph)
@save file meta_graph
return 1
end

Graphs.loadgraph(file::AbstractString, ::String, ::MGFormat) = loadmg(file)
Graphs.savegraph(file::AbstractString, meta_graph::MetaGraph) = savemg(file, meta_graph)

function show_meta_list(io::IO, meta)
if meta !== nothing && length(meta) > 0
next = false
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5"
SimpleTraits = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Aqua
using Documenter
using Graphs
using JLD2
using MetaGraphsNext
using Test

Expand Down
4 changes: 3 additions & 1 deletion test/tutorial/3_files.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ using Test #src
# ## MGFormat

# MetaGraphsNext.jl overloads `Graphs.savegraph` to write graphs in a custom format called `MGFormat`, which is based on JLD2.
# It is not very readable, but it does give the right result when we load it back.
# It is not very readable, but it does give the right result when we load it back. This requires JLD2 to be loaded as well.

using JLD2

example = MetaGraph(Graph(), Symbol);

Expand Down
Loading