From 3866caffc91e52a4770e12a8caba0482291c2f87 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Fri, 11 Aug 2017 22:36:29 -0500 Subject: [PATCH] Allow disabling of config file generation --- defaults/Dockerfile | 2 +- src/generate.jl | 19 ++++----- src/plugins/appveyor.jl | 41 +++++++++++-------- src/plugins/codecov.jl | 29 +++++++++----- src/plugins/docker.jl | 80 +++++++++++++++++++++----------------- src/plugins/githubpages.jl | 21 +++++----- src/plugins/travis.jl | 33 ++++++++++------ 7 files changed, 129 insertions(+), 96 deletions(-) diff --git a/defaults/Dockerfile b/defaults/Dockerfile index 2a47d7f..e9f7257 100644 --- a/defaults/Dockerfile +++ b/defaults/Dockerfile @@ -56,7 +56,7 @@ RUN REF=$(cat .git/HEAD | cut -d' ' -f2) && \ # - BinDeps.jl runtime requirements: sudo, make, gcc, unzip, bzip2, xz, unzip # # BinDeps runtime requirements are only used while other packages are being built which -# makes them safe to only be temporarily installed. When installing system libraries +# makes them safe to only be temporarily installed. When installing system libraries # BinDeps always uses "sudo" to install system packages and waits for user confirmation # before installing a package. We'll both install "sudo" and always supply the `-y` flag # to ensure that BinDeps installations work automatically. A good test to make sure diff --git a/src/generate.jl b/src/generate.jl index 763f0ba..6faec5b 100644 --- a/src/generate.jl +++ b/src/generate.jl @@ -77,7 +77,7 @@ Generate a README with badges for each enabled plugin. * `pkg_dir::AbstractString`: The package directory. * `t::Template`: The template whose README we are generating. -Returns the name of the generated file "README.md" for git-add. +Returns the name of the generated file. """ function gen_readme(pkg_dir::AbstractString, t::Template) pkg_name = basename(pkg_dir) @@ -104,7 +104,7 @@ Generate a .gitignore from the list of enabled `plugins`. * `pkg_dir::AbstractString`: The package directory. * `plugins::Dict{DataType, Plugin}`: The enabled plugins. -Returns the name of the generated file ".gitignore" for git-add. +Returns the name of the generated file. """ function gen_gitignore(pkg_dir::AbstractString, plugins::Dict{DataType,Plugin}) text = ".DS_Store\n" @@ -119,7 +119,7 @@ function gen_gitignore(pkg_dir::AbstractString, plugins::Dict{DataType,Plugin}) end """ - gen_license(pkg_dir, license, authors, years) -> String + gen_license(pkg_dir, license, authors, years) -> Union{String, Void} Creates a license file for the package. @@ -129,7 +129,8 @@ Creates a license file for the package. * `authors::AbstractString`: Author, or comma-delimited list of authors, of the package. * `years::AbstractString`: Copyright year or range of copyright years. -Returns the name of the generated file "LICENSE" for git-add. +Returns the name of the generated file, or `nothing` in the case that +no license is generated. """ function gen_license( pkg_dir::AbstractString, @@ -156,7 +157,7 @@ Creates the module entrypoint ("src/\$pkg_name.jl") in `pkg_dir`. # Arguments * `pkg_dir::AbstractString`: The package directory. -Returns the name of the generated directory "src/" for git-add. +Returns the name of the generated directory. """ function gen_entrypoint(pkg_dir::AbstractString) pkg_name = basename(pkg_dir) @@ -181,7 +182,7 @@ Create the requirements file in the package directory. * `pkg_dir::AbstractString`: The package directory. * `julia_version::VersionNumber`: The minimum Julia version to support. -Returns the name of the generated file "REQUIRE" for git-add. +Returns the name of the generated file. """ function gen_require(pkg_dir::AbstractString, julia_version::VersionNumber) text = "julia $(version_floor(julia_version))\n" @@ -198,7 +199,7 @@ Creates the test file "test/runtests.jl" in the package directory. # Arguments * `pkg_dir::AbstractString`: The package directory. -Returns the name of the generated directory "test/" for git-add. +Returns the name of the generated directory. """ function gen_tests(pkg_dir::AbstractString) text = """ @@ -256,7 +257,7 @@ end template::AbstractString, pkg_name::AbstractString, pkg_template::Template; - view::Dict{String, String}=Dict{String, String}(), + view::Dict{String, Any}=Dict{String, Any}(), ) Replace placeholders in `template`. The input string is not modified. @@ -265,7 +266,7 @@ Replace placeholders in `template`. The input string is not modified. * `template::AbstractString`: Template string to make replacements in. * `pkg_name::AbstractString`: Name of the package being created. * `pkg_template::Template`: The package template in use. -* `view::Dict{String, String}=Dict{String, String}()`: Additional values to be substituted. +* `view::Dict{String, Any}=Dict{String, Any}()`: Additional values to be substituted. Returns the text with substitutions applied. """ diff --git a/src/plugins/appveyor.jl b/src/plugins/appveyor.jl index c053bb7..29ead50 100644 --- a/src/plugins/appveyor.jl +++ b/src/plugins/appveyor.jl @@ -1,22 +1,24 @@ """ - AppVeyor(;config_file::AbstractString="") -> AppVeyor + AppVeyor(; config_file::AbstractString="") -> AppVeyor -Add AppVeyor to a template's plugins to add AppVeyor support. AppVeyor is compatible with -any remote. +Add AppVeyor to a template's plugins to add AppVeyor CI support. -# Arguments: -* `config_file::AbstractString`: Absolute or relative path to a custom `.codecov.yml`. +# Keyword Arguments +* `config_file::Union{AbstractString, Void}`: Path to a custom `.appveyor.yml`. + If `nothing` is supplied, then no file will be generated. """ - struct AppVeyor <: Plugin gitignore_files::Vector{AbstractString} - config_file::AbstractString + config_file::Union{AbstractString, Void} - function AppVeyor(;config_file::AbstractString="") - config_file = isempty(config_file) ? - joinpath(DEFAULTS_DIR, "appveyor.yml") : config_file - if !isfile(abspath(config_file)) - throw(ArgumentError("File $config_file does not exist")) + function AppVeyor(; config_file::Union{AbstractString, Void}="") + if config_file != nothing + if isempty(config_file) + config_file = joinpath(DEFAULTS_DIR, "appveyor.yml") + end + if !isfile(abspath(config_file)) + throw(ArgumentError("File $config_file does not exist")) + end end new(AbstractString[], config_file) end @@ -28,14 +30,16 @@ function ==(a::AppVeyor, b::AppVeyor) end """ - badges(plugin::AppVeyor, pkg_name::AbstractString, t::Template) -> String + badges(plugin::AppVeyor, pkg_name::AbstractString, t::Template) -> Vector{String} -Return Markdown badges for the current package. +Generate Markdown badges for the current package. # Arguments -* `plugin::AppVeyor`: plugin whose badges we are generating. +* `plugin::AppVeyor`: Plugin whose badges we are generating. * `t::Template`: Template configuration options. * `pkg_name::AbstractString`: Name of the package. + +Returns an array of Markdown badges. """ function badges(plugin::AppVeyor, t::Template, pkg_name::AbstractString) user = strip(URI(t.remote_prefix).path, '/') @@ -45,7 +49,7 @@ function badges(plugin::AppVeyor, t::Template, pkg_name::AbstractString) end """ - gen_plugin(plugin::AppVeyor, template::Template, pkg_name::AbstractString) + gen_plugin(plugin::AppVeyor, template::Template, pkg_name::AbstractString) -> Vector{String} Generate a .appveyor.yml. @@ -54,9 +58,12 @@ Generate a .appveyor.yml. * `template::Template`: Template configuration and plugins. * `pkg_name::AbstractString`: Name of the package. -Returns an array of generated files ([".appveyor.yml"]) for git to add. +Returns an array of generated files. """ function gen_plugin(plugin::AppVeyor, template::Template, pkg_name::AbstractString) + if plugin.config_file == nothing + return String[] + end text = substitute(readstring(plugin.config_file), pkg_name, template) pkg_dir = joinpath(template.path, pkg_name) gen_file(joinpath(pkg_dir, ".appveyor.yml"), text) diff --git a/src/plugins/codecov.jl b/src/plugins/codecov.jl index aa572be..fc8c484 100644 --- a/src/plugins/codecov.jl +++ b/src/plugins/codecov.jl @@ -1,20 +1,24 @@ """ - CodeCov(;config_file::AbstractString="") -> CodeCov + CodeCov(; config_file::AbstractString="") -> CodeCov Add CodeCov to a template's plugins to enable CodeCov coverage reports. # Keyword Arguments: * `config_file::AbstractString`: Path to a custom `.codecov.yml`. + If `nothing` is supplied, then no file will be generated. """ struct CodeCov <: Plugin gitignore_files::Vector{AbstractString} config_file::AbstractString - function CodeCov(;config_file::AbstractString="") - config_file = isempty(config_file) ? - joinpath(DEFAULTS_DIR, "codecov.yml") : config_file - if !isfile(abspath(config_file)) - throw(ArgumentError("File $config_file does not exist")) + function CodeCov(; config_file::AbstractString="") + if config_file != nothing + if isempty(config_file) + config_file = joinpath(DEFAULTS_DIR, "codecov.yml") + end + if !isfile(abspath(config_file)) + throw(ArgumentError("File $config_file does not exist")) + end end new(["*.jl.cov", "*.jl.*.cov", "*.jl.mem"], config_file) end @@ -26,14 +30,16 @@ function ==(a::CodeCov, b::CodeCov) end """ - badges(plugin::CodeCov, pkg_name::AbstractString, t::Template) -> String + badges(plugin::CodeCov, pkg_name::AbstractString, t::Template) -> Vector{String} -Return Markdown badges for the current package. +Generate Markdown badges for the current package. # Arguments * `plugin::CodeCov`: plugin whose badges we are generating. * `t::Template`: Template configuration options. * `pkg_name::AbstractString`: Name of the package. + +Returns an array of Markdown badges. """ function badges(plugin::CodeCov, t::Template, pkg_name::AbstractString) user = strip(URI(t.remote_prefix).path, '/') @@ -43,7 +49,7 @@ function badges(plugin::CodeCov, t::Template, pkg_name::AbstractString) end """ - gen_plugin(plugin::CodeCov, template::Template, pkg_name::AbstractString) + gen_plugin(plugin::CodeCov, template::Template, pkg_name::AbstractString) -> Vector{String} Generate a .codecov.yml. @@ -52,9 +58,12 @@ Generate a .codecov.yml. * `template::Template`: Template configuration and plugins. * `pkg_name::AbstractString`: Name of the package. -Returns an array of generated files ([".codecov.yml"]) for git to add. +Returns an array of generated files. """ function gen_plugin(plugin::CodeCov, template::Template, pkg_name::AbstractString) + if plugin.config_file == nothing + return String[] + end text = substitute(readstring(plugin.config_file), pkg_name, template) pkg_dir = joinpath(template.path, pkg_name) gen_file(joinpath(pkg_dir, ".codecov.yml"), text) diff --git a/src/plugins/docker.jl b/src/plugins/docker.jl index 4f31912..8c1b076 100644 --- a/src/plugins/docker.jl +++ b/src/plugins/docker.jl @@ -6,8 +6,10 @@ Docker image containing the package. # Keyword Arguments * `base_image::AbstractString="julia:latest"`: The base image used in the Dockerfile. -* `dockerfile_file::AbstractString=""`: the path to the Dockerfile template to use. -* `dockerignore_file::AbstractString=""`: the path to the .dockerignore template to use. +* `dockerfile_file::Union{AbstractString, Void}=""`: The path to the Dockerfile template + to use. If `nothing` is supplied, then no file will be generated. +* `dockerignore_file::Union{AbstractString, Void}=""`: The path to the .dockerignore + template to use. If `nothing` is supplied, then no file will be generated. * `system_pkgs::Vector{AbstractString}=String[]`: Linux system packages to install. * `python_pkgs::Vector{AbstractString}=String[]`: Python packages to install with `pip`. * `user_image::Bool=true`: Allows the Dockerfile to build a Julia system image which @@ -33,35 +35,39 @@ struct Docker <: Plugin function Docker(; base_image="julia:latest", - dockerfile_file::AbstractString="", - dockerignore_file::AbstractString="", + dockerfile_file::Union{AbstractString, Void}="", + dockerignore_file::Union{AbstractString, Void}="", user_image::Bool=true, - system_pkgs=String[], - python_pkgs=String[], + system_pkgs::Vector{AbstractString}=String[], + python_pkgs::Vector{AbstractString}=String[], ) - if isempty(dockerfile_file) - dockerfile_file = joinpath(DEFAULTS_DIR, "Dockerfile") - end - if !isfile(dockerfile_file) - throw(ArgumentError("File $dockerfile_file does not exist")) + if dockerfile_file != nothing + if isempty(dockerfile_file) + dockerfile_file = joinpath(DEFAULTS_DIR, "Dockerfile") + end + if !isfile(dockerfile_file) + throw(ArgumentError("File $dockerfile_file does not exist")) + end end - if isempty(dockerignore_file) - dockerignore_file = joinpath(DEFAULTS_DIR, "dockerignore") - end - if !isfile(dockerignore_file) - throw(ArgumentError("File $dockerignore_file does not exist")) + if dockerignore_file != nothing + if isempty(dockerignore_file) + dockerignore_file = joinpath(DEFAULTS_DIR, "dockerignore") + end + if !isfile(dockerignore_file) + throw(ArgumentError("File $dockerignore_file does not exist")) + end end new( base_image, dockerfile_file, dockerignore_file, - user_image, system_pkgs, python_pkgs, String[], + user_image, system_pkgs, python_pkgs, String[], ) end end """ - gen_plugin(plugin::Docker, template::Template, pkg_name::AbstractString) + gen_plugin(plugin::Docker, template::Template, pkg_name::AbstractString) -> Vector{String} Generate a Dockerfile for running an app-style package and generate dependency files of different sorts for installation within a Docker container. @@ -72,28 +78,30 @@ different sorts for installation within a Docker container. * `template::Template`: Template configuration and plugins. * `pkg_name::AbstractString`: Name of the package. -Returns an array of generated files for git to add. +Returns an array of generated files. """ function gen_plugin(plugin::Docker, template::Template, pkg_name::AbstractString) pkg_dir = joinpath(template.path, pkg_name) + return_files = String[] - text = substitute(readstring(plugin.dockerignore_file), pkg_name, template) - gen_file(joinpath(pkg_dir, ".dockerignore"), text) + if plugin.dockerignore_file != nothing + push!(return_files, ".dockerignore") + text = substitute(readstring(plugin.dockerignore_file), pkg_name, template) + gen_file(joinpath(pkg_dir, ".dockerignore"), text) + end - view = Dict( - "BASE_IMAGE" => plugin.base_image, - "MAINTAINER" => template.authors, - "!system" => !isempty(plugin.system_pkgs), - "!python" => !isempty(plugin.python_pkgs), - "!userimg" => !plugin.user_image, - ) - text = substitute(readstring(plugin.dockerfile_file), pkg_name, template, view) - gen_file(joinpath(pkg_dir, "Dockerfile"), text) - - return_files = String[ - ".dockerignore", - "Dockerfile", - ] + if plugin.dockerfile_file != nothing + push!(return_files, "Dockerfile") + view = Dict( + "BASE_IMAGE" => plugin.base_image, + "MAINTAINER" => template.authors, + "!system" => !isempty(plugin.system_pkgs), + "!python" => !isempty(plugin.python_pkgs), + "!userimg" => !plugin.user_image, + ) + text = substitute(readstring(plugin.dockerfile_file), pkg_name, template, view) + gen_file(joinpath(pkg_dir, "Dockerfile"), text) + end pkg_lists = Dict( "system-pkgs.txt" => plugin.system_pkgs, @@ -110,5 +118,5 @@ function gen_plugin(plugin::Docker, template::Template, pkg_name::AbstractString push!(return_files, file_name) end - return return_files + return return_files end diff --git a/src/plugins/githubpages.jl b/src/plugins/githubpages.jl index 3b0fc15..0574354 100644 --- a/src/plugins/githubpages.jl +++ b/src/plugins/githubpages.jl @@ -1,38 +1,37 @@ """ - GitHubPages(css_files::Union{String, Vector{AbstractString}}=String[]) -> GitHubPages + GitHubPages(; documenter_assets::Vector{AbstractString}=String[]) -> GitHubPages Add GitHubPages to a template's plugins to add Documenter.jl support via GitHub Pages. # Keyword Arguments -* `css_files::Union{String, Vector{String}}=String[]`: Array of paths to custom CSS files. +* `documenter_assets::Vector{String}=String[]`: Array of paths to Documenter asset files. """ struct GitHubPages <: Documenter gitignore_files::Vector{AbstractString} - css_files::Vector{AbstractString} + documenter_assets::Vector{AbstractString} - function GitHubPages(;css_files::Union{String, Vector{String}}=String[]) - if isa(css_files, String) - css_files = [css_files] - end - for file in css_files + function GitHubPages(; css_files::Vector{String}=String[]) + for file in documenter_assets if !isfile(file) throw(ArgumentError("Asset file $file does not exist")) end end # Windows Git recognizes these paths as well. - new(["/docs/build/", "/docs/site/"], css_files) + new(["/docs/build/", "/docs/site/"], documenter_assets) end end """ badges(plugin::GitHubPages, pkg_name::AbstractString, t::Template) -> Vector{String} -Return Markdown badges for the current package. +Generate Markdown badges for the current package. # Arguments * `plugin::GitHubPages`: plugin whose badges we are generating. * `t::Template`: Template configuration options. * `pkg_name::AbstractString`: Name of the package. + +Returns an array of Markdown badges. """ function badges(plugin::GitHubPages, t::Template, pkg_name::AbstractString) if haskey(t.plugins, TravisCI) @@ -57,7 +56,7 @@ GitHub Pages. * `template::Template`: Template configuration and plugins. * `pkg_name::AbstractString`: Name of the package. -Returns an array of generated directories (["docs"]) for git to add. +Returns an array of generated directories. """ function gen_plugin(plugin::GitHubPages, template::Template, pkg_name::AbstractString) invoke( diff --git a/src/plugins/travis.jl b/src/plugins/travis.jl index c5d5026..04c8f3e 100644 --- a/src/plugins/travis.jl +++ b/src/plugins/travis.jl @@ -1,20 +1,24 @@ """ - TravisCI(;config_file::AbstractString="") -> TravisCI + TravisCI(; config_file::AbstractString="") -> TravisCI -Add TravisCI to a template's plugins to enable Travis CI. +Add TravisCI to a template's plugins to add Travis CI support. # Keyword Arguments: * `config_file::AbstractString`: Path to a custom `.travis.yml`. + If `nothing` is supplied, then no file will be generated. """ struct TravisCI <: Plugin gitignore_files::Vector{AbstractString} - config_file::AbstractString + config_file::Union{AbstractString, Void} - function TravisCI(;config_file::AbstractString="") - config_file = isempty(config_file) ? - joinpath(DEFAULTS_DIR, "travis.yml") : config_file - if !isfile(config_file) - throw(ArgumentError("File $config_file does not exist")) + function TravisCI(; config_file::Union{AbstractString, Void}="") + if config_file != nothing + if isempty(config_file) + config_file = joinpath(DEFAULTS_DIR, "travis.yml") + end + if !isfile(abspath(config_file)) + throw(ArgumentError("File $config_file does not exist")) + end end new(AbstractString[], config_file) end @@ -26,14 +30,16 @@ function ==(a::TravisCI, b::TravisCI) end """ - badges(plugin::TravisCI, pkg_name::AbstractString, t::Template) -> String + badges(plugin::TravisCI, pkg_name::AbstractString, t::Template) -> Vector{String} -Return Markdown badges for the current package. +Generate Markdown badges for the current package. # Arguments * `plugin::TravisCI`: plugin whose badges we are generating. * `t::Template`: Template configuration and plugins. * `pkg_name::AbstractString`: Name of the package. + +Returns an array of Markdown badges. """ function badges(plugin::TravisCI, t::Template, pkg_name::AbstractString) user = strip(URI(t.remote_prefix).path, '/') @@ -43,7 +49,7 @@ function badges(plugin::TravisCI, t::Template, pkg_name::AbstractString) end """ - gen_plugin(plugin::TravisCI, template::Template, pkg_name::AbstractString) + gen_plugin(plugin::TravisCI, template::Template, pkg_name::AbstractString) -> Vector{String} Generate a .travis.yml. @@ -52,9 +58,12 @@ Generate a .travis.yml. * `template::Template`: Template configuration and plugins. * `pkg_name::AbstractString`: Name of the package. -Returns an array of generated files ([".travis.yml"]) for git to add. +Returns an array of generated files. """ function gen_plugin(plugin::TravisCI, template::Template, pkg_name::AbstractString) + if plugin.config_file == nothing + return String[] + end text = substitute(readstring(plugin.config_file), pkg_name, template) pkg_dir = joinpath(template.path, pkg_name) gen_file(joinpath(pkg_dir, ".travis.yml"), text)