Add option to create test/Project.toml (#95)
This commit is contained in:
parent
7a2a43f3f4
commit
f6272e110f
@ -40,4 +40,15 @@ include("generate.jl")
|
|||||||
include("plugin.jl")
|
include("plugin.jl")
|
||||||
include("interactive.jl")
|
include("interactive.jl")
|
||||||
|
|
||||||
|
# Run some function with a project activated at the given path.
|
||||||
|
function with_project(f::Function, path::AbstractString)
|
||||||
|
proj = current_project()
|
||||||
|
try
|
||||||
|
Pkg.activate(path)
|
||||||
|
f()
|
||||||
|
finally
|
||||||
|
proj === nothing ? Pkg.activate() : Pkg.activate(proj)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -57,6 +57,13 @@ function (t::Template)(pkg::AbstractString)
|
|||||||
Pkg.develop(PackageSpec(; path=pkg_dir))
|
Pkg.develop(PackageSpec(; path=pkg_dir))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
manifest = joinpath(pkg_dir, "Manifest.toml")
|
||||||
|
if t.manifest && !isfile(manifest)
|
||||||
|
# If the manifest is going to be committed, make sure it's generated.
|
||||||
|
touch(manifest)
|
||||||
|
with_project(Pkg.update, pkg_dir)
|
||||||
|
end
|
||||||
|
|
||||||
@info "New package is at $pkg_dir"
|
@info "New package is at $pkg_dir"
|
||||||
catch
|
catch
|
||||||
rm(pkg_dir; recursive=true, force=true)
|
rm(pkg_dir; recursive=true, force=true)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
const TEST_UUID = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
const TEST_UUID = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
||||||
|
const TEST_DEP = PackageSpec(; name="Test", uuid=TEST_UUID)
|
||||||
const LICENSE_DIR = normpath(joinpath(@__DIR__, "..", "..", "licenses"))
|
const LICENSE_DIR = normpath(joinpath(@__DIR__, "..", "..", "licenses"))
|
||||||
const LICENSES = Dict(
|
const LICENSES = Dict(
|
||||||
"MIT" => "MIT \"Expat\" License",
|
"MIT" => "MIT \"Expat\" License",
|
||||||
@ -143,15 +144,21 @@ function gen_plugin(p::Gitignore, t::Template, pkg_dir::AbstractString)
|
|||||||
end
|
end
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Tests(; file="$(contractuser(default_file("runtests.jl")))" -> Tests
|
Tests(; file="$(contractuser(default_file("runtests.jl")))", project=false)
|
||||||
|
|
||||||
Sets up testing for packages.
|
Sets up testing for packages.
|
||||||
|
|
||||||
## Keyword Arguments
|
## Keyword Arguments
|
||||||
- `file::AbstractString`: Template file for the `runtests.jl`.
|
- `file::AbstractString`: Template file for the `runtests.jl`.
|
||||||
|
- `project::Bool`: Whether or not to create a new project for tests (`test/Project.toml`).
|
||||||
|
See [here](https://julialang.github.io/Pkg.jl/v1/creating-packages/#Test-specific-dependencies-in-Julia-1.2-and-above-1) for more details.
|
||||||
|
|
||||||
|
!!! note
|
||||||
|
Managing test dependencies with `test/Project.toml` is only supported in Julia 1.2 and later.
|
||||||
"""
|
"""
|
||||||
@with_kw_noshow struct Tests <: BasicPlugin
|
@with_kw_noshow struct Tests <: BasicPlugin
|
||||||
file::String = default_file("runtests.jl")
|
file::String = default_file("runtests.jl")
|
||||||
|
project::Bool = false
|
||||||
end
|
end
|
||||||
|
|
||||||
source(p::Tests) = p.file
|
source(p::Tests) = p.file
|
||||||
@ -162,21 +169,27 @@ function gen_plugin(p::Tests, t::Template, pkg_dir::AbstractString)
|
|||||||
# Do the normal BasicPlugin behaviour to create the test script.
|
# Do the normal BasicPlugin behaviour to create the test script.
|
||||||
invoke(gen_plugin, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir)
|
invoke(gen_plugin, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir)
|
||||||
|
|
||||||
# Add Test as a test-only dependency.
|
# Then set up the test depdendency in the chosen way.
|
||||||
|
f = p.project ? make_test_project : add_test_dependency
|
||||||
|
f(pkg_dir)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Create a new test project.
|
||||||
|
function make_test_project(pkg_dir::AbstractString)
|
||||||
|
with_project(() -> Pkg.add(TEST_DEP), joinpath(pkg_dir, "test"))
|
||||||
|
end
|
||||||
|
|
||||||
|
# Add Test as a test-only dependency.
|
||||||
|
function add_test_dependency(pkg_dir::AbstractString)
|
||||||
|
# Add the dependency manually since there's no programmatic way to add to [extras].
|
||||||
path = joinpath(pkg_dir, "Project.toml")
|
path = joinpath(pkg_dir, "Project.toml")
|
||||||
toml = TOML.parsefile(path)
|
toml = TOML.parsefile(path)
|
||||||
get!(toml, "extras", Dict())["Test"] = TEST_UUID
|
get!(toml, "extras", Dict())["Test"] = TEST_UUID
|
||||||
get!(toml, "targets", Dict())["test"] = ["Test"]
|
get!(toml, "targets", Dict())["test"] = ["Test"]
|
||||||
open(io -> TOML.print(io, toml), path, "w")
|
open(io -> TOML.print(io, toml), path, "w")
|
||||||
|
|
||||||
# Generate the manifest.
|
# Generate the manifest by updating the project.
|
||||||
# This also ensures that keys in Project.toml are sorted properly.
|
# This also ensures that keys in Project.toml are sorted properly.
|
||||||
touch(joinpath(pkg_dir, "Manifest.toml")) # File must exist to be modified by Pkg.
|
touch(joinpath(pkg_dir, "Manifest.toml")) # File must exist to be modified by Pkg.
|
||||||
proj = current_project()
|
with_project(Pkg.update, pkg_dir)
|
||||||
try
|
|
||||||
Pkg.activate(pkg_dir)
|
|
||||||
Pkg.update()
|
|
||||||
finally
|
|
||||||
proj === nothing ? Pkg.activate() : Pkg.activate(proj)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
const DOCUMENTER_UUID = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
|
const DOCUMENTER_DEP = PackageSpec(;
|
||||||
|
name="Documenter",
|
||||||
|
uuid="e30172f5-a6a5-5a46-863b-614d45cd2de4",
|
||||||
|
)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Documenter{T<:Union{TravisCI, GitLabCI, Nothing}}(;
|
Documenter{T<:Union{TravisCI, GitLabCI, Nothing}}(;
|
||||||
@ -98,13 +101,7 @@ function gen_plugin(p::Documenter, t::Template, pkg_dir::AbstractString)
|
|||||||
foreach(a -> cp(a, joinpath(assets_dir, basename(a))), p.assets)
|
foreach(a -> cp(a, joinpath(assets_dir, basename(a))), p.assets)
|
||||||
|
|
||||||
# Create the documentation project.
|
# Create the documentation project.
|
||||||
proj = current_project()
|
with_project(() -> Pkg.add(DOCUMENTER_DEP), docs_dir)
|
||||||
try
|
|
||||||
Pkg.activate(docs_dir)
|
|
||||||
Pkg.add(PackageSpec(; name="Documenter", uuid=DOCUMENTER_UUID))
|
|
||||||
finally
|
|
||||||
proj === nothing ? Pkg.activate() : Pkg.activate(proj)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
github_pages_url(t::Template, pkg::AbstractString) = "https://$(t.user).github.io/$pkg.jl"
|
github_pages_url(t::Template, pkg::AbstractString) = "https://$(t.user).github.io/$pkg.jl"
|
||||||
|
@ -89,13 +89,21 @@ function Template(::Val{false}; kwargs...)
|
|||||||
# which means that default plugins get replaced by user values.
|
# which means that default plugins get replaced by user values.
|
||||||
plugins = Dict(typeof(p) => p for p in enabled)
|
plugins = Dict(typeof(p) => p for p in enabled)
|
||||||
|
|
||||||
|
# TODO: It might be nice to offer some kind of warn_incompatible function
|
||||||
|
# to be optionally implented by plugins instead of hardcoding this case here.
|
||||||
|
julia = getkw(kwargs, :julia_version)
|
||||||
|
julia < v"1.2" && haskey(plugins, Tests) && plugins[Tests].project && @warn string(
|
||||||
|
"The Tests plugin is set to create a project (supported in Julia 1.2 and later)",
|
||||||
|
"but a Julia version older than 1.2 is supported.",
|
||||||
|
)
|
||||||
|
|
||||||
return Template(
|
return Template(
|
||||||
authors,
|
authors,
|
||||||
getkw(kwargs, :develop),
|
getkw(kwargs, :develop),
|
||||||
dir,
|
dir,
|
||||||
getkw(kwargs, :git),
|
getkw(kwargs, :git),
|
||||||
host,
|
host,
|
||||||
getkw(kwargs, :julia_version),
|
julia,
|
||||||
getkw(kwargs, :manifest),
|
getkw(kwargs, :manifest),
|
||||||
plugins,
|
plugins,
|
||||||
getkw(kwargs, :ssh),
|
getkw(kwargs, :ssh),
|
||||||
|
4
test/fixtures/AllPlugins/README.md.txt
vendored
4
test/fixtures/AllPlugins/README.md.txt
vendored
@ -7,7 +7,3 @@
|
|||||||
[](https://cirrus-ci.com/github/tester/AllPlugins.jl)
|
[](https://cirrus-ci.com/github/tester/AllPlugins.jl)
|
||||||
[](https://codecov.io/gh//.jl)
|
[](https://codecov.io/gh//.jl)
|
||||||
[](https://coveralls.io/github//.jl?branch=master)
|
[](https://coveralls.io/github//.jl?branch=master)
|
||||||
|
|
||||||
## Citing
|
|
||||||
|
|
||||||
See [`CITATION.bib`](CITATION.bib) for the relevant reference(s).
|
|
||||||
|
@ -37,6 +37,7 @@ const LICENSE_DIR = contractuser(PT.LICENSE_DIR)
|
|||||||
inline_badges: false
|
inline_badges: false
|
||||||
Tests:
|
Tests:
|
||||||
file: "$DEFAULTS_DIR/runtests.jl"
|
file: "$DEFAULTS_DIR/runtests.jl"
|
||||||
|
project: false
|
||||||
"""
|
"""
|
||||||
@test sprint(show, MIME("text/plain"), tpl(; authors=USER)) == rstrip(expected)
|
@test sprint(show, MIME("text/plain"), tpl(; authors=USER)) == rstrip(expected)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user