Ditch REQUIRE, add [compat]
This commit is contained in:
parent
40c22b1a53
commit
d4f7c8f3b9
@ -25,7 +25,6 @@ generate_interactive
|
||||
|
||||
```@docs
|
||||
gen_tests
|
||||
gen_require
|
||||
gen_readme
|
||||
gen_gitignore
|
||||
gen_license
|
||||
|
@ -18,6 +18,11 @@ function generate(
|
||||
# Create the directory with some boilerplate inside.
|
||||
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
|
||||
# Initialize the repo.
|
||||
repo = LibGit2.init(pkg_dir)
|
||||
@ -55,7 +60,6 @@ function generate(
|
||||
files = vcat(
|
||||
"src/", "Project.toml", # Created by Pkg.generate.
|
||||
gen_tests(pkg_dir, t),
|
||||
gen_require(pkg_dir, t),
|
||||
gen_readme(pkg_dir, t),
|
||||
gen_license(pkg_dir, t),
|
||||
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/"]
|
||||
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}
|
||||
|
||||
@ -348,3 +335,11 @@ function substitute(
|
||||
end
|
||||
|
||||
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
|
||||
|
@ -1,3 +1,5 @@
|
||||
default_version() = VersionNumber(VERSION.major)
|
||||
|
||||
"""
|
||||
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.
|
||||
* `dir::AbstractString=$(replace(Pkg.devdir(), homedir() => "~"))`: Directory in which the
|
||||
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.
|
||||
* `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.
|
||||
@ -43,7 +45,7 @@ struct Template
|
||||
license::AbstractString="MIT",
|
||||
authors::Union{AbstractString, Vector{<:AbstractString}}="",
|
||||
dir::AbstractString=Pkg.devdir(),
|
||||
julia_version::VersionNumber=VERSION,
|
||||
julia_version::VersionNumber=default_version(),
|
||||
ssh::Bool=false,
|
||||
manifest::Bool=false,
|
||||
plugins::Vector{<:Plugin}=Plugin[],
|
||||
|
@ -5,7 +5,7 @@ using LibGit2
|
||||
using Pkg
|
||||
|
||||
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,
|
||||
DEFAULTS_DIR, Documenter
|
||||
|
||||
|
@ -44,7 +44,7 @@ write(test_file, template_text)
|
||||
@test t.license == "MIT"
|
||||
@test t.authors == LibGit2.getconfig("user.name", "")
|
||||
@test t.dir == default_dir
|
||||
@test t.julia_version == VERSION
|
||||
@test t.julia_version == PkgTemplates.default_version()
|
||||
@test !t.ssh
|
||||
@test !t.manifest
|
||||
@test isempty(t.plugins)
|
||||
@ -107,6 +107,7 @@ end
|
||||
|
||||
@testset "Show methods" begin
|
||||
pkg_dir = replace(default_dir, homedir() => "~")
|
||||
ver = PkgTemplates.version_floor(PkgTemplates.default_version())
|
||||
buf = IOBuffer()
|
||||
t = Template(; user=me)
|
||||
show(buf, t)
|
||||
@ -117,7 +118,7 @@ end
|
||||
→ Host: github.com
|
||||
→ License: MIT ($(LibGit2.getconfig("user.name", "")) $(year(today())))
|
||||
→ Package directory: $pkg_dir
|
||||
→ Minimum Julia version: v$(PkgTemplates.version_floor())
|
||||
→ Minimum Julia version: v$ver
|
||||
→ SSH remote: No
|
||||
→ Commit Manifest.toml: No
|
||||
→ Plugins: None
|
||||
@ -142,7 +143,7 @@ end
|
||||
→ Host: github.com
|
||||
→ License: None
|
||||
→ Package directory: $pkg_dir
|
||||
→ Minimum Julia version: v$(PkgTemplates.version_floor())
|
||||
→ Minimum Julia version: v$ver
|
||||
→ SSH remote: Yes
|
||||
→ Commit Manifest.toml: Yes
|
||||
→ Plugins:
|
||||
@ -222,13 +223,6 @@ end
|
||||
@test occursin(t.authors, 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 gen_tests(pkg_dir, t) == ["test/"]
|
||||
@test isfile(joinpath(pkg_dir, "Project.toml"))
|
||||
@ -255,7 +249,6 @@ end
|
||||
# Check that the expected files all exist.
|
||||
@test isfile(joinpath(pkg_dir, "LICENSE"))
|
||||
@test isfile(joinpath(pkg_dir, "README.md"))
|
||||
@test isfile(joinpath(pkg_dir, "REQUIRE"))
|
||||
@test isfile(joinpath(pkg_dir, ".gitignore"))
|
||||
@test isdir(joinpath(pkg_dir, "src"))
|
||||
@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 branches == ["master"]
|
||||
@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)
|
||||
|
||||
# Check that the remote is an SSH URL when we want it to be.
|
||||
|
Loading…
Reference in New Issue
Block a user