diff --git a/.travis.yml b/.travis.yml index 5f40a85..d27fc39 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,8 @@ os: # - osx julia: - - 0.6 + - 0.7 + - 1.0 - nightly matrix: @@ -18,10 +19,9 @@ notifications: # uncomment the following lines to override the default test script script: - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi - - julia -e 'Pkg.add("LightGraphs")' - - julia -e 'Pkg.clone(pwd()); Pkg.build("GraphIO"); Pkg.test("GraphIO"; coverage=true)' + - julia -e 'using Pkg, InteractiveUtils; versioninfo(); Pkg.clone(pwd()); Pkg.build("GraphIO"); Pkg.test("GraphIO"; coverage=true)' after_success: - - julia -e 'cd(Pkg.dir("GraphIO")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())' - - julia -e 'Pkg.add("Documenter")' - - julia -e 'cd(Pkg.dir("GraphIO")); include(joinpath("docs", "make.jl"))' + - julia -e 'using Pkg; cd(Pkg.dir("GraphIO")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())' + - julia -e 'using Pkg; Pkg.add("Documenter")' + - julia -e 'using Pkg; cd(Pkg.dir("GraphIO")); include(joinpath("docs", "make.jl"))' diff --git a/README.md b/README.md index 646be9e..45a33d6 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ Note that support for the jld format was removed from this branch. GraphIO provides support to [LightGraphs.jl](https://github.com/JuliaGraphs/LightGraphs.jl) for reading/writing graphs in various formats. +The current version of GraphIO works with Julia version >= 0.7. + Currently, the following functionality is provided: Format | Read | Write | Multiple Graphs| Format Name | diff --git a/REQUIRE b/REQUIRE index 9add95a..ddbf4d0 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,6 +1,6 @@ -julia 0.6 +julia 0.7 LightGraphs 0.9.5 -EzXML 0.5 -ParserCombinator -JLD +EzXML 0.9.0 +ParserCombinator 2.0.0 +#JLD SimpleTraits diff --git a/src/GraphIO.jl b/src/GraphIO.jl index ea50514..ceba01f 100644 --- a/src/GraphIO.jl +++ b/src/GraphIO.jl @@ -1,4 +1,3 @@ -__precompile__(true) module GraphIO using LightGraphs @@ -6,13 +5,14 @@ using SimpleTraits import LightGraphs: loadgraph, loadgraphs, savegraph, AbstractGraphFormat using EzXML -using ParserCombinator: Parsers.DOT, Parsers.GML +using ParserCombinator.Parsers.DOT +using ParserCombinator.Parsers.GML export DOTFormat, GEXFFormat, GMLFormat, Graph6Format, GraphMLFormat, NETFormat, EdgeListFormat, CDFFormat # package code goes here -include("jld.jl") +#include("jld.jl") include("dot.jl") include("gexf.jl") include("gml.jl") diff --git a/src/cdf.jl b/src/cdf.jl index dedf2a3..b4db0fe 100644 --- a/src/cdf.jl +++ b/src/cdf.jl @@ -13,19 +13,19 @@ function _loadcdf(io::IO) while !eof(io) line = strip(chomp(readline(io))) if inbusdata - if contains(line, "-999") + if occursin("-999", line) inbusdata = false else v = parse(Int, split(line)[1]) push!(vertices, v) end elseif inbranchdata - if contains(line, "-999") + if occursin("-999", line) inbranchdata = false else (src_s, dst_s) = split(line)[1:2] - src = findfirst(vertices, parse(Int, src_s)) - dst = findfirst(vertices, parse(Int, dst_s)) + src = something(findfirst(isequal(parse(Int, src_s)), vertices), 0) + dst = something(findfirst(isequal(parse(Int, dst_s)), vertices), 0) push!(srcs, src) push!(dsts, dst) end diff --git a/src/dot.jl b/src/dot.jl index a5b370e..3557e10 100644 --- a/src/dot.jl +++ b/src/dot.jl @@ -20,7 +20,7 @@ function _dot_read_one_graph(pg::DOT.Graph) end function loaddot(io::IO, gname::String) - p = DOT.parse_dot(readstring(io)) + p = DOT.parse_dot(read(io, String)) for pg in p isdir = pg.directed possname = isdir ? DOT.StringID("digraph") : DOT.StringID("graph") @@ -31,7 +31,7 @@ function loaddot(io::IO, gname::String) end function loaddot_mult(io::IO) - p = DOT.parse_dot(readstring(io)) + p = DOT.parse_dot(read(io, String)) graphs = Dict{String,LightGraphs.AbstractGraph}() diff --git a/src/edgelist.jl b/src/edgelist.jl index f578e80..b692d4c 100644 --- a/src/edgelist.jl +++ b/src/edgelist.jl @@ -2,6 +2,8 @@ # by commas or whitespace. Will only read the first two elements on # each line. Will return a directed graph. +using DelimitedFiles: writedlm + struct EdgeListFormat <: AbstractGraphFormat end function loadedgelist(io::IO, gname::String) @@ -33,7 +35,7 @@ function loadedgelist(io::IO, gname::String) end function saveedgelist(io::IO, g::LightGraphs.AbstractGraph, gname::String) - writecsv(io, [src(e), dst(e)] for e in collect(LightGraphs.edges(g))) + writedlm(io, ([src(e), dst(e)] for e in LightGraphs.edges(g)), ',') return 1 end diff --git a/src/gml.jl b/src/gml.jl index 43ef63f..d58e36e 100644 --- a/src/gml.jl +++ b/src/gml.jl @@ -17,8 +17,9 @@ function _gml_read_one_graph(gs, dir) end return g end + function loadgml(io::IO, gname::String) - p = GML.parse_dict(readstring(io)) + p = GML.parse_dict(read(io, String)) for gs in p[:graph] dir = Bool(get(gs, :directed, 0)) graphname = get(gs, :label, dir ? "digraph" : "graph") @@ -29,7 +30,7 @@ function loadgml(io::IO, gname::String) end function loadgml_mult(io::IO) - p = GML.parse_dict(readstring(io)) + p = GML.parse_dict(read(io, String)) graphs = Dict{String,LightGraphs.AbstractGraph}() for gs in p[:graph] dir = Bool(get(gs, :directed, 0)) diff --git a/src/graph6.jl b/src/graph6.jl index 0bbfa1c..6d16f19 100644 --- a/src/graph6.jl +++ b/src/graph6.jl @@ -1,7 +1,7 @@ struct Graph6Format <: AbstractGraphFormat end function _bv2int(x::BitVector) - assert(length(x) <= 8 * sizeof(Int)) + @assert(length(x) <= 8 * sizeof(Int)) acc = 0 for i = 1:length(x) acc = acc << 1 + x[i] @@ -10,7 +10,7 @@ function _bv2int(x::BitVector) end function _int2bv(n::Int, k::Int) - bitstr = lstrip(bits(n), '0') + bitstr = lstrip(bitstring(n), '0') l = length(bitstr) padding = k - l bv = falses(k) @@ -25,7 +25,7 @@ function _g6_R(_x::BitVector)::Vector{UInt8} padding = cld(k, 6) * 6 - k x = vcat(_x, falses(padding)) nbytes = div(length(x), 6) - bytevec = Vector{UInt8}(nbytes) # uninitialized data! + bytevec = Vector{UInt8}(undef, nbytes) # uninitialized data! for i = 1:nbytes xslice = x[((i - 1) * 6 + 1):(i * 6)] @@ -71,7 +71,7 @@ end """ - \_graphToG6String(g) + _graphToG6String(g) Given a graph `g`, create the corresponding Graph6 string. """ @@ -79,7 +79,7 @@ function _graphToG6String(g::LightGraphs.Graph) A = adjacency_matrix(g, Bool) n = nv(g) nbits = div(n * (n - 1), 2) - x = BitVector(nbits) + x = BitVector(undef, nbits) ind = 0 for col = 2:n, row = 1:(col - 1) diff --git a/src/graphml.jl b/src/graphml.jl index 2950fa2..d8c7bad 100644 --- a/src/graphml.jl +++ b/src/graphml.jl @@ -17,7 +17,7 @@ function _graphml_read_one_graph(reader::EzXML.StreamReader, isdirected::Bool) tar = reader["target"] push!(xedges, LightGraphs.Edge(nodes[src], nodes[tar])) else - warn("Skipping unknown node '$(elname)' - further warnings will be suppressed", once=true, key="unknode") + @warn "Skipping unknown node '$(elname)' - further warnings will be suppressed" maxlog=1 _id=:unknode end end end @@ -51,7 +51,7 @@ function loadgraphml(io::IO, gname::String) elseif elname == "node" || elname == "edge" # ok else - warn("Skipping unknown XML element '$(elname)' - further warnings will be suppressed", once=true, key="unkel") + @warn "Skipping unknown XML element '$(elname)' - further warnings will be suppressed" maxlog=1 _id=:unkel end end end @@ -78,7 +78,7 @@ function loadgraphml_mult(io::IO) end graphs[graphname] = _graphml_read_one_graph(reader, directed) else - warn("Skipping unknown XML element '$(elname)' - further warnings will be suppressed", once=true, key="unkelmult") + @warn "Skipping unknown XML element '$(elname)' - further warnings will be suppressed" maxlog=1 _id=:unkelmult end end end diff --git a/src/net.jl b/src/net.jl index 1cd55e5..39dfb78 100644 --- a/src/net.jl +++ b/src/net.jl @@ -32,30 +32,30 @@ function loadnet(io::IO, gname::String = "graph") while startswith(line, "%") line = readline(io) end - n = parse(Int, matchall(r"\d+", line)[1]) + n = parse(Int, match(r"\d+", line).match) for ioline in eachline(io) line = ioline - (ismatch(r"^\*Arcs", line) || ismatch(r"^\*Edges", line)) && break + (occursin(r"^\*Arcs", line) || occursin(r"^\*Edges", line)) && break end - if ismatch(r"^\*Arcs", line) + if occursin(r"^\*Arcs", line) g = LightGraphs.DiGraph(n) else g = LightGraphs.Graph(n) end - while ismatch(r"^\*Arcs", line) + while occursin(r"^\*Arcs", line) for ioline in eachline(io) line = ioline - m = matchall(r"\d+", line) - length(m) < 2 && break - add_edge!(g, parse(Int, m[1]), parse(Int, m[2])) + ms = collect(m.match for m in eachmatch(r"\d+", line, overlap=false)) + length(ms) < 2 && break + add_edge!(g, parse(Int, ms[1]), parse(Int, ms[2])) end end - while ismatch(r"^\*Edges", line) # add edges in both directions + while occursin(r"^\*Edges", line) # add edges in both directions for ioline in eachline(io) line = ioline - m = matchall(r"\d+", line) - length(m) < 2 && break - i1, i2 = parse(Int, m[1]), parse(Int, m[2]) + ms = collect(m.match for m in eachmatch(r"\d+", line, overlap=false)) + length(ms) < 2 && break + i1, i2 = parse(Int, ms[1]), parse(Int, ms[2]) add_edge!(g, i1, i2) add_edge!(g, i2, i1) end diff --git a/test/graphio.jl b/test/graphio.jl index 9c109eb..56dc11f 100644 --- a/test/graphio.jl +++ b/test/graphio.jl @@ -82,8 +82,8 @@ end end fname = joinpath(testdir, "testdata", "warngraph.graphml") - @test_warn "Skipping unknown node 'warnnode' - further warnings will be suppressed" loadgraphs(fname, GraphMLFormat()) - @test_warn "Skipping unknown XML element 'warnelement' - further warnings will be suppressed" loadgraph(fname, "graph", GraphMLFormat()) + @test_logs (:warn, "Skipping unknown node 'warnnode' - further warnings will be suppressed") match_mode=:any loadgraphs(fname, GraphMLFormat()) + @test_logs (:warn, "Skipping unknown XML element 'warnelement' - further warnings will be suppressed") match_mode=:any loadgraph(fname, "graph", GraphMLFormat()) d = loadgraphs(fname, GraphMLFormat()) write_test(GraphMLFormat(), d) end @@ -145,6 +145,7 @@ end @test length(loadgraphs(fname, NETFormat())) == 1 end +#= @testset "JLD" begin using JLD @@ -182,6 +183,7 @@ end rm(path) end end +=# @testset "CDF" begin #test CDFFormat() diff --git a/test/runtests.jl b/test/runtests.jl index 72f340a..9ab8fe9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,6 @@ using GraphIO using LightGraphs -using Base.Test +using Test testdir = dirname(@__FILE__)