diff --git a/.JuliaFormatter.toml b/.JuliaFormatter.toml new file mode 100644 index 0000000..d808d22 --- /dev/null +++ b/.JuliaFormatter.toml @@ -0,0 +1,2 @@ +# See https://domluna.github.io/JuliaFormatter.jl/stable/ for a list of options +style = "blue" diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..872de76 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,41 @@ +name: CI +on: + push: + branches: + - main + tags: ['*'] + pull_request: + workflow_dispatch: +concurrency: + # Skip intermediate builds: always. + # Cancel intermediate builds: only if it is a pull request build. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} + runs-on: ${{ matrix.os }} + timeout-minutes: 60 + permissions: # needed to allow julia-actions/cache to proactively delete old caches that it has created + actions: write + contents: read + strategy: + fail-fast: false + matrix: + version: + - '1.11' + - '1.6' + - 'pre' + os: + - ubuntu-latest + arch: + - x64 + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: julia-actions/cache@v2 + - uses: julia-actions/julia-buildpkg@v1 + - uses: julia-actions/julia-runtest@v1 diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml new file mode 100644 index 0000000..cba9134 --- /dev/null +++ b/.github/workflows/CompatHelper.yml @@ -0,0 +1,16 @@ +name: CompatHelper +on: + schedule: + - cron: 0 0 * * * + workflow_dispatch: +jobs: + CompatHelper: + runs-on: ubuntu-latest + steps: + - name: Pkg.add("CompatHelper") + run: julia -e 'using Pkg; Pkg.add("CompatHelper")' + - name: CompatHelper.main() + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }} + run: julia -e 'using CompatHelper; CompatHelper.main()' diff --git a/.gitignore b/.gitignore index ba39cc5..06969da 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ Manifest.toml +Dockerfile \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index a8ba32e..5308585 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [1.0.0-DEV] - Unreleased + - Add CI workflow for versions 1.11, 1.6 (LTS), and "pre". + - Format [blue](https://github.com/JuliaDiff/BlueStyle) + ## [0.2.0] - 2022-02-23 - Add support for string markers and string streams ([#2](https://github.com/cbrnr/XDF.jl/pull/2) by [Alberto Barradas](https://github.com/abcsds) and [Clemens Brunner](https://github.com/cbrnr)) - Make header and footer XML available in "xml" key ([#4](https://github.com/cbrnr/XDF.jl/pull/4) by [Alberto Barradas](https://github.com/abcsds)) diff --git a/Project.toml b/Project.toml index 0f300dd..10d2ef7 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "XDF" uuid = "31bc19ec-0089-417f-990e-a2b5e7515868" authors = ["Clemens Brunner "] -version = "0.2.0" +version = "1.0.0-DEV" [deps] Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" diff --git a/src/XDF.jl b/src/XDF.jl index 53d0b6c..cfec946 100644 --- a/src/XDF.jl +++ b/src/XDF.jl @@ -7,22 +7,24 @@ export read_xdf using Logging: @info, @debug - -CHUNK_TYPE = Dict(1=>"FileHeader", - 2=>"StreamHeader", - 3=>"Samples", - 4=>"ClockOffset", - 5=>"Boundary", - 6=>"StreamFooter") - -DATA_TYPE = Dict("int8"=>Int8, - "int16"=>Int16, - "int32"=>Int32, - "int64"=>Int64, - "float32"=>Float32, - "double64"=>Float64, - "string"=>String) - +CHUNK_TYPE = Dict( + 1 => "FileHeader", + 2 => "StreamHeader", + 3 => "Samples", + 4 => "ClockOffset", + 5 => "Boundary", + 6 => "StreamFooter", +) + +DATA_TYPE = Dict( + "int8" => Int8, + "int16" => Int16, + "int32" => Int32, + "int64" => Int64, + "float32" => Float32, + "double64" => Float64, + "string" => String, +) """ read_xdf(filename::AbstractString, sync::Bool=true) @@ -30,7 +32,7 @@ DATA_TYPE = Dict("int8"=>Int8, Read XDF file and optionally sync streams (default true). """ function read_xdf(filename::AbstractString, sync::Bool=true) - streams = Dict{Int, Any}() + streams = Dict{Int,Any}() counter = Dict(zip(keys(CHUNK_TYPE), zeros(Int, length(CHUNK_TYPE)))) # count chunks open(filename) do io @@ -123,9 +125,13 @@ function read_xdf(filename::AbstractString, sync::Bool=true) streams[id]["time"][index[id]] = previous + delta end if streams[id]["dtype"] === String - streams[id]["data"][index[id], :] .= String(read(io, read_varlen_int(io))) + streams[id]["data"][index[id], :] .= String( + read(io, read_varlen_int(io)) + ) else - streams[id]["data"][index[id], :] = reinterpret(dtype, read(io, sizeof(dtype) * nchannels)) + streams[id]["data"][index[id], :] = reinterpret( + dtype, read(io, sizeof(dtype) * nchannels) + ) end index[id] += 1 end @@ -152,7 +158,6 @@ function read_xdf(filename::AbstractString, sync::Bool=true) return streams end - "Read variable-length integer." function read_varlen_int(io::IO) nbytes = read(io, Int8) @@ -165,7 +170,6 @@ function read_varlen_int(io::IO) end end - "Find XML tag and return its content (optionally converted to specified type)." function findtag(xml::AbstractString, tag::AbstractString, type=String::DataType) m = match(Regex("<$tag>(.*)"), xml) @@ -173,7 +177,6 @@ function findtag(xml::AbstractString, tag::AbstractString, type=String::DataType return isnothing(content) || type == String ? content : parse(type, content) end - "Synchronize clock values by their given offsets." function sync_clock(time::Array{Float64,1}, offsets::Array{Float64,2}) x = hcat(ones(size(offsets, 1), 1), offsets[:, 1]) @@ -182,4 +185,4 @@ function sync_clock(time::Array{Float64,1}, offsets::Array{Float64,2}) return time .+ (coefs[1] .+ coefs[2] .* time) end -end \ No newline at end of file +end diff --git a/test/runtests.jl b/test/runtests.jl index b3b3b32..8b10b00 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -14,15 +14,17 @@ using XDF, Downloads, Test @test endswith(streams[0]["header"], "") @test startswith(streams[0]["footer"], "") @test endswith(streams[0]["footer"], "") - @test streams[0]["data"] == [192 255 238 - 12 22 32 - 13 23 33 - 14 24 34 - 15 25 35 - 12 22 32 - 13 23 33 - 14 24 34 - 15 25 35] + @test streams[0]["data"] == [ + 192 255 238 + 12 22 32 + 13 23 33 + 14 24 34 + 15 25 35 + 12 22 32 + 13 23 33 + 14 24 34 + 15 25 35 + ] @test 46202862 in keys(streams) @test streams[46202862]["name"] == "SendDataString" @@ -37,8 +39,8 @@ using XDF, Downloads, Test @test size(streams[46202862]["data"]) == (9, 1) @test startswith(streams[46202862]["data"][1, 1], "") - @test streams[46202862]["data"][2:end, 1] == ["Hello", "World", "from", "LSL", "Hello", - "World", "from", "LSL"] + @test streams[46202862]["data"][2:end, 1] == + ["Hello", "World", "from", "LSL", "Hello", "World", "from", "LSL"] end @testset "XDF file with clock resets" begin