Skip to content

Commit 724107e

Browse files
committed
Move JLD2.jl dependency to a package extension
1 parent 475258f commit 724107e

File tree

5 files changed

+50
-28
lines changed

5 files changed

+50
-28
lines changed

Project.toml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
name = "StaticGraphs"
22
uuid = "4c8beaf5-199b-59a0-a7f2-21d17de635b6"
3-
version = "0.3.1"
3+
version = "0.4.0"
44

55
[deps]
66
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
7-
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
87
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
98

9+
[weakdeps]
10+
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
11+
12+
[extensions]
13+
StaticGraphsJLD2Ext = "JLD2"
14+
1015
[compat]
1116
Graphs = "1.4"
1217
JLD2 = "0.1 - 0.6"
13-
julia = "1"
18+
julia = "1.10"
1419

1520
[extras]
21+
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
1622
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1723

1824
[targets]
19-
test = ["Test"]
25+
test = ["JLD2", "Test"]

ext/StaticGraphsJLD2Ext.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module StaticGraphsJLD2Ext
2+
3+
using JLD2
4+
using StaticGraphs
5+
6+
function StaticGraphs.savesg(fn::AbstractString, g::StaticGraph)
7+
f_ind = g.f_ind
8+
f_vec = g.f_vec
9+
@save fn f_vec f_ind
10+
return 1
11+
end
12+
13+
function StaticGraphs.savesg(fn::AbstractString, g::StaticDiGraph)
14+
f_ind = g.f_ind
15+
f_vec = g.f_vec
16+
b_ind = g.b_ind
17+
b_vec = g.b_vec
18+
@save fn f_vec f_ind b_vec b_ind
19+
return 1
20+
end
21+
22+
function StaticGraphs.loadsg(fn::AbstractString, ::SGFormat)
23+
@load fn f_vec f_ind
24+
return StaticGraph(f_vec, f_ind)
25+
end
26+
27+
function StaticGraphs.loadsg(fn::AbstractString, ::SDGFormat)
28+
@load fn f_vec f_ind b_vec b_ind
29+
return StaticDiGraph(f_vec, f_ind, b_vec, b_ind)
30+
end
31+
32+
end

src/StaticGraphs.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module StaticGraphs
22

33
using Graphs
4-
using JLD2
54
using SparseArrays
65

76
import Base:

src/persistence.jl

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,15 @@ abstract type StaticGraphFormat <: AbstractGraphFormat end
77
struct SGFormat <: StaticGraphFormat end
88
struct SDGFormat <: StaticGraphFormat end
99

10-
function savesg(fn::AbstractString, g::StaticGraph)
11-
f_ind = g.f_ind
12-
f_vec = g.f_vec
13-
@save fn f_vec f_ind
14-
return 1
10+
function loadsg(args...)
11+
error("In order to load static graphs from binary files, you need to load the JLD2.jl \
12+
package")
1513
end
1614

17-
function savesg(fn::AbstractString, g::StaticDiGraph)
18-
f_ind = g.f_ind
19-
f_vec = g.f_vec
20-
b_ind = g.b_ind
21-
b_vec = g.b_vec
22-
@save fn f_vec f_ind b_vec b_ind
23-
return 1
24-
end
25-
26-
function loadsg(fn::AbstractString, ::SGFormat)
27-
@load fn f_vec f_ind
28-
return StaticGraph(f_vec, f_ind)
29-
end
30-
31-
function loadsg(fn::AbstractString, ::SDGFormat)
32-
@load fn f_vec f_ind b_vec b_ind
33-
return StaticDiGraph(f_vec, f_ind, b_vec, b_ind)
15+
function savesg(args...)
16+
error("In order to save static graphs to binary files, you need to load the JLD2.jl \
17+
package")
3418
end
3519

3620
loadgraph(fn::AbstractString, gname::String, s::StaticGraphFormat) = loadsg(fn, s)
37-
savegraph(fn::AbstractString, g::AbstractStaticGraph) = savesg(fn, g)
21+
savegraph(fn::AbstractString, g::AbstractStaticGraph) = savesg(fn, g)

test/runtests.jl

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

67
const testdir = dirname(@__FILE__)

0 commit comments

Comments
 (0)