Add compat with Julia 1.4

This commit is contained in:
Chris de Graaf 2019-09-26 13:22:20 +07:00
parent 5aa0a87c35
commit 0fcbaa83bf
No known key found for this signature in database
GPG Key ID: 150FFDD9B0073C7B
3 changed files with 18 additions and 9 deletions

View File

@ -80,12 +80,8 @@ function posthook(p::Git, ::Template, pkg_dir::AbstractString)
LibGit2.with(GitRepo(pkg_dir)) do repo
LibGit2.add!(repo, ".")
msg = "Files generated by PkgTemplates"
# TODO: Newer versions of Julia will not have Pkg.installed.
installed = Pkg.installed()
if haskey(installed, "PkgTemplates")
ver = string(installed["PkgTemplates"])
msg *= "\n\nPkgTemplates version: $ver"
end
v = version_of("PkgTemplates")
v === nothing || (msg *= "\n\nPkgTemplates version: $v")
commit(p, repo, pkg_dir, msg)
end
end
@ -99,3 +95,14 @@ function commit(p::Git, repo::GitRepo, pkg_dir::AbstractString, msg::AbstractStr
end
needs_username(::Git) = true
if isdefined(Pkg, :dependencies)
function version_of(pkg::AbstractString)
for p in values(Pkg.dependencies())
p.name == pkg && return p.version
end
return nothing
end
else
version_of(pkg::AbstractString) = get(Pkg.installed(), pkg, nothing)
end

View File

@ -38,7 +38,7 @@
@testset "Adds version to commit message" begin
# We're careful to avoid a Pkg.update as it triggers Cassette#130.
t = tpl(; disable_defaults=[Tests], plugins=[Git()])
mock(Pkg.installed => () -> Dict("PkgTemplates" => v"1.2.3")) do _pi
mock(PT.version_of => _p -> v"1.2.3") do _i
with_pkg(t) do pkg
pkg_dir = joinpath(t.dir, pkg)
LibGit2.with(GitRepo(pkg_dir)) do repo

View File

@ -6,7 +6,7 @@ using Random: Random
using Test: @test, @testset, @test_throws
using ReferenceTests: @test_reference
using SimpleMock: Mock, mock
using SimpleMock: mock
using Suppressor: @suppress
using PkgTemplates
@ -30,7 +30,9 @@ function with_pkg(f::Function, t::Template, pkg::AbstractString=pkgname())
try
f(pkg)
finally
haskey(Pkg.installed(), pkg) && @suppress Pkg.rm(pkg)
# On 1.4, this sometimes won't work, but the error is that the package isn't installed.
# We're going to delete the package directory anyways, so just ignore any errors.
PT.version_of(pkg) === nothing || try @suppress Pkg.rm(pkg) catch; end
rm(joinpath(t.dir, pkg); recursive=true, force=true)
end
end