Ditch REQUIRE, add [compat]

This commit is contained in:
Chris de Graaf 2019-05-14 15:35:34 -05:00
parent 40c22b1a53
commit d4f7c8f3b9
5 changed files with 26 additions and 33 deletions

View File

@ -25,7 +25,6 @@ generate_interactive
```@docs ```@docs
gen_tests gen_tests
gen_require
gen_readme gen_readme
gen_gitignore gen_gitignore
gen_license gen_license

View File

@ -18,6 +18,11 @@ function generate(
# Create the directory with some boilerplate inside. # Create the directory with some boilerplate inside.
Pkg.generate(pkg_dir) Pkg.generate(pkg_dir)
# Add a [compat] section for Julia.
open(joinpath(pkg_dir, "Project.toml"), "a") do io
println(io, "\n[compat]\njulia = $(repr_version(t.julia_version))")
end
if git if git
# Initialize the repo. # Initialize the repo.
repo = LibGit2.init(pkg_dir) repo = LibGit2.init(pkg_dir)
@ -55,7 +60,6 @@ function generate(
files = vcat( files = vcat(
"src/", "Project.toml", # Created by Pkg.generate. "src/", "Project.toml", # Created by Pkg.generate.
gen_tests(pkg_dir, t), gen_tests(pkg_dir, t),
gen_require(pkg_dir, t),
gen_readme(pkg_dir, t), gen_readme(pkg_dir, t),
gen_license(pkg_dir, t), gen_license(pkg_dir, t),
vcat(map(p -> gen_plugin(p, t, pkg), values(t.plugins))...), vcat(map(p -> gen_plugin(p, t, pkg), values(t.plugins))...),
@ -161,23 +165,6 @@ function gen_tests(pkg_dir::AbstractString, t::Template)
return ["test/"] return ["test/"]
end end
"""
gen_require(pkg_dir::AbstractString, t::Template) -> Vector{String}
Create the `REQUIRE` file in `pkg_dir`.
# Arguments
* `pkg_dir::AbstractString`: The directory in which the files will be generated.
* `t::Template`: The template whose REQUIRE we are generating.
Returns an array of generated file/directory names.
"""
function gen_require(pkg_dir::AbstractString, t::Template)
text = "julia $(version_floor(t.julia_version))\n"
gen_file(joinpath(pkg_dir, "REQUIRE"), text)
return ["REQUIRE"]
end
""" """
gen_readme(pkg_dir::AbstractString, t::Template) -> Vector{String} gen_readme(pkg_dir::AbstractString, t::Template) -> Vector{String}
@ -348,3 +335,11 @@ function substitute(
end end
splitjl(pkg::AbstractString) = endswith(pkg, ".jl") ? pkg[1:end-3] : pkg splitjl(pkg::AbstractString) = endswith(pkg, ".jl") ? pkg[1:end-3] : pkg
# Format a version in a way suitable for a Project.toml file.
function repr_version(v::VersionNumber)
s = string(v.major)
v.minor == 0 || (s *= ".$(v.minor)")
v.patch == 0 || (s *= ".$(v.patch)")
return repr(s)
end

View File

@ -1,3 +1,5 @@
default_version() = VersionNumber(VERSION.major)
""" """
Template(; kwargs...) -> Template Template(; kwargs...) -> Template
@ -21,7 +23,7 @@ create a template, you can use [`interactive_template`](@ref) instead.
it will take the value of of the global git config's value if it is left unset. it will take the value of of the global git config's value if it is left unset.
* `dir::AbstractString=$(replace(Pkg.devdir(), homedir() => "~"))`: Directory in which the * `dir::AbstractString=$(replace(Pkg.devdir(), homedir() => "~"))`: Directory in which the
package will go. Relative paths are converted to absolute ones at template creation time. package will go. Relative paths are converted to absolute ones at template creation time.
* `julia_version::VersionNumber=$VERSION`: Minimum allowed Julia version. * `julia_version::VersionNumber=$(default_version())`: Minimum allowed Julia version.
* `ssh::Bool=false`: Whether or not to use SSH for the git remote. If `false` HTTPS will be used. * `ssh::Bool=false`: Whether or not to use SSH for the git remote. If `false` HTTPS will be used.
* `manifest::Bool=false`: Whether or not to commit the `Manifest.toml`. * `manifest::Bool=false`: Whether or not to commit the `Manifest.toml`.
* `plugins::Vector{<:Plugin}=Plugin[]`: A list of `Plugin`s that the package will include. * `plugins::Vector{<:Plugin}=Plugin[]`: A list of `Plugin`s that the package will include.
@ -43,7 +45,7 @@ struct Template
license::AbstractString="MIT", license::AbstractString="MIT",
authors::Union{AbstractString, Vector{<:AbstractString}}="", authors::Union{AbstractString, Vector{<:AbstractString}}="",
dir::AbstractString=Pkg.devdir(), dir::AbstractString=Pkg.devdir(),
julia_version::VersionNumber=VERSION, julia_version::VersionNumber=default_version(),
ssh::Bool=false, ssh::Bool=false,
manifest::Bool=false, manifest::Bool=false,
plugins::Vector{<:Plugin}=Plugin[], plugins::Vector{<:Plugin}=Plugin[],

View File

@ -5,7 +5,7 @@ using LibGit2
using Pkg using Pkg
import PkgTemplates: badges, version_floor, substitute, read_license, gen_file, gen_readme, import PkgTemplates: badges, version_floor, substitute, read_license, gen_file, gen_readme,
gen_tests, gen_license, gen_require, gen_gitignore, gen_plugin, show_license, LICENSES, gen_tests, gen_license, gen_gitignore, gen_plugin, show_license, LICENSES,
LICENSE_DIR, Plugin, GenericPlugin, CustomPlugin, Badge, format, interactive, LICENSE_DIR, Plugin, GenericPlugin, CustomPlugin, Badge, format, interactive,
DEFAULTS_DIR, Documenter DEFAULTS_DIR, Documenter

View File

@ -44,7 +44,7 @@ write(test_file, template_text)
@test t.license == "MIT" @test t.license == "MIT"
@test t.authors == LibGit2.getconfig("user.name", "") @test t.authors == LibGit2.getconfig("user.name", "")
@test t.dir == default_dir @test t.dir == default_dir
@test t.julia_version == VERSION @test t.julia_version == PkgTemplates.default_version()
@test !t.ssh @test !t.ssh
@test !t.manifest @test !t.manifest
@test isempty(t.plugins) @test isempty(t.plugins)
@ -107,6 +107,7 @@ end
@testset "Show methods" begin @testset "Show methods" begin
pkg_dir = replace(default_dir, homedir() => "~") pkg_dir = replace(default_dir, homedir() => "~")
ver = PkgTemplates.version_floor(PkgTemplates.default_version())
buf = IOBuffer() buf = IOBuffer()
t = Template(; user=me) t = Template(; user=me)
show(buf, t) show(buf, t)
@ -117,7 +118,7 @@ end
Host: github.com Host: github.com
License: MIT ($(LibGit2.getconfig("user.name", "")) $(year(today()))) License: MIT ($(LibGit2.getconfig("user.name", "")) $(year(today())))
Package directory: $pkg_dir Package directory: $pkg_dir
Minimum Julia version: v$(PkgTemplates.version_floor()) Minimum Julia version: v$ver
SSH remote: No SSH remote: No
Commit Manifest.toml: No Commit Manifest.toml: No
Plugins: None Plugins: None
@ -142,7 +143,7 @@ end
Host: github.com Host: github.com
License: None License: None
Package directory: $pkg_dir Package directory: $pkg_dir
Minimum Julia version: v$(PkgTemplates.version_floor()) Minimum Julia version: v$ver
SSH remote: Yes SSH remote: Yes
Commit Manifest.toml: Yes Commit Manifest.toml: Yes
Plugins: Plugins:
@ -222,13 +223,6 @@ end
@test occursin(t.authors, license) @test occursin(t.authors, license)
@test occursin(read_license(t.license), license) @test occursin(read_license(t.license), license)
# Test the REQUIRE generation.
@test gen_require(pkg_dir, t) == ["REQUIRE"]
@test isfile(joinpath(pkg_dir, "REQUIRE"))
vf = version_floor(t.julia_version)
@test readchomp(joinpath(pkg_dir, "REQUIRE")) == "julia $vf"
rm(joinpath(pkg_dir, "REQUIRE"))
# Test the test generation. # Test the test generation.
@test gen_tests(pkg_dir, t) == ["test/"] @test gen_tests(pkg_dir, t) == ["test/"]
@test isfile(joinpath(pkg_dir, "Project.toml")) @test isfile(joinpath(pkg_dir, "Project.toml"))
@ -255,7 +249,6 @@ end
# Check that the expected files all exist. # Check that the expected files all exist.
@test isfile(joinpath(pkg_dir, "LICENSE")) @test isfile(joinpath(pkg_dir, "LICENSE"))
@test isfile(joinpath(pkg_dir, "README.md")) @test isfile(joinpath(pkg_dir, "README.md"))
@test isfile(joinpath(pkg_dir, "REQUIRE"))
@test isfile(joinpath(pkg_dir, ".gitignore")) @test isfile(joinpath(pkg_dir, ".gitignore"))
@test isdir(joinpath(pkg_dir, "src")) @test isdir(joinpath(pkg_dir, "src"))
@test isfile(joinpath(pkg_dir, "src", "$test_pkg.jl")) @test isfile(joinpath(pkg_dir, "src", "$test_pkg.jl"))
@ -272,6 +265,10 @@ end
@test LibGit2.url(remote) == "https://github.com/$me/$test_pkg.jl" @test LibGit2.url(remote) == "https://github.com/$me/$test_pkg.jl"
@test branches == ["master"] @test branches == ["master"]
@test !LibGit2.isdirty(repo) @test !LibGit2.isdirty(repo)
# Check for the [compat] section.
project = read(joinpath(pkg_dir, "Project.toml"), String)
@test occursin("[compat]", project)
@test occursin("julia = " * PkgTemplates.repr_version(t.julia_version), project)
rm(pkg_dir; recursive=true) rm(pkg_dir; recursive=true)
# Check that the remote is an SSH URL when we want it to be. # Check that the remote is an SSH URL when we want it to be.