From 319acb5215c43f0fdacd6c8c7c7e22aeb6376c5e Mon Sep 17 00:00:00 2001 From: Simon Schoelly Date: Thu, 6 Sep 2018 17:43:41 +0200 Subject: [PATCH 1/4] some fixes for version 1.0 --- .travis.yml | 12 ++++++------ REQUIRE | 2 +- src/GraphIO.jl | 3 ++- src/cdf.jl | 8 ++++---- src/dot.jl | 4 ++-- src/edgelist.jl | 4 +++- src/gml.jl | 5 +++-- src/graph6.jl | 10 +++++----- src/graphml.jl | 6 +++--- src/net.jl | 22 +++++++++++----------- test/graphio.jl | 4 ++-- test/runtests.jl | 2 +- 12 files changed, 43 insertions(+), 39 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5f40a85..4a94547 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; appinfo(); 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/REQUIRE b/REQUIRE index 9add95a..93c59df 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,4 @@ -julia 0.6 +julia 0.7 LightGraphs 0.9.5 EzXML 0.5 ParserCombinator diff --git a/src/GraphIO.jl b/src/GraphIO.jl index ea50514..453dd54 100644 --- a/src/GraphIO.jl +++ b/src/GraphIO.jl @@ -6,7 +6,8 @@ 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 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..d76873c 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 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__) From 6857485db556aff4ab1e0872ca9f0dede8e1320a Mon Sep 17 00:00:00 2001 From: Simon Schoelly Date: Fri, 7 Sep 2018 05:52:38 +0200 Subject: [PATCH 2/4] uncommented functions for jld --- REQUIRE | 2 +- src/GraphIO.jl | 2 +- test/graphio.jl | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/REQUIRE b/REQUIRE index 93c59df..6becd7a 100644 --- a/REQUIRE +++ b/REQUIRE @@ -2,5 +2,5 @@ julia 0.7 LightGraphs 0.9.5 EzXML 0.5 ParserCombinator -JLD +#JLD SimpleTraits diff --git a/src/GraphIO.jl b/src/GraphIO.jl index 453dd54..4cf017e 100644 --- a/src/GraphIO.jl +++ b/src/GraphIO.jl @@ -13,7 +13,7 @@ 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/test/graphio.jl b/test/graphio.jl index d76873c..56dc11f 100644 --- a/test/graphio.jl +++ b/test/graphio.jl @@ -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() From 34be4e30289eee87df881ddec54749634794248a Mon Sep 17 00:00:00 2001 From: Simon Schoelly Date: Fri, 14 Sep 2018 12:21:12 +0200 Subject: [PATCH 3/4] Release for Julia v1.0 --- README.md | 2 ++ REQUIRE | 4 ++-- src/GraphIO.jl | 1 - 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ee3e4ac..2865dee 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ 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 6becd7a..ddbf4d0 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,6 +1,6 @@ julia 0.7 LightGraphs 0.9.5 -EzXML 0.5 -ParserCombinator +EzXML 0.9.0 +ParserCombinator 2.0.0 #JLD SimpleTraits diff --git a/src/GraphIO.jl b/src/GraphIO.jl index 4cf017e..ceba01f 100644 --- a/src/GraphIO.jl +++ b/src/GraphIO.jl @@ -1,4 +1,3 @@ -__precompile__(true) module GraphIO using LightGraphs From 0a9d8a5830d94d5ad85bb0a72ef1b996bdb00f8c Mon Sep 17 00:00:00 2001 From: Simon Schoelly Date: Fri, 14 Sep 2018 12:33:06 +0200 Subject: [PATCH 4/4] replaced appinfo() by versioninfo() in .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4a94547..d27fc39 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ notifications: # uncomment the following lines to override the default test script script: - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi - - julia -e 'using Pkg, InteractiveUtils; appinfo(); 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 'using Pkg; cd(Pkg.dir("GraphIO")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'