Skip to content

Commit

Permalink
Migrate to 0.6+ and HTTP.jl (#144)
Browse files Browse the repository at this point in the history
* Drop support for Julia 0.5

* Migrate from Requests to HTTP

* Fix depwarns for 0.7

* Get rid of "does julia run the script" tests
  • Loading branch information
ararslan authored Jan 22, 2018
1 parent 3601a3f commit 2c3f797
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 83 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: julia
julia:
- 0.5
- 0.6
- nightly
notifications:
Expand Down
6 changes: 3 additions & 3 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
julia 0.5
julia 0.6
JSON
Requests
HTTP
Git
Compat 0.9.5
Compat 0.44.0
22 changes: 11 additions & 11 deletions src/Coverage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Coverage
# The unit for line counts. Counts can be >= 0 or nothing, where
# the nothing means it doesn't make sense to have a count for this
# line (e.g. a comment), but 0 means it could have run but didn't.
const CovCount = Union{Void,Int}
const CovCount = Union{Nothing,Int}

export FileCoverage
"""
Expand All @@ -33,7 +33,7 @@ module Coverage
line was expected to be run the count will be an `Int` >= 0. Other lines
such as comments will have a count of `nothing`.
"""
type FileCoverage
mutable struct FileCoverage
filename::AbstractString
source::AbstractString
coverage::Vector{CovCount}
Expand Down Expand Up @@ -71,7 +71,7 @@ module Coverage
function merge_coverage_counts(a1::Vector{CovCount},
a2::Vector{CovCount})
n = max(length(a1),length(a2))
a = Vector{CovCount}(n)
a = Vector{CovCount}(uninitialized, n)
for i in 1:n
a1v = isassigned(a1, i) ? a1[i] : nothing
a2v = isassigned(a2, i) ? a2[i] : nothing
Expand Down Expand Up @@ -103,17 +103,17 @@ module Coverage
lines = open(filename) do fp
readlines(fp)
end
coverage = Vector{CovCount}(length(lines))
coverage = Vector{CovCount}(uninitialized, length(lines))
return fill!(coverage, nothing)
end
# Keep track of the combined coverage
full_coverage = Vector{CovCount}(0)
full_coverage = Vector{CovCount}(uninitialized, 0)
for file in files
lines = open(file, "r") do fp
readlines(fp)
end
num_lines = length(lines)
coverage = Vector{CovCount}(num_lines)
coverage = Vector{CovCount}(uninitialized, num_lines)
for i in 1:num_lines
# Columns 1:9 contain the coverage count
cov_segment = lines[i][1:9]
Expand Down Expand Up @@ -148,7 +148,7 @@ module Coverage
while !eof(io)
pos = position(io)
linestart = minimum(searchsorted(linepos, pos))
ast = Base.parse(io)
ast = _parse(io)
isa(ast, Expr) || continue
flines = function_body_lines(ast)
if !isempty(flines)
Expand All @@ -166,7 +166,7 @@ module Coverage
end
nothing
end
# function_body_lines is located in parser.jl
# function_body_lines and _parse are located in parser.jl
include("parser.jl")

"""
Expand All @@ -182,7 +182,7 @@ module Coverage
println("Coverage.process_file: Detecting coverage for $filename")
coverage = process_cov(filename,folder)
amend_coverage_from_src!(coverage, filename)
return FileCoverage(filename, readstring(filename), coverage)
return FileCoverage(filename, read(filename, String), coverage)
end
process_file(filename) = process_file(filename,splitdir(filename)[1])

Expand Down Expand Up @@ -216,12 +216,12 @@ module Coverage
end

# matches julia coverage files with and without the PID
iscovfile(filename) = ismatch(r"\.jl\.?[0-9]*\.cov$", filename)
iscovfile(filename) = contains(filename, r"\.jl\.?[0-9]*\.cov$")
# matches a coverage file for the given sourcefile. They can be full paths
# with directories, but the directories must match
function iscovfile(filename, sourcefile)
startswith(filename, sourcefile) || return false
ismatch(r"\.jl\.?[0-9]*\.cov$", filename)
contains(filename, r"\.jl\.?[0-9]*\.cov$")
end

"""
Expand Down
51 changes: 36 additions & 15 deletions src/codecovio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ web service. It exports the `submit` and `submit_token` methods.
"""

module Codecov
using Requests
using HTTP
using Coverage
using JSON
using Compat
Expand Down Expand Up @@ -42,21 +42,42 @@ module Codecov
end


"""
kwargs provides default values to insert into args_array, only if they are
not already specified in args_array.
"""
function set_defaults(args_array; kwargs...)
defined_names = [k for (k,v) in args_array]
for kwarg in kwargs
if !(kwarg[1] in defined_names)
push!(args_array, kwarg)
if VERSION >= v"0.7.0-DEV.3481"
"""
kwargs provides default values to insert into args_array, only if they are
not already specified in args_array.
"""
function set_defaults(args_array; kwargs...)
defined_names = keys(pairs(args_array))
is_args_array = Pair{Symbol, Any}[]
if args_array isa Base.Iterators.IndexValue
is_args_array = vcat(is_args_array, collect(Pair(k, v) for (k,v) in args_array))
else
is_args_array = vcat(is_args_array, vec(args_array))
end
for kwarg in kwargs
if !(kwarg[1] in defined_names)
push!(is_args_array, Pair(kwarg[1], kwarg[2]))
end
end
return is_args_array
end
else
"""
kwargs provides default values to insert into args_array, only if they are
not already specified in args_array.
"""
function set_defaults(args_array; kwargs...)
defined_names = [k for (k, v) in args_array]
for kwarg in kwargs
if !(kwarg[1] in defined_names)
push!(args_array, kwarg)
end
end
return args_array
end
return args_array
end


"""
submit(fcs::Vector{FileCoverage})
Expand Down Expand Up @@ -127,7 +148,7 @@ module Codecov
Takes a `Vector` of file coverage results (produced by `process_folder`),
and submits them to Codecov.io. Assumes the submission is being made from
a local git installation. A repository token should be specified by a
'token' keyword argument or the CODECOV_TOKEN environment variable.
'token' keyword argument or the `CODECOV_TOKEN` environment variable.
"""
function submit_local(fcs::Vector{FileCoverage}; kwargs...)
kwargs = set_defaults(kwargs,
Expand Down Expand Up @@ -194,9 +215,9 @@ module Codecov
if !dry_run
heads = Dict("Content-Type" => "application/json")
data = to_json(fcs)
req = Requests.post(URI(uri_str); json = data, headers = heads)
req = HTTP.post(uri_str; body = JSON.json(data), headers = heads)
println("Result of submission:")
println(Compat.UTF8String(req.data))
println(String(req.data))
end
end

Expand Down
18 changes: 9 additions & 9 deletions src/coveralls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ web service. It exports the `submit` and `submit_token` methods.
"""
module Coveralls
using Coverage
using Requests
using HTTP
using JSON
using Compat

Expand Down Expand Up @@ -57,22 +57,22 @@ module Coveralls
"source_files" => map(to_json, fcs),
"repo_token" => ENV["REPO_TOKEN"])
println("Submitting data to Coveralls...")
req = Requests.post(
URI("https://coveralls.io/api/v1/jobs"),
req = HTTP.post(
"https://coveralls.io/api/v1/jobs",
files = [FileParam(JSON.json(data),"application/json","json_file","coverage.json")])
println("Result of submission:")
println(Compat.UTF8String(req.data))
println(String(req.data))

elseif lowercase(get(ENV, "TRAVIS", "false")) == "true"
data = Dict("service_job_id" => ENV["TRAVIS_JOB_ID"],
"service_name" => "travis-ci",
"source_files" => map(to_json, fcs))
println("Submitting data to Coveralls...")
req = Requests.post(
URI("https://coveralls.io/api/v1/jobs"),
req = HTTP.post(
"https://coveralls.io/api/v1/jobs",
files = [FileParam(JSON.json(data),"application/json","json_file","coverage.json")])
println("Result of submission:")
println(Compat.UTF8String(req.data))
println(String(req.data))
else
error("No compatible CI platform detected")
end
Expand Down Expand Up @@ -135,9 +135,9 @@ module Coveralls
end
end

r = post(URI("https://coveralls.io/api/v1/jobs"), files =
r = HTTP.post("https://coveralls.io/api/v1/jobs", files =
[FileParam(JSON.json(data),"application/json","json_file","coverage.json")])
println("Result of submission:")
println(Compat.UTF8String(r.data))
println(String(r.data))
end
end # module Coveralls
3 changes: 2 additions & 1 deletion src/lcov.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Julia coverage data. It exports the `writefile` function.
"""
module LCOV

using Compat
using Coverage

export writefile
Expand Down Expand Up @@ -68,7 +69,7 @@ function writeline(io::IO, line::Int, count::Int)
println(io, "DA:$line,$count")
(1, count)
end
function writeline(io::IO, line::Int, count::Void)
function writeline(io::IO, line::Int, count::Nothing)
# skipped line, nothing to do here
(0, 0)
end
Expand Down
10 changes: 5 additions & 5 deletions src/memalloc.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## Analyzing memory allocation

immutable MallocInfo
struct MallocInfo
bytes::Int
filename::Compat.UTF8String
filename::String
linenumber::Int
end

Expand Down Expand Up @@ -32,7 +32,7 @@ function analyze_malloc_files(files)
end

function find_malloc_files(dirs)
files = Compat.String[]
files = String[]
for dir in dirs
filelist = readdir(dir)
for file in filelist
Expand All @@ -46,10 +46,10 @@ function find_malloc_files(dirs)
end
files
end
find_malloc_files(file::Compat.String) = find_malloc_files([file])
find_malloc_files(file::String) = find_malloc_files([file])

analyze_malloc(dirs) = analyze_malloc_files(find_malloc_files(dirs))
analyze_malloc(dir::Compat.String) = analyze_malloc([dir])
analyze_malloc(dir::String) = analyze_malloc([dir])

isfuncexpr(ex::Expr) =
ex.head == :function || (ex.head == :(=) && typeof(ex.args[1]) == Expr && ex.args[1].head == :call)
Expand Down
9 changes: 9 additions & 0 deletions src/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@ function function_body_lines!(flines, ast::Expr, infunction)
end
flines
end

if VERSION >= v"0.7.0-DEV.2437"
function _parse(io::IO)
pos = position(io)
Meta.parse(read(io, String), position(io))
end
else
_parse(io::IO) = Base.parse(io)
end
Loading

0 comments on commit 2c3f797

Please sign in to comment.