BioJulia / BioFmtSpecimens

A collection of bioinformatics file format specimens to test against
Other
40 stars 10 forks source link

Use Artifacts.toml? #30

Open kescobo opened 4 years ago

kescobo commented 4 years ago

Right now, most julia packages making use of these files do so using something like this (taken from here)

function get_bio_fmt_specimens()
    path = joinpath(dirname(@__FILE__), "BioFmtSpecimens")
    if !isdir(path)
        run(`git clone --depth 1 https://github.com/BioJulia/BioFmtSpecimens.git $(path)`)
    end
end

I was wondering if we should move instead to using Lazy-loading Artifacts.toml files instead.

TransGirlCodes commented 4 years ago

That could be a good idea, there's also FormatSpecimens.jl which is versioned like a package and has a few functions for querying and getting lists of the provided specimens.

CiaranOMara commented 4 years ago

I wrote this helper to bind downloads of individual files or packed/zipped files. This may assist with setting up Artifacts.toml. It generates both of the required hashes.

using Pkg
using Pkg.Artifacts
using Pkg.PlatformEngines #Note: supplies unpack.

using SHA

function bind_download!(artifacts_toml::String, url::String, artifact_name::String=basename(url); lazy::Bool = true, force::Bool = false, packed::Bool=false, platform::Union{Platform,Nothing} = nothing)

   function acquire(path::AbstractString, io::IO)
      download(url, path)

      tarball_hash = open(path) do f
         bytes2hex(sha2_256(f))
      end

      tree_hash = create_artifact() do path_artifact #Note: this will create an artifact that is ready for use.
         if packed === true
            unpack(path, path_artifact)
         else
            cp(path, joinpath(path_artifact, basename(url))) #Note: path is expected for cleanup.
         end
      end

      return tree_hash, tarball_hash
   end

   # Acquire artifact.
   (tree_hash, tarball_hash) = mktemp(acquire)

   bind_artifact!(artifacts_toml, artifact_name, tree_hash, download_info=[(url,tarball_hash)], lazy=lazy, force=force, platform=platform)

   return tree_hash

end
CiaranOMara commented 4 years ago

I've made my artifacts workflow available at ArtifactHelpers.jl.

CiaranOMara commented 4 years ago

ArtifactHelpers has changed quite a bit over the past 8 days and is probably worth another look.