Skip to content

Commit 08a90b5

Browse files
committed
Move JLD2 dependency to package extension
1 parent 535ecbb commit 08a90b5

File tree

6 files changed

+49
-19
lines changed

6 files changed

+49
-19
lines changed

Project.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
name = "MetaGraphsNext"
22
uuid = "fa8bd995-216d-47f1-8a91-f3b68fbeb377"
3-
version = "0.7.5"
3+
version = "0.8.0"
44

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

9+
[weakdeps]
10+
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
11+
12+
[extensions]
13+
MetaGraphsNextJLD2Ext = ["Graphs", "JLD2"]
14+
1015
[compat]
1116
Graphs = "1.4.1"
1217
JLD2 = "0.1.11, 0.2, 0.3, 0.4, 0.5, 0.6"
1318
SimpleTraits = "0.9"
14-
julia = "1.6"
19+
julia = "1.10"

ext/MetaGraphsNextJLD2Ext.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module MetaGraphsNextJLD2Ext
2+
3+
using Graphs
4+
using JLD2
5+
using MetaGraphsNext
6+
7+
function MetaGraphsNext.loadmg(file::AbstractString)
8+
@load file meta_graph
9+
return meta_graph
10+
end
11+
12+
function MetaGraphsNext.savemg(file::AbstractString, meta_graph::MetaGraph)
13+
@save file meta_graph
14+
return 1
15+
end
16+
17+
18+
end

src/MetaGraphsNext.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ A package for graphs with vertex labels and metadata in Julia. Its main export i
55
"""
66
module MetaGraphsNext
77

8-
using JLD2
98
using Graphs
109
using SimpleTraits
1110

@@ -24,4 +23,19 @@ include("dict_utils.jl")
2423
include("weights.jl")
2524
include("persistence.jl")
2625

26+
function __init__()
27+
# Register error hint for the `loadmg` and `savemg`
28+
if isdefined(Base.Experimental, :register_error_hint)
29+
Base.Experimental.register_error_hint(MethodError) do io, exc, _, _
30+
if exc.f === loadmg
31+
print(io, "\n\nIn order to load meta graphs from binary files, you need \
32+
to load the JLD2.jl package.")
33+
elseif exc.f === savemg
34+
print(io,"\n\nIn order to save meta graphs to binary files, you need to \
35+
load the JLD2.jl package.")
36+
end
37+
end
38+
end
39+
end
40+
2741
end # module

src/persistence.jl

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,23 @@
1-
# Metagraphs files are simply JLD2 files.
2-
31
"""
42
struct MGFormat <: AbstractGraphFormat end
53
64
You can save `MetaGraph`s in a `MGFormat`, currently based on `JLD2`.
75
"""
86
struct MGFormat <: Graphs.AbstractGraphFormat end
97

8+
function loadmg end
9+
function savemg end
10+
11+
Graphs.loadgraph(file::AbstractString, ::String, ::MGFormat) = loadmg(file)
12+
Graphs.savegraph(file::AbstractString, meta_graph::MetaGraph) = savemg(file, meta_graph)
13+
1014
"""
1115
struct DOTFormat <: AbstractGraphFormat end
1216
1317
If all metadata types support `pairs` or are `Nothing`, you can save `MetaGraph`s in `DOTFormat`.
1418
"""
1519
struct DOTFormat <: Graphs.AbstractGraphFormat end
1620

17-
function loadmg(file::AbstractString)
18-
@load file meta_graph
19-
return meta_graph
20-
end
21-
22-
function savemg(file::AbstractString, meta_graph::MetaGraph)
23-
@save file meta_graph
24-
return 1
25-
end
26-
27-
Graphs.loadgraph(file::AbstractString, ::String, ::MGFormat) = loadmg(file)
28-
Graphs.savegraph(file::AbstractString, meta_graph::MetaGraph) = savemg(file, meta_graph)
29-
3021
function show_meta_list(io::IO, meta)
3122
if meta !== nothing && length(meta) > 0
3223
next = false

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
44
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
55
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
66
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
7+
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
78
MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5"
89
SimpleTraits = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"
910
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Aqua
22
using Documenter
33
using Graphs
4+
using JLD2
45
using MetaGraphsNext
56
using Test
67

0 commit comments

Comments
 (0)