Skip to content

Transition test file download from SVN to Base.download? #90

@tclements

Description

@tclements

I am not able to test SeisIO on my work computer because I don't have permission to install svn. A solution to this would be to change the tests to use Base.download. Downloading using Base.download should work on all systems since Julia v1.6 -> https://julialang.org/blog/2021/03/julia-1.6-highlights/#downloads_networkingoptions. Here is a simple, albeit hackish, workaround for downloading the test files without svn:

using HTTP 
using JSON 
using SeisIO 

function get_sample_files()
    sampledir = dirname(pathof(SeisIO))*"/../test/SampleFiles"
    isdir(sampledir) && return nothing 

    # create directory stucture 
    mkpath(sampledir)

    # get test data file structure using Github API  
    r = HTTP.get("https://api.github.com/repos/jpjones76/SeisIO-TestData/git/trees/main?recursive=1",require_ssl_verification = false)
    j = JSON.parse(String(r.body))
    files = [j["tree"][ii]["path"] for ii in 1:length(j["tree"])]
    samplefiles = [file for file in files if occursin("SampleFiles/",file) && (occursin(".", file) || occursin("SampleFiles/UW/", file) || occursin("SampleFiles/Bottle/", file))]
    infiles = [joinpath("https://raw.githubusercontent.com/jpjones76/SeisIO-TestData/main/",file) for file in samplefiles]
    outfiles = [joinpath(dirname(sampledir),file) for file in samplefiles]

    # create directories 
    sampledirs = unique([dirname(file) for file in outfiles])
    mkpath.(sampledirs)

    # download 
    for ii in 1:length(infiles)
        download(infiles[ii],outfiles[ii])
    end
    return nothing 
end

This introduces a new JSON dependency but that is pretty lightweight. We could then change https://github.com/jpjones76/SeisIO.jl/blob/main/test/runtests.jl#L7-#L10 to:

cd(dirname(pathof(SeisIO))*"/../test")
if isdir("SampleFiles") == false
    get_sample_files()
end

The other option would be to use DataDeps.jl. Using DataDeps.jl would involve a little bit more work but I like that solution because test data would be stored once in ~/.julia/datadeps/ rather than in the folder for each version of SeisIO (~/.julia/packages/SeisIO/version/..).

I'm happy to submit a PR on this if it seems helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions