-
-
Save ExpandingMan/41d1b3a07987a5cccc1cfab44e3322ab to your computer and use it in GitHub Desktop.
a quick and dirty tool for generating `Project.toml`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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