Hi! I create my own plugin:
struct Dependencies <: Plugin
deps::Vector{AbstractString} = []
end
dependencies(d::Dependencies) = d.deps
function posthook(d::Dependencies, t::Template, pkg_dir::AbstractString)
Pkg.activate(pkg_dir)
Pkg.add(dependencies(d))
Pkg.activate()
end
That should add deps to created toml. It works if I run the code of adding package externally, but when I add plugin as plugins=[Dependencies([“P”])] it seems like PkgTemplate does not execute it at all. I also wrote a test that also shows that the plugin is not working(maybe is not executed at all )
using TemplatePlugins: Dependencies, DefaultETLService
using Test
using Test
using Pkg: Pkg, PackageSpec, TOML
using PkgTemplates
using Suppressor: @suppress
using Random: Random, randstring
const USER = "tester"
Random.seed!(12)
tpl(; kwargs...) = Template(; user=USER, kwargs...)
pkgname() = titlecase(randstring('A':'Z', 16))
function with_pkg(f::Function, t::Template, pkg::AbstractString=pkgname())
@suppress t(pkg)
try
f(pkg)
finally
PkgTemplates.version_of(pkg) === nothing || try @suppress Pkg.rm(pkg) catch; end
rm(joinpath(t.dir, pkg); recursive=true, force=true)
end
end
@testset "Dependencies plugin test" begin
t = tpl(; plugins=[Dependencies(["PkgTemplates", "GitlabAPI"])])
with_pkg(t) do pkg
pkg_dir = joinpath(t.dir, pkg)
toml = String(read(joinpath(pkg_dir, "Project.toml")))
println(toml)
@test contains(toml, "PkgTemplates")
@test contains(toml, "GitlabAPI")
end
t = tpl(; plugins=[Dependencies([])])
with_pkg(t) do pkg
pkg_dir = joinpath(t.dir, pkg)
toml = String(read(joinpath(pkg_dir, "Project.toml")))
@test !contains(toml, "deps")
end
end
end