Add requirements keyword to Template
This commit is contained in:
parent
f7b8afd8a7
commit
c245bcd556
@ -144,6 +144,7 @@ Returns an array of generated file/directory names.
|
|||||||
"""
|
"""
|
||||||
function gen_require(pkg_name::AbstractString, template::Template)
|
function gen_require(pkg_name::AbstractString, template::Template)
|
||||||
text = "julia $(version_floor(template.julia_version))\n"
|
text = "julia $(version_floor(template.julia_version))\n"
|
||||||
|
text *= join(template.requirements, "\n")
|
||||||
|
|
||||||
gen_file(joinpath(template.temp_dir, pkg_name, "REQUIRE"), text)
|
gen_file(joinpath(template.temp_dir, pkg_name, "REQUIRE"), text)
|
||||||
return ["REQUIRE"]
|
return ["REQUIRE"]
|
||||||
|
@ -21,10 +21,16 @@ Records common information used to generate a package.
|
|||||||
on the license. Can be supplied by a number, or a string such as "2016 - 2017".
|
on the license. Can be supplied by a number, or a string such as "2016 - 2017".
|
||||||
* `dir::AbstractString=Pkg.dir()`: Directory in which the package will go.
|
* `dir::AbstractString=Pkg.dir()`: Directory in which the package will go.
|
||||||
* `julia_version::VersionNumber=VERSION`: Minimum allowed Julia version.
|
* `julia_version::VersionNumber=VERSION`: Minimum allowed Julia version.
|
||||||
|
* `requirements::Vector{String}=String[]`: Package requirements. If there are duplicate
|
||||||
|
requirements with different versions, i.e. ["PkgTemplates", "PkgTemplates 0.1"],
|
||||||
|
an `ArgumentError` is thrown.
|
||||||
|
Each entry in this array will be copied into the `REQUIRE` file of packages generated
|
||||||
|
with this template.
|
||||||
* `git_config::Dict{String, String}=Dict{String, String}()`: Git configuration options.
|
* `git_config::Dict{String, String}=Dict{String, String}()`: Git configuration options.
|
||||||
* `plugins::Vector{Plugin}`: A list of `Plugin`s that the package will include.
|
* `plugins::Plugin[]`: A list of `Plugin`s that the package will include.
|
||||||
|
|
||||||
**Note**: When you create a `Template`, a temporary directory is created with
|
# Notes
|
||||||
|
When you create a `Template`, a temporary directory is created with
|
||||||
`mktempdir()`. This directory will be removed after you call [`generate`](@ref).
|
`mktempdir()`. This directory will be removed after you call [`generate`](@ref).
|
||||||
Creating multiple packages in succession with the same instance of a template will still
|
Creating multiple packages in succession with the same instance of a template will still
|
||||||
work, but there is a miniscule chance of another process sharing the temporary directory,
|
work, but there is a miniscule chance of another process sharing the temporary directory,
|
||||||
@ -40,6 +46,7 @@ don't belong.
|
|||||||
dir::AbstractString
|
dir::AbstractString
|
||||||
temp_dir::AbstractString
|
temp_dir::AbstractString
|
||||||
julia_version::VersionNumber
|
julia_version::VersionNumber
|
||||||
|
requirements::Vector{AbstractString}
|
||||||
git_config::Dict
|
git_config::Dict
|
||||||
plugins::Dict{DataType, Plugin}
|
plugins::Dict{DataType, Plugin}
|
||||||
|
|
||||||
@ -51,8 +58,9 @@ don't belong.
|
|||||||
years::Union{Int, AbstractString}=string(Dates.year(Dates.today())),
|
years::Union{Int, AbstractString}=string(Dates.year(Dates.today())),
|
||||||
dir::AbstractString=Pkg.dir(),
|
dir::AbstractString=Pkg.dir(),
|
||||||
julia_version::VersionNumber=VERSION,
|
julia_version::VersionNumber=VERSION,
|
||||||
|
requirements::Vector{String}=String[],
|
||||||
git_config::Dict=Dict(),
|
git_config::Dict=Dict(),
|
||||||
plugins::Vector{P}=Vector{Plugin}(),
|
plugins::Vector{P}=Plugin[],
|
||||||
) where P <: Plugin
|
) where P <: Plugin
|
||||||
# If no username was set, look for one in a supplied git config,
|
# If no username was set, look for one in a supplied git config,
|
||||||
# and then in the global git config.
|
# and then in the global git config.
|
||||||
@ -84,6 +92,17 @@ don't belong.
|
|||||||
|
|
||||||
temp_dir = mktempdir()
|
temp_dir = mktempdir()
|
||||||
|
|
||||||
|
requirements_dedup = collect(Set(requirements))
|
||||||
|
diff = length(requirements) - length(requirements_dedup)
|
||||||
|
names = [tokens[1] for tokens in split.(requirements_dedup)]
|
||||||
|
if length(names) > length(Set(names))
|
||||||
|
throw(ArgumentError(
|
||||||
|
"requirements contains duplicate packages with conflicting versions"
|
||||||
|
))
|
||||||
|
elseif diff > 0
|
||||||
|
warn("Removed $(diff) duplicate$(diff == 1 ? "" : "s") from requirements")
|
||||||
|
end
|
||||||
|
|
||||||
plugin_dict = Dict{DataType, Plugin}(typeof(p) => p for p in plugins)
|
plugin_dict = Dict{DataType, Plugin}(typeof(p) => p for p in plugins)
|
||||||
if (length(plugins) != length(plugin_dict))
|
if (length(plugins) != length(plugin_dict))
|
||||||
warn("Plugin list contained duplicates, only the last of each type was kept")
|
warn("Plugin list contained duplicates, only the last of each type was kept")
|
||||||
@ -91,7 +110,7 @@ don't belong.
|
|||||||
|
|
||||||
new(
|
new(
|
||||||
user, host, license, authors, years, dir, temp_dir,
|
user, host, license, authors, years, dir, temp_dir,
|
||||||
julia_version, git_config, plugin_dict
|
julia_version, requirements_dedup, git_config, plugin_dict
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -67,6 +67,18 @@ write(test_file, template_text)
|
|||||||
rm(t.temp_dir; recursive=true)
|
rm(t.temp_dir; recursive=true)
|
||||||
@test t.julia_version == v"0.1.2"
|
@test t.julia_version == v"0.1.2"
|
||||||
|
|
||||||
|
t = Template(; user="invenia", requirements=["$test_pkg 0.1"])
|
||||||
|
rm(t.temp_dir; recursive=true)
|
||||||
|
@test t.requirements == ["$test_pkg 0.1"]
|
||||||
|
@test_warn r".+" t = Template(; user="invenia", requirements=[test_pkg, test_pkg])
|
||||||
|
rm(t.temp_dir; recursive=true)
|
||||||
|
@test t.requirements == [test_pkg]
|
||||||
|
@test_throws ArgumentError t = Template(;
|
||||||
|
user="invenia",
|
||||||
|
requirements=[test_pkg, "$test_pkg 0.1"]
|
||||||
|
)
|
||||||
|
rm(t.temp_dir; force=true, recursive=true)
|
||||||
|
|
||||||
t = Template(; user="invenia", git_config=git_config)
|
t = Template(; user="invenia", git_config=git_config)
|
||||||
rm(t.temp_dir; recursive=true)
|
rm(t.temp_dir; recursive=true)
|
||||||
@test t.git_config == git_config
|
@test t.git_config == git_config
|
||||||
@ -102,10 +114,11 @@ write(test_file, template_text)
|
|||||||
@test_throws ArgumentError t = Template()
|
@test_throws ArgumentError t = Template()
|
||||||
else
|
else
|
||||||
t = Template()
|
t = Template()
|
||||||
rm(t.temp_dir; recursive=true)
|
|
||||||
@test t.user == LibGit2.getconfig("github.username", "")
|
@test t.user == LibGit2.getconfig("github.username", "")
|
||||||
end
|
end
|
||||||
|
rm(t.temp_dir; force=true, recursive=true)
|
||||||
@test_throws ArgumentError t = Template(; user="invenia", license="FakeLicense")
|
@test_throws ArgumentError t = Template(; user="invenia", license="FakeLicense")
|
||||||
|
rm(t.temp_dir; force=true, recursive=true)
|
||||||
end
|
end
|
||||||
|
|
||||||
@testset "Plugin creation" begin
|
@testset "Plugin creation" begin
|
||||||
@ -226,6 +239,7 @@ end
|
|||||||
t = Template(;
|
t = Template(;
|
||||||
user="invenia",
|
user="invenia",
|
||||||
license="MPL",
|
license="MPL",
|
||||||
|
requirements=[test_pkg],
|
||||||
git_config=git_config,
|
git_config=git_config,
|
||||||
plugins=[Coveralls(), TravisCI(), CodeCov(), GitHubPages(), AppVeyor()],
|
plugins=[Coveralls(), TravisCI(), CodeCov(), GitHubPages(), AppVeyor()],
|
||||||
)
|
)
|
||||||
@ -287,7 +301,7 @@ end
|
|||||||
@test gen_require(test_pkg, t) == ["REQUIRE"]
|
@test gen_require(test_pkg, t) == ["REQUIRE"]
|
||||||
@test isfile(joinpath(pkg_dir, "REQUIRE"))
|
@test isfile(joinpath(pkg_dir, "REQUIRE"))
|
||||||
vf = version_floor(t.julia_version)
|
vf = version_floor(t.julia_version)
|
||||||
@test readchomp(joinpath(pkg_dir, "REQUIRE")) == "julia $vf"
|
@test readchomp(joinpath(pkg_dir, "REQUIRE")) == "julia $vf\n$test_pkg"
|
||||||
rm(joinpath(pkg_dir, "REQUIRE"))
|
rm(joinpath(pkg_dir, "REQUIRE"))
|
||||||
|
|
||||||
@test gen_tests(test_pkg, t) == ["test/"]
|
@test gen_tests(test_pkg, t) == ["test/"]
|
||||||
|
Loading…
Reference in New Issue
Block a user