Skip to content

Instantly share code, notes, and snippets.

@ExpandingMan
Created Jun 2, 2018
Embed
What would you like to do?
a quick and dirty tool for generating `Project.toml`
module GenProject
using Pkg
export genproject
requirefile(dir::AbstractString) = joinpath(dir, "REQUIRE")
function openrequire(dir::AbstractString)
fname = requirefile(dir)
isfile(fname) || throw(ErrorException("Directory $dir lacks a REQUIRE file"))
open(fname)
end
function deplist(dir::AbstractString; use_latest::Bool=true)
f = openrequire(dir)
pkgs = Any[]
for line eachline(f)
pkg = split(line)
first(pkg) == "julia" && continue
if length(pkg) > 1 && !use_latest
push!(pkgs, Pkg.PackageSpec(first(pkg), VersionNumber(last(pkg))))
else
push!(pkgs, Pkg.PackageSpec(first(pkg)))
end
end
pkgs
end
adddeps(dps::AbstractVector) = foreach(Pkg.add, dps)
adddeps(dir::AbstractString; use_latest::Bool=true) = adddeps(deplist(dir, use_latest=use_latest))
function genproject(dir::AbstractString; use_latest::Bool=true)
Pkg.init(Pkg.Context(), dir)
adddeps(dir, use_latest=use_latest)
end
genproject(;use_latest::Bool=true) = genproject(pwd(), use_latest=use_latest)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment