Skip to content

Commit 9dfe190

Browse files
authored
Merge pull request #5 from galenlynch/femtoCleaner
Deprecations for 0.7 and 1.0
2 parents cab3a5e + ae5498b commit 9dfe190

14 files changed

+133
-61
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ os:
77
julia:
88
- 0.6
99
- 0.7
10+
- 1.0
1011
- nightly
1112

1213
matrix:

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ For documentation on the use of `metadata`, please see the latest docs below.
2323
- [**LATEST**][docs-latest-url] — *in-development version of the documentation.*
2424

2525
## Project Status
26-
This package is tested against Julia `0.6`, `0.7`, and nightlies on Linux, OS X, and Windows.
26+
This package is tested against Julia `0.6`, `0.7`, `1.0`, and nightlies on Linux, OS X, and Windows.
2727

2828
This package only supports reading from continuous files at the moment, with no immediate
2929
plans to support spike data.

REQUIRE

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
julia 0.6
2-
LightXML 0.3
2+
LightXML 0.3 0.9
3+
Compat 1.0 2

appveyor.yml

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ environment:
55
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
66
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
77
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
8+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/1.0/julia-1.0-latest-win32.exe"
9+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/1.0/julia-1.0-latest-win64.exe"
810
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
911
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
1012

src/OpenEphysLoader.jl

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ Provides array interfaces to file contents, without loading the entire file into
66
"""
77
module OpenEphysLoader
88
# Module to interact with Open Ephys files
9-
using LightXML
9+
using Compat, LightXML
10+
11+
@static if VERSION >= v"0.7.0-DEV.2575"
12+
using Dates
13+
end
14+
1015
import Base: show,
11-
showcompact,
1216
showerror,
1317
size,
14-
linearindexing,
1518
getindex,
1619
setindex!,
1720
length

src/continuous.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ mutable struct DataBlock <: BlockBuffer
4747
end
4848
function DataBlock()
4949
head = BlockHeader()
50-
body = Vector{UInt8}(CONT_REC_BODY_SIZE)
51-
data = Vector{CONT_REC_SAMP_BITTYPE}(CONT_REC_N_SAMP)
52-
tail = Vector{UInt8}(CONT_REC_TAIL_SIZE)
50+
body = @compat Vector{UInt8}(undef, CONT_REC_BODY_SIZE)
51+
data = @compat Vector{CONT_REC_SAMP_BITTYPE}(undef, CONT_REC_N_SAMP)
52+
tail = @compat Vector{UInt8}(undef, CONT_REC_TAIL_SIZE)
5353
DataBlock(head, body, data, tail)
5454
end
5555

@@ -311,7 +311,7 @@ function convert_block!(block::DataBlock)
311311
unsafe_store!(ptr, ntoh(unsafe_load(ptr, idx)), idx)
312312
end
313313
end
314-
unsafe_copy!(pointer(block.data), ptr, CONT_REC_N_SAMP)
314+
@compat unsafe_copyto!(pointer(block.data), ptr, CONT_REC_N_SAMP)
315315
return block.data
316316
end
317317

src/metadata.jl

+9-9
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ function OERecordingMeta(settings::OESettings{S, T}, rec_e::LightXML.XMLElement)
309309
throw(CorruptedException("Could not find PROCESSOR elements"))
310310
end
311311
nproc = length(proc_es)
312-
rec_procs = Vector{T}(nproc)
312+
@compat rec_procs = Vector{T}(undef, nproc)
313313

314314
for (i, proc_e) in enumerate(proc_es)
315315
id = find_matching_proc(settings.recording_chain, proc_e)
@@ -367,7 +367,7 @@ function OEExperMeta(settings::OESettings{S, T}, exper_e::LightXML.XMLElement) w
367367
throw(CorruptedException("Could not find RECORDING elements"))
368368
end
369369
nrec = length(rec_es)
370-
recordings = Vector{OERecordingMeta{T}}(nrec)
370+
@compat recordings = Vector{OERecordingMeta{T}}(undef, nrec)
371371
for (i, rec_e) in enumerate(rec_es)
372372
recordings[i] = OERecordingMeta(settings, rec_e)
373373
end
@@ -424,7 +424,7 @@ function channel_arr(proc_e::LightXML.XMLElement, ::Type{T} = String) where {T<:
424424
end
425425
nchan = length(channel_vec)
426426
chan_rec = fill(false, nchan)
427-
chnos = Array{Int}(nchan)
427+
@compat chnos = Array{Int}(undef, nchan)
428428
for (i, chan_e) in enumerate(channel_vec)
429429
sel_e = required_find_element(chan_e, "SELECTIONSTATE")
430430
record_attr = attribute(sel_e, "record", required=true)
@@ -441,7 +441,7 @@ function channel_arr(proc_e::LightXML.XMLElement, ::Type{T} = String) where {T<:
441441
# Channel info
442442
ch_info_e = required_find_element(proc_e, "CHANNEL_INFO")
443443
chinfo_children = collect(child_elements(ch_info_e))
444-
channels = Array{OEChannel{T}}(nrec)
444+
@compat channels = Array{OEChannel{T}}(undef, nrec)
445445
recno = 1
446446
for (i, chan_e) in enumerate(chinfo_children)
447447
if chan_rec[i]
@@ -451,7 +451,7 @@ function channel_arr(proc_e::LightXML.XMLElement, ::Type{T} = String) where {T<:
451451
chname = attribute(chan_e, "name", required = true)
452452
bitvolt_attr = attribute(chan_e, "gain", required = true)
453453
bitvolts = parse(Float64, bitvolt_attr)
454-
channels[recno] = OEChannel{String}(chname,
454+
@compat channels[recno] = OEChannel{String}(chname,
455455
info_chno,
456456
bitvolts,
457457
Vector{Int}(),
@@ -517,7 +517,7 @@ function recordings_are_consistent(rec_es::Vector{LightXML.XMLElement})
517517
chan_xml = XmlNode("CHANNEL", XmlNode[], ["name", "filename"])
518518
proc_xml = XmlNode("PROCESSOR", [chan_xml], ["id"])
519519
nrec = length(rec_es)
520-
attr_sets = Vector{Set{String}}(nrec)
520+
@compat attr_sets = Vector{Set{String}}(undef, nrec)
521521
for (i, rec_e) in enumerate(rec_es)
522522
attr_sets[i] = Set(recurse_xml_attr(rec_e, proc_xml))
523523
end
@@ -585,7 +585,7 @@ end
585585
### Helper Functions ###
586586
function required_find_element(e::LightXML.XMLElement, name::AbstractString)
587587
maybe_e = find_element(e, name)
588-
isa(maybe_e, Void) && throw(CorruptedException("Could not find $name element"))
588+
@compat isa(maybe_e, Nothing) && throw(CorruptedException("Could not find $name element"))
589589
return maybe_e
590590
end
591591

@@ -614,10 +614,10 @@ end
614614
show(io::IO, a::SignalNode) = show(io, a.content)
615615

616616
showfields(io::IO, a::Any) = showfields(IOContext(io, :depth => 0), a)
617-
function showfields(io::IOContext, a::Any)
617+
function showfields(io::IOContext, a::T) where T
618618
depth = get(io, :depth, 0)
619619
pad = " " ^ depth
620-
fields = fieldnames(a)
620+
fields = fieldnames(T)
621621
depth > 0 && print(io, '\n')
622622
next_io = IOContext(IOContext(io, :typeinfo => Any), :depth => depth + 1)
623623
for field in fields

src/original.jl

+17-11
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ function OriginalHeader(io::IOStream)
161161
length(head) == HEADER_N_BYTES || throw(CorruptedException("Header is malformed"))
162162
headstr = transcode(String, head)
163163
isvalid(headstr) || throw(CorruptedException("Header is malformed"))
164-
substrs = split(headstr, ';', keep = false)
164+
substrs = Compat.split(headstr, ';', keepempty = false)
165165
resize!(substrs, N_HEADER_LINE)
166166
return OriginalHeader(
167167
map(parseline, zip(HEADER_MATTYPES, HEADER_TARGET_TYPES, substrs))...
@@ -170,15 +170,19 @@ end
170170

171171
"Parse a line of Matlab source code"
172172
function parseline end
173-
parseline(::Type{M}, ::Type{T}, str::AbstractString) where {T, M<:MATLABdata} = parseto(T, matread(M, str))::T
173+
function parseline(
174+
::Type{M}, ::Type{T}, str::AbstractString
175+
) where {T, M<:MATLABdata}
176+
parseto(T, matread(M, str))
177+
end
174178
parseline(tup::Tuple) = parseline(tup...)
175179

176180
"Convert a string to the desired type"
177181
function parseto end
178-
parseto(::Type{T}, str::AbstractString) where {T<:Number} = parse(str)::T
182+
parseto(::Type{T}, str::AbstractString) where T = parse(T, str)
179183
function parseto(::Type{DateTime}, str::AbstractString)
180184
m = match(HEADER_DATE_REGEX, str)
181-
isa(m, Void) && throw(CorruptedException("Time created is improperly formatted"))
185+
isa(m, @compat(Nothing)) && throw(CorruptedException("Time created is improperly formatted"))
182186
d = DateTime(m.captures[1], HEADER_DATEFORMAT)
183187
local hr, mn, sc
184188
try
@@ -203,32 +207,34 @@ function parseto(::Type{DateTime}, str::AbstractString)
203207
end
204208
parseto(::Type{VersionNumber}, str::AbstractString) = VersionNumber(str)
205209
parseto(::Type{String}, str::AbstractString) = String(str)
206-
parseto(::Type{T}, str::T) where {T<:AbstractString} = str
210+
parseto(::Type{T}, str::T) where T<:AbstractString = str
207211

208212
"read a Matlab source line"
209213
function matread(::Type{T}, str::S) where {T<:MATLABdata, S<:AbstractString}
210214
regex = rx(T)
211215
goodread = false
212216
local m
213-
if ismatch(regex, str)
217+
if @compat occursin(regex, str)
214218
m = match(rx(T), str)
215219
isempty(m.captures) && throw(CorruptedException("Cannot parse header"))
216220
end
217-
return S(m.captures[1])
221+
return string(m.captures[1])
218222
end
219223

220224
### Matlab regular expressions ###
221225
rx(::Type{MATstr}) = r" = '(.*)'$"
222226
rx(::Type{MATint}) = r" = (\d*)$"
223227
rx(::Type{MATfloat}) = r" = ([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)$"
224228

225-
function show(io::IO, a::OriginalHeader)
226-
fields = fieldnames(a)
229+
function show(io::IO, a::O) where O<:OriginalHeader
230+
fields = fieldnames(O)
227231
for field in fields
228-
println(io, "$field: $(getfield(a, field))")
232+
println(io, field, ": ", getfield(a, field))
229233
end
230234
end
231-
showcompact(io::IO, header::OriginalHeader) = show(io, "channel: $(header.channel)")
235+
function showcompact(io::IO, header::OriginalHeader)
236+
show(IOContext(io, :compact => true), "channel: $(header.channel)")
237+
end
232238
function show(io::IO, headers::Vector{OriginalHeader})
233239
for header in headers
234240
println(io, showcompact(header))

test/continuous.jl

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1+
__precompile__()
12
module TestContinuous
2-
using OpenEphysLoader, Main.TestUtilities, Main.TestOriginal, Base.Test
3+
using Compat, OpenEphysLoader
4+
using Main.TestUtilities, Main.TestOriginal
5+
6+
@static if VERSION < v"0.7.0-DEV.2005"
7+
using Base.Test
8+
else
9+
using Test
10+
end
11+
12+
@static if VERSION >= v"0.7.0-DEV.2575"
13+
using Random
14+
end
15+
16+
317
# Helper functions to test OpenEphysLoader's handling of
418
# continuous files
519

@@ -72,7 +86,7 @@ end
7286

7387
function block_idxes(blockno::Integer)
7488
nblocksamp = OpenEphysLoader.CONT_REC_N_SAMP
75-
return (blockno - 1) * nblocksamp + (1:nblocksamp)
89+
return (blockno - 1) * nblocksamp .+ (1:nblocksamp)
7690
end
7791

7892
function to_block_contents(D::Vector, blockno::Integer, startsamp::Integer)
@@ -252,7 +266,7 @@ function write_continuous(
252266
io,
253267
view(
254268
padded,
255-
offset + (1:OpenEphysLoader.CONT_REC_N_SAMP)
269+
offset .+ (1:OpenEphysLoader.CONT_REC_N_SAMP)
256270
),
257271
tblock,
258272
recno
@@ -336,9 +350,9 @@ function time_conversion(
336350
startsamp::Integer,
337351
nsamp::Integer
338352
) where T<:AbstractFloat
339-
timepoints = (time_conversion(Int, startsamp, nsamp) - 1) / 30000
353+
timepoints = (time_conversion(Int, startsamp, nsamp) .- 1) / 30000
340354
converted_times = similar(timepoints, T)
341-
copy!(converted_times, timepoints)
355+
@compat copyto!(converted_times, timepoints)
342356
return converted_times
343357
end
344358

test/metadata.jl

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1+
__precompile__()
12
module TestMetadata
2-
using OpenEphysLoader, Main.TestUtilities, Base.Test
3+
using Compat, OpenEphysLoader
4+
using Main.TestUtilities
5+
6+
@static if VERSION < v"0.7.0-DEV.2005"
7+
using Base.Test
8+
else
9+
using Test
10+
end
11+
12+
@static if VERSION >= v"0.7.0-DEV.2575"
13+
using Dates
14+
using Random
15+
end
316

417
test_dir = joinpath(dirname(@__FILE__), "data")
518

@@ -31,7 +44,7 @@ test_dir = joinpath(dirname(@__FILE__), "data")
3144
true, # dsp_offset
3245
0 # dsp_cutoff
3346
)
34-
const BITVOLTS = 0.19499999284744263
47+
BITVOLTS = 0.19499999284744263
3548
channel_1_ans = (
3649
"CH1",
3750
0,
@@ -71,10 +84,10 @@ test_dir = joinpath(dirname(@__FILE__), "data")
7184
test_fields(expermeta, expermeta_ans..., recordings = false, settings = false)
7285
@test ! isempty(expermeta.recordings)
7386
test_fields(expermeta.recordings[1], recording_ans..., recording_processors = false)
74-
@test (show(DevNull, settings.recording_chain); true) # Test that this does not error
75-
@test (show(DevNull, settings); true)
76-
@test (show(DevNull, expermeta.recordings[1]); true)
77-
@test (show(DevNull, expermeta); true)
87+
@test @compat (show(devnull, settings.recording_chain); true) # Test that this does not error
88+
@test @compat (show(devnull, settings); true)
89+
@test @compat (show(devnull, expermeta.recordings[1]); true)
90+
@test @compat (show(devnull, expermeta); true)
7891

7992
#plug in settings
8093
@test_throws CorruptedException metadata(

test/original.jl

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
__precompile__()
12
module TestOriginal
2-
using OpenEphysLoader, Main.TestUtilities, Base.Test
3+
using Compat, OpenEphysLoader
4+
using Main.TestUtilities
5+
6+
@static if VERSION < v"0.7.0-DEV.2005"
7+
using Base.Test
8+
else
9+
using Test
10+
end
11+
@static if VERSION >= v"0.7.0-DEV.2575"
12+
using Dates
13+
end
314

415
export write_fheader_fun,
516
verify_header
@@ -29,7 +40,7 @@ function write_fheader_fun(
2940
@assert isfile(headerpath) "Could not load header file"
3041
open(headerpath, "r") do readio
3142
@assert stat(readio).size >= nbytes "Header not long enough"
32-
head = readstring(readio)
43+
head = read(readio, String)
3344
end
3445
trunchead = head[1:nbytes]
3546
return io::IOStream -> write(io, trunchead)
@@ -55,11 +66,11 @@ end
5566
filecontext(write_fheader_fun()) do io
5667
header = OriginalHeader(io)
5768
verify_header(header)
58-
@test (show(DevNull, header); true) # test that it does not error
59-
@test (showcompact(DevNull, header); true)
69+
@test (show(@compat(devnull), header); true) # test that it does not error
70+
@test (OpenEphysLoader.showcompact(@compat(devnull), header); true)
6071
end
6172

62-
@test (showerror(DevNull, CorruptedException("test")); true)
73+
@test (showerror(@compat(devnull), CorruptedException("test")); true)
6374

6475
# truncated header
6576
filecontext(write_fheader_fun(512)) do io

test/runtests.jl

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
using Base.Test
1+
@static if VERSION < v"0.7.0-DEV.2005"
2+
using Base.Test
3+
else
4+
using Test
5+
end
6+
27
@testset "OpenEphysLoader.jl" begin
38
include("util.jl")
49
include("original.jl")

0 commit comments

Comments
 (0)