Skip to content

Commit 53568e8

Browse files
authored
Merge pull request #16 from simonschoelly/v1.0_fixes
Working version for Julia v1.0
2 parents 3ca5f23 + 0a9d8a5 commit 53568e8

File tree

13 files changed

+51
-44
lines changed

13 files changed

+51
-44
lines changed

.travis.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ os:
55
# - osx
66

77
julia:
8-
- 0.6
8+
- 0.7
9+
- 1.0
910
- nightly
1011

1112
matrix:
@@ -18,10 +19,9 @@ notifications:
1819
# uncomment the following lines to override the default test script
1920
script:
2021
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
21-
- julia -e 'Pkg.add("LightGraphs")'
22-
- julia -e 'Pkg.clone(pwd()); Pkg.build("GraphIO"); Pkg.test("GraphIO"; coverage=true)'
22+
- julia -e 'using Pkg, InteractiveUtils; versioninfo(); Pkg.clone(pwd()); Pkg.build("GraphIO"); Pkg.test("GraphIO"; coverage=true)'
2323

2424
after_success:
25-
- julia -e 'cd(Pkg.dir("GraphIO")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'
26-
- julia -e 'Pkg.add("Documenter")'
27-
- julia -e 'cd(Pkg.dir("GraphIO")); include(joinpath("docs", "make.jl"))'
25+
- julia -e 'using Pkg; cd(Pkg.dir("GraphIO")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'
26+
- julia -e 'using Pkg; Pkg.add("Documenter")'
27+
- julia -e 'using Pkg; cd(Pkg.dir("GraphIO")); include(joinpath("docs", "make.jl"))'

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Note that support for the jld format was removed from this branch.
1717

1818
GraphIO provides support to [LightGraphs.jl](https://github.com/JuliaGraphs/LightGraphs.jl) for reading/writing graphs in various formats.
1919

20+
The current version of GraphIO works with Julia version >= 0.7.
21+
2022
Currently, the following functionality is provided:
2123

2224
Format | Read | Write | Multiple Graphs| Format Name |

REQUIRE

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
julia 0.6
1+
julia 0.7
22
LightGraphs 0.9.5
3-
EzXML 0.5
4-
ParserCombinator
5-
JLD
3+
EzXML 0.9.0
4+
ParserCombinator 2.0.0
5+
#JLD
66
SimpleTraits

src/GraphIO.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
__precompile__(true)
21
module GraphIO
32

43
using LightGraphs
54
using SimpleTraits
65

76
import LightGraphs: loadgraph, loadgraphs, savegraph, AbstractGraphFormat
87
using EzXML
9-
using ParserCombinator: Parsers.DOT, Parsers.GML
8+
using ParserCombinator.Parsers.DOT
9+
using ParserCombinator.Parsers.GML
1010

1111
export DOTFormat, GEXFFormat, GMLFormat, Graph6Format,
1212
GraphMLFormat, NETFormat, EdgeListFormat, CDFFormat
1313
# package code goes here
1414

15-
include("jld.jl")
15+
#include("jld.jl")
1616
include("dot.jl")
1717
include("gexf.jl")
1818
include("gml.jl")

src/cdf.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ function _loadcdf(io::IO)
1313
while !eof(io)
1414
line = strip(chomp(readline(io)))
1515
if inbusdata
16-
if contains(line, "-999")
16+
if occursin("-999", line)
1717
inbusdata = false
1818
else
1919
v = parse(Int, split(line)[1])
2020
push!(vertices, v)
2121
end
2222
elseif inbranchdata
23-
if contains(line, "-999")
23+
if occursin("-999", line)
2424
inbranchdata = false
2525
else
2626
(src_s, dst_s) = split(line)[1:2]
27-
src = findfirst(vertices, parse(Int, src_s))
28-
dst = findfirst(vertices, parse(Int, dst_s))
27+
src = something(findfirst(isequal(parse(Int, src_s)), vertices), 0)
28+
dst = something(findfirst(isequal(parse(Int, dst_s)), vertices), 0)
2929
push!(srcs, src)
3030
push!(dsts, dst)
3131
end

src/dot.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function _dot_read_one_graph(pg::DOT.Graph)
2020
end
2121

2222
function loaddot(io::IO, gname::String)
23-
p = DOT.parse_dot(readstring(io))
23+
p = DOT.parse_dot(read(io, String))
2424
for pg in p
2525
isdir = pg.directed
2626
possname = isdir ? DOT.StringID("digraph") : DOT.StringID("graph")
@@ -31,7 +31,7 @@ function loaddot(io::IO, gname::String)
3131
end
3232

3333
function loaddot_mult(io::IO)
34-
p = DOT.parse_dot(readstring(io))
34+
p = DOT.parse_dot(read(io, String))
3535

3636
graphs = Dict{String,LightGraphs.AbstractGraph}()
3737

src/edgelist.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# by commas or whitespace. Will only read the first two elements on
33
# each line. Will return a directed graph.
44

5+
using DelimitedFiles: writedlm
6+
57
struct EdgeListFormat <: AbstractGraphFormat end
68

79
function loadedgelist(io::IO, gname::String)
@@ -33,7 +35,7 @@ function loadedgelist(io::IO, gname::String)
3335
end
3436

3537
function saveedgelist(io::IO, g::LightGraphs.AbstractGraph, gname::String)
36-
writecsv(io, [src(e), dst(e)] for e in collect(LightGraphs.edges(g)))
38+
writedlm(io, ([src(e), dst(e)] for e in LightGraphs.edges(g)), ',')
3739
return 1
3840
end
3941

src/gml.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ function _gml_read_one_graph(gs, dir)
1717
end
1818
return g
1919
end
20+
2021
function loadgml(io::IO, gname::String)
21-
p = GML.parse_dict(readstring(io))
22+
p = GML.parse_dict(read(io, String))
2223
for gs in p[:graph]
2324
dir = Bool(get(gs, :directed, 0))
2425
graphname = get(gs, :label, dir ? "digraph" : "graph")
@@ -29,7 +30,7 @@ function loadgml(io::IO, gname::String)
2930
end
3031

3132
function loadgml_mult(io::IO)
32-
p = GML.parse_dict(readstring(io))
33+
p = GML.parse_dict(read(io, String))
3334
graphs = Dict{String,LightGraphs.AbstractGraph}()
3435
for gs in p[:graph]
3536
dir = Bool(get(gs, :directed, 0))

src/graph6.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
struct Graph6Format <: AbstractGraphFormat end
22

33
function _bv2int(x::BitVector)
4-
assert(length(x) <= 8 * sizeof(Int))
4+
@assert(length(x) <= 8 * sizeof(Int))
55
acc = 0
66
for i = 1:length(x)
77
acc = acc << 1 + x[i]
@@ -10,7 +10,7 @@ function _bv2int(x::BitVector)
1010
end
1111

1212
function _int2bv(n::Int, k::Int)
13-
bitstr = lstrip(bits(n), '0')
13+
bitstr = lstrip(bitstring(n), '0')
1414
l = length(bitstr)
1515
padding = k - l
1616
bv = falses(k)
@@ -25,7 +25,7 @@ function _g6_R(_x::BitVector)::Vector{UInt8}
2525
padding = cld(k, 6) * 6 - k
2626
x = vcat(_x, falses(padding))
2727
nbytes = div(length(x), 6)
28-
bytevec = Vector{UInt8}(nbytes) # uninitialized data!
28+
bytevec = Vector{UInt8}(undef, nbytes) # uninitialized data!
2929
for i = 1:nbytes
3030
xslice = x[((i - 1) * 6 + 1):(i * 6)]
3131

@@ -71,15 +71,15 @@ end
7171

7272

7373
"""
74-
\_graphToG6String(g)
74+
_graphToG6String(g)
7575
7676
Given a graph `g`, create the corresponding Graph6 string.
7777
"""
7878
function _graphToG6String(g::LightGraphs.Graph)
7979
A = adjacency_matrix(g, Bool)
8080
n = nv(g)
8181
nbits = div(n * (n - 1), 2)
82-
x = BitVector(nbits)
82+
x = BitVector(undef, nbits)
8383

8484
ind = 0
8585
for col = 2:n, row = 1:(col - 1)

src/graphml.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function _graphml_read_one_graph(reader::EzXML.StreamReader, isdirected::Bool)
1717
tar = reader["target"]
1818
push!(xedges, LightGraphs.Edge(nodes[src], nodes[tar]))
1919
else
20-
warn("Skipping unknown node '$(elname)' - further warnings will be suppressed", once=true, key="unknode")
20+
@warn "Skipping unknown node '$(elname)' - further warnings will be suppressed" maxlog=1 _id=:unknode
2121
end
2222
end
2323
end
@@ -51,7 +51,7 @@ function loadgraphml(io::IO, gname::String)
5151
elseif elname == "node" || elname == "edge"
5252
# ok
5353
else
54-
warn("Skipping unknown XML element '$(elname)' - further warnings will be suppressed", once=true, key="unkel")
54+
@warn "Skipping unknown XML element '$(elname)' - further warnings will be suppressed" maxlog=1 _id=:unkel
5555
end
5656
end
5757
end
@@ -78,7 +78,7 @@ function loadgraphml_mult(io::IO)
7878
end
7979
graphs[graphname] = _graphml_read_one_graph(reader, directed)
8080
else
81-
warn("Skipping unknown XML element '$(elname)' - further warnings will be suppressed", once=true, key="unkelmult")
81+
@warn "Skipping unknown XML element '$(elname)' - further warnings will be suppressed" maxlog=1 _id=:unkelmult
8282
end
8383
end
8484
end

src/net.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,30 @@ function loadnet(io::IO, gname::String = "graph")
3232
while startswith(line, "%")
3333
line = readline(io)
3434
end
35-
n = parse(Int, matchall(r"\d+", line)[1])
35+
n = parse(Int, match(r"\d+", line).match)
3636
for ioline in eachline(io)
3737
line = ioline
38-
(ismatch(r"^\*Arcs", line) || ismatch(r"^\*Edges", line)) && break
38+
(occursin(r"^\*Arcs", line) || occursin(r"^\*Edges", line)) && break
3939
end
40-
if ismatch(r"^\*Arcs", line)
40+
if occursin(r"^\*Arcs", line)
4141
g = LightGraphs.DiGraph(n)
4242
else
4343
g = LightGraphs.Graph(n)
4444
end
45-
while ismatch(r"^\*Arcs", line)
45+
while occursin(r"^\*Arcs", line)
4646
for ioline in eachline(io)
4747
line = ioline
48-
m = matchall(r"\d+", line)
49-
length(m) < 2 && break
50-
add_edge!(g, parse(Int, m[1]), parse(Int, m[2]))
48+
ms = collect(m.match for m in eachmatch(r"\d+", line, overlap=false))
49+
length(ms) < 2 && break
50+
add_edge!(g, parse(Int, ms[1]), parse(Int, ms[2]))
5151
end
5252
end
53-
while ismatch(r"^\*Edges", line) # add edges in both directions
53+
while occursin(r"^\*Edges", line) # add edges in both directions
5454
for ioline in eachline(io)
5555
line = ioline
56-
m = matchall(r"\d+", line)
57-
length(m) < 2 && break
58-
i1, i2 = parse(Int, m[1]), parse(Int, m[2])
56+
ms = collect(m.match for m in eachmatch(r"\d+", line, overlap=false))
57+
length(ms) < 2 && break
58+
i1, i2 = parse(Int, ms[1]), parse(Int, ms[2])
5959
add_edge!(g, i1, i2)
6060
add_edge!(g, i2, i1)
6161
end

test/graphio.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ end
8282
end
8383
fname = joinpath(testdir, "testdata", "warngraph.graphml")
8484

85-
@test_warn "Skipping unknown node 'warnnode' - further warnings will be suppressed" loadgraphs(fname, GraphMLFormat())
86-
@test_warn "Skipping unknown XML element 'warnelement' - further warnings will be suppressed" loadgraph(fname, "graph", GraphMLFormat())
85+
@test_logs (:warn, "Skipping unknown node 'warnnode' - further warnings will be suppressed") match_mode=:any loadgraphs(fname, GraphMLFormat())
86+
@test_logs (:warn, "Skipping unknown XML element 'warnelement' - further warnings will be suppressed") match_mode=:any loadgraph(fname, "graph", GraphMLFormat())
8787
d = loadgraphs(fname, GraphMLFormat())
8888
write_test(GraphMLFormat(), d)
8989
end
@@ -145,6 +145,7 @@ end
145145
@test length(loadgraphs(fname, NETFormat())) == 1
146146
end
147147

148+
#=
148149
@testset "JLD" begin
149150
using JLD
150151
@@ -182,6 +183,7 @@ end
182183
rm(path)
183184
end
184185
end
186+
=#
185187

186188
@testset "CDF" begin
187189
#test CDFFormat()

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using GraphIO
22
using LightGraphs
3-
using Base.Test
3+
using Test
44

55
testdir = dirname(@__FILE__)
66

0 commit comments

Comments
 (0)