From c0fe7bb2c2073fbdf745124213d9fca5a0ff6cf5 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Tue, 5 Feb 2019 11:31:51 -0600 Subject: [PATCH 01/81] The Big Squash: A bunch of irrelevant garbage --- .appveyor.yml | 27 --- .codecov.yml | 1 - .travis.yml | 20 +- Manifest.toml | 26 ++- Project.toml | 3 +- defaults/CITATION.bib | 8 + defaults/README.md | 13 ++ defaults/appveyor.yml | 16 +- defaults/cirrus.yml | 12 +- defaults/gitlab-ci.yml | 29 ++- defaults/index.md | 8 + defaults/make.jl | 31 +++ defaults/runtests.jl | 6 + defaults/travis.yml | 57 +++-- docs/Manifest.toml | 40 ++-- docs/src/index.md | 6 +- docs/src/pages/licenses.md | 12 +- docs/src/pages/package_generation.md | 16 -- docs/src/pages/plugin_development.md | 69 +++--- docs/src/pages/plugins.md | 2 - src/PkgTemplates.jl | 54 ++--- src/generate.jl | 334 ++------------------------- src/interactive.jl | 152 ++++++++++++ src/licenses.jl | 45 ---- src/plugin.jl | 279 +++++++--------------- src/plugins/appveyor.jl | 42 ---- src/plugins/ci.jl | 140 +++++++++++ src/plugins/cirrusci.jl | 45 ---- src/plugins/citation.jl | 62 ++--- src/plugins/codecov.jl | 44 ---- src/plugins/coverage.jl | 31 +++ src/plugins/coveralls.jl | 43 ---- src/plugins/documenter.jl | 211 +++++++++-------- src/plugins/essentials.jl | 115 +++++++++ src/plugins/githubpages.jl | 69 ------ src/plugins/gitlabci.jl | 83 ------- src/plugins/gitlabpages.jl | 47 ---- src/plugins/travisci.jl | 44 ---- src/template.jl | 307 +++++++----------------- test/gitconfig | 3 - test/interactive/interactive.jl | 68 ------ test/interactive/plugins.jl | 90 -------- test/plugins/appveyor.jl | 57 ----- test/plugins/cirrusci.jl | 54 ----- test/plugins/citation.jl | 48 ---- test/plugins/codecov.jl | 41 ---- test/plugins/coveralls.jl | 40 ---- test/plugins/githubpages.jl | 68 ------ test/plugins/gitlabci.jl | 69 ------ test/plugins/gitlabpages.jl | 60 ----- test/plugins/travisci.jl | 82 ------- test/runtests.jl | 20 -- test/tests.jl | 93 +------- 53 files changed, 999 insertions(+), 2343 deletions(-) delete mode 100644 .appveyor.yml delete mode 100644 .codecov.yml create mode 100644 defaults/CITATION.bib create mode 100644 defaults/README.md create mode 100644 defaults/index.md create mode 100644 defaults/make.jl create mode 100644 defaults/runtests.jl create mode 100644 src/interactive.jl delete mode 100644 src/plugins/appveyor.jl create mode 100644 src/plugins/ci.jl delete mode 100644 src/plugins/cirrusci.jl delete mode 100644 src/plugins/codecov.jl create mode 100644 src/plugins/coverage.jl delete mode 100644 src/plugins/coveralls.jl create mode 100644 src/plugins/essentials.jl delete mode 100644 src/plugins/githubpages.jl delete mode 100644 src/plugins/gitlabci.jl delete mode 100644 src/plugins/gitlabpages.jl delete mode 100644 src/plugins/travisci.jl delete mode 100644 test/gitconfig delete mode 100644 test/interactive/interactive.jl delete mode 100644 test/interactive/plugins.jl delete mode 100644 test/plugins/appveyor.jl delete mode 100644 test/plugins/cirrusci.jl delete mode 100644 test/plugins/citation.jl delete mode 100644 test/plugins/codecov.jl delete mode 100644 test/plugins/coveralls.jl delete mode 100644 test/plugins/githubpages.jl delete mode 100644 test/plugins/gitlabci.jl delete mode 100644 test/plugins/gitlabpages.jl delete mode 100644 test/plugins/travisci.jl diff --git a/.appveyor.yml b/.appveyor.yml deleted file mode 100644 index 11ec9322..00000000 --- a/.appveyor.yml +++ /dev/null @@ -1,27 +0,0 @@ -environment: - matrix: - - julia_version: 0.7 - - julia_version: 1.0 - - julia_version: nightly -platform: - - x86 - - x64 -matrix: - allow_failures: - - julia_version: nightly -notifications: - - provider: Email - on_build_success: false - on_build_failure: false - on_build_status_changed: false -install: - - ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1")) -build_script: - - echo "%JL_BUILD_SCRIPT%" - - C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%" -test_script: - - echo "%JL_TEST_SCRIPT%" - - C:\julia\bin\julia -e "%JL_TEST_SCRIPT%" -on_success: - - echo "%JL_CODECOV_SCRIPT%" - - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%" diff --git a/.codecov.yml b/.codecov.yml deleted file mode 100644 index 69cb7601..00000000 --- a/.codecov.yml +++ /dev/null @@ -1 +0,0 @@ -comment: false diff --git a/.travis.yml b/.travis.yml index 24b05746..b3fd9064 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,10 @@ language: julia os: - linux - osx + - windows julia: - 1.0 - - 1.1 + - 1.2 - nightly matrix: allow_failures: @@ -12,14 +13,19 @@ matrix: fast_finish: true notifications: email: false -after_success: julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())' +after_success: + - julia -e ' + using Pkg + Pkg.add("Coverage") + using Coverage + Codecov.submit(process_folder())' jobs: include: - stage: Documentation - julia: 1.1 + julia: 1.2 script: julia --project=docs -e ' - using Pkg; - Pkg.develop(PackageSpec(path=pwd())); - Pkg.instantiate(); - include("docs/make.jl");' + using Pkg + Pkg.develop(PackageSpec(; path=pwd())) + Pkg.instantiate() + include("docs/make.jl")' after_success: skip diff --git a/Manifest.toml b/Manifest.toml index 95994a2e..24d77f8a 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -3,6 +3,16 @@ [[Base64]] uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" +[[DataAPI]] +git-tree-sha1 = "8903f0219d3472543fc4b2f5ebaf675a07f817c0" +uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" +version = "1.0.1" + +[[DataValueInterfaces]] +git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" +uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464" +version = "1.0.0" + [[Dates]] deps = ["Printf"] uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" @@ -39,9 +49,9 @@ uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" [[Mustache]] deps = ["Printf", "Tables"] -git-tree-sha1 = "d27b8b8b99c052ea1fdd40c678bfb2dfaec4e96e" +git-tree-sha1 = "f39de3a12232eb47bd0629b3a661054287780276" uuid = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" -version = "0.5.12" +version = "0.5.13" [[Pkg]] deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] @@ -59,12 +69,6 @@ uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" deps = ["Serialization"] uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -[[Requires]] -deps = ["Test"] -git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1" -uuid = "ae029012-a4dd-5104-9daa-d747884805df" -version = "0.5.2" - [[SHA]] uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" @@ -81,10 +85,10 @@ uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" version = "1.0.0" [[Tables]] -deps = ["IteratorInterfaceExtensions", "LinearAlgebra", "Requires", "TableTraits", "Test"] -git-tree-sha1 = "351a4b894122e1553c6ed05fda54086ab036adef" +deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"] +git-tree-sha1 = "aaed7b3b00248ff6a794375ad6adf30f30ca5591" uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" -version = "0.2.5" +version = "0.2.11" [[Test]] deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] diff --git a/Project.toml b/Project.toml index 4ddb9884..5df5d898 100644 --- a/Project.toml +++ b/Project.toml @@ -16,7 +16,8 @@ URIParser = "30578b45-9adc-5946-b283-645ec420af67" julia = "1" [extras] +Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test"] +test = ["Suppressor", "Test"] diff --git a/defaults/CITATION.bib b/defaults/CITATION.bib new file mode 100644 index 00000000..b49e5ea9 --- /dev/null +++ b/defaults/CITATION.bib @@ -0,0 +1,8 @@ +@misc{<>.jl, + author = {<>}, + title = {<>.jl}, + url = {<>}, + version = {v0.1.0}, + year = {<>}, + month = {<>} +} diff --git a/defaults/README.md b/defaults/README.md new file mode 100644 index 00000000..230e5a50 --- /dev/null +++ b/defaults/README.md @@ -0,0 +1,13 @@ +# {{PKG}}{{#HAS_INLINE_BADGES}} {{#BADGES}}{{.}} {{/BADGES}}{{/HAS_INLINE_BADGES}} +{{^HAS_INLINE_BADGES}} + +{{#BADGES}} +{{.}} +{{/BADGES}} +{{/HAS_INLINE_BADGES}} +{{#HAS_CITATION}} + +## Citing + +See [`CITATION.bib`](CITATION.bib) for the relevant reference(s). +{{/HAS_CITATION}} diff --git a/defaults/appveyor.yml b/defaults/appveyor.yml index c9f4dec7..afa1848d 100644 --- a/defaults/appveyor.yml +++ b/defaults/appveyor.yml @@ -1,14 +1,18 @@ # Documentation: https://github.com/JuliaCI/Appveyor.jl environment: matrix: - - julia_version: {{VERSION}} - - julia_version: nightly +{{#VERSIONS}} + - julia_version: {{.}} +{{/VERSIONS}} platform: - - x86 - - x64 +{{#PLATFORMS}} + - {{.}} +{{/PLATFORMS}} +{{#HAS_NIGHTLY}} matrix: allow_failures: - julia_version: nightly +{{/HAS_NIGHTLY}} branches: only: - master @@ -26,8 +30,8 @@ build_script: test_script: - echo "%JL_TEST_SCRIPT%" - C:\julia\bin\julia -e "%JL_TEST_SCRIPT%" -{{#CODECOV}} +{{#HAS_CODECOV}} on_success: - echo "%JL_CODECOV_SCRIPT%" - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%" -{{/CODECOV}} +{{/HAS_CODECOV}} diff --git a/defaults/cirrus.yml b/defaults/cirrus.yml index 2b1949ea..1e182e2e 100644 --- a/defaults/cirrus.yml +++ b/defaults/cirrus.yml @@ -1,16 +1,18 @@ freebsd_instance: - image: freebsd-12-0-release-amd64 + image: {{IMAGE}} task: name: FreeBSD env: - JULIA_VERSION: {{VERSION}} +{{#VERSIONS}} + JULIA_VERSION: {{.}} +{{/VERSIONS}} install_script: - sh -c "$(fetch https://raw.githubusercontent.com/ararslan/CirrusCI.jl/master/bin/install.sh -o -)" build_script: - cirrusjl build test_script: - cirrusjl test -{{#COVERAGE}} +{{#HAS_COVERAGE}} coverage_script: - - cirrusjl coverage{{#CODECOV}} codecov{{/CODECOV}}{{#COVERALLS}} coveralls{{/COVERALLS}} -{{/COVERAGE}} + - cirrusjl coverage{{#HAS_CODECOV}} codecov{{/HAS_CODECOV}}{{#HAS_COVERALLS}} coveralls{{/HAS_COVERALLS}} +{{/HAS_COVERAGE}} diff --git a/defaults/gitlab-ci.yml b/defaults/gitlab-ci.yml index ab0908b6..d8209975 100644 --- a/defaults/gitlab-ci.yml +++ b/defaults/gitlab-ci.yml @@ -1,19 +1,30 @@ -Julia {{VERSION}}: - image: julia:{{VERSION}} - script: julia --project='@.' -e 'using Pkg; Pkg.build(); Pkg.test({{#GITLABCOVERAGE}}; coverage=true{{/GITLABCOVERAGE}})' -{{#GITLABCOVERAGE}} +{{#VERSIONS}} +Julia {{.}}: + image: julia:{{.}} + script: julia --project=@. -e ' + using Pkg + Pkg.build() + Pkg.test({{#HAS_COVERAGE}}coverage=true{{/HAS_COVERAGE}})' +{{/VERSIONS}} +{{#HAS_COVERAGE}} coverage: /Test Coverage (\d+\.\d+%)/ after_script: - - julia -e 'using Printf; using Pkg; Pkg.add("Coverage"); using Coverage; c, t = get_summary(process_folder()); @printf "Test Coverage %.2f%%\n" 100c/t' -{{/GITLABCOVERAGE}} -{{#DOCUMENTER}} + - julia -e ' + using Pkg + Pkg.add("Coverage") + using Coverage + c, t = get_summary(process_folder()) + using Printf + @printf "Test Coverage %.2f%%\n" 100c/t' +{{/HAS_COVERAGE}} +{{#HAS_DOCUMENTER}} pages: image: julia:{{VERSION}} stage: deploy script: - julia --project=docs -e ' using Pkg; - Pkg.develop(PackageSpec(path=pwd())); + Pkg.develop(PackageSpec(; path=pwd())); Pkg.instantiate(); include("docs/make.jl");' - mkdir -p public @@ -23,4 +34,4 @@ pages: - public only: - master -{{/DOCUMENTER}} +{{/HAS_DOCUMENTER}} diff --git a/defaults/index.md b/defaults/index.md new file mode 100644 index 00000000..e5e882f3 --- /dev/null +++ b/defaults/index.md @@ -0,0 +1,8 @@ +# {{PKG}} + +```@index +``` + +```@autodocs +Modules = [{{PKG}}] +``` diff --git a/defaults/make.jl b/defaults/make.jl new file mode 100644 index 00000000..93adc9b4 --- /dev/null +++ b/defaults/make.jl @@ -0,0 +1,31 @@ +using {{PKG}} +using Documenter + +makedocs( + modules=[{{PKG}}], + authors="{{AUTHORS}}", + repo="{{REPO}}", + sitename="{{PKG}}.jl", + format=Documenter.HTML(; + canonical="{{CANONICAL}}", + assets={{^HAS_ASSETS}}String{{/HAS_ASSETS}}[{{^HAS_ASSETS}}],{{/HAS_ASSETS}} + {{#ASSETS}} + "{{.}}", + {{/ASSETS}} +{{#HAS_ASSETS}} + ], +{{/HAS_ASSETS}} + ), + pages=[ + "Home" => "index.md", + ], + {{#MAKEDOCS_KWARGS}} + {{first}}={{second}}, + {{/MAKEDOCS_KWARGS}} +) +{{#HAS_DEPLOY}} + +deploydocs(; + repo="{{REPO}}", +) +{{/HAS_DEPLOY}} diff --git a/defaults/runtests.jl b/defaults/runtests.jl new file mode 100644 index 00000000..072ffb37 --- /dev/null +++ b/defaults/runtests.jl @@ -0,0 +1,6 @@ +using {{PKG}} +using Test + +@testset "{{PKG}}.jl" begin + # Write your tests here. +end diff --git a/defaults/travis.yml b/defaults/travis.yml index 91e1500f..21bc8eb6 100644 --- a/defaults/travis.yml +++ b/defaults/travis.yml @@ -1,35 +1,46 @@ -# Documentation: http://docs.travis-ci.com/user/languages/julia/ +# Documentation: http://docs.travis-ci.com/user/languages/julia language: julia -os: - - linux - - osx -julia: - - {{VERSION}} - - nightly -matrix: - allow_failures: - - julia: nightly - fast_finish: true notifications: email: false -{{#COVERAGE}} -after_success: -{{#CODECOV}} - - julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())' -{{/CODECOV}} -{{#COVERALLS}} - - julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder())' -{{/COVERALLS}} -{{/COVERAGE}} -{{#DOCUMENTER}} +{{#HAS_DOCUMENTER}} jobs: + fast_finish: true +{{#HAS_NIGHTLY}} + allow_failures: + - julia: nightly +{{/HAS_NIGHTLY}} include: +{{#JOBS}} + - julia: {{JULIA}} + os: {{OS}} +{{#ARCH}} + arch: {{ARCH}} +{{/ARCH}} +{{/JOBS}} +{{#HAS_DOCUMENTER}} - stage: Documentation julia: {{VERSION}} script: julia --project=docs -e ' using Pkg; - Pkg.develop(PackageSpec(path=pwd())); + Pkg.develop(PackageSpec(; path=pwd())); Pkg.instantiate(); include("docs/make.jl");' after_success: skip -{{/DOCUMENTER}} +{{/HAS_DOCUMENTER}} +{{#HAS_COVERAGE}} +after_success: +{{#HAS_CODECOV}} + - julia -e ' + using Pkg; + Pkg.add("Coverage"); + using Coverage; + Codecov.submit(process_folder());' +{{/HAS_CODECOV}} +{{#HAS_COVERALLS}} + - julia -e ' + using Pkg; + Pkg.add("Coverage"); + using Coverage; + Coveralls.submit(process_folder());' +{{/HAS_COVERALLS}} +{{/HAS_COVERAGE}} diff --git a/docs/Manifest.toml b/docs/Manifest.toml index 2af149e4..bf9d220a 100644 --- a/docs/Manifest.toml +++ b/docs/Manifest.toml @@ -1,3 +1,5 @@ +# This file is machine-generated - editing it directly is not advised + [[Base64]] uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" @@ -6,35 +8,34 @@ deps = ["Printf"] uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" [[Distributed]] -deps = ["LinearAlgebra", "Random", "Serialization", "Sockets"] +deps = ["Random", "Serialization", "Sockets"] uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" [[DocStringExtensions]] deps = ["LibGit2", "Markdown", "Pkg", "Test"] -git-tree-sha1 = "1df01539a1c952cef21f2d2d1c092c2bcf0177d7" +git-tree-sha1 = "0513f1a8991e9d83255e0140aace0d0fc4486600" uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" -version = "0.6.0" +version = "0.8.0" [[Documenter]] -deps = ["Base64", "DocStringExtensions", "InteractiveUtils", "LibGit2", "Logging", "Markdown", "Pkg", "REPL", "Random", "Test", "Unicode"] -git-tree-sha1 = "a6db1c69925cdc53aafb38caec4446be26e0c617" +deps = ["Base64", "DocStringExtensions", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"] +git-tree-sha1 = "c61d6eedbc3c4323c08b64af12d29c8ee0fcbb5f" uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4" -version = "0.21.0" +version = "0.23.2" [[InteractiveUtils]] -deps = ["LinearAlgebra", "Markdown"] +deps = ["Markdown"] uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" +[[JSON]] +deps = ["Dates", "Mmap", "Parsers", "Unicode"] +git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.21.0" + [[LibGit2]] uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" -[[Libdl]] -uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" - -[[LinearAlgebra]] -deps = ["Libdl"] -uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" - [[Logging]] uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" @@ -42,6 +43,15 @@ uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" deps = ["Base64"] uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[Parsers]] +deps = ["Dates", "Test"] +git-tree-sha1 = "db2b35dedab3c0e46dc15996d170af07a5ab91c9" +uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" +version = "0.3.6" + [[Pkg]] deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" @@ -72,7 +82,7 @@ deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [[UUIDs]] -deps = ["Random"] +deps = ["Random", "SHA"] uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [[Unicode]] diff --git a/docs/src/index.md b/docs/src/index.md index b41a3f5f..f2bb79a3 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -72,8 +72,7 @@ t = Template(; Codecov(), Coveralls(), AppVeyor(), - GitHubPages(), - CirrusCI(), + Documenter{TravisCI}(), ], ) generate("MyPkg2", t) @@ -103,5 +102,4 @@ include, you are encouraged to use [AttoBot](https://github.com/apps/attobot) in ## Contributing It's extremely easy to extend `PkgTemplates` with new plugins. To get started, -check out the -[plugin development guide](https://invenia.github.io/PkgTemplates.jl/stable/pages/plugin_development.html). +check out [Plugin Development](@ref). diff --git a/docs/src/pages/licenses.md b/docs/src/pages/licenses.md index bf6b886b..f8adc5d6 100644 --- a/docs/src/pages/licenses.md +++ b/docs/src/pages/licenses.md @@ -4,17 +4,11 @@ CurrentModule = PkgTemplates # Licenses -[Many open-source licenses](https://github.com/christopher-dG/PkgTemplates.jl/tree/master/licenses) -are available for use with `PkgTemplates`, but if you see that one is missing, -don't hesitate to open an issue or PR. +[Many open-source licenses](https://github.com/invenia/PkgTemplates.jl/tree/master/licenses) +are available for use with `PkgTemplates`, but if you see that one is missing, don't +hesitate to open an issue or PR. ```@docs available_licenses show_license ``` - -### Helper Functions - -```@docs -read_license -``` diff --git a/docs/src/pages/package_generation.md b/docs/src/pages/package_generation.md index 24a1995d..e3bd5679 100644 --- a/docs/src/pages/package_generation.md +++ b/docs/src/pages/package_generation.md @@ -7,25 +7,9 @@ CurrentModule = PkgTemplates Creating new packages with `PkgTemplates` revolves around creating a new [`Template`](@ref), then calling [`generate`](@ref) on it. -## `Template` - ```@docs Template interactive_template -``` - -## `generate` - -```@docs generate generate_interactive ``` - -### Helper Functions - -```@docs -gen_tests -gen_readme -gen_gitignore -gen_license -``` diff --git a/docs/src/pages/plugin_development.md b/docs/src/pages/plugin_development.md index 31aa9927..e77b8826 100644 --- a/docs/src/pages/plugin_development.md +++ b/docs/src/pages/plugin_development.md @@ -4,72 +4,69 @@ CurrentModule = PkgTemplates # Plugin Development -The best and easiest way to contribute to `PkgTemplates` is to write new -plugins. +The best and easiest way to contribute to `PkgTemplates` is to write new plugins. ```@docs Plugin ``` -## Generic Plugins +## "Generic" Plugins -```@docs -GenericPlugin -``` - -## Custom Plugins +Many plugins fall into the category of managing some configuration file. +Think Travis CI's `.travis.yml`, and so on for every CI service ever. +For these one-file plugins, a shortcut macro is available to define a plugin in one line. ```@docs -CustomPlugin +GeneratedPlugin +@plugin ``` -### `CustomPlugin` Required Methods +### `GeneratedPlugin` Customization -#### `gen_plugin` - -```@docs -gen_plugin -interactive -``` - -**Note**: [`interactive`](@ref) is not strictly required, however without it, -your custom plugin will not be available when creating templates with -[`interactive_template`](@ref). - -#### `badges` +When you generate a plugin type with [`@plugin`](@ref), all required methods are +implemented for you. However, you're still allowed to override behaviour if you so desire. +These are the relevant methods: ```@docs +source +destination +gitignore badges +view ``` -## Helper Types/Functions +For some examples, see +[`generated.jl`](https://github.com/invenia/PkgTemplates.jl/tree/master/src/plugins/generated.jl). -#### `gen_file` +## Custom Plugins -```@docs -gen_file -``` +When a plugin is too complicated to be expressed with [`GeneratedPlugin`](@ref), we only +need to implement a few methods to create something fully custom. -#### `substitute` +### Required Methods ```@docs -substitute +gen_plugin ``` -#### `Badge` +### Optional Methods ```@docs -Badge +interactive ``` -#### `format` +Additionally, [`gitignore`](@ref), [`badges`](@ref), and [`view`](@ref) can also be +implemented in the same way as for [`GeneratedPlugin`](@ref)s (they have empty default +implementations). [`source`](@ref) and [`destination`](@ref) have no meaning for custom +plugins. -```@docs -format -``` +### Helpers -#### `version_floor` +These types and functions will make implementing the above methods much easier. ```@docs +Badge +gen_file +substitute version_floor ``` diff --git a/docs/src/pages/plugins.md b/docs/src/pages/plugins.md index dd4f07a9..af81a08b 100644 --- a/docs/src/pages/plugins.md +++ b/docs/src/pages/plugins.md @@ -28,6 +28,4 @@ Coveralls ```@docs Documenter -GitHubPages -GitLabPages ``` diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index 6f54e10b..76c715ae 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -1,36 +1,34 @@ module PkgTemplates -using Dates -using InteractiveUtils -using LibGit2 -using Mustache -using Pkg -using REPL.TerminalMenus -using URIParser +using Base: @kwdef, current_project +using Base.Filesystem: contractuser +using Dates: month, today, year +using InteractiveUtils: subtypes +using LibGit2: LibGit2 +using Mustache: render +using Pkg: PackageSpec, Pkg +using REPL.TerminalMenus: MultiSelectMenu, RadioMenu, request +using URIParser: URI export - # Template/package generation. Template, - generate, - interactive_template, - generate_interactive, - # Licenses. - show_license, - available_licenses, - # Plugins. - GitHubPages, - GitLabPages, AppVeyor, - TravisCI, - GitLabCI, CirrusCI, + Citation, Codecov, Coveralls, - Citation + Documenter, + Gitignore, + GitLabCI, + License, + Readme, + Tests, + TravisCI + +const DEFAULT_VERSION = VersionNumber(VERSION.major) """ A plugin to be added to a [`Template`](@ref), which adds some functionality or integration. -New plugins should almost always extend [`GenericPlugin`](@ref) or [`CustomPlugin`](@ref). """ abstract type Plugin end @@ -38,18 +36,6 @@ include("licenses.jl") include("template.jl") include("generate.jl") include("plugin.jl") -include(joinpath("plugins", "documenter.jl")) -include(joinpath("plugins", "coveralls.jl")) -include(joinpath("plugins", "appveyor.jl")) -include(joinpath("plugins", "codecov.jl")) -include(joinpath("plugins", "travisci.jl")) -include(joinpath("plugins", "gitlabci.jl")) -include(joinpath("plugins", "cirrusci.jl")) -include(joinpath("plugins", "githubpages.jl")) -include(joinpath("plugins", "gitlabpages.jl")) -include(joinpath("plugins", "citation.jl")) - -const DEFAULTS_DIR = normpath(joinpath(@__DIR__, "..", "defaults")) -const BADGE_ORDER = [GitHubPages, GitLabPages, TravisCI, AppVeyor, GitLabCI, Codecov, Coveralls] +include("interactive.jl") end diff --git a/src/generate.jl b/src/generate.jl index 3ab577de..c0e7b022 100644 --- a/src/generate.jl +++ b/src/generate.jl @@ -1,16 +1,12 @@ +const TEST_UUID = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + """ - generate(pkg::AbstractString, t::Template) -> Nothing - generate(t::Template, pkg::AbstractString) -> Nothing + (::Template)(pkg::AbstractString) -Generate a package named `pkg` from `t`. If `git` is `false`, no Git repository is created. +Generate a package named `pkg` from a [`Template`](@ref). """ -function generate( - pkg::AbstractString, - t::Template; - git::Bool=true, - gitconfig::Union{GitConfig, Nothing}=nothing, -) - pkg = splitjl(pkg) +function (t::Template)(pkg::AbstractString) + endswith(pkg, ".jl") && (pkg = pkg[1:end-3]) pkg_dir = joinpath(t.dir, pkg) ispath(pkg_dir) && throw(ArgumentError("$pkg_dir already exists")) @@ -18,9 +14,9 @@ function generate( # Create the directory with some boilerplate inside. Pkg.generate(pkg_dir) - # Add a [compat] section for Julia. + # Add a [compat] section for Julia. By default, Julia 1.x is supported. open(joinpath(pkg_dir, "Project.toml"), "a") do io - println(io, "\n[compat]\njulia = $(repr_version(t.julia_version))") + println(io, "\n[compat]\njulia = \"1\"") end # Replace the authors field with the template's authors. @@ -31,329 +27,35 @@ function generate( write(path, replace(project, r"authors = .*" => "authors = $authors")) end - if git - # Initialize the repo. + if t.git + # Initialize the repo, make a commit, and set the remote. repo = LibGit2.init(pkg_dir) - @info "Initialized Git repo at $pkg_dir" - - if gitconfig !== nothing - # Configure the repo. - repoconfig = GitConfig(repo) - for c in LibGit2.GitConfigIter(gitconfig) - LibGit2.set!(repoconfig, unsafe_string(c.name), unsafe_string(c.value)) - end - end - - # Commit and set the remote. LibGit2.commit(repo, "Initial commit") rmt = if t.ssh "git@$(t.host):$(t.user)/$pkg.jl.git" else "https://$(t.host)/$(t.user)/$pkg.jl" end - # We need to set the remote in a strange way, see #8. close(LibGit2.GitRemote(repo, "origin", rmt)) - @info "Set remote origin to $rmt" - - # Create the gh-pages branch if necessary. - if haskey(t.plugins, GitHubPages) - LibGit2.branch!(repo, "gh-pages") - LibGit2.commit(repo, "Initial commit") - @info "Created empty gh-pages branch" - LibGit2.branch!(repo, "master") - end end # Generate the files. - files = vcat( - "src/", "Project.toml", # Created by Pkg.generate. - gen_tests(pkg_dir, t), - gen_readme(pkg_dir, t), - gen_license(pkg_dir, t), - vcat(map(p -> gen_plugin(p, t, pkg), values(t.plugins))...), - ) + foreach(p -> gen_plugin(p, t, pkg_dir), values(t.plugins)) - if git - append!(files, gen_gitignore(pkg_dir, t)) - LibGit2.add!(repo, files...) + if t.git + # Commit the files. + LibGit2.add!(repo, ".") LibGit2.commit(repo, "Files generated by PkgTemplates") - @info "Committed $(length(files)) files/directories: $(join(files, ", "))" - - - if length(collect(LibGit2.GitBranchIter(repo))) > 1 - @info "Remember to push all created branches to your remote: git push --all" - end end if t.dev # Add the new package to the current environment. - Pkg.develop(PackageSpec(path=pkg_dir)) + Pkg.develop(PackageSpec(; path=pkg_dir)) end @info "New package is at $pkg_dir" - catch e - rm(pkg_dir; recursive=true) - rethrow(e) - end -end - -function generate( - t::Template, - pkg::AbstractString; - git::Bool=true, - gitconfig::Union{GitConfig, Nothing}=nothing, -) - generate(pkg, t; git=git, gitconfig=gitconfig) -end - -""" - generate_interactive(pkg::AbstractString; fast::Bool=false, git::Bool=true) -> Template - -Interactively create a template, and then generate a package with it. Arguments and -keywords are used in the same way as in [`generate`](@ref) and -[`interactive_template`](@ref). -""" -function generate_interactive( - pkg::AbstractString; - fast::Bool=false, - git::Bool=true, - gitconfig::Union{GitConfig, Nothing}=nothing, -) - t = interactive_template(; git=git, fast=fast) - generate(pkg, t; git=git, gitconfig=gitconfig) - return t -end - -""" - gen_tests(pkg_dir::AbstractString, t::Template) -> Vector{String} - -Create the test entrypoint in `pkg_dir`. - -# Arguments -* `pkg_dir::AbstractString`: The package directory in which the files will be generated -* `t::Template`: The template whose tests we are generating. - -Returns an array of generated file/directory names. -""" -function gen_tests(pkg_dir::AbstractString, t::Template) - # TODO: Silence Pkg for this section? Adding and removing Test creates a lot of noise. - proj = Base.current_project() - try - Pkg.activate(pkg_dir) - Pkg.add("Test") - - # Move the Test dependency into the [extras] section. - toml = read(joinpath(pkg_dir, "Project.toml"), String) - lines = split(toml, "\n") - idx = findfirst(l -> startswith(l, "Test = "), lines) - testdep = lines[idx] - deleteat!(lines, idx) - toml = join(lines, "\n") * """ - [extras] - $testdep - - [targets] - test = ["Test"] - """ - gen_file(joinpath(pkg_dir, "Project.toml"), toml) - Pkg.update() # Regenerate Manifest.toml (this cleans up Project.toml too). - finally - proj === nothing ? Pkg.activate() : Pkg.activate(proj) - end - - pkg = basename(pkg_dir) - text = """ - using $pkg - using Test - - @testset "$pkg.jl" begin - # Write your own tests here. - end - """ - - gen_file(joinpath(pkg_dir, "test", "runtests.jl"), text) - return ["test/"] -end - -""" - gen_readme(pkg_dir::AbstractString, t::Template) -> Vector{String} - -Create a README in `pkg_dir` with badges for each enabled plugin. - -# Arguments -* `pkg_dir::AbstractString`: The directory in which the files will be generated. -* `t::Template`: The template whose README we are generating. - -Returns an array of generated file/directory names. -""" -function gen_readme(pkg_dir::AbstractString, t::Template) - pkg = basename(pkg_dir) - text = "# $pkg\n" - done = [] - # Generate the ordered badges first, then add any remaining ones to the right. - for plugin_type in BADGE_ORDER - if haskey(t.plugins, plugin_type) - text *= "\n" - text *= join( - badges(t.plugins[plugin_type], t.user, pkg), - "\n", - ) - push!(done, plugin_type) - end - end - for plugin_type in setdiff(keys(t.plugins), done) - text *= "\n" - text *= join( - badges(t.plugins[plugin_type], t.user, pkg), - "\n", - ) - end - if haskey(t.plugins, Citation) && t.plugins[Citation].readme_section - text *= "\n## Citing\n\nSee `CITATION.bib` for the relevant reference(s).\n" - end - - - gen_file(joinpath(pkg_dir, "README.md"), text) - return ["README.md"] -end - -""" - gen_gitignore(pkg_dir::AbstractString, t::Template) -> Vector{String} - -Create a `.gitignore` in `pkg_dir`. - -# Arguments -* `pkg_dir::AbstractString`: The directory in which the files will be generated. -* `t::Template`: The template whose .gitignore we are generating. - -Returns an array of generated file/directory names. -""" -function gen_gitignore(pkg_dir::AbstractString, t::Template) - pkg = basename(pkg_dir) - init = [".DS_Store", "/dev/"] - entries = mapfoldl(p -> p.gitignore, append!, values(t.plugins); init=init) - if !t.manifest && !in("Manifest.toml", entries) - push!(entries, "/Manifest.toml") # Only ignore manifests at the repo root. + catch + rm(pkg_dir; recursive=true, force=true) + rethrow() end - unique!(sort!(entries)) - text = join(entries, "\n") - - gen_file(joinpath(pkg_dir, ".gitignore"), text) - files = [".gitignore"] - t.manifest && push!(files, "Manifest.toml") - return files -end - -""" - gen_license(pkg_dir::AbstractString, t::Template) -> Vector{String} - -Create a license in `pkg_dir`. - -# Arguments -* `pkg_dir::AbstractString`: The directory in which the files will be generated. -* `t::Template`: The template whose LICENSE we are generating. - -Returns an array of generated file/directory names. -""" -function gen_license(pkg_dir::AbstractString, t::Template) - if isempty(t.license) - return String[] - end - - text = "Copyright (c) $(year(today())) $(t.authors)\n" - text *= read_license(t.license) - - gen_file(joinpath(pkg_dir, "LICENSE"), text) - return ["LICENSE"] -end - -""" - gen_file(file::AbstractString, text::AbstractString) -> Int - -Create a new file containing some given text. Always ends the file with a newline. - -# Arguments -* `file::AbstractString`: Path to the file to be created. -* `text::AbstractString`: Text to write to the file. - -Returns the number of bytes written to the file. -""" -function gen_file(file::AbstractString, text::AbstractString) - mkpath(dirname(file)) - if !endswith(text , "\n") - text *= "\n" - end - return write(file, text) -end - -""" - version_floor(v::VersionNumber=VERSION) -> String - -Format the given Julia version. - -# Keyword arguments -* `v::VersionNumber=VERSION`: Version to floor. - -Returns "major.minor" for the most recent release version relative to v. For prereleases -with v.minor == v.patch == 0, returns "major.minor-". -""" -function version_floor(v::VersionNumber=VERSION) - return if isempty(v.prerelease) || v.patch > 0 - "$(v.major).$(v.minor)" - else - "$(v.major).$(v.minor)-" - end -end - -""" - substitute(template::AbstractString, view::Dict{String, Any}) -> String - substitute( - template::AbstractString, - pkg_template::Template; - view::Dict{String, Any}=Dict{String, Any}(), - ) -> String - -Replace placeholders in `template` with values in `view` via -[`Mustache`](https://github.com/jverzani/Mustache.jl). `template` is not modified. -If `pkg_template` is supplied, some default replacements are also performed. - -For information on how to structure `template`, see "Defining Template Files" section in -[Custom Plugins](@ref). - -**Note**: Conditionals in `template` without a corresponding key in `view` won't error, -but will simply be evaluated as false. -""" -substitute(template::AbstractString, view::Dict{String, Any}) = render(template, view) - -function substitute( - template::AbstractString, - pkg_template::Template; - view::Dict{String, Any}=Dict{String, Any}(), -) - # Don't use version_floor here because we don't want the trailing '-' on prereleases. - v = pkg_template.julia_version - d = Dict{String, Any}( - "USER" => pkg_template.user, - "VERSION" => "$(v.major).$(v.minor)", - "DOCUMENTER" => any(map(p -> isa(p, Documenter), values(pkg_template.plugins))), - "CODECOV" => haskey(pkg_template.plugins, Codecov), - "COVERALLS" => haskey(pkg_template.plugins, Coveralls), - ) - # d["AFTER"] is true whenever something needs to occur in a CI "after_script". - d["AFTER"] = d["DOCUMENTER"] || d["CODECOV"] || d["COVERALLS"] - # d["COVERAGE"] is true whenever a coverage plugin is enabled. - # TODO: This doesn't handle user-defined coverage plugins. - # Maybe we need an abstract CoveragePlugin <: GenericPlugin? - d["COVERAGE"] = d["CODECOV"] || d["COVERALLS"] - return substitute(template, merge(d, view)) -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 diff --git a/src/interactive.jl b/src/interactive.jl new file mode 100644 index 00000000..230393c0 --- /dev/null +++ b/src/interactive.jl @@ -0,0 +1,152 @@ +# Printing utils. +const TAB = repeat(' ', 4) +const HALFTAB = repeat(' ', 2) +const DOT = "• " +const ARROW = "→ " +const PLUGIN_TYPES = let + leaves(T::Type) = isabstracttype(T) ? vcat(map(leaves, subtypes(T))...) : [T] + leaves(Plugin) +end + +yesno(x::Bool) = x ? "Yes" : "No" + +maybe_string(s::AbstractString) = isempty(s) ? "None" : string(s) + +""" + interactive(T::Type{<:Plugin}) -> T + +Interactively create a plugin of type `T`. +When this method is implemented for a type, it becomes available to [`Template`](@ref)s created with `interactive=true`. +""" +function interactive end + +function make_template(::Val{true}; kwargs...) + @info "Default values are shown in [brackets]" + + opts = Dict{Symbol, Any}() + fast = get(kwargs, :fast, false) + + opts[:user] = get(kwargs, :user) do + default = defaultkw(:user) + default = isempty(default) ? nothing : default + prompt_string("Username", default) + end + + git = opts[:git] = get(kwargs, :git) do + default = defaultkw(:git) + fast ? default : prompt_bool("Create Git repositories for packages", default) + end + + opts[:host] = get(kwargs, :host) do + default = defaultkw(:host) + if fast || !git + default + else + prompt_string("Code hosting service", default) + end + end + + opts[:license] = get(kwargs, :license) do + default = defaultkw(:license) + if fast + default + else + # TODO: Break this out into something reusable? + choices = String["None"; split(sprint(available_licenses), "\n")] + licenses = ["" => "", pairs(LICENSES)...] + menu = RadioMenu(choices) + first(licenses[request("License:", menu)]) + end + end + + opts[:authors] = get(kwargs, :authors) do + default = defaultkw(:authors) + if fast || !git + default + else + prompt_string("Package author(s)", isempty(default) ? "None" : default) + end + end + + opts[:dir] = get(kwargs, :dir) do + default = defaultkw(:dir) + fast ? default : prompt_string("Path to package directory", default) + end + + opts[:julia_version] = get(kwargs, :julia_version) do + default = defaultkw(:julia_version) + if fast + default + else + VersionNumber(prompt_string("Minimum Julia version", string(default))) + end + end + + opts[:ssh] = get(kwargs, :ssh) do + default = defaultkw(:ssh) + fast || !git ? default : prompt_bool("Set remote to SSH", default) + end + + opts[:manifest] = get(kwargs, :manifest) do + default = defaultkw(:manifest) + fast || !git ? default : prompt_bool("Commit Manifest.toml", default) + end + + opts[:develop] = get(kwargs, :develop) do + default = defaultkw(:develop) + fast || !git ? default : prompt_bool("Develop generated packages", default) + end + + opts[:plugins] = get(kwargs, :plugins) do + # TODO: Break this out into something reusable? + types = filter(T -> applicable(interactive, T), PLUGIN_TYPES) + menu = MultiSelectMenu(map(string ∘ nameof, types)) + selected = types[collect(request("Plugins:", menu))] + map(interactive, selected) + end + + return make_template(Val(false); opts...) +end + +prompt_string(s::AbstractString, default=nothing) = prompt(string, s, default) + +function prompt_bool(s::AbstractString, default=nothing) + return prompt(s, default) do answer + answer = lowercase(answer) + if answer in ["yes", "true", "y", "t"] + true + elseif answer in ["no", "false", "n", "f"] + false + else + throw(ArgumentError("Invalid yes/no response")) + end + end +end + +function prompt(f::Function, s::AbstractString, default) + required = default === nothing + default_display = default isa Bool ? yesno(default) : default + print(s, " [", required ? "REQUIRED" : default_display, "]: ") + answer = readline() + return if isempty(answer) + required && throw(ArgumentError("This argument is required")) + default + else + f(answer) + end +end + +function prompt_config(T::Type{<:BasicPlugin}) + s = "$(nameof(T)): Source file template path" + default = source(T) + default === nothing && (s *= " (\"None\" for no file)") + answer = prompt_string(s, default === nothing ? "None" : contractuser(default)) + + return if lowercase(answer) == "none" + nothing + elseif isempty(answer) + default + else + answer + end +end diff --git a/src/licenses.jl b/src/licenses.jl index 0ef1bd83..e69de29b 100644 --- a/src/licenses.jl +++ b/src/licenses.jl @@ -1,45 +0,0 @@ -const LICENSE_DIR = normpath(joinpath(@__DIR__, "..", "licenses")) -const LICENSES = Dict( - "MIT" => "MIT \"Expat\" License", - "BSD2" => "Simplified \"2-clause\" BSD License", - "BSD3" => "Modified \"3-clause\" BSD License", - "ISC" => "Internet Systems Consortium License", - "ASL" => "Apache License, Version 2.0", - "MPL" => "Mozilla Public License, Version 2.0", - "GPL-2.0+" => "GNU Public License, Version 2.0+", - "GPL-3.0+" => "GNU Public License, Version 3.0+", - "LGPL-2.1+" => "Lesser GNU Public License, Version 2.1+", - "LGPL-3.0+" => "Lesser GNU Public License, Version 3.0+", - "EUPL-1.2+" => "European Union Public Licence, Version 1.2+", -) - -""" - available_licenses([io::IO]) -> Nothing - -Print the names of all available licenses. -""" -available_licenses(io::IO) = print(io, join(("$k: $v" for (k, v) in LICENSES), "\n")) -available_licenses() = available_licenses(stdout) - -""" - show_license([io::IO], license::AbstractString) -> Nothing - -Print the text of `license`. Errors if the license is not found. -""" -show_license(io::IO, license::AbstractString) = print(io, read_license(license)) -show_license(license::AbstractString) = show_license(stdout, license) - -""" - read_license(license::AbstractString) -> String - -Returns the contents of `license`. Errors if the license is not found. Use -[`available_licenses`](@ref) to view available licenses. -""" -function read_license(license::AbstractString) - path = joinpath(LICENSE_DIR, license) - if isfile(path) - return string(readchomp(path)) - else - throw(ArgumentError("License '$license' is not available")) - end -end diff --git a/src/plugin.jl b/src/plugin.jl index 0fc082d0..9abb6b60 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -1,153 +1,51 @@ +const DEFAULTS_DIR = normpath(joinpath(@__DIR__, "..", "defaults")) + +abstract type BasicPlugin <: Plugin end + +default_file(paths::AbstractString...) = joinpath(DEFAULTS_DIR, paths...) + """ -Generic plugins are plugins that add any number of patterns to the generated package's -`.gitignore`, and have at most one associated file to generate. - -# Attributes -* `gitignore::Vector{AbstractString}`: Array of patterns to be added to the `.gitignore` of - generated packages that use this plugin. -* `src::Union{AbstractString, Nothing}`: Path to the file that will be copied into the generated - package repository. If set to `nothing`, no file will be generated. When this defaults - to an empty string, there should be a default file in `defaults` that will be copied. - That file's name is usually the same as the plugin's name, except in all lowercase and - with the `.yml` extension. If this is not the case, an `interactive` method needs to be - implemented to call `interactive(; file="file.ext")`. -* `dest::AbstractString`: Path to the generated file, relative to the root of the generated - package repository. -* `badges::Vector{Badge}`: Array of [`Badge`](@ref)s containing information used to - create Markdown-formatted badges from the plugin. Entries will be run through - [`substitute`](@ref), so they may contain placeholder values. -* `view::Dict{String, Any}`: Additional substitutions to make in both the plugin's badges - and its associated file. See [`substitute`](@ref) for details. - -# Example -```julia -struct MyPlugin <: GenericPlugin - gitignore::Vector{AbstractString} - src::Union{AbstractString, Nothing} - dest::AbstractString - badges::Vector{Badge} - view::Dict{String, Any} - - function MyPlugin(; config_file::Union{AbstractString, Nothing}="") - if config_file != nothing - config_file = if isempty(config_file) - joinpath(DEFAULTS_DIR, "my-plugin.toml") - elseif isfile(config_file) - abspath(config_file) - else - throw(ArgumentError( - "File \$(abspath(config_file)) does not exist" - )) - end - end - new( - ["*.mgp"], - config_file, - ".my-plugin.toml", - [ - Badge( - "My Plugin", - "https://myplugin.com/badge-{{YEAR}}.png", - "https://myplugin.com/{{USER}}/{{PKGNAME}}.jl", - ), - ], - Dict{String, Any}("YEAR" => year(today())), - ) - end -end + view(::Plugin, ::Template, pkg::AbstractString) -> Dict{String} -interactive(::Type{MyPlugin}) = interactive(MyPlugin; file="my-plugin.toml") -``` +Return extra string substitutions to be made for this plugin. +""" +view(::Plugin, ::Template, ::AbstractString) = Dict{String, Any}() -The above plugin ignores files ending with `.mgp`, copies `defaults/my-plugin.toml` by -default, and creates a badge that links to the project on its own site, using the default -substitutions with one addition: `{{YEAR}} => year(today())`. Since the default config -template file doesn't follow the generic naming convention, we added another `interactive` -method to correct the assumed filename. """ -abstract type GenericPlugin <: Plugin end + gitignore(::Plugin) -> Vector{String} -function Base.show(io::IO, p::GenericPlugin) - spc = " " - println(io, nameof(typeof(p)), ":") +Return patterns that should be added to `.gitignore`. +""" +gitignore(::Plugin) = String[] - cfg = if p.src === nothing - "None" - else - dirname(p.src) == DEFAULTS_DIR ? "Default" : p.src - end - println(io, spc, "→ Config file: ", cfg) +""" + badges(::Plugin) -> Union{Badge, Vector{Badge}} - n = length(p.gitignore) - s = n == 1 ? "" : "s" - print(io, spc, "→ $n gitignore entrie$s") - n > 0 && print(io, ": ", join(map(repr, p.gitignore), ", ")) -end +Return a list of [`Badge`](@ref)s, or just one, to be added to `README.md`. +""" +badges(::Plugin) = Badge[] """ -Custom plugins are plugins whose behaviour does not follow the [`GenericPlugin`](@ref) -pattern. They can implement [`gen_plugin`](@ref), [`badges`](@ref), and -[`interactive`](@ref) in any way they choose, as long as they conform to the usual type -signature. - -# Attributes -* `gitignore::Vector{AbstractString}`: Array of patterns to be added to the `.gitignore` of - generated packages that use this plugin. - -# Example -```julia -struct MyPlugin <: CustomPlugin - gitignore::Vector{AbstractString} - lucky::Bool - - MyPlugin() = new([], rand() > 0.8) - - function gen_plugin(p::MyPlugin, t::Template, pkg_name::AbstractString) - return if p.lucky - text = substitute("You got lucky with {{PKGNAME}}, {{USER}}!", t) - gen_file(joinpath(t.dir, pkg_name, ".myplugin.yml"), text) - [".myplugin.yml"] - else - println("Maybe next time.") - String[] - end - end - - function badges(p::MyPlugin, user::AbstractString, pkg_name::AbstractString) - return if p.lucky - [ - format(Badge( - "You got lucky!", - "https://myplugin.com/badge.png", - "https://myplugin.com/\$user/\$pkg_name.jl", - )), - ] - else - String[] - end - end -end + source(::BasicPlugin) -> Union{String, Nothing} -interactive(:Type{MyPlugin}) = MyPlugin() -``` +Return the path to a plugin's configuration file template, or `nothing` to indicate no file. +""" +source(::BasicPlugin) = nothing -This plugin doesn't do much, but it demonstrates how [`gen_plugin`](@ref), [`badges`](@ref) -and [`interactive`](@ref) can be implemented using [`substitute`](@ref), -[`gen_file`](@ref), [`Badge`](@ref), and [`format`](@ref). +""" + destination(::BasicPlugin) -> String -# Defining Template Files -Often, the contents of the config file that your plugin generates depends on variables like -the package name, the user's username, etc. Template files (which are stored in `defaults`) -can use [here](https://github.com/jverzani/Mustache.jl)'s syntax to define replacements. +Return the destination, relative to the package root, of a plugin's configuration file. """ -abstract type CustomPlugin <: Plugin end +function destination end """ Badge(hover::AbstractString, image::AbstractString, link::AbstractString) -> Badge -A `Badge` contains the data necessary to generate a Markdown badge. +Container for Markdown badge data. +Each argument can contain placeholders. -# Arguments +## Arguments * `hover::AbstractString`: Text to appear when the mouse is hovered over the badge. * `image::AbstractString`: URL to the image to display. * `link::AbstractString`: URL to go to upon clicking the badge. @@ -158,89 +56,70 @@ struct Badge link::String end -""" - format(b::Badge) -> String +Base.string(b::Badge) = "[![$(b.hover)]($(b.image))]($(b.link))" -Return `badge`'s data formatted as a Markdown string. -""" -format(b::Badge) = "[![$(b.hover)]($(b.image))]($(b.link))" +# Format a plugin's badges as a list of strings, with all substitutions applied. +function badges(p::Plugin, t::Template, pkg_name::AbstractString) + bs = badges(p) + bs isa Vector || (bs = [bs]) + bs = map(string, bs) + # TODO render +end """ - gen_plugin(p::Plugin, t::Template, pkg_name::AbstractString) -> Vector{String} + gen_plugin(p::Plugin, t::Template, pkg::AbstractString) -> Nothing Generate any files associated with a plugin. -# Arguments +## Arguments * `p::Plugin`: Plugin whose files are being generated. * `t::Template`: Template configuration. -* `pkg_name::AbstractString`: Name of the package. - -Returns an array of generated file/directory names. -""" -gen_plugin(::Plugin, ::Template, ::AbstractString) = String[] - -function gen_plugin(p::GenericPlugin, t::Template, pkg_name::AbstractString) - if p.src === nothing - return String[] - end - text = substitute( - read(p.src, String), - t; - view=merge(Dict("PKGNAME" => pkg_name), p.view), - ) - gen_file(joinpath(t.dir, pkg_name, p.dest), text) - return [p.dest] +* `pkg::AbstractString`: Name of the package. +""" +gen_plugin(::Plugin, ::Template, ::AbstractString) = nothing + +function gen_plugin(p::BasicPlugin, t::Template, pkg::AbstractString) + source(p) === nothing && return + text = render(source(p), view(p, t, pkg); tags=tags(p)) + gen_file(joinpath(t.dir, pkg_name, destination(p)), text) end """ - badges(p::Plugin, user::AbstractString, pkg_name::AbstractString) -> Vector{String} + gen_file(file::AbstractString, text::AbstractString) -> Int -Generate Markdown badges for the plugin. +Create a new file containing some given text. +Trailing whitespace is removed, and the file will end with a newline. +""" +function gen_file(file::AbstractString, text::AbstractString) + mkpath(dirname(file)) + text = join(map(rstrip, split(text, "\n")), "\n") + endswith(text , "\n") || (text *= "\n") + write(file, text) +end -# Arguments -* `p::Plugin`: Plugin whose badges we are generating. -* `user::AbstractString`: Username of the package creator. -* `pkg_name::AbstractString`: Name of the package. +render_file(file::AbstractString, view, tags) = render_text(read(file, String), view, tags) -Returns an array of Markdown badges. -""" -badges(::Plugin, ::AbstractString, ::AbstractString) = String[] +render_text(text::AbstractString, view, tags) = render(text, view; tags=tags) -function badges(p::GenericPlugin, user::AbstractString, pkg_name::AbstractString) - # Give higher priority to replacements defined in the plugin's view. - view = merge(Dict("USER" => user, "PKGNAME" => pkg_name), p.view) - return map(b -> substitute(format(b), view), p.badges) +function render_badges(p::BasicPlugin, t::Template, pkg::AbstractString) end -""" - interactive(T::Type{<:Plugin}; file::Union{AbstractString, Nothing}="") -> Plugin - -Interactively create a plugin of type `T`, where `file` is the plugin type's default -config template with a non-standard name (for `MyPlugin`, this is anything but -"myplugin.yml"). -""" -function interactive(T::Type{<:GenericPlugin}; file::Union{AbstractString, Nothing}="") - name = string(nameof(T)) - # By default, we expect the default plugin file template for a plugin called - # "MyPlugin" to be called "myplugin.yml". - fn = file != nothing && isempty(file) ? "$(lowercase(name)).yml" : file - default_config_file = fn == nothing ? fn : joinpath(DEFAULTS_DIR, fn) - - print("$name: Enter the config template filename (\"None\" for no file) ") - if default_config_file == nothing - print("[None]: ") - else - print("[", replace(default_config_file, homedir() => "~"), "]: ") - end - - config_file = readline() - config_file = if uppercase(config_file) == "NONE" - nothing - elseif isempty(config_file) - default_config_file - else - config_file - end - - return T(; config_file=config_file) +function render_plugin(p::BasicPlugin, t::Template, pkg::AbstractString) + render_file(source(p), view(p, t, pkg), tags(p)) end + +include(joinpath("plugins", "essentials.jl")) +include(joinpath("plugins", "coverage.jl")) +include(joinpath("plugins", "ci.jl")) +include(joinpath("plugins", "citation.jl")) +include(joinpath("plugins", "documenter.jl")) + +const BADGE_ORDER = [ + Documenter{GitLabCI}, + Documenter{TravisCI}, + TravisCI, + AppVeyor, + GitLabCI, + Codecov, + Coveralls, +] diff --git a/src/plugins/appveyor.jl b/src/plugins/appveyor.jl deleted file mode 100644 index 7b42767b..00000000 --- a/src/plugins/appveyor.jl +++ /dev/null @@ -1,42 +0,0 @@ -""" - AppVeyor(; config_file::Union{AbstractString, Nothing}="") -> AppVeyor - -Add `AppVeyor` to a template's plugins to add a `.appveyor.yml` configuration file to -generated repositories, and an appropriate badge to the README. - -# Keyword Arguments -* `config_file::Union{AbstractString, Nothing}=""`: Path to a custom `.appveyor.yml`. - If `nothing` is supplied, no file will be generated. -""" -struct AppVeyor <: GenericPlugin - gitignore::Vector{String} - src::Union{String, Nothing} - dest::String - badges::Vector{Badge} - view::Dict{String, Any} - - function AppVeyor(; config_file::Union{AbstractString, Nothing}="") - if config_file != nothing - config_file = if isempty(config_file) - config_file = joinpath(DEFAULTS_DIR, "appveyor.yml") - elseif isfile(config_file) - abspath(config_file) - else - throw(ArgumentError("File $(abspath(config_file)) does not exist")) - end - end - new( - [], - config_file, - ".appveyor.yml", - [ - Badge( - "Build Status", - "https://ci.appveyor.com/api/projects/status/github/{{USER}}/{{PKGNAME}}.jl?svg=true", - "https://ci.appveyor.com/project/{{USER}}/{{PKGNAME}}-jl", - ) - ], - Dict{String, Any}(), - ) - end -end diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl new file mode 100644 index 00000000..0fde8a22 --- /dev/null +++ b/src/plugins/ci.jl @@ -0,0 +1,140 @@ +const DEFAULT_CI_VERSIONS = ["1.0", "nightly"] +const VersionsOrStrings = Vector{Union{VersionNumber, String}} + +format_version(v::VersionNumber) = "$(v.major).$(v.minor)" + +function collect_versions(versions::Vector, t::Template) + return unique(sort([versions; format_version(t.julia_version)]; by=string)) +end + +abstract type CI <: Plugin end + +@kwdef struct TravisCI <: CI + file::String = default_file("travis.yml") + linux::Bool = true + osx::Bool = true + windows::Bool = true + x86::Bool = false + coverage::Bool = true + extra_versions::VersionsOrStrings = DEFAULT_CI_VERSIONS +end + +source(p::TravisCI) = p.file +destination(::TravisCI) = ".travis.yml" + +badges(::TravisCI) = Badge( + "Build Status", + "https://travis-ci.com/{{USER}}/{{PKG}}.jl.svg?branch=master", + "https://travis-ci.com/{{USER}}/{{PKG}}.jl", +) + +function view(p::TravisCI, t::Template, ::AbstractString) + jobs = Dict{String, String}[] + for v in collect_versions(p.extra_versions, t) + p.linux && push!(jobs, Dict("JULIA" => v, "OS" => "linux", "ARCH" => "x64")) + p.linux && p.x86 && push!(jobs, Dict("JULIA" => v, "OS" => "linux", "ARCH" => "x86")) + p.osx && push!(jobs, Dict("JULIA" => v, "OS" => "osx")) + p.windows && push!(jobs, Dict("JULIA" => v, "OS" => "windows", "ARCH" => "x64")) + p.windows && p.x86 && push!(jobs, Dict("JULIA" => v, "OS" => "windows", "ARCH" => "x86")) + end + return Dict( + "HAS_CODECOV" => hasplugin(t, Codecov), + "HAS_COVERAGE" => p.coverage && hasplugin(t, Coverage), + "HAS_COVERALLS" => hasplugin(t, Coveralls), + "HAS_DOCUMENTER" => hasplugin(t, Documenter{TravisCI}), + "HAS_NIGHTLY" => "nightly" in versions, + "PKG" => pkg, + "VERSION" => format_version(t.julia_version), + ) +end + +@kwdef struct AppVeyor <: CI + file::String = default_file("appveyor.yml") + x86::Bool = false + coverage::Bool = true + extra_versions::VersionsOrStrings = DEFAULT_CI_VERSIONS +end + +source(p::AppVeyor) = p.file +destination(::AppVeyor) = ".appveyor.yml" + +badges(::AppVeyor) = Badge( + "Build Status", + "https://ci.appveyor.com/api/projects/status/github/{{USER}}/{{PKG}}.jl?svg=true", + "https://ci.appveyor.com/project/{{USER}}/{{PKG}}-jl", +) + +function view(p::AppVeyor, t::Template, ::AbstractString) + platforms = ["x64"] + t.x86 && push!(platforms, "x86") + return Dict( + "HAS_CODECOV" => t.coverage && hasplugin(t, Codecov), + "HAS_NIGHTLY" => "nightly" in versions, + "PKG" => pkg, + "PLATFORMS" => os, + "VERSIONS" => collect_versions(p.extra_versions, t), + ) +end + +@kwdef struct CirrusCI <: CI + file::String = default_file("cirrus.yml") + image::String = "freebsd-12-0-release-amd64" + coverage::Bool = true + extra_versions::VersionsOrStrings = DEFAULT_CI_VERSIONS +end + +source(p::CirrusCI) = p.file +destination(::CirrusCI) = ".cirrus.yml" + +badges(::CirrusCI) = Badge( + "Build Status", + "https://api.cirrus-ci.com/github/{{USER}}/{{PACKAGE}}.jl.svg", + "https://cirrus-ci.com/github/{{USER}}/{{PKG}}.jl", +) + +function view(p::CirrusCI, t::Template, ::AbstractString) + return Dict( + "HAS_CODECOV" => hasplugin(t, Codecov), + "HAS_COVERALLS" => hasplugin(t, Coveralls), + "HAS_COVERAGE" => p.coverage && hasplugin(t, Coverage), + "IMAGE" => p.image, + "PKG" => pkg, + "VERSIONS" => collect_versions(p.extra_versions, t), + ) +end + +@kwdef struct GitLabCI <: CI + file::String + documentation::Bool = true + coverage::Bool = true + extra_versions::Vector{VersionNumber} = [v"1.0"] +end + +gitignore(p::GitLabCI) = p.coverage ? COVERAGE_GITIGNORE : String[] + +source(p::GitLabCI) = p.source +destination(::GitLabCI) = ".gitlab-ci.yml" + +function badges(p::GitLabCI) + ci = Badge( + "Build Status", + "https://gitlab.com/{{USER}}/{{PKG}}.jl/badges/master/build.svg", + "https://gitlab.com/{{USER}}/{{PKG}}.jl/pipelines", + ) + cov = Badge( + "Coverage", + "https://gitlab.com/{{USER}}/{{PKG}}.jl/badges/master/coverage.svg", + "https://gitlab.com/{{USER}}/{{PKG}}.jl/commits/master", + ) + return p.coverage ? [ci, cov] : [ci] +end + +function view(p::GitLabCI, t::Template, ::AbstractString) + return Dict( + "HAS_COVERAGE" => p.coverage, + "HAS_DOCUMENTER" => hasplugin(t, Documenter{GitLabCI}), + "PKG" => pkg, + "VERSION" => format_version(t.julia_version), + "VERSIONS" => collect_versions(p.extra_versions, t), + ) +end diff --git a/src/plugins/cirrusci.jl b/src/plugins/cirrusci.jl deleted file mode 100644 index 7daca529..00000000 --- a/src/plugins/cirrusci.jl +++ /dev/null @@ -1,45 +0,0 @@ -""" - CirrusCI(; config_file::Union{AbstractString, Nothing}="") -> CirrusCI - -Add `CirrusCI` to a template's plugins to add a `.cirrus.yml` configuration file to -generated repositories, and an appropriate badge to the README. The default configuration -file supports only FreeBSD builds via [CirrusCI.jl](https://github.com/ararslan/CirrusCI.jl) - -# Keyword Arguments -* `config_file::Union{AbstractString, Nothing}=""`: Path to a custom `.cirrus.yml`. - If `nothing` is supplied, no file will be generated. -""" -struct CirrusCI <: GenericPlugin - gitignore::Vector{String} - src::Union{String, Nothing} - dest::String - badges::Vector{Badge} - view::Dict{String, Any} - - function CirrusCI(; config_file::Union{AbstractString, Nothing}="") - if config_file !== nothing - config_file = if isempty(config_file) - joinpath(DEFAULTS_DIR, "cirrus.yml") - elseif isfile(config_file) - abspath(config_file) - else - throw(ArgumentError("File $(abspath(config_file)) does not exist")) - end - end - return new( - [], - config_file, - ".cirrus.yml", - [ - Badge( - "Build Status", - "https://api.cirrus-ci.com/github/{{USER}}/{{PKGNAME}}.jl.svg", - "https://cirrus-ci.com/github/{{USER}}/{{PKGNAME}}.jl", - ), - ], - Dict{String, Any}(), - ) - end -end - -interactive(::Type{CirrusCI}) = interactive(CirrusCI; file="cirrus.yml") diff --git a/src/plugins/citation.jl b/src/plugins/citation.jl index 761a493c..34365d50 100644 --- a/src/plugins/citation.jl +++ b/src/plugins/citation.jl @@ -1,50 +1,28 @@ """ - Citation(; readme_section::Bool=false) + Citation(; readme_section::Bool=false) -> Citation -Add `Citation` to a template's plugins to add a `CITATION.bib` file to -generated repositories, and an appropriate section in the README. - -# Keyword Arguments: -* `readme_section::Bool=false`: whether to add a section in the readme pointing to `CITATION.bib`. +Add `Citation` to a [`Template`](@ref)'s plugin list to generate a `CITATION.bib` file. +If `readme` is set, then `README.md` will contain a section about citing. """ -struct Citation <: GenericPlugin - gitignore::Vector{AbstractString} - src::Union{String, Nothing} - dest::AbstractString - badges::Vector{Badge} - view::Dict{String, Any} - readme_section::Bool - function Citation(; readme_section::Bool=false) - new( - [], - nothing, - "CITATION.bib", - [], - Dict{String, Any}(), - readme_section, - ) - end +@kwdef struct Citation <: BasicPlugin + file::String = default_file("CITATION.bib") + readme::Bool = false end -function interactive(::Type{Citation}) - print("Citation: Add a section to README.md mentioning CITATION.bib? [no]: ") - readme = uppercase(readline()) in ["Y", "YES", "TRUE"] - return Citation(; readme_section=readme) -end +tags(::Citation) = "<<", ">>" +source(p::Citation) = p.file +destination(::Citation) = "CITATION.bib" -function gen_plugin(p::Citation, t::Template, pkg_name::AbstractString) - pkg_dir = joinpath(t.dir, pkg_name) - text = """ - @misc{$pkg_name.jl, - \tauthor = {$(t.authors)}, - \ttitle = {{$(pkg_name).jl}}, - \turl = {https://$(t.host)/$(t.user)/$(pkg_name).jl}, - \tversion = {v0.1.0}, - \tyear = {$(year(today()))}, - \tmonth = {$(month(today()))} - } - """ - gen_file(joinpath(pkg_dir, "CITATION.bib"), text) - return ["CITATION.bib"] +view(::Citation, t::Template, pkg::AbstractString) = Dict( + "AUTHORS" => t.authors, + "MONTH" => month(today()), + "PKG" => pkg, + "URL" => "https://$(t.host)/$(t.user)/$pkg.jl", + "YEAR" => year(today()), +) + +function interactive(::Type{Citation}) + readme = prompt_bool("Citation: Add a section to the README", false) + return Citation(; readme_section=readme) end diff --git a/src/plugins/codecov.jl b/src/plugins/codecov.jl deleted file mode 100644 index 7865c3d4..00000000 --- a/src/plugins/codecov.jl +++ /dev/null @@ -1,44 +0,0 @@ -""" - Codecov(; config_file::Union{AbstractString, Nothing}=nothing) -> Codecov - -Add `Codecov` to a template's plugins to optionally add a `.codecov.yml` configuration file -to generated repositories, and an appropriate badge to the README. Also updates the -`.gitignore` accordingly. - -# Keyword Arguments: -* `config_file::Union{AbstractString, Nothing}=nothing`: Path to a custom `.codecov.yml`. - If left unset, no file will be generated. -""" -struct Codecov <: GenericPlugin - gitignore::Vector{String} - src::Union{String, Nothing} - dest::String - badges::Vector{Badge} - view::Dict{String, Any} - - function Codecov(; config_file::Union{AbstractString, Nothing}=nothing) - if config_file != nothing - config_file = if isfile(config_file) - abspath(config_file) - else - throw(ArgumentError("File $(abspath(config_file)) does not exist")) - end - end - new( - ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"], - config_file, - ".codecov.yml", - [ - Badge( - "Codecov", - "https://codecov.io/gh/{{USER}}/{{PKGNAME}}.jl/branch/master/graph/badge.svg", - "https://codecov.io/gh/{{USER}}/{{PKGNAME}}.jl", - ), - ], - Dict{String, Any}(), - ) - end -end -Base.@deprecate_binding CodeCov Codecov - -interactive(::Type{Codecov}) = interactive(Codecov; file=nothing) diff --git a/src/plugins/coverage.jl b/src/plugins/coverage.jl new file mode 100644 index 00000000..25cf03f4 --- /dev/null +++ b/src/plugins/coverage.jl @@ -0,0 +1,31 @@ +abstract type Coverage <: Plugin end + +const COVERAGE_GITIGNORE = ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] + +gitignore(::Coverage) = COVERAGE_GITIGNORE + +@kwdef struct Codecov <: Coverage + file::Union{String, Nothing} = nothing +end + +source(p::Codecov) = p.file +destination(::Codecov) = ".codecov.yml" + +badges(::Codecov) = Badge( + "Coverage", + "https://codecov.io/gh/{{USER}}/{{PKG}}.jl/branch/master/graph/badge.svg", + "https://codecov.io/gh/{{USER}}/{{PKG}}.jl", +) + +@kwdef struct Coveralls <: Coverage + file::Union{String, Nothing} = nothing +end + +source(p::Coveralls) = p.file +destination(::Coveralls) = ".coveralls.yml" + +badges(::Coveralls) = Badge( + "Coverage", + "https://coveralls.io/repos/github/{{USER}}/{{PKG}}.jl/badge.svg?branch=master", + "https://coveralls.io/github/{{USER}}/{{PKG}}.jl?branch=master", +) diff --git a/src/plugins/coveralls.jl b/src/plugins/coveralls.jl deleted file mode 100644 index 8be6392e..00000000 --- a/src/plugins/coveralls.jl +++ /dev/null @@ -1,43 +0,0 @@ -""" - Coveralls(; config_file::Union{AbstractString, Nothing}=nothing) -> Coveralls - -Add `Coveralls` to a template's plugins to optionally add a `.coveralls.yml` configuration -file to generated repositories, and an appropriate badge to the README. Also updates the -`.gitignore` accordingly. - -# Keyword Arguments: -* `config_file::Union{AbstractString, Nothing}=nothing`: Path to a custom `.coveralls.yml`. - If left unset, no file will be generated. -""" -struct Coveralls <: GenericPlugin - gitignore::Vector{String} - src::Union{String, Nothing} - dest::String - badges::Vector{Badge} - view::Dict{String, Any} - - function Coveralls(; config_file::Union{AbstractString, Nothing}=nothing) - if config_file != nothing - config_file = if isfile(config_file) - abspath(config_file) - else - throw(ArgumentError("File $(abspath(config_file)) does not exist")) - end - end - new( - ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"], - config_file, - ".coveralls.yml", - [ - Badge( - "Coveralls", - "https://coveralls.io/repos/github/{{USER}}/{{PKGNAME}}.jl/badge.svg?branch=master", - "https://coveralls.io/github/{{USER}}/{{PKGNAME}}.jl?branch=master", - ), - ], - Dict{String, Any}(), - ) - end -end - -interactive(::Type{Coveralls}) = interactive(Coveralls; file=nothing) diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index c8b3195a..5b6c0196 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -1,31 +1,85 @@ const DOCUMENTER_UUID = "e30172f5-a6a5-5a46-863b-614d45cd2de4" -const STANDARD_KWS = [:modules, :format, :pages, :repo, :sitename, :authors, :assets] """ -Add a `Documenter` subtype to a template's plugins to add support for documentation -generation via [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl). - -By default, the plugin generates a minimal index.md and a make.jl file. The make.jl -file contains the Documenter.makedocs command with predefined values for `modules`, -`format`, `pages`, `repo`, `sitename`, and `authors`. - -The subtype is expected to include the following fields: -* `assets::Vector{AbstractString}`, a list of filenames to be included as the `assets` -kwarg to `makedocs` -* `gitignore::Vector{AbstractString}`, a list of files to be added to the `.gitignore` - -It may optionally include the field `additional_kwargs::Union{AbstractDict, NamedTuple}` -to allow additional kwargs to be added to `makedocs`. + Documenter{T<:Union{TravisCI, GitLabCI, Nothing}}(; + assets::Vector{<:AbstractString}=String[], + makedocs_kwargs::Dict{Symbol}=Dict(), + canonical_url::Union{Function, Nothing}=nothing, + ) -> Documenter{T} + +The `Documenter` plugin adds support for documentation generation via [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl). +Documentation deployment depends on `T`, where `T` is some supported CI plugin, or `Nothing` to only support local documentation builds. + +## Keyword Arguments +todo +- `assets::Vector{<:AbstractString}=String[]`: +- `makedocs_kwargs::Dict{Symbol}=Dict{Symbol, Any}()`: +- `canonical_url::Union{Function, Nothing}=nothing`:` + +!!! note + If deploying documentation with Travis CI, don't forget to complete the required configuration. + See [here](https://juliadocs.github.io/Documenter.jl/stable/man/hosting/#SSH-Deploy-Keys-1). """ -abstract type Documenter <: CustomPlugin end +struct Documenter{T<:Union{TravisCI, GitLabCI, Nothing}} <: Plugin + assets::Vector{String} + makedocs_kwargs::Dict{Symbol} + canonical_url::Union{Function, Nothing} + + # Can't use @kwdef due to some weird precompilation issues. + function Documenter{T}( + assets::Vector{<:AbstractString}=String[], + makedocs_kwargs::Dict{Symbol}=Dict{Symbol, Any}(), + canonical_url::Union{Function, Nothing}=T === TravisCI ? github_pages_url : nothing, + ) where T <: Union{TravisCI, GitLabCI, Nothing} + return new(assets, makedocs_kwargs, canonical_url) + end +end + +Documenter(; kwargs...) = Documenter{Nothing}(; kwargs...) + +gitignore(::Documenter) = ["/docs/build/", "/docs/site/"] + +badges(::Documenter) = Badge[] +badges(::Documenter{TravisCI}) = [ + Badge( + "Stable", + "https://img.shields.io/badge/docs-stable-blue.svg", + "https://{{USER}}.github.io/{{PKG}}.jl/stable", + ), + Badge( + "Dev", + "https://img.shields.io/badge/docs-dev-blue.svg", + "https://{{USER}}.github.io/{{PKG}}.jl/dev", + ), +] +badges(::Documenter{GitLabCI}) = Badge( + "Dev", + "https://img.shields.io/badge/docs-dev-blue.svg", + "https://{{USER}}.gitlab.io/{{PKG}}.jl/dev", +) + +view(p::Documenter, t::Template, pkg::AbstractString) = Dict( + "ASSETS" => p.assets, + "AUTHORS" => t.authors, + "CANONICAL" => p.canonical_url === nothing ? nothing : p.canonical_url(t, pkg), + "HAS_ASSETS" => !isempty(p.assets), + "MAKEDOCS_KWARGS" => map((k, v) -> k => repr(v), collect(p.makedocs_kwargs)), + "PKG" => pkg, + "REPO" => "https://$(t.host)/$(t.user)/$pkg.jl", +) + +function view(p::Documenter{TravisCI}, t::Template, pkg::AbstractString) + base = invoke(view, Tuple{Documenter, Template, AbstractString}, p, t, pkg) + return merge(base, Dict("HAS_DEPLOY" => true)) +end -function gen_plugin(p::Documenter, t::Template, pkg_name::AbstractString) - path = joinpath(t.dir, pkg_name) - docs_dir = joinpath(path, "docs") - mkpath(docs_dir) +function gen_plugin(p::Documenter, t::Template, pkg_dir::AbstractString) + # TODO: gen make.jl + # TODO: gen index.md # Create the documentation project. - proj = Base.current_project() + docs_dir = joinpath(pkg_dir, "docs") + proj = current_project() try Pkg.activate(docs_dir) Pkg.add(PackageSpec(; name="Documenter", uuid=DOCUMENTER_UUID)) @@ -33,95 +87,38 @@ function gen_plugin(p::Documenter, t::Template, pkg_name::AbstractString) proj === nothing ? Pkg.activate() : Pkg.activate(proj) end - tab = repeat(" ", 4) - assets_string = if !isempty(p.assets) - mkpath(joinpath(docs_dir, "src", "assets")) - for file in p.assets - cp(file, joinpath(docs_dir, "src", "assets", basename(file))) - end - - # We want something that looks like the following: - # [ - # assets/file1, - # assets/file2, - # ] - s = "[\n" - for asset in p.assets - s *= """$(tab^2)"assets/$(basename(asset))",\n""" - end - s *= "$tab]" - - s - else - "String[]" - end + # Copy any assets. + assets_dir = joinpath(docs_dir, "src", "assets") + isempty(p.assets) || mkpath(assets_dir) + foreach(a -> cp(a, joinpath(assets_dir, basename(asset))), p.assets) +end - kwargs_string = if :additional_kwargs in fieldnames(typeof(p)) && - fieldtype(typeof(p), :additional_kwargs) <: Union{AbstractDict, NamedTuple} - # We want something that looks like the following: - # key1="val1", - # key2="val2", - # - kws = [keys(p.additional_kwargs)...] - valid_keys = filter(k -> !in(Symbol(k), STANDARD_KWS), kws) - if length(p.additional_kwargs) > length(valid_keys) - invalid_keys = filter(k -> Symbol(k) in STANDARD_KWS, kws) - @warn string( - "Ignoring predefined Documenter kwargs ", - join(map(repr, invalid_keys), ", "), - " from additional kwargs" - ) - end - join(map(k -> string(tab, k, "=", repr(p.additional_kwargs[k]), ",\n"), valid_keys)) - else - "" - end +function interactive(::Type{Documenter{T}}) where T + name = "Documenter{$T}" - make = """ - using Documenter, $pkg_name - - makedocs(; - modules=[$pkg_name], - format=Documenter.HTML(), - pages=[ - "Home" => "index.md", - ], - repo="https://$(t.host)/$(t.user)/$pkg_name.jl/blob/{commit}{path}#L{line}", - sitename="$pkg_name.jl", - authors="$(t.authors)", - assets=$assets_string, - $kwargs_string) - """ - docs = """ - # $pkg_name.jl - - ```@index - ``` - - ```@autodocs - Modules = [$pkg_name] - ``` - """ - - gen_file(joinpath(docs_dir, "make.jl"), make) - gen_file(joinpath(docs_dir, "src", "index.md"), docs) -end + print("$name: Enter any Documenter asset files (separated by spaces) [none]: ") + assets = split(readline()) -function Base.show(io::IO, p::Documenter) - spc = " " - println(io, nameof(typeof(p)), ":") - - n = length(p.assets) - s = n == 1 ? "" : "s" - print(io, spc, "→ $n asset file$s") - if n == 0 - println(io) - else - println(io, ": ", join(map(a -> replace(a, homedir() => "~"), p.assets), ", ")) + print("$name: Enter any extra makedocs key-value pairs (joined by '=') [none]\n> ") + kwargs = Dict{Symbol, Any}() + line = map(split(readline())) do kv + k, v = split(kv, "="; limit=2) + kwargs[Symbol(k)] = eval(Meta.parse(v)) end - n = length(p.gitignore) - s = n == 1 ? "" : "s" - print(io, "$spc→ $n gitignore entrie$s") - n > 0 && print(io, ": ", join(map(repr, p.gitignore), ", ")) + return Documenter{T}(; assets=assets, kwargs=kwargs) end + +function interactive(::Type{Documenter}) + types = Dict( + "None (local documentation only)" => Nothing, + "TravisCI (GitHub Pages)" => TravisCI, + "GitLabCI (GitLab Pages)" => GitLabCI, + ) + options = collect(keys(types)) + menu = RadioMenu(options) + T = types[options[request("Documenter: Select integration:", menu)]] + return interactive(Documenter{T}) +end + +github_pages_url(t::Template, pkg::AbstractString) = "https://$(t.user).github.io/$pkg.jl" diff --git a/src/plugins/essentials.jl b/src/plugins/essentials.jl new file mode 100644 index 00000000..49741e05 --- /dev/null +++ b/src/plugins/essentials.jl @@ -0,0 +1,115 @@ +const LICENSE_DIR = normpath(joinpath(@__DIR__, "..", "..", "licenses")) +const LICENSES = Dict( + "MIT" => "MIT \"Expat\" License", + "BSD2" => "Simplified \"2-clause\" BSD License", + "BSD3" => "Modified \"3-clause\" BSD License", + "ISC" => "Internet Systems Consortium License", + "ASL" => "Apache License, Version 2.0", + "MPL" => "Mozilla Public License, Version 2.0", + "GPL-2.0+" => "GNU Public License, Version 2.0+", + "GPL-3.0+" => "GNU Public License, Version 3.0+", + "LGPL-2.1+" => "Lesser GNU Public License, Version 2.1+", + "LGPL-3.0+" => "Lesser GNU Public License, Version 3.0+", + "EUPL-1.2+" => "European Union Public Licence, Version 1.2+", +) + +@kwdef struct Readme <: BasicPlugin + file::String = default_file("README.md") + destination::String = "README.md" + inline_badges::Bool = false +end + +source(p::Readme) = p.file +destination(p::Readme) = p.destination + +function view(::Readme, t::Template, pkg::AbstractString) + # Explicitly ordered badges go first. + strings = String[] + done = DataType[] + foreach(BADGE_ORDER) do T + if hasplugin(t, T) + bs = badges(t.plugins[T], t, pkg) + append!(strings, badges(t.plugins[T], t, pkg)) + push!(done, T) + end + end + foreach(setdiff(keys(t.plugins), done)) do T + bs = badges(t.plugins[T], t, pkg) + text *= "\n" * join(badges(t.plugins[T], t.user, pkg), "\n") + end + + return Dict( + "HAS_CITATION" => hasplugin(t, Citation), + "HAS_INLINE_BADGES" => p.inline_badges, + ) +end + +struct License <: Plugin + path::String + destination::String + + function License(name::AbstractString="MIT", destination::AbstractString="LICENSE") + return new(license_path(name), destination) + end +end + +function license_path(license::AbstractString) + path = joinpath(LICENSE_DIR, license) + isfile(path) || throw(ArgumentError("License '$license' is not available")) + return path +end + +read_license(license::AbstractString) = string(readchomp(license_path(license))) + +function render_plugin(p::License, t::Template) + text = "Copyright (c) $(year(today())) $(t.authors)\n" + license = read(p.path, String) + startswith(license, "\n") || (text *= "\n") + return text * license +end + +function gen_plugin(p::License, t::Template, pkg_dir::AbstractString) + gen_file(joinpath(pkg_dir, p.destination), render_plugin(p, t)) +end + +struct Gitignore <: Plugin end + +function render_plugin(p::Gitignore, t::Template) + entries = mapreduce(gitignore, append!, values(t.plugins); init=[".DS_Store", "/dev/"]) + # Only ignore manifests at the repo root. + t.manifest || "Manifest.toml" in entries || push!(entries, "/Manifest.toml") + unique!(sort!(entries)) + return join(entries, "\n") +end + +function gen_plugin(p::Gitignore, t::Template, pkg_dir::AbstractString) + gen_file(joinpath(pkg_dir, ".gitignore"), render_plugin(p, t)) +end + +@kwdef struct Tests <: BasicPlugin + file::String = default_file("runtests.jl") +end + +source(p::Tests) = p.file +destination(::Tests) = joinpath("test", "runtests.jl") +view(::Tests, ::Template, pkg::AbstractString) = Dict("PKG" => pkg) + +function gen_plugin(p::Tests, t::Template, pkg_dir::AbstractString) + # Do the normal BasicPlugin behaviour to create the test script. + invoke(gen_plugin, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) + + # Add the Test dependency as a test-only dependency. + # To avoid visual noise from adding/removing the dependency, insert it manually. + proj = current_project() + try + Pkg.activate(pkg_dir) + lines = readlines(joinpath(pkg_dir, "Project.toml")) + dep = "Test = $(repr(TEST_UUID))" + push!(lines, "[extras]", dep, "", "[targets]", "test = [\"Test\"]") + gen_file(joinpath(pkg_dir, "Project.toml"), join(lines, "\n")) + touch(joinpath(pkg_dir, "Manifest.toml")) # File must exist to be modified by Pkg. + Pkg.update() # Clean up both Manifest.toml and Project.toml. + finally + proj === nothing ? Pkg.activate() : Pkg.activate(proj) + end +end diff --git a/src/plugins/githubpages.jl b/src/plugins/githubpages.jl deleted file mode 100644 index 10a28a93..00000000 --- a/src/plugins/githubpages.jl +++ /dev/null @@ -1,69 +0,0 @@ -""" - GitHubPages(; assets::Vector{<:AbstractString}=String[]) -> GitHubPages - -Add `GitHubPages` to a template's plugins to add [`Documenter`](@ref) support via GitHub -Pages, including automatic uploading of documentation from [`TravisCI`](@ref). Also -adds appropriate badges to the README, and updates the `.gitignore` accordingly. - -# Keyword Arguments -* `assets::Vector{<:AbstractString}=String[]`: Array of paths to Documenter asset files. - -!!! note - If deploying documentation with Travis CI, don't forget to complete the required - configuration (see - [here](https://juliadocs.github.io/Documenter.jl/stable/man/hosting/#SSH-Deploy-Keys-1)). -""" -struct GitHubPages <: Documenter - gitignore::Vector{String} - assets::Vector{String} - - function GitHubPages(; assets::Vector{<:AbstractString}=String[]) - for file in assets - if !isfile(file) - throw(ArgumentError("Asset file $(abspath(file)) does not exist")) - end - end - # Windows Git recognizes these paths as well. - new(["/docs/build/", "/docs/site/"], abspath.(assets)) - end -end - -function badges(::GitHubPages, user::AbstractString, pkg_name::AbstractString) - return [ - format(Badge( - "Stable", - "https://img.shields.io/badge/docs-stable-blue.svg", - "https://$user.github.io/$pkg_name.jl/stable" - )), - format(Badge( - "Dev", - "https://img.shields.io/badge/docs-dev-blue.svg", - "https://$user.github.io/$pkg_name.jl/dev" - )), - ] -end - -function gen_plugin(p::GitHubPages, t::Template, pkg_name::AbstractString) - invoke(gen_plugin, Tuple{Documenter, Template, AbstractString}, p, t, pkg_name) - - if haskey(t.plugins, TravisCI) - docs_src = joinpath(t.dir, pkg_name, "docs", "src") - open(joinpath(dirname(docs_src), "make.jl"), "a") do file - write( - file, - """ - - deploydocs(; - repo="$(t.host)/$(t.user)/$pkg_name.jl", - ) - """ - ) - end - end - return ["docs/"] -end - -function interactive(::Type{GitHubPages}) - print("GitHubPages: Enter any Documenter asset files (separated by spaces) []: ") - return GitHubPages(; assets=string.(split(readline()))) -end diff --git a/src/plugins/gitlabci.jl b/src/plugins/gitlabci.jl deleted file mode 100644 index 4d2e1a2d..00000000 --- a/src/plugins/gitlabci.jl +++ /dev/null @@ -1,83 +0,0 @@ -""" - GitLabCI(; config_file::Union{AbstractString, Nothing}="", coverage::Bool=true) -> GitLabCI - -Add `GitLabCI` to a template's plugins to add a `.gitlab-ci.yml` configuration file to -generated repositories, and appropriate badge(s) to the README. - -# Keyword Arguments: -* `config_file::Union{AbstractString, Nothing}=""`: Path to a custom `.gitlab-ci.yml`. - If `nothing` is supplied, no file will be generated. -* `coverage::Bool=true`: Whether or not GitLab CI's built-in code coverage analysis should - be enabled. -""" -struct GitLabCI <: GenericPlugin - gitignore::Vector{String} - src::Union{String, Nothing} - dest::String - badges::Vector{Badge} - view::Dict{String, Any} - - function GitLabCI(; config_file::Union{AbstractString, Nothing}="", coverage::Bool=true) - if config_file != nothing - config_file = if isempty(config_file) - config_file = joinpath(DEFAULTS_DIR, "gitlab-ci.yml") - elseif isfile(config_file) - abspath(config_file) - else - throw(ArgumentError("File $(abspath(config_file)) does not exist")) - end - end - badges = [ - Badge( - "Build Status", - "https://gitlab.com/{{USER}}/{{PKGNAME}}.jl/badges/master/build.svg", - "https://gitlab.com/{{USER}}/{{PKGNAME}}.jl/pipelines", - ), - ] - if coverage - push!( - badges, - Badge( - "Coverage", - "https://gitlab.com/{{USER}}/{{PKGNAME}}.jl/badges/master/coverage.svg", - "https://gitlab.com/{{USER}}/{{PKGNAME}}.jl/commits/master", - ), - ) - end - - new( - coverage ? ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] : [], - config_file, - ".gitlab-ci.yml", - badges, - Dict("GITLABCOVERAGE" => coverage), - ) - end -end - -function interactive(::Type{GitLabCI}) - name = "GitLabCI" - kwargs = Dict{Symbol, Any}() - default_config_file = joinpath(DEFAULTS_DIR, "gitlab-ci.yml") - - print("$name: Enter the config template filename (\"None\" for no file) ") - print("[", replace(default_config_file, homedir() => "~"), "]: ") - config_file = readline() - kwargs[:config_file] = if uppercase(config_file) == "NONE" - nothing - elseif isempty(config_file) - default_config_file - else - config_file - end - - print("$name: Enable test coverage analysis? [yes]: ") - coverage = readline() - kwargs[:coverage] = if isempty(coverage) - true - else - !in(uppercase(coverage), ["N", "NO", "FALSE", "NONE"]) - end - - return GitLabCI(; kwargs...) -end diff --git a/src/plugins/gitlabpages.jl b/src/plugins/gitlabpages.jl deleted file mode 100644 index 3f2c0325..00000000 --- a/src/plugins/gitlabpages.jl +++ /dev/null @@ -1,47 +0,0 @@ -""" - GitLabPages(; assets::Vector{<:AbstractString}=String[]) -> GitLabPages - -Add `GitLabPages` to a template's plugins to add [`Documenter`](@ref) support via GitLab -Pages, including automatic uploading of documentation from [`GitLabCI`](@ref). Also -adds appropriate badges to the README, and updates the `.gitignore` accordingly. - -# Keyword Arguments -* `assets::Vector{<:AbstractString}=String[]`: Array of paths to Documenter asset files. -""" -struct GitLabPages <: Documenter - gitignore::Vector{String} - assets::Vector{String} - - function GitLabPages(; assets::Vector{<:AbstractString}=String[]) - for file in assets - if !isfile(file) - throw(ArgumentError("Asset file $(abspath(file)) does not exist")) - end - end - # Windows Git recognizes these paths as well. - new(["/docs/build/", "/docs/site/"], abspath.(assets)) - end -end - -function badges(::GitLabPages, user::AbstractString, pkg_name::AbstractString) - # We are only including a badge for `dev` documentation since versioned documentation - # is not supported in GitLab pages yet. See: - # https://github.com/invenia/PkgTemplates.jl/pull/54 - return [ - format(Badge( - "Dev", - "https://img.shields.io/badge/docs-dev-blue.svg", - "https://$user.gitlab.io/$pkg_name.jl/dev" - )), - ] -end - -function gen_plugin(p::GitLabPages, t::Template, pkg_name::AbstractString) - invoke(gen_plugin, Tuple{Documenter, Template, AbstractString}, p, t, pkg_name) - return ["docs/"] -end - -function interactive(::Type{GitLabPages}) - print("GitLabPages: Enter any Documenter asset files (separated by spaces) []: ") - return GitLabPages(; assets=string.(split(readline()))) -end diff --git a/src/plugins/travisci.jl b/src/plugins/travisci.jl deleted file mode 100644 index 2d3eb72e..00000000 --- a/src/plugins/travisci.jl +++ /dev/null @@ -1,44 +0,0 @@ -""" - TravisCI(; config_file::Union{AbstractString, Nothing}="") -> TravisCI - -Add `TravisCI` to a template's plugins to add a `.travis.yml` configuration file to -generated repositories, and an appropriate badge to the README. - -# Keyword Arguments: -* `config_file::Union{AbstractString, Nothing}=""`: Path to a custom `.travis.yml`. - If `nothing` is supplied, no file will be generated. -""" -struct TravisCI <: GenericPlugin - gitignore::Vector{String} - src::Union{String, Nothing} - dest::String - badges::Vector{Badge} - view::Dict{String, Any} - - function TravisCI(; config_file::Union{AbstractString, Nothing}="") - if config_file != nothing - config_file = if isempty(config_file) - config_file = joinpath(DEFAULTS_DIR, "travis.yml") - elseif isfile(config_file) - abspath(config_file) - else - throw(ArgumentError("File $(abspath(config_file)) does not exist")) - end - end - new( - [], - config_file, - ".travis.yml", - [ - Badge( - "Build Status", - "https://travis-ci.com/{{USER}}/{{PKGNAME}}.jl.svg?branch=master", - "https://travis-ci.com/{{USER}}/{{PKGNAME}}.jl", - ), - ], - Dict{String, Any}(), - ) - end -end - -interactive(::Type{TravisCI}) = interactive(TravisCI; file="travis.yml") diff --git a/src/template.jl b/src/template.jl index d26b371b..8fa59c75 100644 --- a/src/template.jl +++ b/src/template.jl @@ -1,242 +1,107 @@ default_version() = VersionNumber(VERSION.major) """ - Template(; kwargs...) -> Template - -Records common information used to generate a package. If you don't wish to manually -create a template, you can use [`interactive_template`](@ref) instead. - -# Keyword Arguments -* `user::AbstractString=""`: GitHub (or other code hosting service) username. If left - unset, it will take the the global git config's value (`github.user`). If that is not - set, an `ArgumentError` is thrown. **This is case-sensitive for some plugins, so take - care to enter it correctly.** -* `host::AbstractString="github.com"`: URL to the code hosting service where your package - will reside. Note that while hosts other than GitHub won't cause errors, they are not - officially supported and they will cause certain plugins will produce incorrect output. -* `license::AbstractString="MIT"`: Name of the package license. If an empty string is - given, no license is created. [`available_licenses`](@ref) can be used to list all - available licenses, and [`show_license`](@ref) can be used to print out a particular - license's text. -* `authors::Union{AbstractString, Vector{<:AbstractString}}=""`: Names that appear on the - license. Supply a string for one author or an array for multiple. Similarly to `user`, - 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=$(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. -* `dev::Bool=true`: Whether or not to `Pkg.develop` generated packages. -* `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. + Template(interactive::Bool=false; kwargs...) -> Template + +Records common information used to generate a package. + +## Keyword Arguments +- `user::AbstractString=""`: GitHub (or other code hosting service) username. + If left unset, it will take the the global Git config's value (`github.user`). + If that is not set, an `ArgumentError` is thrown. + This is case-sensitive for some plugins, so take care to enter it correctly! +- `host::AbstractString="github.com"`: URL to the code hosting service where your package will reside. + Note that while hosts other than GitHub won't cause errors, they are not officially supported and they will cause certain plugins will produce incorrect output. +- `authors::Union{AbstractString, Vector{<:AbstractString}}=""`: Names that appear on the license. + Supply a string for one author or an array for multiple. + Similarly to `user`, it will take the value of of the global Git config's value if it is left unset. +- `dir::AbstractString=$(contractuser(Pkg.devdir()))`: Directory in which the package will go. + Relative paths are converted to absolute ones at template creation time. +- `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`. +- `git::Bool=true`: Whether or not to create a Git repository for generated packages. +- `develop::Bool=true`: Whether or not to `develop` generated packages in the active environment. +- `plugins::Vector{<:Plugin}=Plugin[]`: A list of plugins that the package will include. +- `disable_default_plugins::Vector{DataType}=DataType[]`: Default plugins to disable. + The default plugins are [`Readme`](@ref), [`License`](@ref), [`Tests`](@ref), and [`Gitignore`](@ref). + To override a default plugin instead of disabling it altogether, supply it via `plugins`. +- `interactive::Bool=false`: When set, creates the template interactively from user input, + using the previous keywords as a starting point. +- `fast::Bool=false`: Only applicable when `interactive` is set. + Skips prompts for any unsupplied keywords except `user` and `plugins`. """ struct Template user::String host::String - license::String authors::String dir::String julia_version::VersionNumber ssh::Bool - dev::Bool manifest::Bool + git::Bool + develop::Bool plugins::Dict{DataType, <:Plugin} - - function Template(; - user::AbstractString="", - host::AbstractString="https://github.com", - license::AbstractString="MIT", - authors::Union{AbstractString, Vector{<:AbstractString}}="", - dir::AbstractString=Pkg.devdir(), - julia_version::VersionNumber=default_version(), - ssh::Bool=false, - dev::Bool=true, - manifest::Bool=false, - plugins::Vector{<:Plugin}=Plugin[], - git::Bool=true, - ) - # Check for required Git options for package generation - # (you can't commit to a repository without them). - git && isempty(LibGit2.getconfig("user.name", "")) && missingopt("user.name") - git && isempty(LibGit2.getconfig("user.email", "")) && missingopt("user.email") - - # If no username was set, look for one in the global git config. - # Note: This is one of a few GitHub specifics (maybe we could use the host value). - if isempty(user) - user = LibGit2.getconfig("github.user", "") - end - if isempty(user) - throw(ArgumentError("No GitHub username found, set one with user=username")) - end - - host = URI(startswith(host, "https://") ? host : "https://$host").host - - if !isempty(license) && !isfile(joinpath(LICENSE_DIR, license)) - throw(ArgumentError("License '$license' is not available")) - end - - # If no author was set, look for one in the global git config. - if isempty(authors) - authors = LibGit2.getconfig("user.name", "") - email = LibGit2.getconfig("user.email", "") - isempty(email) || (authors *= " <$email>") - elseif authors isa Vector - authors = join(authors, ", ") - end - - dir = abspath(expanduser(dir)) - - plugin_dict = Dict{DataType, Plugin}(typeof(p) => p for p in plugins) - if (length(plugins) != length(plugin_dict)) - @warn "Plugin list contained duplicates, only the last of each type was kept" - end - - new(user, host, license, authors, dir, julia_version, ssh, dev, manifest, plugin_dict) - end end -function Base.show(io::IO, t::Template) - maybe(s::String) = isempty(s) ? "None" : s - spc = " " - - println(io, "Template:") - println(io, spc, "→ User: ", maybe(t.user)) - println(io, spc, "→ Host: ", maybe(t.host)) +Template(; interactive::Bool=false, kwargs...) = make_template(Val(interactive); kwargs...) - print(io, spc, "→ License: ") - if isempty(t.license) - println(io, "None") - else - println(io, t.license, " ($(t.authors) ", year(today()), ")") +function make_template(::Val{false}; kwargs...) + user = getkw(kwargs, :user) + if isempty(user) + throw(ArgumentError("No username found, set one with user=username")) end - println(io, spc, "→ Package directory: ", replace(maybe(t.dir), homedir() => "~")) - println(io, spc, "→ Minimum Julia version: v", version_floor(t.julia_version)) - println(io, spc, "→ SSH remote: ", t.ssh ? "Yes" : "No") - println(io, spc, "→ Add packages to main environment: ", t.dev ? "Yes" : "No") - println(io, spc, "→ Commit Manifest.toml: ", t.manifest ? "Yes" : "No") - - print(io, spc, "→ Plugins:") - if isempty(t.plugins) - print(io, " None") - else - for plugin in sort(collect(values(t.plugins)); by=string) - println(io) - buf = IOBuffer() - show(buf, plugin) - print(io, spc^2, "• ") - print(io, join(split(String(take!(buf)), "\n"), "\n$(spc^2)")) - end - end + host = getkw(kwargs, :host) + host = URI(occursin("://", host) ? host : "https://$host").host + + authors = getkw(kwargs, :authors) + authors isa Vector && (authors = join(authors, ", ")) + + dir = abspath(expanduser(getkw(kwargs, :dir))) + + disabled = getkw(kwargs, :disabled_defaults) + defaults = [Readme, License, Tests, Gitignore] + plugins = map(T -> T(), filter(T -> !in(T, disabled), defaults)) + append!(plugins, getkw(kwargs, :plugins)) + # This comprehensions resolves duplicate plugin types by overwriting, + # which means that default plugins get replaced by user values. + plugin_dict = Dict(typeof(p) => p for p in plugins) + + return Template( + user, + host, + authors, + dir, + getkw(kwargs, :julia_version), + getkw(kwargs, :ssh), + getkw(kwargs, :manifest), + getkw(kwargs, :git), + getkw(kwargs, :develop), + plugin_dict, + ) end -""" - interactive_template(; fast::Bool=false) -> Template - -Interactively create a [`Template`](@ref). If `fast` is set, defaults will be assumed for -all values except username and plugins. -""" -function interactive_template(; git::Bool=true, fast::Bool=false) - @info "Default values are shown in [brackets]" - # Getting the leaf types in a separate thread eliminates an awkward wait after - # "Select plugins" is printed. - plugin_types = @async leaves(Plugin) - kwargs = Dict{Symbol, Any}() - - default_user = LibGit2.getconfig("github.user", "") - print("Username [", isempty(default_user) ? "REQUIRED" : default_user, "]: ") - user = readline() - kwargs[:user] = if !isempty(user) - user - elseif !isempty(default_user) - default_user - else - throw(ArgumentError("Username is required")) - end - - kwargs[:host] = if fast || !git - "https://github.com" # If Git isn't enabled, this value never gets used. - else - default_host = "github.com" - print("Code hosting service [$default_host]: ") - host = readline() - isempty(host) ? default_host : host - end - - kwargs[:license] = if fast - "MIT" - else - println("License:") - io = IOBuffer() - available_licenses(io) - licenses = ["" => "", collect(LICENSES)...] - menu = RadioMenu(String["None", split(String(take!(io)), "\n")...]) - # If the user breaks out of the menu with Ctrl-c, the result is -1, the absolute - # value of which correponds to no license. - first(licenses[abs(request(menu))]) - end - - # We don't need to ask for authors if there is no license, - # because the license is the only place that they matter. - kwargs[:authors] = if fast || isempty(kwargs[:license]) - LibGit2.getconfig("user.name", "") - else - default_authors = LibGit2.getconfig("user.name", "") - default_str = isempty(default_authors) ? "None" : default_authors - print("Package author(s) [$default_str]: ") - authors = readline() - isempty(authors) ? default_authors : authors - end - - kwargs[:dir] = if fast - Pkg.devdir() - else - default_dir = Pkg.devdir() - print("Path to package directory [$default_dir]: ") - dir = readline() - isempty(dir) ? default_dir : dir - end - - kwargs[:julia_version] = if fast - VERSION - else - default_julia_version = VERSION - print("Minimum Julia version [", version_floor(default_julia_version), "]: ") - julia_version = readline() - isempty(julia_version) ? default_julia_version : VersionNumber(julia_version) - end - - kwargs[:ssh] = if fast || !git - false - else - print("Set remote to SSH? [no]: ") - uppercase(readline()) in ["Y", "YES", "T", "TRUE"] - end - - kwargs[:dev] = if fast - true - else - print("Add packages to main environment? [yes]: ") - uppercase(readline()) in ["", "Y", "YES", "T", "TRUE"] - end - - kwargs[:manifest] = if fast - false - else - print("Commit Manifest.toml? [no]: ") - uppercase(readline()) in ["Y", "YES", "T", "TRUE"] - end - - println("Plugins:") - # Only include plugin types which have an `interactive` method. - plugin_types = filter(t -> hasmethod(interactive, (Type{t},)), fetch(plugin_types)) - type_names = map(t -> split(string(t), ".")[end], plugin_types) - menu = MultiSelectMenu(String.(type_names); pagesize=length(type_names)) - selected = collect(request(menu)) - kwargs[:plugins] = Vector{Plugin}(map(interactive, getindex(plugin_types, selected))) - - return Template(; git=git, kwargs...) +hasplugin(t::Template, ::Type{T}) where T <: Plugin = any(U -> U <: T, keys(t.plugins)) + +getkw(kwargs, k) = get(() -> defaultkw(k), kwargs, k) + +defaultkw(s::Symbol) = defaultkw(Val(s)) +defaultkw(::Val{:user}) = LibGit2.getconfig("github.user", "") +defaultkw(::Val{:host}) = "https://github.com" +defaultkw(::Val{:dir}) = Pkg.devdir() +defaultkw(::Val{:julia_version}) = DEFAULT_VERSION +defaultkw(::Val{:ssh}) = false +defaultkw(::Val{:manifest}) = false +defaultkw(::Val{:git}) = true +defaultkw(::Val{:develop}) = true +defaultkw(::Val{:plugins}) = Plugin[] +defaultkw(::Val{:disabled_defaults}) = DataType[] +function defaultkw(::Val{:authors}) + name = LibGit2.getconfig("user.name", "") + email = LibGit2.getconfig("user.email", "") + isempty(name) && return "" + author = name * " " + isempty(email) || (author *= "<$email>") + return strip(author) end - -leaves(T::Type)::Vector{DataType} = isconcretetype(T) ? [T] : vcat(leaves.(subtypes(T))...) - -missingopt(name) = @warn "Git config option '$name' missing, package generation will fail unless you supply a GitConfig" diff --git a/test/gitconfig b/test/gitconfig deleted file mode 100644 index 8675f326..00000000 --- a/test/gitconfig +++ /dev/null @@ -1,3 +0,0 @@ -[user] - name = Travis - email = travis@c.i diff --git a/test/interactive/interactive.jl b/test/interactive/interactive.jl deleted file mode 100644 index f04e8f6c..00000000 --- a/test/interactive/interactive.jl +++ /dev/null @@ -1,68 +0,0 @@ -@testset "Interactive mode" begin - @testset "Template creation" begin - write(stdin.buffer, "$me\n\n\r\n\n\n\n\nd") - t = interactive_template() - @test t.user == me - @test t.host == "github.com" - @test isempty(t.license) - @test t.authors == LibGit2.getconfig("user.name", "") - @test t.dir == default_dir - @test t.julia_version == VERSION - @test !t.ssh - @test t.dev - @test !t.manifest - @test isempty(t.plugins) - - if isempty(LibGit2.getconfig("github.user", "")) - write(stdin.buffer, "\n") - @test_throws ArgumentError t = interactive_template() - end - - down = '\x1b' * "[B" # Down array key. - write(stdin.buffer, "$me\ngitlab.com\n$down\r$me\n$test_file\n0.5\nyes\nno\nyes\n$down\r$down\rd\n\n") - t = interactive_template() - @test t.user == me - @test t.host == "gitlab.com" - # Not sure if the order the licenses are displayed in is consistent. - @test !isempty(t.license) - @test t.authors == me - @test t.dir == abspath(test_file) - @test t.julia_version == v"0.5.0" - @test t.ssh - @test !t.dev - @test t.manifest - # Like above, not sure which plugins this will generate. - @test length(t.plugins) == 2 - - write(stdin.buffer, "$me\nd") - t = interactive_template(; fast=true) - @test t.user == me - @test t.host == "github.com" - @test t.license == "MIT" - @test t.authors == LibGit2.getconfig("user.name", "") - @test t.dir == default_dir - @test t.julia_version == VERSION - @test !t.ssh - @test !t.manifest - @test isempty(t.plugins) - println() - - # Host and SSH aren't prompted for when git is disabled. - write(stdin.buffer, "$me\n\n\r\n\n\n\nd") - t = interactive_template(; git=false) - @test t.host == "github.com" - @test !t.ssh - println() - end - - @testset "Package generation" begin - write(stdin.buffer, "$me\n\n\r\n\n\n\n\n\n\n\nd") - generate_interactive(test_pkg; gitconfig=gitconfig) - @test isdir(joinpath(default_dir, test_pkg)) - rm(joinpath(default_dir, test_pkg); force=true, recursive=true) - end - - @testset "Plugins" begin - include("plugins.jl") - end -end diff --git a/test/interactive/plugins.jl b/test/interactive/plugins.jl deleted file mode 100644 index 3c8760d0..00000000 --- a/test/interactive/plugins.jl +++ /dev/null @@ -1,90 +0,0 @@ -# These tests are to be skipped in OSX builds, see ./interactive.jl for more info. - -@testset "TravisCI" begin - write(stdin.buffer, "\n") - p = interactive(TravisCI) - @test p.src == joinpath(DEFAULTS_DIR, "travis.yml") - write(stdin.buffer, "$test_file\n") - p = interactive(TravisCI) - @test p.src == test_file - write(stdin.buffer, "none\n") - p = interactive(TravisCI) - @test p.src === nothing - write(stdin.buffer, "$fake_path\n") - @test_throws ArgumentError interactive(TravisCI) - println() -end - -@testset "AppVeyor" begin - write(stdin.buffer, "\n") - p = interactive(AppVeyor) - @test p.src == joinpath(DEFAULTS_DIR, "appveyor.yml") - write(stdin.buffer, "$test_file\n") - p = interactive(AppVeyor) - @test p.src == test_file - write(stdin.buffer, "none\n") - p = interactive(AppVeyor) - @test p.src === nothing - write(stdin.buffer, "$fake_path\n") - @test_throws ArgumentError interactive(AppVeyor) - println() -end - -@testset "GitLabCI" begin - write(stdin.buffer, "\n\n") - p = interactive(GitLabCI) - @test p.src == joinpath(DEFAULTS_DIR, "gitlab-ci.yml") - @test p.view == Dict("GITLABCOVERAGE" => true) - write(stdin.buffer, "$test_file\nno\n") - p = interactive(GitLabCI) - @test p.src == test_file - @test p.view == Dict("GITLABCOVERAGE" => false) - write(stdin.buffer, "none\n\n") - p = interactive(GitLabCI) - @test p.src === nothing - write(stdin.buffer, "$fake_path\n\n") - @test_throws ArgumentError interactive(GitLabCI) - println() -end - -@testset "Codecov" begin - write(stdin.buffer, "\n") - p = interactive(Codecov) - @test p.src === nothing - write(stdin.buffer, "$test_file\n") - p = interactive(Codecov) - @test p.src == test_file - write(stdin.buffer, "none\n") - p = interactive(Codecov) - @test p.src === nothing - write(stdin.buffer, "$fake_path\n") - @test_throws ArgumentError interactive(Codecov) - println() -end - -@testset "Coveralls" begin - write(stdin.buffer, "\n") - p = interactive(Coveralls) - @test p.src === nothing - write(stdin.buffer, "$test_file\n") - p = interactive(Coveralls) - @test p.src == test_file - write(stdin.buffer, "none\n") - p = interactive(Coveralls) - @test p.src === nothing - write(stdin.buffer, "$fake_path\n") - @test_throws ArgumentError interactive(Coveralls) - println() -end - -@testset "GitHubPages" begin - write(stdin.buffer, "\n") - p = interactive(GitHubPages) - @test isempty(p.assets) - write(stdin.buffer, "$test_file\n") - p = interactive(GitHubPages) - @test p.assets == [test_file] - write(stdin.buffer, "$fake_path\n") - @test_throws ArgumentError interactive(GitHubPages) - println() -end diff --git a/test/plugins/appveyor.jl b/test/plugins/appveyor.jl deleted file mode 100644 index de81e727..00000000 --- a/test/plugins/appveyor.jl +++ /dev/null @@ -1,57 +0,0 @@ -t = Template(; user=me) -pkg_dir = joinpath(t.dir, test_pkg) - -@testset "AppVeyor" begin - @testset "Plugin creation" begin - p = AppVeyor() - @test isempty(p.gitignore) - @test p.src == joinpath(PkgTemplates.DEFAULTS_DIR, "appveyor.yml") - @test p.dest == ".appveyor.yml" - @test p.badges == [ - Badge( - "Build Status", - "https://ci.appveyor.com/api/projects/status/github/{{USER}}/{{PKGNAME}}.jl?svg=true", - "https://ci.appveyor.com/project/{{USER}}/{{PKGNAME}}-jl", - ), - ] - @test isempty(p.view) - p = AppVeyor(; config_file=nothing) - @test p.src === nothing - p = AppVeyor(; config_file=test_file) - @test p.src == test_file - @test_throws ArgumentError AppVeyor(; config_file=fake_path) - end - - @testset "Badge generation" begin - p = AppVeyor() - @test badges(p, me, test_pkg) == ["[![Build Status](https://ci.appveyor.com/api/projects/status/github/$me/$test_pkg.jl?svg=true)](https://ci.appveyor.com/project/$me/$test_pkg-jl)"] - end - - @testset "File generation" begin - # Without a coverage plugin in the template, there should be no post-test step. - p = AppVeyor() - @test gen_plugin(p, t, test_pkg) == [".appveyor.yml"] - @test isfile(joinpath(pkg_dir, ".appveyor.yml")) - appveyor = read(joinpath(pkg_dir, ".appveyor.yml"), String) - @test !occursin("on_success", appveyor) - @test !occursin("%JL_CODECOV_SCRIPT%", appveyor) - rm(joinpath(pkg_dir, ".appveyor.yml")) - - # Generating the plugin with Codecov in the template should create a post-test step. - t.plugins[Codecov] = Codecov() - gen_plugin(p, t, test_pkg) - delete!(t.plugins, Codecov) - appveyor = read(joinpath(pkg_dir, ".appveyor.yml"), String) - @test occursin("on_success", appveyor) - @test occursin("%JL_CODECOV_SCRIPT%", appveyor) - rm(joinpath(pkg_dir, ".appveyor.yml")) - - # TODO: Add Coveralls tests when AppVeyor.jl supports it. - - p = AppVeyor(; config_file=nothing) - @test isempty(gen_plugin(p, t, test_pkg)) - @test !isfile(joinpath(pkg_dir, ".appveyor.yml")) - end -end - -rm(pkg_dir; recursive=true) diff --git a/test/plugins/cirrusci.jl b/test/plugins/cirrusci.jl deleted file mode 100644 index 9efc1eb7..00000000 --- a/test/plugins/cirrusci.jl +++ /dev/null @@ -1,54 +0,0 @@ -t = Template(; user=me) -pkg_dir = joinpath(t.dir, test_pkg) - -@testset "CirrusCI" begin - @testset "Plugin creation" begin - p = CirrusCI() - @test isempty(p.gitignore) - @test p.src == joinpath(DEFAULTS_DIR, "cirrus.yml") - @test p.dest == ".cirrus.yml" - @test p.badges == [ - Badge( - "Build Status", - "https://api.cirrus-ci.com/github/{{USER}}/{{PKGNAME}}.jl.svg", - "https://cirrus-ci.com/github/{{USER}}/{{PKGNAME}}.jl", - ), - ] - @test isempty(p.view) - p = CirrusCI(; config_file=nothing) - @test p.src === nothing - p = CirrusCI(; config_file=test_file) - @test p.src == test_file - @test_throws ArgumentError CirrusCI(; config_file=fake_path) - end - - @testset "Badge generation" begin - p = CirrusCI() - @test badges(p, me, test_pkg) == ["[![Build Status](https://api.cirrus-ci.com/github/$me/$test_pkg.jl.svg)](https://cirrus-ci.com/github/$me/$test_pkg.jl)"] - end - - @testset "File generation" begin - # Without a coverage plugin in the template, there should be no coverage step. - p = CirrusCI() - @test gen_plugin(p, t, test_pkg) == [".cirrus.yml"] - @test isfile(joinpath(pkg_dir, ".cirrus.yml")) - cirrus = read(joinpath(pkg_dir, ".cirrus.yml"), String) - @test !occursin("coverage_script", cirrus) - rm(joinpath(pkg_dir, ".cirrus.yml")) - - # Generating the plugin with Codecov in the template should create a post-test step. - t.plugins[Codecov] = Codecov() - gen_plugin(p, t, test_pkg) - delete!(t.plugins, Codecov) - cirrus = read(joinpath(pkg_dir, ".cirrus.yml"), String) - @test occursin("coverage_script", cirrus) - @test occursin("cirrusjl coverage", cirrus) - rm(joinpath(pkg_dir, ".cirrus.yml")) - - p = CirrusCI(; config_file=nothing) - @test isempty(gen_plugin(p, t, test_pkg)) - @test !isfile(joinpath(pkg_dir, ".cirrus.yml")) - end -end - -rm(pkg_dir; recursive=true) diff --git a/test/plugins/citation.jl b/test/plugins/citation.jl deleted file mode 100644 index 888660f7..00000000 --- a/test/plugins/citation.jl +++ /dev/null @@ -1,48 +0,0 @@ -t = Template(; user=me) -pkg_dir = joinpath(t.dir, test_pkg) - -@testset "CITATION" begin - @testset "Plugin creation" begin - p = Citation() - @test isempty(p.gitignore) - @test p.dest == "CITATION.bib" - @test isempty(p.badges) - @test isempty(p.view) - @test !p.readme_section - p = Citation(; readme_section=true) - @test p.readme_section - end - - @testset "File generation" begin - p = Citation() - @test gen_plugin(p, t, test_pkg) == ["CITATION.bib"] - @test isfile(joinpath(pkg_dir, "CITATION.bib")) - citation = read(joinpath(pkg_dir, "CITATION.bib"), String) - - @test occursin("@misc", citation) - @test occursin("$(t.authors)", citation) - @test occursin("v0.1.0", citation) - end - - @testset "Readme untouched" begin - p = Citation(; readme_section=false) - t.plugins[Citation] = p - isdir(pkg_dir) && rm(pkg_dir; recursive=true) - generate(test_pkg, t, git=false) - readme = read(joinpath(pkg_dir, "README.md"), String) - @test !occursin("## Citing", readme) - @test !occursin("CITATION.bib", readme) - end - - @testset "Readme modification" begin - p = Citation(; readme_section=true) - t.plugins[Citation] = p - isdir(pkg_dir) && rm(pkg_dir; recursive=true) - generate(test_pkg, t, git=false) - readme = read(joinpath(pkg_dir, "README.md"), String) - @test occursin("## Citing", readme) - @test occursin("CITATION.bib", readme) - end -end - -rm(pkg_dir; recursive=true) diff --git a/test/plugins/codecov.jl b/test/plugins/codecov.jl deleted file mode 100644 index b7648d8d..00000000 --- a/test/plugins/codecov.jl +++ /dev/null @@ -1,41 +0,0 @@ -t = Template(; user=me) -pkg_dir = joinpath(t.dir, test_pkg) - -@testset "Codecov" begin - @testset "Plugin creation" begin - p = Codecov() - @test p.gitignore == ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] - @test p.src === nothing - @test p.dest == ".codecov.yml" - @test p.badges == [ - Badge( - "Codecov", - "https://codecov.io/gh/{{USER}}/{{PKGNAME}}.jl/branch/master/graph/badge.svg", - "https://codecov.io/gh/{{USER}}/{{PKGNAME}}.jl", - ) - ] - @test isempty(p.view) - p = Codecov(; config_file=nothing) - @test p.src === nothing - p = Codecov(; config_file=test_file) - @test p.src == test_file - @test_throws ArgumentError Codecov(; config_file=fake_path) - end - - @testset "Badge generation" begin - p = Codecov() - @test badges(p, me, test_pkg) == ["[![Codecov](https://codecov.io/gh/$me/$test_pkg.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/$me/$test_pkg.jl)"] - end - - @testset "File generation" begin - p = Codecov() - @test isempty(gen_plugin(p, t, test_pkg)) - @test !isfile(joinpath(pkg_dir, ".codecov.yml")) - - p = Codecov(; config_file=test_file) - @test gen_plugin(p, t, test_pkg) == [".codecov.yml"] - @test isfile(joinpath(pkg_dir, ".codecov.yml")) - end -end - -rm(pkg_dir; recursive=true) diff --git a/test/plugins/coveralls.jl b/test/plugins/coveralls.jl deleted file mode 100644 index f74e2197..00000000 --- a/test/plugins/coveralls.jl +++ /dev/null @@ -1,40 +0,0 @@ -t = Template(; user=me) -pkg_dir = joinpath(t.dir, test_pkg) - -@testset "Coveralls" begin - @testset "Plugin creation" begin - p = Coveralls() - @test p.gitignore == ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] - @test p.src === nothing - @test p.dest == ".coveralls.yml" - @test p.badges == [ - Badge( - "Coveralls", - "https://coveralls.io/repos/github/{{USER}}/{{PKGNAME}}.jl/badge.svg?branch=master", - "https://coveralls.io/github/{{USER}}/{{PKGNAME}}.jl?branch=master", - ) - ] - @test isempty(p.view) - p = Coveralls(; config_file=nothing) - @test p.src === nothing - p = Coveralls(; config_file=test_file) - @test p.src == test_file - @test_throws ArgumentError Coveralls(; config_file=fake_path) - end - - @testset "Badge generation" begin - p = Coveralls() - @test badges(p, me, test_pkg) == ["[![Coveralls](https://coveralls.io/repos/github/$me/$test_pkg.jl/badge.svg?branch=master)](https://coveralls.io/github/$me/$test_pkg.jl?branch=master)"] - end - - @testset "File generation" begin - p = Coveralls() - @test isempty(gen_plugin(p, t, test_pkg)) - @test !isfile(joinpath(pkg_dir, ".coveralls.yml")) - p = Coveralls(; config_file=test_file) - @test gen_plugin(p, t, test_pkg) == [".coveralls.yml"] - @test isfile(joinpath(pkg_dir, ".coveralls.yml")) - end -end - -rm(pkg_dir; recursive=true) diff --git a/test/plugins/githubpages.jl b/test/plugins/githubpages.jl deleted file mode 100644 index 7ea563fb..00000000 --- a/test/plugins/githubpages.jl +++ /dev/null @@ -1,68 +0,0 @@ -t = Template(; user=me) -pkg_dir = joinpath(t.dir, test_pkg) - -@testset "GitHubPages" begin - @testset "Plugin creation" begin - p = GitHubPages() - @test p.gitignore == ["/docs/build/", "/docs/site/"] - @test isempty(p.assets) - p = GitHubPages(; assets=[test_file]) - @test p.assets == [test_file] - @test_throws ArgumentError GitHubPages(; assets=[fake_path]) - end - - @testset "Badge generation" begin - p = GitHubPages() - @test badges(p, me, test_pkg) == [ - "[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://$me.github.io/$test_pkg.jl/stable)" - "[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://$me.github.io/$test_pkg.jl/dev)" - ] - end - - @testset "File generation" begin - p = GitHubPages() - @test gen_plugin(p, t, test_pkg) == ["docs/"] - @test isdir(joinpath(pkg_dir, "docs")) - @test isfile(joinpath(pkg_dir, "docs", "make.jl")) - make = readchomp(joinpath(pkg_dir, "docs", "make.jl")) - @test occursin("assets=String[]", make) - @test !occursin("deploydocs", make) - @test isdir(joinpath(pkg_dir, "docs", "src")) - @test isfile(joinpath(pkg_dir, "docs", "src", "index.md")) - index = readchomp(joinpath(pkg_dir, "docs", "src", "index.md")) - @test occursin("autodocs", index) - rm(joinpath(pkg_dir, "docs"); recursive=true) - p = GitHubPages(; assets=[test_file]) - @test gen_plugin(p, t, test_pkg) == ["docs/"] - make = readchomp(joinpath(pkg_dir, "docs", "make.jl")) - # Check the formatting of the assets list. - @test occursin( - strip(""" - assets=[ - "assets/$(basename(test_file))", - ] - """), - make, - ) - @test isfile(joinpath(pkg_dir, "docs", "src", "assets", basename(test_file))) - rm(joinpath(pkg_dir, "docs"); recursive=true) - t.plugins[TravisCI] = TravisCI() - @test gen_plugin(p, t, test_pkg) == ["docs/"] - make = readchomp(joinpath(pkg_dir, "docs", "make.jl")) - @test occursin("deploydocs", make) - rm(joinpath(pkg_dir, "docs"); recursive=true) - end - - @testset "Package generation with GitHubPages plugin" begin - temp_dir = mktempdir() - t = Template(; user=me, dir=temp_dir, plugins=[GitHubPages()]) - generate(test_pkg, t; gitconfig=gitconfig) - - # Check that the gh-pages branch exists. - repo = LibGit2.GitRepo(joinpath(t.dir, test_pkg)) - branches = map(b -> LibGit2.shortname(first(b)), LibGit2.GitBranchIter(repo)) - @test in("gh-pages", branches) - end -end - -rm(pkg_dir; recursive=true) diff --git a/test/plugins/gitlabci.jl b/test/plugins/gitlabci.jl deleted file mode 100644 index e5561564..00000000 --- a/test/plugins/gitlabci.jl +++ /dev/null @@ -1,69 +0,0 @@ -t = Template(; user=me) -pkg_dir = joinpath(t.dir, test_pkg) - -@testset "GitLabCI" begin - @testset "Plugin creation" begin - p = GitLabCI() - @test p.gitignore == ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] - @test p.src == joinpath(PkgTemplates.DEFAULTS_DIR, "gitlab-ci.yml") - @test p.dest == ".gitlab-ci.yml" - @test p.badges == [ - Badge( - "Build Status", - "https://gitlab.com/{{USER}}/{{PKGNAME}}.jl/badges/master/build.svg", - "https://gitlab.com/{{USER}}/{{PKGNAME}}.jl/pipelines", - ), - Badge( - "Coverage", - "https://gitlab.com/{{USER}}/{{PKGNAME}}.jl/badges/master/coverage.svg", - "https://gitlab.com/{{USER}}/{{PKGNAME}}.jl/commits/master", - ), - ] - @test p.view == Dict("GITLABCOVERAGE" => true) - p = GitLabCI(; config_file=nothing) - @test p.src === nothing - p = GitLabCI(; config_file=test_file) - @test p.src == test_file - @test_throws ArgumentError GitLabCI(; config_file=fake_path) - p = GitLabCI(; coverage=false) - @test p.badges == [ - Badge( - "Build Status", - "https://gitlab.com/{{USER}}/{{PKGNAME}}.jl/badges/master/build.svg", - "https://gitlab.com/{{USER}}/{{PKGNAME}}.jl/pipelines", - ), - ] - @test p.view == Dict("GITLABCOVERAGE" => false) - end - - @testset "Badge generation" begin - p = GitLabCI() - @test badges(p, me, test_pkg) == [ - "[![Build Status](https://gitlab.com/$me/$test_pkg.jl/badges/master/build.svg)](https://gitlab.com/$me/$test_pkg.jl/pipelines)", - "[![Coverage](https://gitlab.com/$me/$test_pkg.jl/badges/master/coverage.svg)](https://gitlab.com/$me/$test_pkg.jl/commits/master)", - ] - end - - @testset "File generation" begin - p = GitLabCI() - @test gen_plugin(p, t, test_pkg) == [".gitlab-ci.yml"] - @test isfile(joinpath(pkg_dir, ".gitlab-ci.yml")) - gitlab = read(joinpath(pkg_dir, ".gitlab-ci.yml"), String) - # The default plugin should enable the coverage step. - @test occursin("using Coverage", gitlab) - rm(joinpath(pkg_dir, ".gitlab-ci.yml")) - - p = GitLabCI(; coverage=false) - gen_plugin(p, t, test_pkg) - gitlab = read(joinpath(pkg_dir, ".gitlab-ci.yml"), String) - # If coverage is false, there should be no coverage step. - @test !occursin("using Coverage", gitlab) - rm(joinpath(pkg_dir, ".gitlab-ci.yml")) - p = GitLabCI(; config_file=nothing) - - @test isempty(gen_plugin(p, t, test_pkg)) - @test !isfile(joinpath(pkg_dir, ".gitlab-ci.yml")) - end -end - -rm(pkg_dir; recursive=true) diff --git a/test/plugins/gitlabpages.jl b/test/plugins/gitlabpages.jl deleted file mode 100644 index 299206d5..00000000 --- a/test/plugins/gitlabpages.jl +++ /dev/null @@ -1,60 +0,0 @@ -t = Template(; user=me) -pkg_dir = joinpath(t.dir, test_pkg) - -@testset "GitLabPages" begin - @testset "Plugin creation" begin - p = GitLabPages() - @test p.gitignore == ["/docs/build/", "/docs/site/"] - @test isempty(p.assets) - p = GitLabPages(; assets=[test_file]) - @test p.assets == [test_file] - @test_throws ArgumentError GitLabPages(; assets=[fake_path]) - end - - @testset "Badge generation" begin - p = GitLabPages() - @test badges(p, me, test_pkg) == [ - "[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://$me.gitlab.io/$test_pkg.jl/dev)" - ] - end - - @testset "File generation" begin - p = GitLabPages() - @test gen_plugin(p, t, test_pkg) == ["docs/"] - @test isdir(joinpath(pkg_dir, "docs")) - @test isfile(joinpath(pkg_dir, "docs", "make.jl")) - make = readchomp(joinpath(pkg_dir, "docs", "make.jl")) - @test occursin("assets=String[]", make) - @test !occursin("deploydocs", make) - @test isdir(joinpath(pkg_dir, "docs", "src")) - @test isfile(joinpath(pkg_dir, "docs", "src", "index.md")) - index = readchomp(joinpath(pkg_dir, "docs", "src", "index.md")) - @test occursin("autodocs", index) - rm(joinpath(pkg_dir, "docs"); recursive=true) - p = GitLabPages(; assets=[test_file]) - @test gen_plugin(p, t, test_pkg) == ["docs/"] - make = readchomp(joinpath(pkg_dir, "docs", "make.jl")) - # Check the formatting of the assets list. - @test occursin( - strip(""" - assets=[ - "assets/$(basename(test_file))", - ] - """), - make, - ) - @test isfile(joinpath(pkg_dir, "docs", "src", "assets", basename(test_file))) - rm(joinpath(pkg_dir, "docs"); recursive=true) - end - - @testset "Package generation with GitLabPages plugin" begin - temp_dir = mktempdir() - t = Template(; user=me, dir=temp_dir, plugins=[GitLabCI(), GitLabPages()]) - generate(test_pkg, t; gitconfig=gitconfig) - - gitlab = read(joinpath(t.dir, test_pkg, ".gitlab-ci.yml"), String) - @test occursin("pages:", gitlab) - end -end - -rm(pkg_dir; recursive=true) diff --git a/test/plugins/travisci.jl b/test/plugins/travisci.jl deleted file mode 100644 index 20d1fbb8..00000000 --- a/test/plugins/travisci.jl +++ /dev/null @@ -1,82 +0,0 @@ -t = Template(; user=me) -pkg_dir = joinpath(t.dir, test_pkg) - -@testset "TravisCI" begin - @testset "Plugin creation" begin - p = TravisCI() - @test isempty(p.gitignore) - @test p.src == joinpath(PkgTemplates.DEFAULTS_DIR, "travis.yml") - @test p.dest == ".travis.yml" - @test p.badges == [ - Badge( - "Build Status", - "https://travis-ci.com/{{USER}}/{{PKGNAME}}.jl.svg?branch=master", - "https://travis-ci.com/{{USER}}/{{PKGNAME}}.jl", - ), - ] - @test isempty(p.view) - p = TravisCI(; config_file=nothing) - @test p.src === nothing - p = TravisCI(; config_file=test_file) - @test p.src == test_file - @test_throws ArgumentError TravisCI(; config_file=fake_path) - end - - @testset "Badge generation" begin - p = TravisCI() - @test badges(p, me, test_pkg) == ["[![Build Status](https://travis-ci.com/$me/$test_pkg.jl.svg?branch=master)](https://travis-ci.com/$me/$test_pkg.jl)"] - end - - @testset "File generation" begin - # Without a coverage plugin in the template, there should be no post-test step. - p = TravisCI() - @test gen_plugin(p, t, test_pkg) == [".travis.yml"] - @test isfile(joinpath(pkg_dir, ".travis.yml")) - travis = read(joinpath(pkg_dir, ".travis.yml"), String) - - @test !occursin("after_success", travis) - @test !occursin("Codecov.submit", travis) - @test !occursin("Coveralls.submit", travis) - @test !occursin("stage: Documentation", travis) - rm(joinpath(pkg_dir, ".travis.yml")) - - # Generating the plugin with Codecov in the template should create a post-test step. - t.plugins[Codecov] = Codecov() - gen_plugin(p, t, test_pkg) - delete!(t.plugins, Codecov) - travis = read(joinpath(pkg_dir, ".travis.yml"), String) - @test occursin("after_success", travis) - @test occursin("Codecov.submit", travis) - @test !occursin("Coveralls.submit", travis) - @test !occursin("stage: Documentation", travis) - rm(joinpath(pkg_dir, ".travis.yml")) - - # Coveralls should do the same. - t.plugins[Coveralls] = Coveralls() - gen_plugin(p, t, test_pkg) - delete!(t.plugins, Coveralls) - travis = read(joinpath(pkg_dir, ".travis.yml"), String) - @test occursin("after_success", travis) - @test occursin("Coveralls.submit", travis) - @test !occursin("Codecov.submit", travis) - @test !occursin("stage: Documentation", travis) - rm(joinpath(pkg_dir, ".travis.yml")) - - # With a Documenter plugin, there should be a docs deployment step. - t.plugins[GitHubPages] = GitHubPages() - gen_plugin(p, t, test_pkg) - delete!(t.plugins, GitHubPages) - travis = read(joinpath(pkg_dir, ".travis.yml"), String) - @test occursin("after_success", travis) - @test occursin("stage: Documentation", travis) - @test !occursin("Codecov.submit", travis) - @test !occursin("Coveralls.submit", travis) - rm(joinpath(pkg_dir, ".travis.yml")) - - p = TravisCI(; config_file=nothing) - @test isempty(gen_plugin(p, t, test_pkg)) - @test !isfile(joinpath(pkg_dir, ".travis.yml")) - end -end - -rm(pkg_dir; recursive=true) diff --git a/test/runtests.jl b/test/runtests.jl index d3234388..e69de29b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,20 +0,0 @@ -using PkgTemplates -using Test -using Dates -using LibGit2 -using Pkg - -import PkgTemplates: badges, version_floor, substitute, read_license, gen_file, gen_readme, - gen_tests, gen_license, gen_gitignore, gen_plugin, show_license, LICENSES, - LICENSE_DIR, Plugin, GenericPlugin, CustomPlugin, Badge, format, interactive, - DEFAULTS_DIR, Documenter - -mktempdir() do temp_dir - mkdir(joinpath(temp_dir, "dev")) - pushfirst!(DEPOT_PATH, temp_dir) - cd(temp_dir) do - @testset "PkgTemplates.jl" begin - include("tests.jl") - end - end -end diff --git a/test/tests.jl b/test/tests.jl index ea8a0adf..1b3e5ae9 100644 --- a/test/tests.jl +++ b/test/tests.jl @@ -44,7 +44,7 @@ write(test_file, template_text) @test t.license == "MIT" @test t.authors == "foo" @test t.dir == default_dir - @test t.julia_version == PkgTemplates.default_version() + @test t.julia_version == PkgTemplates.default_version @test !t.ssh @test !t.manifest @test isempty(t.plugins) @@ -107,7 +107,7 @@ end @testset "Show methods" begin pkg_dir = replace(default_dir, homedir() => "~") - ver = PkgTemplates.version_floor(PkgTemplates.default_version()) + ver = PkgTemplates.version_floor(PkgTemplates.default_version) buf = IOBuffer() t = Template(; user=me, authors="foo") show(buf, t) @@ -327,12 +327,6 @@ end rm(temp_dir; recursive=true) end -@testset "Git-less template creation" begin - if isempty(LibGit2.getconfig("user.name", "")) - @test_logs Template(; user=me, git=false) - end -end - @testset "Git-less package generation" begin t = Template(; user=me) generate(test_pkg, t; git=false) @@ -340,84 +334,6 @@ end @test !isfile(joinpath(t.dir, ".gitignore")) end -@testset "Version floor" begin - @test version_floor(v"1.0.0") == "1.0" - @test version_floor(v"1.0.1") == "1.0" - @test version_floor(v"1.0.1-pre") == "1.0" - @test version_floor(v"1.0.0-pre") == "1.0-" -end - -@testset "Mustache substitution" begin - view = Dict{String, Any}() - text = substitute(template_text, view) - @test !occursin("PKGNAME: $test_pkg", text) - @test !occursin("Documenter", text) - @test !occursin("Codecov", text) - @test !occursin("Coveralls", text) - @test !occursin("After", text) - @test !occursin("Other", text) - view["PKGNAME"] = test_pkg - view["OTHER"] = true - text = substitute(template_text, view) - @test occursin("PKGNAME: $test_pkg", text) - @test occursin("Other", text) - - t = Template(; user=me) - view["OTHER"] = false - - text = substitute(template_text, t; view=view) - @test occursin("PKGNAME: $test_pkg", text) - @test occursin("VERSION: $(t.julia_version.major).$(t.julia_version.minor)", text) - @test !occursin("Documenter", text) - @test !occursin("After", text) - @test !occursin("Other", text) - - t.plugins[GitHubPages] = GitHubPages() - text = substitute(template_text, t; view=view) - @test occursin("Documenter", text) - @test occursin("After", text) - empty!(t.plugins) - - t.plugins[Codecov] = Codecov() - text = substitute(template_text, t; view=view) - @test occursin("Codecov", text) - @test occursin("After", text) - empty!(t.plugins) - - t.plugins[Coveralls] = Coveralls() - text = substitute(template_text, t; view=view) - @test occursin("Coveralls", text) - @test occursin("After", text) - empty!(t.plugins) - - view["OTHER"] = true - text = substitute(template_text, t; view=view) - @test occursin("Other", text) -end - -@testset "License display" begin - io = IOBuffer() - available_licenses(io) - licenses = String(take!(io)) - show_license(io, "MIT") - mit = String(take!(io)) - - # Check that all licenses are included in the display. - for (short, long) in LICENSES - @test occursin("$short: $long", licenses) - end - @test strip(mit) == strip(read_license("MIT")) - @test strip(read_license("MIT")) == strip(read(joinpath(LICENSE_DIR, "MIT"), String)) - @test_throws ArgumentError read_license(fake_path) - - # Check that all licenses included with the package are displayed. - for license in readdir(LICENSE_DIR) - @test haskey(LICENSES, license) - end - # Check that all licenses displayed are included with the package. - @test length(readdir(LICENSE_DIR)) == length(LICENSES) -end - @testset "Plugins" begin t = Template(; user=me) pkg_dir = joinpath(t.dir, test_pkg) @@ -474,7 +390,8 @@ end warn_str = "Ignoring predefined Documenter kwargs \"format\" from additional kwargs" check_kwargs(kwargs, warn_str) - kwargs = Dict(:checkdocs => :none, + kwargs = Dict( + :checkdocs => :none, :strict => true, :format => :markdown, :stringarg => "string", @@ -488,5 +405,3 @@ end end include(joinpath("interactive", "interactive.jl")) - -rm(test_file) From ea386ec0d9d921b3428cf027daee22396aea58d0 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Mon, 26 Aug 2019 21:28:02 +0700 Subject: [PATCH 02/81] Delete REQUIRE --- REQUIRE | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 REQUIRE diff --git a/REQUIRE b/REQUIRE deleted file mode 100644 index c08c8c1a..00000000 --- a/REQUIRE +++ /dev/null @@ -1,3 +0,0 @@ -julia 0.7 -Mustache -URIParser From 9dedf9109c00e442d4cee51a8f182a5785b7e57f Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Mon, 26 Aug 2019 22:01:26 +0700 Subject: [PATCH 03/81] Travis tweaks --- .travis.yml | 50 +++++++++++++++++++++++++++++++++-------------- src/plugins/ci.jl | 25 ++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index b3fd9064..8bcbbb89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,31 +1,51 @@ language: julia +notifications: + email: false os: - linux - osx - windows julia: - 1.0 + - 1.1 - 1.2 + - 1.3 - nightly matrix: + fast_finish: true allow_failures: + - julia: 1.3 - julia: nightly - fast_finish: true -notifications: - email: false -after_success: - - julia -e ' - using Pkg - Pkg.add("Coverage") - using Coverage - Codecov.submit(process_folder())' -jobs: include: - - stage: Documentation + - os: linux + arch: x86 + julia: 1.0 + - os: windows + arch: x86 + julia: 1.0 + - os: linux + arch: x86 + julia: 1.1 + - os: windows + arch: x86 + julia: 1.1 + - os: linux + arch: x86 julia: 1.2 + - os: windows + arch: x86 + julia: 1.2 + - os: linux + arch: x86 + julia: nightly + - os: windows + arch: x86 + julia: nightly + - stage: Documentation + julia: 1.0 script: julia --project=docs -e ' - using Pkg - Pkg.develop(PackageSpec(; path=pwd())) - Pkg.instantiate() - include("docs/make.jl")' + using Pkg; + Pkg.develop(PackageSpec(; path=pwd())); + Pkg.instantiate(); + include("docs/make.jl");' after_success: skip diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index 0fde8a22..f4f02b80 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -9,6 +9,31 @@ end abstract type CI <: Plugin end +# TODO: A template that yields this: +# os: +# - linux +# - osx +# - windows +# julia: +# - 1.0 +# - 1.1 +# - 1.2 +# - 1.3 +# - nightly +# matrix: +# fast_finish: true +# allow_failures: +# - julia: 1.3 +# - julia: nightly +# include: +# - os: linux +# arch: x86 +# julia: 1.0 +# - os: windows +# arch: x86 +# julia: 1.0 +# (and maybe all the other Julia versions for 32-bit too) + @kwdef struct TravisCI <: CI file::String = default_file("travis.yml") linux::Bool = true From cfed5fc7e6c181710969fe7aa53a00027c2c1009 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Mon, 26 Aug 2019 22:24:49 +0700 Subject: [PATCH 04/81] Use Parameters.with_kw instead of kwdef for 1.0 compat --- Manifest.toml | 12 ++++++++++++ Project.toml | 1 + src/PkgTemplates.jl | 9 ++++++--- src/plugins/ci.jl | 8 ++++---- src/plugins/citation.jl | 2 +- src/plugins/coverage.jl | 4 ++-- src/plugins/essentials.jl | 4 ++-- 7 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index 24d77f8a..c709f1dd 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -53,6 +53,18 @@ git-tree-sha1 = "f39de3a12232eb47bd0629b3a661054287780276" uuid = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" version = "0.5.13" +[[OrderedCollections]] +deps = ["Random", "Serialization", "Test"] +git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.1.0" + +[[Parameters]] +deps = ["OrderedCollections"] +git-tree-sha1 = "1dfd7cd50a8eb06ef693a4c2bbe945943cd000c5" +uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a" +version = "0.11.0" + [[Pkg]] deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" diff --git a/Project.toml b/Project.toml index 5df5d898..863df150 100644 --- a/Project.toml +++ b/Project.toml @@ -8,6 +8,7 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433" Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" +Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" URIParser = "30578b45-9adc-5946-b283-645ec420af67" diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index 76c715ae..7fe5abb9 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -1,13 +1,16 @@ module PkgTemplates -using Base: @kwdef, current_project +using Base: current_project using Base.Filesystem: contractuser + using Dates: month, today, year using InteractiveUtils: subtypes using LibGit2: LibGit2 -using Mustache: render -using Pkg: PackageSpec, Pkg +using Pkg: Pkg, PackageSpec using REPL.TerminalMenus: MultiSelectMenu, RadioMenu, request + +using Mustache: render +using Parameters: @with_kw using URIParser: URI export diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index f4f02b80..4ce207ed 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -34,7 +34,7 @@ abstract type CI <: Plugin end # julia: 1.0 # (and maybe all the other Julia versions for 32-bit too) -@kwdef struct TravisCI <: CI +@with_kw struct TravisCI <: CI file::String = default_file("travis.yml") linux::Bool = true osx::Bool = true @@ -73,7 +73,7 @@ function view(p::TravisCI, t::Template, ::AbstractString) ) end -@kwdef struct AppVeyor <: CI +@with_kw struct AppVeyor <: CI file::String = default_file("appveyor.yml") x86::Bool = false coverage::Bool = true @@ -101,7 +101,7 @@ function view(p::AppVeyor, t::Template, ::AbstractString) ) end -@kwdef struct CirrusCI <: CI +@with_kw struct CirrusCI <: CI file::String = default_file("cirrus.yml") image::String = "freebsd-12-0-release-amd64" coverage::Bool = true @@ -128,7 +128,7 @@ function view(p::CirrusCI, t::Template, ::AbstractString) ) end -@kwdef struct GitLabCI <: CI +@with_kw struct GitLabCI <: CI file::String documentation::Bool = true coverage::Bool = true diff --git a/src/plugins/citation.jl b/src/plugins/citation.jl index 34365d50..8d3e2a43 100644 --- a/src/plugins/citation.jl +++ b/src/plugins/citation.jl @@ -4,7 +4,7 @@ Add `Citation` to a [`Template`](@ref)'s plugin list to generate a `CITATION.bib` file. If `readme` is set, then `README.md` will contain a section about citing. """ -@kwdef struct Citation <: BasicPlugin +@with_kw struct Citation <: BasicPlugin file::String = default_file("CITATION.bib") readme::Bool = false end diff --git a/src/plugins/coverage.jl b/src/plugins/coverage.jl index 25cf03f4..f1cd7091 100644 --- a/src/plugins/coverage.jl +++ b/src/plugins/coverage.jl @@ -4,7 +4,7 @@ const COVERAGE_GITIGNORE = ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] gitignore(::Coverage) = COVERAGE_GITIGNORE -@kwdef struct Codecov <: Coverage +@with_kw struct Codecov <: Coverage file::Union{String, Nothing} = nothing end @@ -17,7 +17,7 @@ badges(::Codecov) = Badge( "https://codecov.io/gh/{{USER}}/{{PKG}}.jl", ) -@kwdef struct Coveralls <: Coverage +@with_kw struct Coveralls <: Coverage file::Union{String, Nothing} = nothing end diff --git a/src/plugins/essentials.jl b/src/plugins/essentials.jl index 49741e05..5522d68d 100644 --- a/src/plugins/essentials.jl +++ b/src/plugins/essentials.jl @@ -13,7 +13,7 @@ const LICENSES = Dict( "EUPL-1.2+" => "European Union Public Licence, Version 1.2+", ) -@kwdef struct Readme <: BasicPlugin +@with_kw struct Readme <: BasicPlugin file::String = default_file("README.md") destination::String = "README.md" inline_badges::Bool = false @@ -86,7 +86,7 @@ function gen_plugin(p::Gitignore, t::Template, pkg_dir::AbstractString) gen_file(joinpath(pkg_dir, ".gitignore"), render_plugin(p, t)) end -@kwdef struct Tests <: BasicPlugin +@with_kw struct Tests <: BasicPlugin file::String = default_file("runtests.jl") end From 05255f55558b6d13fd4751ee83507565d22e97de Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Tue, 27 Aug 2019 12:05:51 +0700 Subject: [PATCH 05/81] Update the Project.toml with TOML instead of string manipulation --- src/PkgTemplates.jl | 2 +- src/generate.jl | 28 +++++++++++++++++----------- src/plugins/essentials.jl | 17 ++++++++++------- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index 7fe5abb9..3e674694 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -6,7 +6,7 @@ using Base.Filesystem: contractuser using Dates: month, today, year using InteractiveUtils: subtypes using LibGit2: LibGit2 -using Pkg: Pkg, PackageSpec +using Pkg: Pkg, TOML, PackageSpec using REPL.TerminalMenus: MultiSelectMenu, RadioMenu, request using Mustache: render diff --git a/src/generate.jl b/src/generate.jl index c0e7b022..276f1b38 100644 --- a/src/generate.jl +++ b/src/generate.jl @@ -1,5 +1,3 @@ -const TEST_UUID = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - """ (::Template)(pkg::AbstractString) @@ -14,17 +12,14 @@ function (t::Template)(pkg::AbstractString) # Create the directory with some boilerplate inside. Pkg.generate(pkg_dir) - # Add a [compat] section for Julia. By default, Julia 1.x is supported. - open(joinpath(pkg_dir, "Project.toml"), "a") do io - println(io, "\n[compat]\njulia = \"1\"") - end - - # Replace the authors field with the template's authors. + # Replace the authors field with the template's authors, and add a compat entry. if !isempty(t.authors) path = joinpath(pkg_dir, "Project.toml") - project = read(path, String) - authors = string("[", join(map(repr ∘ strip, split(t.authors, ",")), ", "), "]") - write(path, replace(project, r"authors = .*" => "authors = $authors")) + toml = TOML.parsefile(path) + # TODO: authors should probably be kept as a vector. + toml["authors"] = split(t.authors, ",") + get!(toml, "compat", Dict())["julia"] = compat_version(t.julia_version) + open(io -> TOML.print(io, toml), path, "w") end if t.git @@ -59,3 +54,14 @@ function (t::Template)(pkg::AbstractString) rethrow() end end + +# Format the version to be included in Project.toml's [compat] section. +function compat_version(v::VersionNumber) + return if v.patch == 0 && v.minor == 0 + string(v.major) + elseif v.patch == 0 + "$(v.major).$(v.minor)" + else + "$(v.major).$(v.minor).$(v.patch)" + end +end diff --git a/src/plugins/essentials.jl b/src/plugins/essentials.jl index 5522d68d..e0db4fd0 100644 --- a/src/plugins/essentials.jl +++ b/src/plugins/essentials.jl @@ -1,3 +1,4 @@ +const TEST_UUID = "8dfed614-e22c-5e08-85e1-65c5234f0b40" const LICENSE_DIR = normpath(joinpath(@__DIR__, "..", "..", "licenses")) const LICENSES = Dict( "MIT" => "MIT \"Expat\" License", @@ -98,16 +99,18 @@ function gen_plugin(p::Tests, t::Template, pkg_dir::AbstractString) # Do the normal BasicPlugin behaviour to create the test script. invoke(gen_plugin, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) - # Add the Test dependency as a test-only dependency. - # To avoid visual noise from adding/removing the dependency, insert it manually. + # Add Test as a test-only dependency. + path = joinpath(pkg_dir, "Project.toml") + toml = TOML.parsefile(path) + get!(toml, "extras", Dict())["Test"] = TEST_UUID + get!(toml, "targets", Dict())["test"] = ["Test"] + open(io -> TOML.print(io, toml), path, "w") + + # Generate the manifest. + touch(joinpath(pkg_dir, "Manifest.toml")) # File must exist to be modified by Pkg. proj = current_project() try Pkg.activate(pkg_dir) - lines = readlines(joinpath(pkg_dir, "Project.toml")) - dep = "Test = $(repr(TEST_UUID))" - push!(lines, "[extras]", dep, "", "[targets]", "test = [\"Test\"]") - gen_file(joinpath(pkg_dir, "Project.toml"), join(lines, "\n")) - touch(joinpath(pkg_dir, "Manifest.toml")) # File must exist to be modified by Pkg. Pkg.update() # Clean up both Manifest.toml and Project.toml. finally proj === nothing ? Pkg.activate() : Pkg.activate(proj) From 47ccb10a9966c919849b8e24e273a8809513fc2f Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Tue, 27 Aug 2019 12:43:10 +0700 Subject: [PATCH 06/81] More Travis changes --- defaults/travis.yml | 35 +++++++++++++++++++----------- src/plugins/ci.jl | 53 +++++++++++++++++---------------------------- 2 files changed, 42 insertions(+), 46 deletions(-) diff --git a/defaults/travis.yml b/defaults/travis.yml index 21bc8eb6..1100682d 100644 --- a/defaults/travis.yml +++ b/defaults/travis.yml @@ -2,29 +2,38 @@ language: julia notifications: email: false -{{#HAS_DOCUMENTER}} +julia: +{{#VERSIONS}} + - {{.}} +{{/VERSIONS}} +os: +{{#OS}} + - {{.}} +{{/OS}} jobs: fast_finish: true -{{#HAS_NIGHTLY}} +{{#HAS_ALLOW_FAILURES}} allow_failures: - - julia: nightly -{{/HAS_NIGHTLY}} +{{/HAS_ALLOW_FAILURES}} +{{#ALLOW_FAILURES}} + - julia: {{.}} +{{/ALLOW_FAILURES}} +{{#HAS_JOBS}} include: -{{#JOBS}} +{{/HAS_JOBS}} +{{#X86}} - julia: {{JULIA}} os: {{OS}} -{{#ARCH}} - arch: {{ARCH}} -{{/ARCH}} -{{/JOBS}} + arch: x86 +{{/X86}} {{#HAS_DOCUMENTER}} - stage: Documentation julia: {{VERSION}} script: julia --project=docs -e ' - using Pkg; - Pkg.develop(PackageSpec(; path=pwd())); - Pkg.instantiate(); - include("docs/make.jl");' + using Pkg; + Pkg.develop(PackageSpec(; path=pwd())); + Pkg.instantiate(); + include("docs/make.jl");' after_success: skip {{/HAS_DOCUMENTER}} {{#HAS_COVERAGE}} diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index 4ce207ed..2e0b49ce 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -9,31 +9,6 @@ end abstract type CI <: Plugin end -# TODO: A template that yields this: -# os: -# - linux -# - osx -# - windows -# julia: -# - 1.0 -# - 1.1 -# - 1.2 -# - 1.3 -# - nightly -# matrix: -# fast_finish: true -# allow_failures: -# - julia: 1.3 -# - julia: nightly -# include: -# - os: linux -# arch: x86 -# julia: 1.0 -# - os: windows -# arch: x86 -# julia: 1.0 -# (and maybe all the other Julia versions for 32-bit too) - @with_kw struct TravisCI <: CI file::String = default_file("travis.yml") linux::Bool = true @@ -54,22 +29,34 @@ badges(::TravisCI) = Badge( ) function view(p::TravisCI, t::Template, ::AbstractString) - jobs = Dict{String, String}[] - for v in collect_versions(p.extra_versions, t) - p.linux && push!(jobs, Dict("JULIA" => v, "OS" => "linux", "ARCH" => "x64")) - p.linux && p.x86 && push!(jobs, Dict("JULIA" => v, "OS" => "linux", "ARCH" => "x86")) - p.osx && push!(jobs, Dict("JULIA" => v, "OS" => "osx")) - p.windows && push!(jobs, Dict("JULIA" => v, "OS" => "windows", "ARCH" => "x64")) - p.windows && p.x86 && push!(jobs, Dict("JULIA" => v, "OS" => "windows", "ARCH" => "x86")) + os = String[] + p.linux && push!(os, "linux") + p.osx && push!(os, "osx") + p.windows && push!(os, "windows") + + # TODO: Update the allowed failures as new versions come out. + versions = collect_versions(p.extra_versions, t) + allow_failures = filter(v -> v in versions, ("1.3", "nightly")) + + x86 = Dict{String, String}[] + if p.x86 + foreach(versions) do v + p.linux && push!(x86, Dict("JULIA" => v, "OS" => "linux", "ARCH" => "x86")) + p.windows && push!(x86, Dict("JULIA" => v, "OS" => "windows", "ARCH" => "x86")) end + return Dict( + "ALLOW_FAILURES" => allow_failures, + "HAS_ALLOW_FAILURES" => !isempty(allow_failures), "HAS_CODECOV" => hasplugin(t, Codecov), "HAS_COVERAGE" => p.coverage && hasplugin(t, Coverage), "HAS_COVERALLS" => hasplugin(t, Coveralls), "HAS_DOCUMENTER" => hasplugin(t, Documenter{TravisCI}), - "HAS_NIGHTLY" => "nightly" in versions, + "HAS_JOBS" => p.x86 || hasplugin(t, Documenter{TravisCI}), + "OS" => os, "PKG" => pkg, "VERSION" => format_version(t.julia_version), + "X86" => x86, ) end From 0d3b124c07abc5b818f201c66ac7d5b09e8d96d0 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Tue, 27 Aug 2019 18:17:15 +0700 Subject: [PATCH 07/81] Make authors a vector, misc tweaks --- src/PkgTemplates.jl | 2 -- src/generate.jl | 3 +-- src/interactive.jl | 2 ++ src/licenses.jl | 0 src/plugin.jl | 30 +++++++++++++++++++----------- src/plugins/citation.jl | 2 +- src/plugins/documenter.jl | 2 +- src/plugins/essentials.jl | 7 ++++--- src/template.jl | 12 ++++++++---- 9 files changed, 36 insertions(+), 24 deletions(-) delete mode 100644 src/licenses.jl diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index 3e674694..fe4bc4ad 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -28,8 +28,6 @@ export Tests, TravisCI -const DEFAULT_VERSION = VersionNumber(VERSION.major) - """ A plugin to be added to a [`Template`](@ref), which adds some functionality or integration. """ diff --git a/src/generate.jl b/src/generate.jl index 276f1b38..3e7f9ce9 100644 --- a/src/generate.jl +++ b/src/generate.jl @@ -16,8 +16,7 @@ function (t::Template)(pkg::AbstractString) if !isempty(t.authors) path = joinpath(pkg_dir, "Project.toml") toml = TOML.parsefile(path) - # TODO: authors should probably be kept as a vector. - toml["authors"] = split(t.authors, ",") + toml["authors"] = t.authors get!(toml, "compat", Dict())["julia"] = compat_version(t.julia_version) open(io -> TOML.print(io, toml), path, "w") end diff --git a/src/interactive.jl b/src/interactive.jl index 230393c0..c6d5f677 100644 --- a/src/interactive.jl +++ b/src/interactive.jl @@ -1,3 +1,5 @@ +# TODO ::IO APIs for easier testing + # Printing utils. const TAB = repeat(' ', 4) const HALFTAB = repeat(' ', 2) diff --git a/src/licenses.jl b/src/licenses.jl deleted file mode 100644 index e69de29b..00000000 diff --git a/src/plugin.jl b/src/plugin.jl index 9abb6b60..bf872fec 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -1,13 +1,20 @@ const DEFAULTS_DIR = normpath(joinpath(@__DIR__, "..", "defaults")) +""" +A simple plugin that, in general, manages a single file. +For example, most CI services reply on one configuration file. + +TODO: Dev guide. +""" abstract type BasicPlugin <: Plugin end +# Compute the path to a default template file in this repository. default_file(paths::AbstractString...) = joinpath(DEFAULTS_DIR, paths...) """ view(::Plugin, ::Template, pkg::AbstractString) -> Dict{String} -Return extra string substitutions to be made for this plugin. +Return the string replacements to be made for this plugin. """ view(::Plugin, ::Template, ::AbstractString) = Dict{String, Any}() @@ -67,25 +74,23 @@ function badges(p::Plugin, t::Template, pkg_name::AbstractString) end """ - gen_plugin(p::Plugin, t::Template, pkg::AbstractString) -> Nothing + gen_plugin(p::Plugin, t::Template, pkg::AbstractString) Generate any files associated with a plugin. - -## Arguments -* `p::Plugin`: Plugin whose files are being generated. -* `t::Template`: Template configuration. -* `pkg::AbstractString`: Name of the package. +`pkg` is the name of the package being generated. """ gen_plugin(::Plugin, ::Template, ::AbstractString) = nothing function gen_plugin(p::BasicPlugin, t::Template, pkg::AbstractString) - source(p) === nothing && return - text = render(source(p), view(p, t, pkg); tags=tags(p)) - gen_file(joinpath(t.dir, pkg_name, destination(p)), text) + src = source(p) + src === nothing && return + # TODO template rendering code + text = render(src, view(p, t, pkg); tags=tags(p)) + gen_file(joinpath(t.dir, pkg, destination(p)), text) end """ - gen_file(file::AbstractString, text::AbstractString) -> Int + gen_file(file::AbstractString, text::AbstractString) Create a new file containing some given text. Trailing whitespace is removed, and the file will end with a newline. @@ -97,6 +102,8 @@ function gen_file(file::AbstractString, text::AbstractString) write(file, text) end +# TODO pls make me better + render_file(file::AbstractString, view, tags) = render_text(read(file, String), view, tags) render_text(text::AbstractString, view, tags) = render(text, view; tags=tags) @@ -120,6 +127,7 @@ const BADGE_ORDER = [ TravisCI, AppVeyor, GitLabCI, + CirrusCI, Codecov, Coveralls, ] diff --git a/src/plugins/citation.jl b/src/plugins/citation.jl index 8d3e2a43..82e27080 100644 --- a/src/plugins/citation.jl +++ b/src/plugins/citation.jl @@ -15,7 +15,7 @@ source(p::Citation) = p.file destination(::Citation) = "CITATION.bib" view(::Citation, t::Template, pkg::AbstractString) = Dict( - "AUTHORS" => t.authors, + "AUTHORS" => join(t.authors, ", "), "MONTH" => month(today()), "PKG" => pkg, "URL" => "https://$(t.host)/$(t.user)/$pkg.jl", diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index 5b6c0196..064c98c5 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -60,7 +60,7 @@ badges(::Documenter{GitLabCI}) = Badge( view(p::Documenter, t::Template, pkg::AbstractString) = Dict( "ASSETS" => p.assets, - "AUTHORS" => t.authors, + "AUTHORS" => join(t.authors, ", "), "CANONICAL" => p.canonical_url === nothing ? nothing : p.canonical_url(t, pkg), "HAS_ASSETS" => !isempty(p.assets), "MAKEDOCS_KWARGS" => map((k, v) -> k => repr(v), collect(p.makedocs_kwargs)), diff --git a/src/plugins/essentials.jl b/src/plugins/essentials.jl index e0db4fd0..5b43a442 100644 --- a/src/plugins/essentials.jl +++ b/src/plugins/essentials.jl @@ -63,9 +63,10 @@ end read_license(license::AbstractString) = string(readchomp(license_path(license))) function render_plugin(p::License, t::Template) - text = "Copyright (c) $(year(today())) $(t.authors)\n" - license = read(p.path, String) - startswith(license, "\n") || (text *= "\n") + date = year(today()) + authors = join(t.authors, ", ") + text = "Copyright (c) $date $authors\n\n" + license = strip(read(p.path, String)) return text * license end diff --git a/src/template.jl b/src/template.jl index 8fa59c75..98628eef 100644 --- a/src/template.jl +++ b/src/template.jl @@ -1,4 +1,4 @@ -default_version() = VersionNumber(VERSION.major) +const DEFAULT_VERSION = VersionNumber(VERSION.major) """ Template(interactive::Bool=false; kwargs...) -> Template @@ -34,7 +34,7 @@ Records common information used to generate a package. struct Template user::String host::String - authors::String + authors::Vector{String} dir::String julia_version::VersionNumber ssh::Bool @@ -46,6 +46,7 @@ end Template(; interactive::Bool=false, kwargs...) = make_template(Val(interactive); kwargs...) +# Non-interactive Template constructor. function make_template(::Val{false}; kwargs...) user = getkw(kwargs, :user) if isempty(user) @@ -56,7 +57,7 @@ function make_template(::Val{false}; kwargs...) host = URI(occursin("://", host) ? host : "https://$host").host authors = getkw(kwargs, :authors) - authors isa Vector && (authors = join(authors, ", ")) + authors isa Vector || (authors = map(strip, split(authors, ","))) dir = abspath(expanduser(getkw(kwargs, :dir))) @@ -82,10 +83,13 @@ function make_template(::Val{false}; kwargs...) ) end +# Does the template have a plugin of this type? Subtypes count too. hasplugin(t::Template, ::Type{T}) where T <: Plugin = any(U -> U <: T, keys(t.plugins)) +# Get a keyword, or compute some default value. getkw(kwargs, k) = get(() -> defaultkw(k), kwargs, k) +# Default Template keyword values. defaultkw(s::Symbol) = defaultkw(Val(s)) defaultkw(::Val{:user}) = LibGit2.getconfig("github.user", "") defaultkw(::Val{:host}) = "https://github.com" @@ -103,5 +107,5 @@ function defaultkw(::Val{:authors}) isempty(name) && return "" author = name * " " isempty(email) || (author *= "<$email>") - return strip(author) + return [strip(author)] end From 4d8b5d360d081339b3cf86bdd280558133ec6963 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Tue, 27 Aug 2019 21:59:25 +0700 Subject: [PATCH 08/81] Some rendering stuff Not quite working. --- src/PkgTemplates.jl | 4 +-- src/plugin.jl | 67 ++++++++++++++++++++++++++++----------- src/plugins/ci.jl | 11 ++++--- src/plugins/documenter.jl | 8 ++++- src/plugins/essentials.jl | 8 +++-- src/template.jl | 10 +++--- 6 files changed, 73 insertions(+), 35 deletions(-) diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index fe4bc4ad..6d07a025 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -9,7 +9,7 @@ using LibGit2: LibGit2 using Pkg: Pkg, TOML, PackageSpec using REPL.TerminalMenus: MultiSelectMenu, RadioMenu, request -using Mustache: render +using Mustache: entityMap, render using Parameters: @with_kw using URIParser: URI @@ -33,10 +33,8 @@ A plugin to be added to a [`Template`](@ref), which adds some functionality or i """ abstract type Plugin end -include("licenses.jl") include("template.jl") include("generate.jl") include("plugin.jl") -include("interactive.jl") end diff --git a/src/plugin.jl b/src/plugin.jl index bf872fec..6175ce21 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -12,12 +12,28 @@ abstract type BasicPlugin <: Plugin end default_file(paths::AbstractString...) = joinpath(DEFAULTS_DIR, paths...) """ - view(::Plugin, ::Template, pkg::AbstractString) -> Dict{String} + view(::Plugin, ::Template, pkg::AbstractString) -> Dict{String, Any} Return the string replacements to be made for this plugin. +`pkg` is the name of the package being generated. """ view(::Plugin, ::Template, ::AbstractString) = Dict{String, Any}() +""" + user_view(::Plugin, ::Template, pkg::AbstractString) -> Dict{String, Any} + +The same as [`view`](@ref), but for use only by package *users* for extension. +TODO better explanation +""" +user_view(::Plugin, ::Template, ::AbstractString) = Dict{String, Any}() + +""" + tags(::Plugin) -> Tuple{String, String} + +Return the tags used for Mustache templating. +""" +tags(::Plugin) = ("{{", "}}") + """ gitignore(::Plugin) -> Vector{String} @@ -66,29 +82,39 @@ end Base.string(b::Badge) = "[![$(b.hover)]($(b.image))]($(b.link))" # Format a plugin's badges as a list of strings, with all substitutions applied. -function badges(p::Plugin, t::Template, pkg_name::AbstractString) +function badges(p::Plugin, t::Template, pkg::AbstractString) bs = badges(p) bs isa Vector || (bs = [bs]) - bs = map(string, bs) - # TODO render + return map(b -> render_text(string(b), combined_view(p, t, pkg)), bs) end """ - gen_plugin(p::Plugin, t::Template, pkg::AbstractString) + gen_plugin(::Plugin, ::Template, pkg::AbstractString) -Generate any files associated with a plugin. +Perform any work associated with a plugin. `pkg` is the name of the package being generated. """ gen_plugin(::Plugin, ::Template, ::AbstractString) = nothing -function gen_plugin(p::BasicPlugin, t::Template, pkg::AbstractString) +function gen_plugin(p::BasicPlugin, t::Template, pkg_dir::AbstractString) + pkg = basename(pkg_dir) + path = joinpath(pkg_dir, destination(p)) + text = render_plugin(p, t, pkg) + gen_file(path, text) +end + +function render_plugin(p::BasicPlugin, t::Template, pkg::AbstractString) src = source(p) src === nothing && return # TODO template rendering code - text = render(src, view(p, t, pkg); tags=tags(p)) - gen_file(joinpath(t.dir, pkg, destination(p)), text) + return render_file(src, combined_view(p, t, pkg), tags(p)) end +function combined_view(p::Plugin, t::Template, pkg::AbstractString) + return merge(view(p, t, pkg), user_view(p, t, pkg)) +end + + """ gen_file(file::AbstractString, text::AbstractString) @@ -102,17 +128,22 @@ function gen_file(file::AbstractString, text::AbstractString) write(file, text) end -# TODO pls make me better - +# Render text from a file. render_file(file::AbstractString, view, tags) = render_text(read(file, String), view, tags) -render_text(text::AbstractString, view, tags) = render(text, view; tags=tags) - -function render_badges(p::BasicPlugin, t::Template, pkg::AbstractString) -end - -function render_plugin(p::BasicPlugin, t::Template, pkg::AbstractString) - render_file(source(p), view(p, t, pkg), tags(p)) +# Render text, using Mustache's templating system. HTML escaping is disabled. +function render_text(text::AbstractString, view::Dict{<:AbstractString}, tags=nothing) + saved = copy(entityMap) + empty!(entityMap) + return try + if tags === nothing + render(text, view) + else + render(text, view; tags=tags) + end + finally + append!(entityMap, saved) + end end include(joinpath("plugins", "essentials.jl")) diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index 2e0b49ce..34455139 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -28,7 +28,7 @@ badges(::TravisCI) = Badge( "https://travis-ci.com/{{USER}}/{{PKG}}.jl", ) -function view(p::TravisCI, t::Template, ::AbstractString) +function view(p::TravisCI, t::Template, pkg::AbstractString) os = String[] p.linux && push!(os, "linux") p.osx && push!(os, "osx") @@ -36,13 +36,14 @@ function view(p::TravisCI, t::Template, ::AbstractString) # TODO: Update the allowed failures as new versions come out. versions = collect_versions(p.extra_versions, t) - allow_failures = filter(v -> v in versions, ("1.3", "nightly")) + allow_failures = filter(v -> v in versions, ["1.3", "nightly"]) x86 = Dict{String, String}[] if p.x86 - foreach(versions) do v - p.linux && push!(x86, Dict("JULIA" => v, "OS" => "linux", "ARCH" => "x86")) - p.windows && push!(x86, Dict("JULIA" => v, "OS" => "windows", "ARCH" => "x86")) + foreach(versions) do v + p.linux && push!(x86, Dict("JULIA" => v, "OS" => "linux", "ARCH" => "x86")) + p.windows && push!(x86, Dict("JULIA" => v, "OS" => "windows", "ARCH" => "x86")) + end end return Dict( diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index 064c98c5..02cc94d6 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -15,6 +15,8 @@ todo - `assets::Vector{<:AbstractString}=String[]`: - `makedocs_kwargs::Dict{Symbol}=Dict{Symbol, Any}()`: - `canonical_url::Union{Function, Nothing}=nothing`:` +- `index_md::AbstractString` +- `make_jl::AbstractString` !!! note If deploying documentation with Travis CI, don't forget to complete the required configuration. @@ -24,14 +26,18 @@ struct Documenter{T<:Union{TravisCI, GitLabCI, Nothing}} <: Plugin assets::Vector{String} makedocs_kwargs::Dict{Symbol} canonical_url::Union{Function, Nothing} + make_jl::String + index_md::String # Can't use @kwdef due to some weird precompilation issues. function Documenter{T}( assets::Vector{<:AbstractString}=String[], makedocs_kwargs::Dict{Symbol}=Dict{Symbol, Any}(), canonical_url::Union{Function, Nothing}=T === TravisCI ? github_pages_url : nothing, + index_md::AbstractString=default_file("index.md"), + make_jl::AbstractString=default_file("make.jl"), ) where T <: Union{TravisCI, GitLabCI, Nothing} - return new(assets, makedocs_kwargs, canonical_url) + return new(assets, makedocs_kwargs, canonical_url, index_md, make_jl) end end diff --git a/src/plugins/essentials.jl b/src/plugins/essentials.jl index 5b43a442..7b9c3e16 100644 --- a/src/plugins/essentials.jl +++ b/src/plugins/essentials.jl @@ -23,7 +23,7 @@ end source(p::Readme) = p.file destination(p::Readme) = p.destination -function view(::Readme, t::Template, pkg::AbstractString) +function view(p::Readme, t::Template, pkg::AbstractString) # Explicitly ordered badges go first. strings = String[] done = DataType[] @@ -36,12 +36,14 @@ function view(::Readme, t::Template, pkg::AbstractString) end foreach(setdiff(keys(t.plugins), done)) do T bs = badges(t.plugins[T], t, pkg) - text *= "\n" * join(badges(t.plugins[T], t.user, pkg), "\n") + append!(strings, badges(t.plugins[T], t, pkg)) end return Dict( + "BADGES" => strings, "HAS_CITATION" => hasplugin(t, Citation), - "HAS_INLINE_BADGES" => p.inline_badges, + "HAS_INLINE_BADGES" => !isempty(strings) && p.inline_badges, + "PKG" => pkg, ) end diff --git a/src/template.jl b/src/template.jl index 98628eef..b89dfe4e 100644 --- a/src/template.jl +++ b/src/template.jl @@ -1,7 +1,7 @@ const DEFAULT_VERSION = VersionNumber(VERSION.major) """ - Template(interactive::Bool=false; kwargs...) -> Template + Template(; interactive::Bool=false, kwargs...) -> Template Records common information used to generate a package. @@ -26,10 +26,10 @@ Records common information used to generate a package. - `disable_default_plugins::Vector{DataType}=DataType[]`: Default plugins to disable. The default plugins are [`Readme`](@ref), [`License`](@ref), [`Tests`](@ref), and [`Gitignore`](@ref). To override a default plugin instead of disabling it altogether, supply it via `plugins`. -- `interactive::Bool=false`: When set, creates the template interactively from user input, - using the previous keywords as a starting point. -- `fast::Bool=false`: Only applicable when `interactive` is set. - Skips prompts for any unsupplied keywords except `user` and `plugins`. + +## Interactive Usage +- `interactive::Bool=false`: When set, creates the template interactively, filling unset keywords with user input. +- `fast::Bool=false`: Skips prompts for any unsupplied keywords except `user` and `plugins`. """ struct Template user::String From 4fa7d9a62b7d92d1f8b3e0269fa14f8ec4b5484a Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Tue, 27 Aug 2019 23:06:17 +0700 Subject: [PATCH 09/81] Track the PkgTemplates version in commit messages --- src/generate.jl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/generate.jl b/src/generate.jl index 3e7f9ce9..d4469e18 100644 --- a/src/generate.jl +++ b/src/generate.jl @@ -39,7 +39,13 @@ function (t::Template)(pkg::AbstractString) if t.git # Commit the files. LibGit2.add!(repo, ".") - LibGit2.commit(repo, "Files generated by PkgTemplates") + msg = "Files generated by PkgTemplates" + installed = Pkg.installed() + if haskey(installed, "PkgTemplates") + ver = string(installed["PkgTemplates"]) + msg *= "\n\nPkgTemplates version: $ver" + end + LibGit2.commit(repo, msg) end if t.dev From 810ac5ab28658e4deebfd1520d0dc3ec424cf013 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Thu, 29 Aug 2019 23:04:11 +0700 Subject: [PATCH 10/81] Many misc changes and bug fixes --- defaults/appveyor.yml | 10 +- src/plugin.jl | 16 +-- src/plugins/ci.jl | 59 +++++++---- src/plugins/coverage.jl | 13 +-- src/plugins/{essentials.jl => defaults.jl} | 11 +- src/plugins/documenter.jl | 29 ++++-- src/template.jl | 114 +++++++++++---------- 7 files changed, 146 insertions(+), 106 deletions(-) rename src/plugins/{essentials.jl => defaults.jl} (93%) diff --git a/defaults/appveyor.yml b/defaults/appveyor.yml index afa1848d..2d4682bb 100644 --- a/defaults/appveyor.yml +++ b/defaults/appveyor.yml @@ -2,17 +2,19 @@ environment: matrix: {{#VERSIONS}} - - julia_version: {{.}} + - julia_version: {{.}} {{/VERSIONS}} platform: {{#PLATFORMS}} - {{.}} {{/PLATFORMS}} -{{#HAS_NIGHTLY}} +{{#HAS_ALLOW_FAILURES}} matrix: allow_failures: - - julia_version: nightly -{{/HAS_NIGHTLY}} +{{#ALLOW_FAILURES}} + - julia_version: {{.}} +{{/ALLOW_FAILURES}} +{{/HAS_ALLOW_FAILURES}} branches: only: - master diff --git a/src/plugin.jl b/src/plugin.jl index 6175ce21..ae331027 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -97,6 +97,7 @@ Perform any work associated with a plugin. gen_plugin(::Plugin, ::Template, ::AbstractString) = nothing function gen_plugin(p::BasicPlugin, t::Template, pkg_dir::AbstractString) + source(p) === nothing && return pkg = basename(pkg_dir) path = joinpath(pkg_dir, destination(p)) text = render_plugin(p, t, pkg) @@ -104,10 +105,8 @@ function gen_plugin(p::BasicPlugin, t::Template, pkg_dir::AbstractString) end function render_plugin(p::BasicPlugin, t::Template, pkg::AbstractString) - src = source(p) - src === nothing && return # TODO template rendering code - return render_file(src, combined_view(p, t, pkg), tags(p)) + return render_file(source(p), combined_view(p, t, pkg), tags(p)) end function combined_view(p::Plugin, t::Template, pkg::AbstractString) @@ -123,15 +122,16 @@ Trailing whitespace is removed, and the file will end with a newline. """ function gen_file(file::AbstractString, text::AbstractString) mkpath(dirname(file)) - text = join(map(rstrip, split(text, "\n")), "\n") - endswith(text , "\n") || (text *= "\n") + text = strip(join(map(rstrip, split(text, "\n")), "\n")) * "\n" write(file, text) end # Render text from a file. -render_file(file::AbstractString, view, tags) = render_text(read(file, String), view, tags) +function render_file(file::AbstractString, view::Dict{<:AbstractString}, tags) + render_text(read(file, String), view, tags) +end -# Render text, using Mustache's templating system. HTML escaping is disabled. +# Render text using Mustache's templating system. HTML escaping is disabled. function render_text(text::AbstractString, view::Dict{<:AbstractString}, tags=nothing) saved = copy(entityMap) empty!(entityMap) @@ -146,7 +146,7 @@ function render_text(text::AbstractString, view::Dict{<:AbstractString}, tags=no end end -include(joinpath("plugins", "essentials.jl")) +include(joinpath("plugins", "defaults.jl")) include(joinpath("plugins", "coverage.jl")) include(joinpath("plugins", "ci.jl")) include(joinpath("plugins", "citation.jl")) diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index 34455139..b6ad6063 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -1,15 +1,17 @@ -const DEFAULT_CI_VERSIONS = ["1.0", "nightly"] +# TODO: Update the allowed failures as new versions come out. const VersionsOrStrings = Vector{Union{VersionNumber, String}} +const ALLOWED_FAILURES = ["1.3", "nightly"] +const DEFAULT_CI_VERSIONS = VersionsOrStrings([VERSION, "1.0", "nightly"]) format_version(v::VersionNumber) = "$(v.major).$(v.minor)" +format_version(v::AbstractString) = string(v) -function collect_versions(versions::Vector, t::Template) - return unique(sort([versions; format_version(t.julia_version)]; by=string)) +function collect_versions(t::Template, versions::Vector) + vs = [format_version(t.julia_version); map(format_version, versions)] + return unique!(sort!(vs)) end -abstract type CI <: Plugin end - -@with_kw struct TravisCI <: CI +@with_kw struct TravisCI <: BasicPlugin file::String = default_file("travis.yml") linux::Bool = true osx::Bool = true @@ -34,9 +36,9 @@ function view(p::TravisCI, t::Template, pkg::AbstractString) p.osx && push!(os, "osx") p.windows && push!(os, "windows") - # TODO: Update the allowed failures as new versions come out. - versions = collect_versions(p.extra_versions, t) - allow_failures = filter(v -> v in versions, ["1.3", "nightly"]) + + versions = collect_versions(t, p.extra_versions) + allow_failures = filter(in(versions), ALLOWED_FAILURES) x86 = Dict{String, String}[] if p.x86 @@ -50,18 +52,20 @@ function view(p::TravisCI, t::Template, pkg::AbstractString) "ALLOW_FAILURES" => allow_failures, "HAS_ALLOW_FAILURES" => !isempty(allow_failures), "HAS_CODECOV" => hasplugin(t, Codecov), - "HAS_COVERAGE" => p.coverage && hasplugin(t, Coverage), + "HAS_COVERAGE" => p.coverage && hasplugin(t, is_coverage), "HAS_COVERALLS" => hasplugin(t, Coveralls), "HAS_DOCUMENTER" => hasplugin(t, Documenter{TravisCI}), "HAS_JOBS" => p.x86 || hasplugin(t, Documenter{TravisCI}), "OS" => os, "PKG" => pkg, + "USER" => t.user, "VERSION" => format_version(t.julia_version), + "VERSIONS" => versions, "X86" => x86, ) end -@with_kw struct AppVeyor <: CI +@with_kw struct AppVeyor <: BasicPlugin file::String = default_file("appveyor.yml") x86::Bool = false coverage::Bool = true @@ -77,19 +81,25 @@ badges(::AppVeyor) = Badge( "https://ci.appveyor.com/project/{{USER}}/{{PKG}}-jl", ) -function view(p::AppVeyor, t::Template, ::AbstractString) +function view(p::AppVeyor, t::Template, pkg::AbstractString) platforms = ["x64"] - t.x86 && push!(platforms, "x86") + p.x86 && push!(platforms, "x86") + + versions = collect_versions(t, p.extra_versions) + allow_failures = filter(in(versions), ALLOWED_FAILURES) + return Dict( - "HAS_CODECOV" => t.coverage && hasplugin(t, Codecov), - "HAS_NIGHTLY" => "nightly" in versions, + "ALLOW_FAILURES" => allow_failures, + "HAS_ALLOW_FAILURES" => !isempty(allow_failures), + "HAS_CODECOV" => p.coverage && hasplugin(t, Codecov), "PKG" => pkg, - "PLATFORMS" => os, - "VERSIONS" => collect_versions(p.extra_versions, t), + "PLATFORMS" => platforms, + "USER" => t.user, + "VERSIONS" => versions, ) end -@with_kw struct CirrusCI <: CI +@with_kw struct CirrusCI <: BasicPlugin file::String = default_file("cirrus.yml") image::String = "freebsd-12-0-release-amd64" coverage::Bool = true @@ -109,14 +119,15 @@ function view(p::CirrusCI, t::Template, ::AbstractString) return Dict( "HAS_CODECOV" => hasplugin(t, Codecov), "HAS_COVERALLS" => hasplugin(t, Coveralls), - "HAS_COVERAGE" => p.coverage && hasplugin(t, Coverage), + "HAS_COVERAGE" => p.coverage && hasplugin(t, is_coverage), "IMAGE" => p.image, "PKG" => pkg, - "VERSIONS" => collect_versions(p.extra_versions, t), + "USER" => t.user, + "VERSIONS" => collect_versions(t, p.extra_versions), ) end -@with_kw struct GitLabCI <: CI +@with_kw struct GitLabCI <: BasicPlugin file::String documentation::Bool = true coverage::Bool = true @@ -147,7 +158,11 @@ function view(p::GitLabCI, t::Template, ::AbstractString) "HAS_COVERAGE" => p.coverage, "HAS_DOCUMENTER" => hasplugin(t, Documenter{GitLabCI}), "PKG" => pkg, + "USER" => t.user, "VERSION" => format_version(t.julia_version), - "VERSIONS" => collect_versions(p.extra_versions, t), + "VERSIONS" => collect_versions(t, p.extra_versions), ) end + +is_ci(::Type) = false +is_ci(::Type{<:Union{AppVeyor, TravisCI, CirrusCI, GitLabCI}}) = true diff --git a/src/plugins/coverage.jl b/src/plugins/coverage.jl index f1cd7091..4025be0c 100644 --- a/src/plugins/coverage.jl +++ b/src/plugins/coverage.jl @@ -1,10 +1,6 @@ -abstract type Coverage <: Plugin end - const COVERAGE_GITIGNORE = ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] -gitignore(::Coverage) = COVERAGE_GITIGNORE - -@with_kw struct Codecov <: Coverage +@with_kw struct Codecov <: BasicPlugin file::Union{String, Nothing} = nothing end @@ -17,7 +13,7 @@ badges(::Codecov) = Badge( "https://codecov.io/gh/{{USER}}/{{PKG}}.jl", ) -@with_kw struct Coveralls <: Coverage +@with_kw struct Coveralls <: BasicPlugin file::Union{String, Nothing} = nothing end @@ -29,3 +25,8 @@ badges(::Coveralls) = Badge( "https://coveralls.io/repos/github/{{USER}}/{{PKG}}.jl/badge.svg?branch=master", "https://coveralls.io/github/{{USER}}/{{PKG}}.jl?branch=master", ) + +gitignore(::Union{Codecov, Coveralls}) = COVERAGE_GITIGNORE + +is_coverage(::Type) = false +is_coverage(::Type{<:Union{Codecov, Coveralls}}) = true diff --git a/src/plugins/essentials.jl b/src/plugins/defaults.jl similarity index 93% rename from src/plugins/essentials.jl rename to src/plugins/defaults.jl index 7b9c3e16..5f614137 100644 --- a/src/plugins/essentials.jl +++ b/src/plugins/defaults.jl @@ -76,10 +76,16 @@ function gen_plugin(p::License, t::Template, pkg_dir::AbstractString) gen_file(joinpath(pkg_dir, p.destination), render_plugin(p, t)) end -struct Gitignore <: Plugin end +@with_kw struct Gitignore <: Plugin + ds_store::Bool = true + dev::Bool = true +end function render_plugin(p::Gitignore, t::Template) - entries = mapreduce(gitignore, append!, values(t.plugins); init=[".DS_Store", "/dev/"]) + init = String[] + p.ds_store && push!(init, ".DS_Store") + p.dev && push!(init, "/dev/") + entries = mapreduce(gitignore, append!, values(t.plugins); init=init) # Only ignore manifests at the repo root. t.manifest || "Manifest.toml" in entries || push!(entries, "/Manifest.toml") unique!(sort!(entries)) @@ -110,6 +116,7 @@ function gen_plugin(p::Tests, t::Template, pkg_dir::AbstractString) open(io -> TOML.print(io, toml), path, "w") # Generate the manifest. + # 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. proj = current_project() try diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index 02cc94d6..45812e8a 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -5,16 +5,18 @@ const DOCUMENTER_UUID = "e30172f5-a6a5-5a46-863b-614d45cd2de4" assets::Vector{<:AbstractString}=String[], makedocs_kwargs::Dict{Symbol}=Dict(), canonical_url::Union{Function, Nothing}=nothing, + make_jl::AbstractString="$(contractuser(default_file("make.jl")))", + index_md::AbstractString="$(contractuser(default_file("index.md")))", ) -> Documenter{T} The `Documenter` plugin adds support for documentation generation via [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl). Documentation deployment depends on `T`, where `T` is some supported CI plugin, or `Nothing` to only support local documentation builds. ## Keyword Arguments -todo +TODO - `assets::Vector{<:AbstractString}=String[]`: - `makedocs_kwargs::Dict{Symbol}=Dict{Symbol, Any}()`: -- `canonical_url::Union{Function, Nothing}=nothing`:` +- `canonical_url::Union{Function, Nothing}=nothing`: - `index_md::AbstractString` - `make_jl::AbstractString` @@ -29,7 +31,7 @@ struct Documenter{T<:Union{TravisCI, GitLabCI, Nothing}} <: Plugin make_jl::String index_md::String - # Can't use @kwdef due to some weird precompilation issues. + # Can't use @with_kw due to some weird precompilation issues. function Documenter{T}( assets::Vector{<:AbstractString}=String[], makedocs_kwargs::Dict{Symbol}=Dict{Symbol, Any}(), @@ -72,6 +74,7 @@ view(p::Documenter, t::Template, pkg::AbstractString) = Dict( "MAKEDOCS_KWARGS" => map((k, v) -> k => repr(v), collect(p.makedocs_kwargs)), "PKG" => pkg, "REPO" => "https://$(t.host)/$(t.user)/$pkg.jl", + "USER" => t.user, ) function view(p::Documenter{TravisCI}, t::Template, pkg::AbstractString) @@ -80,11 +83,20 @@ function view(p::Documenter{TravisCI}, t::Template, pkg::AbstractString) end function gen_plugin(p::Documenter, t::Template, pkg_dir::AbstractString) - # TODO: gen make.jl - # TODO: gen index.md + docs_dir = joinpath(pkg_dir, "docs") + + # Generate files. + make = render_file(p.make_jl, combined_view(p, t, pkg), tags(p)) + gen_file(joinpath(docs_dir, "make.jl"), make) + index = render_file(p.index_md, combined_view(p, t, pkg), tags(p)) + gen_file(joinpath(docs_dir, "src", "index.md"), index) + + # Copy over any assets. + assets_dir = joinpath(docs_dir, "src", "assets") + isempty(p.assets) || mkpath(assets_dir) + foreach(a -> cp(a, joinpath(assets_dir, basename(a))), p.assets) # Create the documentation project. - docs_dir = joinpath(pkg_dir, "docs") proj = current_project() try Pkg.activate(docs_dir) @@ -92,11 +104,6 @@ function gen_plugin(p::Documenter, t::Template, pkg_dir::AbstractString) finally proj === nothing ? Pkg.activate() : Pkg.activate(proj) end - - # Copy any assets. - assets_dir = joinpath(docs_dir, "src", "assets") - isempty(p.assets) || mkpath(assets_dir) - foreach(a -> cp(a, joinpath(assets_dir, basename(asset))), p.assets) end function interactive(::Type{Documenter{T}}) where T diff --git a/src/template.jl b/src/template.jl index b89dfe4e..2d8f3dca 100644 --- a/src/template.jl +++ b/src/template.jl @@ -1,4 +1,14 @@ +const DEFAULT_USER = LibGit2.getconfig("github.user", "") const DEFAULT_VERSION = VersionNumber(VERSION.major) +const DEFAULT_AUTHORS = let + name = LibGit2.getconfig("user.name", "") + email = LibGit2.getconfig("user.email", "") + if isempty(name) + "" + else + isempty(email) ? name : "$name <$email>" + end +end """ Template(; interactive::Bool=false, kwargs...) -> Template @@ -6,52 +16,56 @@ const DEFAULT_VERSION = VersionNumber(VERSION.major) Records common information used to generate a package. ## Keyword Arguments -- `user::AbstractString=""`: GitHub (or other code hosting service) username. - If left unset, it will take the the global Git config's value (`github.user`). - If that is not set, an `ArgumentError` is thrown. - This is case-sensitive for some plugins, so take care to enter it correctly! -- `host::AbstractString="github.com"`: URL to the code hosting service where your package will reside. - Note that while hosts other than GitHub won't cause errors, they are not officially supported and they will cause certain plugins will produce incorrect output. -- `authors::Union{AbstractString, Vector{<:AbstractString}}=""`: Names that appear on the license. + +### User Options +- `user::AbstractString="$DEFAULT_USER"`: GitHub (or other code hosting service) username. + The default value comes from the global Git config (`github.user`). + If no value is obtained, an `ArgumentError` is thrown. +- `authors::Union{AbstractString, Vector{<:AbstractString}}="$DEFAULT_AUTHORS"`: Package authors. Supply a string for one author or an array for multiple. - Similarly to `user`, it will take the value of of the global Git config's value if it is left unset. -- `dir::AbstractString=$(contractuser(Pkg.devdir()))`: Directory in which the package will go. - Relative paths are converted to absolute ones at template creation time. -- `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. + Like `user`, it takes its default value from the global Git config (`user.name` and `user.email`). + +### Package Options +- `host::AbstractString="github.com"`: URL to the code hosting service where packages will reside. +- `dir::AbstractString="$(contractuser(Pkg.devdir()))"`: Directory to place packages in. +- `julia_version::VersionNumber=$(repr(DEFAULT_VERSION))`: Minimum allowed Julia version. +- `develop::Bool=true`: Whether or not to `develop` new packages in the active environment. + +### Git Options +- `git::Bool=true`: Whether or not to create a Git repository for new packages. +- `ssh::Bool=false`: Whether or not to use SSH for the Git remote. + If left unset, HTTPS will be used. - `manifest::Bool=false`: Whether or not to commit the `Manifest.toml`. -- `git::Bool=true`: Whether or not to create a Git repository for generated packages. -- `develop::Bool=true`: Whether or not to `develop` generated packages in the active environment. -- `plugins::Vector{<:Plugin}=Plugin[]`: A list of plugins that the package will include. -- `disable_default_plugins::Vector{DataType}=DataType[]`: Default plugins to disable. + +### Template Plugins +- `plugins::Vector{<:Plugin}=Plugin[]`: A list of [`Plugin`](@ref)s used by the template. +- `disabled_defaults::Vector{DataType}=DataType[]`: Default plugins to disable. The default plugins are [`Readme`](@ref), [`License`](@ref), [`Tests`](@ref), and [`Gitignore`](@ref). To override a default plugin instead of disabling it altogether, supply it via `plugins`. -## Interactive Usage -- `interactive::Bool=false`: When set, creates the template interactively, filling unset keywords with user input. -- `fast::Bool=false`: Skips prompts for any unsupplied keywords except `user` and `plugins`. +### Interactive Usage +- `interactive::Bool=false`: When set, the template is created interactively, filling unset keywords with user input. +- `fast::Bool=false`: Skips prompts for any unsupplied keywords except `user` and `plugins`, accepting default values. """ struct Template - user::String - host::String authors::Vector{String} + develop::Bool dir::String + git::Bool + host::String julia_version::VersionNumber - ssh::Bool manifest::Bool - git::Bool - develop::Bool plugins::Dict{DataType, <:Plugin} + ssh::Bool + user::String end -Template(; interactive::Bool=false, kwargs...) = make_template(Val(interactive); kwargs...) +Template(; interactive::Bool=false, kwargs...) = Template(Val(interactive); kwargs...) -# Non-interactive Template constructor. -function make_template(::Val{false}; kwargs...) +# Non-interactive constructor. +function Template(::Val{false}; kwargs...) user = getkw(kwargs, :user) - if isempty(user) - throw(ArgumentError("No username found, set one with user=username")) - end + isempty(user) && throw(ArgumentError("No user set, please pass user=username")) host = getkw(kwargs, :host) host = URI(occursin("://", host) ? host : "https://$host").host @@ -63,49 +77,43 @@ function make_template(::Val{false}; kwargs...) disabled = getkw(kwargs, :disabled_defaults) defaults = [Readme, License, Tests, Gitignore] - plugins = map(T -> T(), filter(T -> !in(T, disabled), defaults)) + plugins = map(T -> T(), filter(T -> !(T in disabled), defaults)) append!(plugins, getkw(kwargs, :plugins)) - # This comprehensions resolves duplicate plugin types by overwriting, + # This comprehension resolves duplicate plugin types by overwriting, # which means that default plugins get replaced by user values. plugin_dict = Dict(typeof(p) => p for p in plugins) return Template( - user, - host, authors, + getkw(kwargs, :develop), dir, + getkw(kwargs, :git), + host, getkw(kwargs, :julia_version), - getkw(kwargs, :ssh), getkw(kwargs, :manifest), - getkw(kwargs, :git), - getkw(kwargs, :develop), plugin_dict, + getkw(kwargs, :ssh), + user, ) end -# Does the template have a plugin of this type? Subtypes count too. -hasplugin(t::Template, ::Type{T}) where T <: Plugin = any(U -> U <: T, keys(t.plugins)) +# Does the template have a plugin that satisfies some predicate? +hasplugin(t::Template, f::Function) = any(f, keys(t.plugins)) +hasplugin(t::Template, ::Type{T}) where T <: Plugin = hasplugin(t, U -> U <: T) # Get a keyword, or compute some default value. getkw(kwargs, k) = get(() -> defaultkw(k), kwargs, k) # Default Template keyword values. defaultkw(s::Symbol) = defaultkw(Val(s)) -defaultkw(::Val{:user}) = LibGit2.getconfig("github.user", "") -defaultkw(::Val{:host}) = "https://github.com" +defaultkw(::Val{:authors}) = DEFAULT_AUTHORS +defaultkw(::Val{:develop}) = true defaultkw(::Val{:dir}) = Pkg.devdir() +defaultkw(::Val{:disabled_defaults}) = DataType[] +defaultkw(::Val{:git}) = true +defaultkw(::Val{:host}) = "github.com" defaultkw(::Val{:julia_version}) = DEFAULT_VERSION -defaultkw(::Val{:ssh}) = false defaultkw(::Val{:manifest}) = false -defaultkw(::Val{:git}) = true -defaultkw(::Val{:develop}) = true defaultkw(::Val{:plugins}) = Plugin[] -defaultkw(::Val{:disabled_defaults}) = DataType[] -function defaultkw(::Val{:authors}) - name = LibGit2.getconfig("user.name", "") - email = LibGit2.getconfig("user.email", "") - isempty(name) && return "" - author = name * " " - isempty(email) || (author *= "<$email>") - return [strip(author)] -end +defaultkw(::Val{:ssh}) = false +defaultkw(::Val{:user}) = DEFAULT_USER From 5adde3ad7c5d0ce2e1297e4fe5c5a2e1f7610505 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sat, 31 Aug 2019 17:33:33 +0700 Subject: [PATCH 11/81] Add some basic tests --- .gitignore | 6 +-- .travis.yml | 3 ++ Manifest.toml | 6 --- Project.toml | 8 ++-- src/PkgTemplates.jl | 2 +- src/generate.jl | 1 - src/plugins/ci.jl | 17 ++++---- src/plugins/defaults.jl | 4 +- src/template.jl | 48 ++++++++++------------ test/fixtures/Basic/.gitignore.txt | 3 ++ test/fixtures/Basic/LICENSE.txt | 19 +++++++++ test/fixtures/Basic/Manifest.toml.txt | 2 + test/fixtures/Basic/Project.toml.txt | 13 ++++++ test/fixtures/Basic/README.md.txt | 1 + test/fixtures/Basic/src/Basic.jl.txt | 5 +++ test/fixtures/Basic/test/runtests.jl.txt | 6 +++ test/generate.jl | 25 ++++++++++++ test/runtests.jl | 32 +++++++++++++++ test/template.jl | 52 ++++++++++++++++++++++++ 19 files changed, 201 insertions(+), 52 deletions(-) create mode 100644 test/fixtures/Basic/.gitignore.txt create mode 100644 test/fixtures/Basic/LICENSE.txt create mode 100644 test/fixtures/Basic/Manifest.toml.txt create mode 100644 test/fixtures/Basic/Project.toml.txt create mode 100644 test/fixtures/Basic/README.md.txt create mode 100644 test/fixtures/Basic/src/Basic.jl.txt create mode 100644 test/fixtures/Basic/test/runtests.jl.txt create mode 100644 test/generate.jl create mode 100644 test/template.jl diff --git a/.gitignore b/.gitignore index 7be7ea33..de2e6edb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ +/docs/build/ +/docs/site/ .DS_Store -*.jl.cov *.jl.*.cov +*.jl.cov *.jl.mem -/docs/build/ -/docs/site/ diff --git a/.travis.yml b/.travis.yml index 8bcbbb89..e4d9dcec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,9 @@ julia: - 1.2 - 1.3 - nightly +before_script: + - git config --global user.name Tester + - git config --global user.email te@st.er matrix: fast_finish: true allow_failures: diff --git a/Manifest.toml b/Manifest.toml index c709f1dd..afff9f01 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -106,12 +106,6 @@ version = "0.2.11" deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -[[URIParser]] -deps = ["Test", "Unicode"] -git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69" -uuid = "30578b45-9adc-5946-b283-645ec420af67" -version = "0.4.0" - [[UUIDs]] deps = ["Random", "SHA"] uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" diff --git a/Project.toml b/Project.toml index 863df150..5e069c6f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PkgTemplates" uuid = "14b8a8f1-9102-5b29-a752-f990bacb7fe1" authors = ["Chris de Graaf "] -version = "0.6.2" +version = "0.7.0" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" @@ -11,14 +11,14 @@ Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" -URIParser = "30578b45-9adc-5946-b283-645ec420af67" [compat] julia = "1" [extras] -Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Suppressor", "Test"] +test = ["Random", "ReferenceTests", "Test"] diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index 6d07a025..801958b0 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -11,7 +11,6 @@ using REPL.TerminalMenus: MultiSelectMenu, RadioMenu, request using Mustache: entityMap, render using Parameters: @with_kw -using URIParser: URI export Template, @@ -36,5 +35,6 @@ abstract type Plugin end include("template.jl") include("generate.jl") include("plugin.jl") +# include("interactive.jl") end diff --git a/src/generate.jl b/src/generate.jl index d4469e18..cc5404ad 100644 --- a/src/generate.jl +++ b/src/generate.jl @@ -6,7 +6,6 @@ Generate a package named `pkg` from a [`Template`](@ref). function (t::Template)(pkg::AbstractString) endswith(pkg, ".jl") && (pkg = pkg[1:end-3]) pkg_dir = joinpath(t.dir, pkg) - ispath(pkg_dir) && throw(ArgumentError("$pkg_dir already exists")) try # Create the directory with some boilerplate inside. diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index b6ad6063..b792ef44 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -1,14 +1,13 @@ -# TODO: Update the allowed failures as new versions come out. const VersionsOrStrings = Vector{Union{VersionNumber, String}} -const ALLOWED_FAILURES = ["1.3", "nightly"] -const DEFAULT_CI_VERSIONS = VersionsOrStrings([VERSION, "1.0", "nightly"]) +const ALLOWED_FAILURES = ["1.3", "nightly"] # TODO: Update this list with new RCs. +const DEFAULT_CI_VERSIONS = VersionsOrStrings([VERSION, default_version(), "nightly"]) format_version(v::VersionNumber) = "$(v.major).$(v.minor)" format_version(v::AbstractString) = string(v) function collect_versions(t::Template, versions::Vector) - vs = [format_version(t.julia_version); map(format_version, versions)] - return unique!(sort!(vs)) + vs = map(format_version, [t.julia_version, versions...]) + return unique(sort(vs)) end @with_kw struct TravisCI <: BasicPlugin @@ -43,8 +42,8 @@ function view(p::TravisCI, t::Template, pkg::AbstractString) x86 = Dict{String, String}[] if p.x86 foreach(versions) do v - p.linux && push!(x86, Dict("JULIA" => v, "OS" => "linux", "ARCH" => "x86")) - p.windows && push!(x86, Dict("JULIA" => v, "OS" => "windows", "ARCH" => "x86")) + p.linux && push!(x86, Dict("JULIA" => v, "OS" => "linux")) + p.windows && push!(x86, Dict("JULIA" => v, "OS" => "windows")) end end @@ -128,10 +127,10 @@ function view(p::CirrusCI, t::Template, ::AbstractString) end @with_kw struct GitLabCI <: BasicPlugin - file::String + file::String = default_file("gitlab-ci.yml") documentation::Bool = true coverage::Bool = true - extra_versions::Vector{VersionNumber} = [v"1.0"] + extra_versions::VersionsOrStrings = ["1.0"] # Nightly has no Docker image. end gitignore(p::GitLabCI) = p.coverage ? COVERAGE_GITIGNORE : String[] diff --git a/src/plugins/defaults.jl b/src/plugins/defaults.jl index 5f614137..2c4d5968 100644 --- a/src/plugins/defaults.jl +++ b/src/plugins/defaults.jl @@ -93,7 +93,7 @@ function render_plugin(p::Gitignore, t::Template) end function gen_plugin(p::Gitignore, t::Template, pkg_dir::AbstractString) - gen_file(joinpath(pkg_dir, ".gitignore"), render_plugin(p, t)) + t.git && gen_file(joinpath(pkg_dir, ".gitignore"), render_plugin(p, t)) end @with_kw struct Tests <: BasicPlugin @@ -121,7 +121,7 @@ function gen_plugin(p::Tests, t::Template, pkg_dir::AbstractString) proj = current_project() try Pkg.activate(pkg_dir) - Pkg.update() # Clean up both Manifest.toml and Project.toml. + Pkg.update() finally proj === nothing ? Pkg.activate() : Pkg.activate(proj) end diff --git a/src/template.jl b/src/template.jl index 2d8f3dca..72dc581e 100644 --- a/src/template.jl +++ b/src/template.jl @@ -1,13 +1,12 @@ -const DEFAULT_USER = LibGit2.getconfig("github.user", "") -const DEFAULT_VERSION = VersionNumber(VERSION.major) -const DEFAULT_AUTHORS = let +default_plugins() = [Gitignore(), License(), Readme(), Tests()] +default_user() = LibGit2.getconfig("github.user", "") +default_version() = VersionNumber(VERSION.major) + +function default_authors() name = LibGit2.getconfig("user.name", "") + isempty(name) && return "" email = LibGit2.getconfig("user.email", "") - if isempty(name) - "" - else - isempty(email) ? name : "$name <$email>" - end + return isempty(email) ? name : "$name <$email>" end """ @@ -18,17 +17,17 @@ Records common information used to generate a package. ## Keyword Arguments ### User Options -- `user::AbstractString="$DEFAULT_USER"`: GitHub (or other code hosting service) username. +- `user::AbstractString="$(default_user())"`: GitHub (or other code hosting service) username. The default value comes from the global Git config (`github.user`). If no value is obtained, an `ArgumentError` is thrown. -- `authors::Union{AbstractString, Vector{<:AbstractString}}="$DEFAULT_AUTHORS"`: Package authors. +- `authors::Union{AbstractString, Vector{<:AbstractString}}="$(default_authors())"`: Package authors. Supply a string for one author or an array for multiple. Like `user`, it takes its default value from the global Git config (`user.name` and `user.email`). ### Package Options - `host::AbstractString="github.com"`: URL to the code hosting service where packages will reside. - `dir::AbstractString="$(contractuser(Pkg.devdir()))"`: Directory to place packages in. -- `julia_version::VersionNumber=$(repr(DEFAULT_VERSION))`: Minimum allowed Julia version. +- `julia_version::VersionNumber=$(repr(default_version()))`: Minimum allowed Julia version. - `develop::Bool=true`: Whether or not to `develop` new packages in the active environment. ### Git Options @@ -39,13 +38,12 @@ Records common information used to generate a package. ### Template Plugins - `plugins::Vector{<:Plugin}=Plugin[]`: A list of [`Plugin`](@ref)s used by the template. -- `disabled_defaults::Vector{DataType}=DataType[]`: Default plugins to disable. +- `disable_defaults::Vector{DataType}=DataType[]`: Default plugins to disable. The default plugins are [`Readme`](@ref), [`License`](@ref), [`Tests`](@ref), and [`Gitignore`](@ref). To override a default plugin instead of disabling it altogether, supply it via `plugins`. ### Interactive Usage - `interactive::Bool=false`: When set, the template is created interactively, filling unset keywords with user input. -- `fast::Bool=false`: Skips prompts for any unsupplied keywords except `user` and `plugins`, accepting default values. """ struct Template authors::Vector{String} @@ -67,21 +65,19 @@ function Template(::Val{false}; kwargs...) user = getkw(kwargs, :user) isempty(user) && throw(ArgumentError("No user set, please pass user=username")) - host = getkw(kwargs, :host) - host = URI(occursin("://", host) ? host : "https://$host").host - authors = getkw(kwargs, :authors) authors isa Vector || (authors = map(strip, split(authors, ","))) + host = replace(getkw(kwargs, :host), r".*://" => "") + dir = abspath(expanduser(getkw(kwargs, :dir))) - disabled = getkw(kwargs, :disabled_defaults) - defaults = [Readme, License, Tests, Gitignore] - plugins = map(T -> T(), filter(T -> !(T in disabled), defaults)) - append!(plugins, getkw(kwargs, :plugins)) + disabled = getkw(kwargs, :disable_defaults) + enabled = filter(p -> !(typeof(p) in disabled), default_plugins()) + append!(enabled, getkw(kwargs, :plugins)) # This comprehension resolves duplicate plugin types by overwriting, # which means that default plugins get replaced by user values. - plugin_dict = Dict(typeof(p) => p for p in plugins) + plugins = Dict(typeof(p) => p for p in enabled) return Template( authors, @@ -91,7 +87,7 @@ function Template(::Val{false}; kwargs...) host, getkw(kwargs, :julia_version), getkw(kwargs, :manifest), - plugin_dict, + plugins, getkw(kwargs, :ssh), user, ) @@ -106,14 +102,14 @@ getkw(kwargs, k) = get(() -> defaultkw(k), kwargs, k) # Default Template keyword values. defaultkw(s::Symbol) = defaultkw(Val(s)) -defaultkw(::Val{:authors}) = DEFAULT_AUTHORS +defaultkw(::Val{:authors}) = default_authors() defaultkw(::Val{:develop}) = true defaultkw(::Val{:dir}) = Pkg.devdir() -defaultkw(::Val{:disabled_defaults}) = DataType[] +defaultkw(::Val{:disable_defaults}) = DataType[] defaultkw(::Val{:git}) = true defaultkw(::Val{:host}) = "github.com" -defaultkw(::Val{:julia_version}) = DEFAULT_VERSION +defaultkw(::Val{:julia_version}) = default_version() defaultkw(::Val{:manifest}) = false defaultkw(::Val{:plugins}) = Plugin[] defaultkw(::Val{:ssh}) = false -defaultkw(::Val{:user}) = DEFAULT_USER +defaultkw(::Val{:user}) = default_user() diff --git a/test/fixtures/Basic/.gitignore.txt b/test/fixtures/Basic/.gitignore.txt new file mode 100644 index 00000000..145cb1a6 --- /dev/null +++ b/test/fixtures/Basic/.gitignore.txt @@ -0,0 +1,3 @@ +.DS_Store +/Manifest.toml +/dev/ diff --git a/test/fixtures/Basic/LICENSE.txt b/test/fixtures/Basic/LICENSE.txt new file mode 100644 index 00000000..9ce1e635 --- /dev/null +++ b/test/fixtures/Basic/LICENSE.txt @@ -0,0 +1,19 @@ +Copyright (c) 2019 tester + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/test/fixtures/Basic/Manifest.toml.txt b/test/fixtures/Basic/Manifest.toml.txt new file mode 100644 index 00000000..f45eecff --- /dev/null +++ b/test/fixtures/Basic/Manifest.toml.txt @@ -0,0 +1,2 @@ +# This file is machine-generated - editing it directly is not advised + diff --git a/test/fixtures/Basic/Project.toml.txt b/test/fixtures/Basic/Project.toml.txt new file mode 100644 index 00000000..3d5ccb69 --- /dev/null +++ b/test/fixtures/Basic/Project.toml.txt @@ -0,0 +1,13 @@ +name = "Basic" +uuid = "5b7e9947-ddc0-4b3f-9b55-0d8042f74170" +authors = ["tester"] +version = "0.1.0" + +[compat] +julia = "1" + +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test"] diff --git a/test/fixtures/Basic/README.md.txt b/test/fixtures/Basic/README.md.txt new file mode 100644 index 00000000..0b51bff1 --- /dev/null +++ b/test/fixtures/Basic/README.md.txt @@ -0,0 +1 @@ +# Basic diff --git a/test/fixtures/Basic/src/Basic.jl.txt b/test/fixtures/Basic/src/Basic.jl.txt new file mode 100644 index 00000000..5c9a3d6f --- /dev/null +++ b/test/fixtures/Basic/src/Basic.jl.txt @@ -0,0 +1,5 @@ +module Basic + +greet() = print("Hello World!") + +end # module diff --git a/test/fixtures/Basic/test/runtests.jl.txt b/test/fixtures/Basic/test/runtests.jl.txt new file mode 100644 index 00000000..085a7069 --- /dev/null +++ b/test/fixtures/Basic/test/runtests.jl.txt @@ -0,0 +1,6 @@ +using Basic +using Test + +@testset "Basic.jl" begin + # Write your tests here. +end diff --git a/test/generate.jl b/test/generate.jl new file mode 100644 index 00000000..58fb980b --- /dev/null +++ b/test/generate.jl @@ -0,0 +1,25 @@ +default_files(pkg::AbstractString) = [ + ".gitignore", + "LICENSE", + "Manifest.toml", + "Project.toml", + "README.md", + "src/$pkg.jl", + "test/runtests.jl", +] + +function reference_test(pkg_dir::AbstractString, path::AbstractString) + pkg = basename(pkg_dir) + path = replace(path, "/" => path_separator) + # All fixture files are .txt because otherwise ReferenceTests/FileIO can't handle them. + reference = joinpath(@__DIR__, "fixtures", pkg, path * ".txt") + observed = read(joinpath(pkg_dir, path), String) + @test_reference reference observed +end + +@testset "Default package" begin + pkg = "Basic" + t = tpl(; develop=false, authors=USER) + t(pkg) + foreach(f -> reference_test(joinpath(t.dir, pkg), f), default_files(pkg)) +end diff --git a/test/runtests.jl b/test/runtests.jl index e69de29b..f023f0d7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -0,0 +1,32 @@ +using Base.Filesystem: path_separator + +using Pkg: Pkg +using Random: Random +using Test: @test, @testset, @test_throws + +using ReferenceTests: @test_reference + +using PkgTemplates +const PT = PkgTemplates + +const PKG = "TestPkg" +const USER = "tester" + +Random.seed!(1) + +tpl(; kwargs...) = Template(; user=USER, kwargs...) + +@testset "PkgTemplates.jl" begin + mktempdir() do dir + Pkg.activate(dir) + pushfirst!(DEPOT_PATH, dir) + try + include("template.jl") + include("generate.jl") + # include("plugin.jl") + # include("interactive.jl") + finally + popfirst!(DEPOT_PATH) + end + end +end diff --git a/test/template.jl b/test/template.jl new file mode 100644 index 00000000..95ffa552 --- /dev/null +++ b/test/template.jl @@ -0,0 +1,52 @@ +@testset "Template constructor" begin + @testset "user" begin + if isempty(PT.default_user()) + @test_throws ArgumentError Template() + haskey(ENV, "CI") && run(`git config --global github.user $USER`) + end + @test Template().user == PT.default_user() + end + + @testset "authors" begin + @test tpl(; authors=["a"]).authors == ["a"] + @test tpl(; authors="a").authors == ["a"] + @test tpl(; authors="a,b").authors == ["a", "b"] + @test tpl(; authors="a, b").authors == ["a", "b"] + end + + @testset "host" begin + @test tpl(; host="https://foo.com").host == "foo.com" + end + + @testset "dir" begin + @test tpl(; dir="/foo/bar").dir == "/foo/bar" + @test tpl(; dir="foo").dir == abspath("foo") + @test tpl(; dir="~/foo").dir == abspath(expanduser("~/foo")) + end + + @testset "plugins / disabled_defaults" begin + function test_plugins(plugins, expected, disabled=DataType[]) + t = tpl(; plugins=plugins, disable_defaults=disabled) + @test issetequal(values(t.plugins), expected) + end + + defaults = PT.default_plugins() + test_plugins([], defaults) + test_plugins([Citation()], union(defaults, [Citation()])) + # Overriding a default plugin. + gi = Gitignore(; dev=false) + test_plugins([gi], union(setdiff(defaults, [Gitignore()]), [gi])) + # Disabling a default plugin. + test_plugins([], setdiff(defaults, [Gitignore()]), [Gitignore]) + end +end + +@testset "hasplugin" begin + t = tpl(; plugins=[Documenter{TravisCI}()]) + @test PT.hasplugin(t, typeof(first(PT.default_plugins()))) + @test PT.hasplugin(t, Documenter) + @test PT.hasplugin(t, _ -> true) + @test !PT.hasplugin(t, _ -> false) + @test !PT.hasplugin(t, Citation) + @test !PT.hasplugin(t, PT.is_ci) +end From e7a51c909a8a7649ff2ce19421f0e2c1da959dd7 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sat, 31 Aug 2019 17:49:20 +0700 Subject: [PATCH 12/81] Delete old docs, update build --- defaults/make.jl | 4 +- docs/make.jl | 20 +++--- docs/src/index.md | 103 +-------------------------- docs/src/pages/index.md | 4 -- docs/src/pages/licenses.md | 14 ---- docs/src/pages/package_generation.md | 15 ---- docs/src/pages/plugin_development.md | 72 ------------------- docs/src/pages/plugins.md | 31 -------- src/plugins/documenter.jl | 2 +- 9 files changed, 15 insertions(+), 250 deletions(-) delete mode 100644 docs/src/pages/index.md delete mode 100644 docs/src/pages/licenses.md delete mode 100644 docs/src/pages/package_generation.md delete mode 100644 docs/src/pages/plugin_development.md delete mode 100644 docs/src/pages/plugins.md diff --git a/defaults/make.jl b/defaults/make.jl index 93adc9b4..f21f821e 100644 --- a/defaults/make.jl +++ b/defaults/make.jl @@ -1,10 +1,10 @@ using {{PKG}} using Documenter -makedocs( +makedocs(; modules=[{{PKG}}], authors="{{AUTHORS}}", - repo="{{REPO}}", + repo="https://{{REPO}}/blob/{commit}{path}#L{line}", sitename="{{PKG}}.jl", format=Documenter.HTML(; canonical="{{CANONICAL}}", diff --git a/docs/make.jl b/docs/make.jl index 1ed399d0..b80a9130 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,20 +1,18 @@ -using Documenter, PkgTemplates +using Documenter +using PkgTemplates makedocs(; modules=[PkgTemplates], - format=Documenter.HTML(), + authors="Chris de Graaf, Invenia Technical Computing Corporation", + repo="https://github.com/invenia/PkgTemplates.jl/blob/{commit}{path}#L{line}", + sitename="PkgTemplates.jl", + format=Documenter.HTML(; + canonical="https://invenia.github.io/PkgTemplates.jl", + assets=String[], + ), pages=[ "Home" => "index.md", - "Package Generation" => "pages/package_generation.md", - "Plugins" => "pages/plugins.md", - "Plugin Development" => "pages/plugin_development.md", - "Licenses" => "pages/licenses.md", - "Index" => "pages/index.md", ], - repo="https://github.com/invenia/PkgTemplates.jl/blob/{commit}{path}#L{line}", - sitename="PkgTemplates.jl", - authors="Chris de Graaf, Invenia Technical Computing Corporation", - assets=[], ) deploydocs(; diff --git a/docs/src/index.md b/docs/src/index.md index f2bb79a3..d819939e 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -1,105 +1,8 @@ # PkgTemplates -[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://invenia.github.io/PkgTemplates.jl/stable) -[![Latest](https://img.shields.io/badge/docs-latest-blue.svg)](https://invenia.github.io/PkgTemplates.jl/latest) -[![Build Status](https://travis-ci.org/invenia/PkgTemplates.jl.svg?branch=master)](https://travis-ci.org/invenia/PkgTemplates.jl) -[![Build Status](https://ci.appveyor.com/api/projects/status/r24xamruqlm88uti/branch/master?svg=true)](https://ci.appveyor.com/project/christopher-dG/pkgtemplates-jl/branch/master) -[![Codecov](https://codecov.io/gh/invenia/PkgTemplates.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/invenia/PkgTemplates.jl) - -**PkgTemplates is a Julia package for creating new Julia packages in an easy, -repeatable, and customizable way.** - -## Installation - -```julia -pkg> add PkgTemplates -``` - -## Plugins - -`PkgTemplates` is based on plugins which handle the setup of individual package components. -The available plugins are: - -* Continuous Integration (CI) - * [Travis CI](https://travis-ci.com) (Linux, MacOS) - * [AppVeyor](https://appveyor.com) (Windows) - * [GitLabCI](https://gitlab.com) (Linux) - * [CirrusCI](https://cirrus-ci.org) (FreeBSD) -* Code Coverage - * [Codecov](https://codecov.io) - * [Coveralls](https://coveralls.io) -* Documentation - * [GitHubPages](https://pages.github.com) -* Citation - -## Usage - -```@setup usage -using LibGit2: getconfig -isempty(getconfig("user.name", "")) && run(`git config --global user.name "Travis"`) -isempty(getconfig("user.email", "")) && run(`git config --global user.email "travis@c.i"`) -isempty(getconfig("github.user", "")) && run(`git config --global github.user "travis"`) -using Pkg -Pkg.activate(mktempdir()) -# This code gets run in docs/build/, so this path evaluates to the repo root. -Pkg.add(PackageSpec(path=dirname(dirname(pwd())))) -``` - -Assuming you have the relatively standard Git options `user.name`, `user.email` and `github.user` set up globally with `git config --global`, the simplest template requires no arguments: - - -```@repl usage -using PkgTemplates -t = Template() -generate("MyPkg", t) -run(`git -C $(joinpath(t.dir, "MyPkg")) ls-files`); +```@index ``` -However, we can also configure a number of keyword arguments to -[`Template`](@ref): - -```@repl usage -using PkgTemplates -t = Template(; - user="myusername", - license="MIT", - authors=["Chris de Graaf", "Invenia Technical Computing Corporation"], - dir="~/code", - julia_version=v"0.7", - ssh=true, - plugins=[ - TravisCI(), - Codecov(), - Coveralls(), - AppVeyor(), - Documenter{TravisCI}(), - ], -) -generate("MyPkg2", t) -run(`git -C $(joinpath(t.dir, "MyPkg2")) ls-files`); +```@autodocs +Modules = [PkgTemplates] ``` - -If that looks like a lot of work, you can also create templates interactively -with [`interactive_template`](@ref): - -[![asciicast](https://asciinema.org/a/31bZqW9u8h5RHpd7gtsemioRV.png)](https://asciinema.org/a/31bZqW9u8h5RHpd7gtsemioRV) - -And if that's **still** too much work for you, you can call -`interactive_template` with `fast=true` to use default values for everything -but username and plugin selection. - -You can also use [`generate_interactive`](@ref) to interactively generate a template and then -immediately use it to create a new package. - -## Comparison to PkgDev - -`PkgTemplates` is similar in functionality to -[`PkgDev`](https://github.com/JuliaLang/PkgDev.jl)'s `generate` function. However, -`PkgTemplates` offers more customizability in templates and more extensibility via plugins. -For the package registration and release management features that `PkgTemplates` doesn't -include, you are encouraged to use [AttoBot](https://github.com/apps/attobot) instead. - -## Contributing - -It's extremely easy to extend `PkgTemplates` with new plugins. To get started, -check out [Plugin Development](@ref). diff --git a/docs/src/pages/index.md b/docs/src/pages/index.md deleted file mode 100644 index aa651b91..00000000 --- a/docs/src/pages/index.md +++ /dev/null @@ -1,4 +0,0 @@ -# Index - -```@index -``` diff --git a/docs/src/pages/licenses.md b/docs/src/pages/licenses.md deleted file mode 100644 index f8adc5d6..00000000 --- a/docs/src/pages/licenses.md +++ /dev/null @@ -1,14 +0,0 @@ -```@meta -CurrentModule = PkgTemplates -``` - -# Licenses - -[Many open-source licenses](https://github.com/invenia/PkgTemplates.jl/tree/master/licenses) -are available for use with `PkgTemplates`, but if you see that one is missing, don't -hesitate to open an issue or PR. - -```@docs -available_licenses -show_license -``` diff --git a/docs/src/pages/package_generation.md b/docs/src/pages/package_generation.md deleted file mode 100644 index e3bd5679..00000000 --- a/docs/src/pages/package_generation.md +++ /dev/null @@ -1,15 +0,0 @@ -```@meta -CurrentModule = PkgTemplates -``` - -# Package Generation - -Creating new packages with `PkgTemplates` revolves around creating a new -[`Template`](@ref), then calling [`generate`](@ref) on it. - -```@docs -Template -interactive_template -generate -generate_interactive -``` diff --git a/docs/src/pages/plugin_development.md b/docs/src/pages/plugin_development.md deleted file mode 100644 index e77b8826..00000000 --- a/docs/src/pages/plugin_development.md +++ /dev/null @@ -1,72 +0,0 @@ -```@meta -CurrentModule = PkgTemplates -``` - -# Plugin Development - -The best and easiest way to contribute to `PkgTemplates` is to write new plugins. - -```@docs -Plugin -``` - -## "Generic" Plugins - -Many plugins fall into the category of managing some configuration file. -Think Travis CI's `.travis.yml`, and so on for every CI service ever. -For these one-file plugins, a shortcut macro is available to define a plugin in one line. - -```@docs -GeneratedPlugin -@plugin -``` - -### `GeneratedPlugin` Customization - -When you generate a plugin type with [`@plugin`](@ref), all required methods are -implemented for you. However, you're still allowed to override behaviour if you so desire. -These are the relevant methods: - -```@docs -source -destination -gitignore -badges -view -``` - -For some examples, see -[`generated.jl`](https://github.com/invenia/PkgTemplates.jl/tree/master/src/plugins/generated.jl). - -## Custom Plugins - -When a plugin is too complicated to be expressed with [`GeneratedPlugin`](@ref), we only -need to implement a few methods to create something fully custom. - -### Required Methods - -```@docs -gen_plugin -``` - -### Optional Methods - -```@docs -interactive -``` - -Additionally, [`gitignore`](@ref), [`badges`](@ref), and [`view`](@ref) can also be -implemented in the same way as for [`GeneratedPlugin`](@ref)s (they have empty default -implementations). [`source`](@ref) and [`destination`](@ref) have no meaning for custom -plugins. - -### Helpers - -These types and functions will make implementing the above methods much easier. - -```@docs -Badge -gen_file -substitute -version_floor -``` diff --git a/docs/src/pages/plugins.md b/docs/src/pages/plugins.md deleted file mode 100644 index af81a08b..00000000 --- a/docs/src/pages/plugins.md +++ /dev/null @@ -1,31 +0,0 @@ -```@meta -CurrentModule = PkgTemplates -``` - -# Plugins - -Plugins are the secret sauce behind `PkgTemplates`'s customization and extension. This page -describes plugins that already exist; for information on writing your own plugins, see -[Plugin Development](@ref). - -## Continuous Integration (CI) - -```@docs -TravisCI -AppVeyor -GitLabCI -CirrusCI -``` - -## Code Coverage - -```@docs -Codecov -Coveralls -``` - -## Documentation - -```@docs -Documenter -``` diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index 45812e8a..abf76ba9 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -73,7 +73,7 @@ view(p::Documenter, t::Template, pkg::AbstractString) = Dict( "HAS_ASSETS" => !isempty(p.assets), "MAKEDOCS_KWARGS" => map((k, v) -> k => repr(v), collect(p.makedocs_kwargs)), "PKG" => pkg, - "REPO" => "https://$(t.host)/$(t.user)/$pkg.jl", + "REPO" => "$(t.host)/$(t.user)/$pkg.jl", "USER" => t.user, ) From c8bc144653e517095e4e0f8c5ecdfea9bacc2f07 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sat, 31 Aug 2019 18:10:42 +0700 Subject: [PATCH 13/81] Fix some doc stuff --- defaults/make.jl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/defaults/make.jl b/defaults/make.jl index f21f821e..26dd48f8 100644 --- a/defaults/make.jl +++ b/defaults/make.jl @@ -7,11 +7,13 @@ makedocs(; repo="https://{{REPO}}/blob/{commit}{path}#L{line}", sitename="{{PKG}}.jl", format=Documenter.HTML(; +{{#CANONICAL}} canonical="{{CANONICAL}}", +{{/CANONICAL}} assets={{^HAS_ASSETS}}String{{/HAS_ASSETS}}[{{^HAS_ASSETS}}],{{/HAS_ASSETS}} - {{#ASSETS}} +{{#ASSETS}} "{{.}}", - {{/ASSETS}} +{{/ASSETS}} {{#HAS_ASSETS}} ], {{/HAS_ASSETS}} @@ -19,9 +21,9 @@ makedocs(; pages=[ "Home" => "index.md", ], - {{#MAKEDOCS_KWARGS}} +{{#MAKEDOCS_KWARGS}} {{first}}={{second}}, - {{/MAKEDOCS_KWARGS}} +{{/MAKEDOCS_KWARGS}} ) {{#HAS_DEPLOY}} From 439ad335132f976c42681c57a44983ac193d7fb8 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sat, 31 Aug 2019 18:45:41 +0700 Subject: [PATCH 14/81] More reference tests, fix a bug or two --- src/plugins/ci.jl | 6 +- src/plugins/documenter.jl | 1 + test/fixtures/AllPlugins/.appveyor.yml.txt | 31 +++++++ test/fixtures/AllPlugins/.cirrus.yml.txt | 16 ++++ test/fixtures/AllPlugins/.gitignore.txt | 7 ++ test/fixtures/AllPlugins/.gitlab-ci.yml.txt | 15 ++++ test/fixtures/AllPlugins/.travis.yml.txt | 27 ++++++ test/fixtures/AllPlugins/CITATION.bib.txt | 8 ++ test/fixtures/AllPlugins/LICENSE.txt | 19 ++++ test/fixtures/AllPlugins/Manifest.toml.txt | 2 + test/fixtures/AllPlugins/Project.toml.txt | 13 +++ test/fixtures/AllPlugins/README.md.txt | 13 +++ .../AllPlugins/docs/Manifest.toml.txt | 89 +++++++++++++++++++ .../fixtures/AllPlugins/docs/Project.toml.txt | 2 + test/fixtures/AllPlugins/docs/make.jl.txt | 8 ++ .../fixtures/AllPlugins/docs/src/index.md.txt | 15 ++++ .../fixtures/AllPlugins/src/AllPlugins.jl.txt | 5 ++ test/fixtures/AllPlugins/test/runtests.jl.txt | 6 ++ test/fixtures/Basic/.gitignore.txt | 1 - test/generate.jl | 47 +++++----- test/runtests.jl | 13 +-- 21 files changed, 315 insertions(+), 29 deletions(-) create mode 100644 test/fixtures/AllPlugins/.appveyor.yml.txt create mode 100644 test/fixtures/AllPlugins/.cirrus.yml.txt create mode 100644 test/fixtures/AllPlugins/.gitignore.txt create mode 100644 test/fixtures/AllPlugins/.gitlab-ci.yml.txt create mode 100644 test/fixtures/AllPlugins/.travis.yml.txt create mode 100644 test/fixtures/AllPlugins/CITATION.bib.txt create mode 100644 test/fixtures/AllPlugins/LICENSE.txt create mode 100644 test/fixtures/AllPlugins/Manifest.toml.txt create mode 100644 test/fixtures/AllPlugins/Project.toml.txt create mode 100644 test/fixtures/AllPlugins/README.md.txt create mode 100644 test/fixtures/AllPlugins/docs/Manifest.toml.txt create mode 100644 test/fixtures/AllPlugins/docs/Project.toml.txt create mode 100644 test/fixtures/AllPlugins/docs/make.jl.txt create mode 100644 test/fixtures/AllPlugins/docs/src/index.md.txt create mode 100644 test/fixtures/AllPlugins/src/AllPlugins.jl.txt create mode 100644 test/fixtures/AllPlugins/test/runtests.jl.txt diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index b792ef44..d084a897 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -114,7 +114,7 @@ badges(::CirrusCI) = Badge( "https://cirrus-ci.com/github/{{USER}}/{{PKG}}.jl", ) -function view(p::CirrusCI, t::Template, ::AbstractString) +function view(p::CirrusCI, t::Template, pkg::AbstractString) return Dict( "HAS_CODECOV" => hasplugin(t, Codecov), "HAS_COVERALLS" => hasplugin(t, Coveralls), @@ -135,7 +135,7 @@ end gitignore(p::GitLabCI) = p.coverage ? COVERAGE_GITIGNORE : String[] -source(p::GitLabCI) = p.source +source(p::GitLabCI) = p.file destination(::GitLabCI) = ".gitlab-ci.yml" function badges(p::GitLabCI) @@ -152,7 +152,7 @@ function badges(p::GitLabCI) return p.coverage ? [ci, cov] : [ci] end -function view(p::GitLabCI, t::Template, ::AbstractString) +function view(p::GitLabCI, t::Template, pkg::AbstractString) return Dict( "HAS_COVERAGE" => p.coverage, "HAS_DOCUMENTER" => hasplugin(t, Documenter{GitLabCI}), diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index abf76ba9..095a334d 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -83,6 +83,7 @@ function view(p::Documenter{TravisCI}, t::Template, pkg::AbstractString) end function gen_plugin(p::Documenter, t::Template, pkg_dir::AbstractString) + pkg = basename(pkg_dir) docs_dir = joinpath(pkg_dir, "docs") # Generate files. diff --git a/test/fixtures/AllPlugins/.appveyor.yml.txt b/test/fixtures/AllPlugins/.appveyor.yml.txt new file mode 100644 index 00000000..9eee8d14 --- /dev/null +++ b/test/fixtures/AllPlugins/.appveyor.yml.txt @@ -0,0 +1,31 @@ +# Documentation: https://github.com/JuliaCI/Appveyor.jl +environment: + matrix: + - julia_version: 1.0 + - julia_version: 1.2 + - julia_version: nightly +platform: + - x64 +matrix: + allow_failures: + - julia_version: nightly +branches: + only: + - master + - /release-.*/ +notifications: + - provider: Email + on_build_success: false + on_build_failure: false + on_build_status_changed: false +install: + - ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1")) +build_script: + - echo "%JL_BUILD_SCRIPT%" + - C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%" +test_script: + - echo "%JL_TEST_SCRIPT%" + - C:\julia\bin\julia -e "%JL_TEST_SCRIPT%" +on_success: + - echo "%JL_CODECOV_SCRIPT%" + - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%" diff --git a/test/fixtures/AllPlugins/.cirrus.yml.txt b/test/fixtures/AllPlugins/.cirrus.yml.txt new file mode 100644 index 00000000..a8874cb5 --- /dev/null +++ b/test/fixtures/AllPlugins/.cirrus.yml.txt @@ -0,0 +1,16 @@ +freebsd_instance: + image: freebsd-12-0-release-amd64 +task: + name: FreeBSD + env: + JULIA_VERSION: 1.0 + JULIA_VERSION: 1.2 + JULIA_VERSION: nightly + install_script: + - sh -c "$(fetch https://raw.githubusercontent.com/ararslan/CirrusCI.jl/master/bin/install.sh -o -)" + build_script: + - cirrusjl build + test_script: + - cirrusjl test + coverage_script: + - cirrusjl coverage codecov coveralls diff --git a/test/fixtures/AllPlugins/.gitignore.txt b/test/fixtures/AllPlugins/.gitignore.txt new file mode 100644 index 00000000..f1338cfb --- /dev/null +++ b/test/fixtures/AllPlugins/.gitignore.txt @@ -0,0 +1,7 @@ +*.jl.*.cov +*.jl.cov +*.jl.mem +.DS_Store +/dev/ +/docs/build/ +/docs/site/ diff --git a/test/fixtures/AllPlugins/.gitlab-ci.yml.txt b/test/fixtures/AllPlugins/.gitlab-ci.yml.txt new file mode 100644 index 00000000..896d4add --- /dev/null +++ b/test/fixtures/AllPlugins/.gitlab-ci.yml.txt @@ -0,0 +1,15 @@ +Julia 1.0: + image: julia:1.0 + script: julia --project=@. -e ' + using Pkg + Pkg.build() + Pkg.test(coverage=true)' + coverage: /Test Coverage (\d+\.\d+%)/ + after_script: + - julia -e ' + using Pkg + Pkg.add("Coverage") + using Coverage + c, t = get_summary(process_folder()) + using Printf + @printf "Test Coverage %.2f%%\n" 100c/t' diff --git a/test/fixtures/AllPlugins/.travis.yml.txt b/test/fixtures/AllPlugins/.travis.yml.txt new file mode 100644 index 00000000..91a26e33 --- /dev/null +++ b/test/fixtures/AllPlugins/.travis.yml.txt @@ -0,0 +1,27 @@ +# Documentation: http://docs.travis-ci.com/user/languages/julia +language: julia +notifications: + email: false +julia: + - 1.0 + - 1.2 + - nightly +os: + - linux + - osx + - windows +jobs: + fast_finish: true + allow_failures: + - julia: nightly +after_success: + - julia -e ' + using Pkg; + Pkg.add("Coverage"); + using Coverage; + Codecov.submit(process_folder());' + - julia -e ' + using Pkg; + Pkg.add("Coverage"); + using Coverage; + Coveralls.submit(process_folder());' diff --git a/test/fixtures/AllPlugins/CITATION.bib.txt b/test/fixtures/AllPlugins/CITATION.bib.txt new file mode 100644 index 00000000..b39b28c2 --- /dev/null +++ b/test/fixtures/AllPlugins/CITATION.bib.txt @@ -0,0 +1,8 @@ +@misc{AllPlugins.jl, + author = {tester}, + title = {AllPlugins.jl}, + url = {https://github.com/tester/AllPlugins.jl}, + version = {v0.1.0}, + year = {2019}, + month = {8} +} diff --git a/test/fixtures/AllPlugins/LICENSE.txt b/test/fixtures/AllPlugins/LICENSE.txt new file mode 100644 index 00000000..9ce1e635 --- /dev/null +++ b/test/fixtures/AllPlugins/LICENSE.txt @@ -0,0 +1,19 @@ +Copyright (c) 2019 tester + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/test/fixtures/AllPlugins/Manifest.toml.txt b/test/fixtures/AllPlugins/Manifest.toml.txt new file mode 100644 index 00000000..f45eecff --- /dev/null +++ b/test/fixtures/AllPlugins/Manifest.toml.txt @@ -0,0 +1,2 @@ +# This file is machine-generated - editing it directly is not advised + diff --git a/test/fixtures/AllPlugins/Project.toml.txt b/test/fixtures/AllPlugins/Project.toml.txt new file mode 100644 index 00000000..60e925dd --- /dev/null +++ b/test/fixtures/AllPlugins/Project.toml.txt @@ -0,0 +1,13 @@ +name = "AllPlugins" +uuid = "5b7e9947-ddc0-4b3f-9b55-0d8042f74170" +authors = ["tester"] +version = "0.1.0" + +[compat] +julia = "1" + +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test"] diff --git a/test/fixtures/AllPlugins/README.md.txt b/test/fixtures/AllPlugins/README.md.txt new file mode 100644 index 00000000..603070b1 --- /dev/null +++ b/test/fixtures/AllPlugins/README.md.txt @@ -0,0 +1,13 @@ +# AllPlugins + +[![Build Status](https://travis-ci.com/tester/AllPlugins.jl.svg?branch=master)](https://travis-ci.com/tester/AllPlugins.jl) +[![Build Status](https://ci.appveyor.com/api/projects/status/github/tester/AllPlugins.jl?svg=true)](https://ci.appveyor.com/project/tester/AllPlugins-jl) +[![Build Status](https://gitlab.com/tester/AllPlugins.jl/badges/master/build.svg)](https://gitlab.com/tester/AllPlugins.jl/pipelines) +[![Coverage](https://gitlab.com/tester/AllPlugins.jl/badges/master/coverage.svg)](https://gitlab.com/tester/AllPlugins.jl/commits/master) +[![Build Status](https://api.cirrus-ci.com/github/tester/.jl.svg)](https://cirrus-ci.com/github/tester/AllPlugins.jl) +[![Coverage](https://codecov.io/gh//.jl/branch/master/graph/badge.svg)](https://codecov.io/gh//.jl) +[![Coverage](https://coveralls.io/repos/github//.jl/badge.svg?branch=master)](https://coveralls.io/github//.jl?branch=master) + +## Citing + +See [`CITATION.bib`](CITATION.bib) for the relevant reference(s). diff --git a/test/fixtures/AllPlugins/docs/Manifest.toml.txt b/test/fixtures/AllPlugins/docs/Manifest.toml.txt new file mode 100644 index 00000000..f1332b5d --- /dev/null +++ b/test/fixtures/AllPlugins/docs/Manifest.toml.txt @@ -0,0 +1,89 @@ +# This file is machine-generated - editing it directly is not advised + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[Distributed]] +deps = ["Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[DocStringExtensions]] +deps = ["LibGit2", "Markdown", "Pkg", "Test"] +git-tree-sha1 = "0513f1a8991e9d83255e0140aace0d0fc4486600" +uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" +version = "0.8.0" + +[[Documenter]] +deps = ["Base64", "DocStringExtensions", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"] +git-tree-sha1 = "1b6ae3796f60311e39cd1770566140d2c056e87f" +uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +version = "0.23.3" + +[[InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[JSON]] +deps = ["Dates", "Mmap", "Parsers", "Unicode"] +git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.21.0" + +[[LibGit2]] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[Parsers]] +deps = ["Dates", "Test"] +git-tree-sha1 = "db2b35dedab3c0e46dc15996d170af07a5ab91c9" +uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" +version = "0.3.6" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" diff --git a/test/fixtures/AllPlugins/docs/Project.toml.txt b/test/fixtures/AllPlugins/docs/Project.toml.txt new file mode 100644 index 00000000..dfa65cd1 --- /dev/null +++ b/test/fixtures/AllPlugins/docs/Project.toml.txt @@ -0,0 +1,2 @@ +[deps] +Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" diff --git a/test/fixtures/AllPlugins/docs/make.jl.txt b/test/fixtures/AllPlugins/docs/make.jl.txt new file mode 100644 index 00000000..744bc7e8 --- /dev/null +++ b/test/fixtures/AllPlugins/docs/make.jl.txt @@ -0,0 +1,8 @@ +# AllPlugins + +```@index +``` + +```@autodocs +Modules = [AllPlugins] +``` diff --git a/test/fixtures/AllPlugins/docs/src/index.md.txt b/test/fixtures/AllPlugins/docs/src/index.md.txt new file mode 100644 index 00000000..4141053f --- /dev/null +++ b/test/fixtures/AllPlugins/docs/src/index.md.txt @@ -0,0 +1,15 @@ +using AllPlugins +using Documenter + +makedocs(; + modules=[AllPlugins], + authors="tester", + repo="https://github.com/tester/AllPlugins.jl/blob/{commit}{path}#L{line}", + sitename="AllPlugins.jl", + format=Documenter.HTML(; + assets=String[], + ), + pages=[ + "Home" => "index.md", + ], +) diff --git a/test/fixtures/AllPlugins/src/AllPlugins.jl.txt b/test/fixtures/AllPlugins/src/AllPlugins.jl.txt new file mode 100644 index 00000000..44ba550a --- /dev/null +++ b/test/fixtures/AllPlugins/src/AllPlugins.jl.txt @@ -0,0 +1,5 @@ +module AllPlugins + +greet() = print("Hello World!") + +end # module diff --git a/test/fixtures/AllPlugins/test/runtests.jl.txt b/test/fixtures/AllPlugins/test/runtests.jl.txt new file mode 100644 index 00000000..c12f6d96 --- /dev/null +++ b/test/fixtures/AllPlugins/test/runtests.jl.txt @@ -0,0 +1,6 @@ +using AllPlugins +using Test + +@testset "AllPlugins.jl" begin + # Write your tests here. +end diff --git a/test/fixtures/Basic/.gitignore.txt b/test/fixtures/Basic/.gitignore.txt index 145cb1a6..37719915 100644 --- a/test/fixtures/Basic/.gitignore.txt +++ b/test/fixtures/Basic/.gitignore.txt @@ -1,3 +1,2 @@ .DS_Store -/Manifest.toml /dev/ diff --git a/test/generate.jl b/test/generate.jl index 58fb980b..1fada75c 100644 --- a/test/generate.jl +++ b/test/generate.jl @@ -1,25 +1,32 @@ -default_files(pkg::AbstractString) = [ - ".gitignore", - "LICENSE", - "Manifest.toml", - "Project.toml", - "README.md", - "src/$pkg.jl", - "test/runtests.jl", -] +# TODO: License fixtures need to be updated every year because they don't use Mustache. -function reference_test(pkg_dir::AbstractString, path::AbstractString) - pkg = basename(pkg_dir) - path = replace(path, "/" => path_separator) - # All fixture files are .txt because otherwise ReferenceTests/FileIO can't handle them. - reference = joinpath(@__DIR__, "fixtures", pkg, path * ".txt") - observed = read(joinpath(pkg_dir, path), String) - @test_reference reference observed +function PT.user_view(::Citation, ::Template, ::AbstractString) + return Dict("MONTH" => 8, "YEAR" => 2019) end -@testset "Default package" begin - pkg = "Basic" - t = tpl(; develop=false, authors=USER) +function test_all(pkg::AbstractString; kwargs...) + t = tpl(; kwargs...) + pkg_dir = joinpath(t.dir, pkg) t(pkg) - foreach(f -> reference_test(joinpath(t.dir, pkg), f), default_files(pkg)) + try + foreach(readlines(`git -C $pkg_dir ls-files`)) do f + # All fixture files are .txt so that ReferenceTests can't handle them. + reference = joinpath(@__DIR__, "fixtures", pkg, f * ".txt") + observed = read(joinpath(pkg_dir, f), String) + @test_reference reference observed + end + finally + rm(pkg_dir; recursive=true, force=true) + end +end + +@testset "Default package" begin + test_all("Basic"; authors=USER, develop=false, manifest=true) +end + +@testset "All plugins" begin + test_all("AllPlugins"; authors=USER, develop=false, manifest=true, plugins=[ + AppVeyor(), CirrusCI(), Citation(), Codecov(), + Coveralls(), Documenter(), GitLabCI(), TravisCI(), + ]) end diff --git a/test/runtests.jl b/test/runtests.jl index f023f0d7..304a311a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,3 @@ -using Base.Filesystem: path_separator - using Pkg: Pkg using Random: Random using Test: @test, @testset, @test_throws @@ -22,9 +20,14 @@ tpl(; kwargs...) = Template(; user=USER, kwargs...) pushfirst!(DEPOT_PATH, dir) try include("template.jl") - include("generate.jl") - # include("plugin.jl") - # include("interactive.jl") + + # Some plugins use the current Julia version in their output, + # and the test fixtures are generated with Julia 1.2. + if VERSION.major == 1 && VERSION.minor == 2 + include("generate.jl") + else + @info "Skipping reference tests (Julia = $VERSION)" + end finally popfirst!(DEPOT_PATH) end From 1d26885983931fc7baa632336bec62fe5db2aef3 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sat, 31 Aug 2019 18:48:54 +0700 Subject: [PATCH 15/81] Semicolons --- defaults/gitlab-ci.yml | 18 +++++++++--------- test/fixtures/AllPlugins/.gitlab-ci.yml.txt | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/defaults/gitlab-ci.yml b/defaults/gitlab-ci.yml index d8209975..16515fc0 100644 --- a/defaults/gitlab-ci.yml +++ b/defaults/gitlab-ci.yml @@ -2,20 +2,20 @@ Julia {{.}}: image: julia:{{.}} script: julia --project=@. -e ' - using Pkg - Pkg.build() - Pkg.test({{#HAS_COVERAGE}}coverage=true{{/HAS_COVERAGE}})' + using Pkg; + Pkg.build(); + Pkg.test({{#HAS_COVERAGE}}coverage=true{{/HAS_COVERAGE}});' {{/VERSIONS}} {{#HAS_COVERAGE}} coverage: /Test Coverage (\d+\.\d+%)/ after_script: - julia -e ' - using Pkg - Pkg.add("Coverage") - using Coverage - c, t = get_summary(process_folder()) - using Printf - @printf "Test Coverage %.2f%%\n" 100c/t' + using Pkg; + Pkg.add("Coverage"); + using Coverage; + c, t = get_summary(process_folder()); + using Printf; + @printf "Test Coverage %.2f%%\n" 100c/t;' {{/HAS_COVERAGE}} {{#HAS_DOCUMENTER}} pages: diff --git a/test/fixtures/AllPlugins/.gitlab-ci.yml.txt b/test/fixtures/AllPlugins/.gitlab-ci.yml.txt index 896d4add..a64c0459 100644 --- a/test/fixtures/AllPlugins/.gitlab-ci.yml.txt +++ b/test/fixtures/AllPlugins/.gitlab-ci.yml.txt @@ -1,15 +1,15 @@ Julia 1.0: image: julia:1.0 script: julia --project=@. -e ' - using Pkg - Pkg.build() - Pkg.test(coverage=true)' + using Pkg; + Pkg.build(); + Pkg.test(coverage=true);' coverage: /Test Coverage (\d+\.\d+%)/ after_script: - julia -e ' - using Pkg - Pkg.add("Coverage") - using Coverage - c, t = get_summary(process_folder()) - using Printf - @printf "Test Coverage %.2f%%\n" 100c/t' + using Pkgl + Pkg.add("Coverage"); + using Coverage; + c, t = get_summary(process_folder()); + using Printf; + @printf "Test Coverage %.2f%%\n" 100c/t;' From 99bc709ef3576242b06eedeb7ab567d034dbd914 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sat, 31 Aug 2019 21:09:22 +0700 Subject: [PATCH 16/81] Fixes for GitLabCI and Documenter --- defaults/gitlab-ci.yml | 46 +++++++++++-------- src/plugins/ci.jl | 6 +-- src/plugins/documenter.jl | 43 ++++------------- test/fixtures/AllPlugins/.gitlab-ci.yml.txt | 36 +++++++++------ test/fixtures/AllPlugins/docs/make.jl.txt | 21 ++++++--- .../fixtures/AllPlugins/docs/src/index.md.txt | 21 +++------ test/generate.jl | 2 +- test/runtests.jl | 3 +- 8 files changed, 86 insertions(+), 92 deletions(-) diff --git a/defaults/gitlab-ci.yml b/defaults/gitlab-ci.yml index 16515fc0..d9f965d5 100644 --- a/defaults/gitlab-ci.yml +++ b/defaults/gitlab-ci.yml @@ -1,32 +1,40 @@ +.definitions: + script: &script + script: + - julia --project=@. -e ' + using Pkg; + Pkg.build(); + Pkg.test({{#HAS_COVERAGE}}; coverage=true{{/HAS_COVERAGE}});' +{{#HAS_COVERAGE}} + coverage: &coverage + coverage: /Test coverage (\d+\.\d+%)/ + after_script: + - julia -e ' + using Pkg; + Pkg.add("Coverage"); + using Coverage; + c, t = get_summary(process_folder()); + using Printf; + @printf "Test coverage %.2f%%\n" 100c / t;' +{{/HAS_COVERAGE}} {{#VERSIONS}} Julia {{.}}: image: julia:{{.}} - script: julia --project=@. -e ' - using Pkg; - Pkg.build(); - Pkg.test({{#HAS_COVERAGE}}coverage=true{{/HAS_COVERAGE}});' + <<: *script + {{#HAS_COVERAGE}} + <<: *coverage + {{/HAS_COVERAGE}} {{/VERSIONS}} -{{#HAS_COVERAGE}} - coverage: /Test Coverage (\d+\.\d+%)/ - after_script: - - julia -e ' - using Pkg; - Pkg.add("Coverage"); - using Coverage; - c, t = get_summary(process_folder()); - using Printf; - @printf "Test Coverage %.2f%%\n" 100c/t;' -{{/HAS_COVERAGE}} {{#HAS_DOCUMENTER}} pages: image: julia:{{VERSION}} stage: deploy script: - julia --project=docs -e ' - using Pkg; - Pkg.develop(PackageSpec(; path=pwd())); - Pkg.instantiate(); - include("docs/make.jl");' + using Pkg; + Pkg.develop(PackageSpec(; path=pwd())); + Pkg.instantiate(); + include("docs/make.jl");' - mkdir -p public - mv docs/build public/dev artifacts: diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index d084a897..e83c1c64 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -7,7 +7,7 @@ format_version(v::AbstractString) = string(v) function collect_versions(t::Template, versions::Vector) vs = map(format_version, [t.julia_version, versions...]) - return unique(sort(vs)) + return sort(unique(vs)) end @with_kw struct TravisCI <: BasicPlugin @@ -128,9 +128,9 @@ end @with_kw struct GitLabCI <: BasicPlugin file::String = default_file("gitlab-ci.yml") - documentation::Bool = true coverage::Bool = true - extra_versions::VersionsOrStrings = ["1.0"] # Nightly has no Docker image. + # Nightly has no Docker image. + extra_versions::VersionsOrStrings = [VERSION, default_version()] end gitignore(p::GitLabCI) = p.coverage ? COVERAGE_GITIGNORE : String[] diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index 095a334d..70c5618f 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -32,14 +32,14 @@ struct Documenter{T<:Union{TravisCI, GitLabCI, Nothing}} <: Plugin index_md::String # Can't use @with_kw due to some weird precompilation issues. - function Documenter{T}( + function Documenter{T}(; assets::Vector{<:AbstractString}=String[], makedocs_kwargs::Dict{Symbol}=Dict{Symbol, Any}(), - canonical_url::Union{Function, Nothing}=T === TravisCI ? github_pages_url : nothing, - index_md::AbstractString=default_file("index.md"), + canonical_url::Union{Function, Nothing}=make_canonical(T), make_jl::AbstractString=default_file("make.jl"), + index_md::AbstractString=default_file("index.md"), ) where T <: Union{TravisCI, GitLabCI, Nothing} - return new(assets, makedocs_kwargs, canonical_url, index_md, make_jl) + return new(assets, makedocs_kwargs, canonical_url, make_jl, index_md) end end @@ -71,7 +71,7 @@ view(p::Documenter, t::Template, pkg::AbstractString) = Dict( "AUTHORS" => join(t.authors, ", "), "CANONICAL" => p.canonical_url === nothing ? nothing : p.canonical_url(t, pkg), "HAS_ASSETS" => !isempty(p.assets), - "MAKEDOCS_KWARGS" => map((k, v) -> k => repr(v), collect(p.makedocs_kwargs)), + "MAKEDOCS_KWARGS" => map(((k, v),) -> k => repr(v), collect(p.makedocs_kwargs)), "PKG" => pkg, "REPO" => "$(t.host)/$(t.user)/$pkg.jl", "USER" => t.user, @@ -107,32 +107,9 @@ function gen_plugin(p::Documenter, t::Template, pkg_dir::AbstractString) end end -function interactive(::Type{Documenter{T}}) where T - name = "Documenter{$T}" - - print("$name: Enter any Documenter asset files (separated by spaces) [none]: ") - assets = split(readline()) - - print("$name: Enter any extra makedocs key-value pairs (joined by '=') [none]\n> ") - kwargs = Dict{Symbol, Any}() - line = map(split(readline())) do kv - k, v = split(kv, "="; limit=2) - kwargs[Symbol(k)] = eval(Meta.parse(v)) - end - - return Documenter{T}(; assets=assets, kwargs=kwargs) -end - -function interactive(::Type{Documenter}) - types = Dict( - "None (local documentation only)" => Nothing, - "TravisCI (GitHub Pages)" => TravisCI, - "GitLabCI (GitLab Pages)" => GitLabCI, - ) - options = collect(keys(types)) - menu = RadioMenu(options) - T = types[options[request("Documenter: Select integration:", menu)]] - return interactive(Documenter{T}) -end - github_pages_url(t::Template, pkg::AbstractString) = "https://$(t.user).github.io/$pkg.jl" +gitlab_pages_url(t::Template, pkg::AbstractString) = "https://$(t.user).gitlab.io/$pkg.jl" + +make_canonical(::Type{TravisCI}) = github_pages_url +make_canonical(::Type{GitLabCI}) = gitlab_pages_url +make_canonical(::Type{Nothing}) = nothing diff --git a/test/fixtures/AllPlugins/.gitlab-ci.yml.txt b/test/fixtures/AllPlugins/.gitlab-ci.yml.txt index a64c0459..44d9d344 100644 --- a/test/fixtures/AllPlugins/.gitlab-ci.yml.txt +++ b/test/fixtures/AllPlugins/.gitlab-ci.yml.txt @@ -1,15 +1,25 @@ +.definitions: + script: &script + script: + - julia --project=@. -e ' + using Pkg; + Pkg.build(); + Pkg.test(; coverage=true);' + coverage: &coverage + coverage: /Test coverage (\d+\.\d+%)/ + after_script: + - julia -e ' + using Pkg; + Pkg.add("Coverage"); + using Coverage; + c, t = get_summary(process_folder()); + using Printf; + @printf "Test coverage %.2f%%\n" 100c / t;' Julia 1.0: image: julia:1.0 - script: julia --project=@. -e ' - using Pkg; - Pkg.build(); - Pkg.test(coverage=true);' - coverage: /Test Coverage (\d+\.\d+%)/ - after_script: - - julia -e ' - using Pkgl - Pkg.add("Coverage"); - using Coverage; - c, t = get_summary(process_folder()); - using Printf; - @printf "Test Coverage %.2f%%\n" 100c/t;' + <<: *script + <<: *coverage +Julia 1.2: + image: julia:1.2 + <<: *script + <<: *coverage diff --git a/test/fixtures/AllPlugins/docs/make.jl.txt b/test/fixtures/AllPlugins/docs/make.jl.txt index 744bc7e8..4141053f 100644 --- a/test/fixtures/AllPlugins/docs/make.jl.txt +++ b/test/fixtures/AllPlugins/docs/make.jl.txt @@ -1,8 +1,15 @@ -# AllPlugins +using AllPlugins +using Documenter -```@index -``` - -```@autodocs -Modules = [AllPlugins] -``` +makedocs(; + modules=[AllPlugins], + authors="tester", + repo="https://github.com/tester/AllPlugins.jl/blob/{commit}{path}#L{line}", + sitename="AllPlugins.jl", + format=Documenter.HTML(; + assets=String[], + ), + pages=[ + "Home" => "index.md", + ], +) diff --git a/test/fixtures/AllPlugins/docs/src/index.md.txt b/test/fixtures/AllPlugins/docs/src/index.md.txt index 4141053f..744bc7e8 100644 --- a/test/fixtures/AllPlugins/docs/src/index.md.txt +++ b/test/fixtures/AllPlugins/docs/src/index.md.txt @@ -1,15 +1,8 @@ -using AllPlugins -using Documenter +# AllPlugins -makedocs(; - modules=[AllPlugins], - authors="tester", - repo="https://github.com/tester/AllPlugins.jl/blob/{commit}{path}#L{line}", - sitename="AllPlugins.jl", - format=Documenter.HTML(; - assets=String[], - ), - pages=[ - "Home" => "index.md", - ], -) +```@index +``` + +```@autodocs +Modules = [AllPlugins] +``` diff --git a/test/generate.jl b/test/generate.jl index 1fada75c..bd31ea5f 100644 --- a/test/generate.jl +++ b/test/generate.jl @@ -10,7 +10,7 @@ function test_all(pkg::AbstractString; kwargs...) t(pkg) try foreach(readlines(`git -C $pkg_dir ls-files`)) do f - # All fixture files are .txt so that ReferenceTests can't handle them. + # All fixture files are .txt so that ReferenceTests can handle them. reference = joinpath(@__DIR__, "fixtures", pkg, f * ".txt") observed = read(joinpath(pkg_dir, f), String) @test_reference reference observed diff --git a/test/runtests.jl b/test/runtests.jl index 304a311a..5d97feb8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,7 +7,6 @@ using ReferenceTests: @test_reference using PkgTemplates const PT = PkgTemplates -const PKG = "TestPkg" const USER = "tester" Random.seed!(1) @@ -21,7 +20,7 @@ tpl(; kwargs...) = Template(; user=USER, kwargs...) try include("template.jl") - # Some plugins use the current Julia version in their output, + # Quite a bit of output depends on the Julia version, # and the test fixtures are generated with Julia 1.2. if VERSION.major == 1 && VERSION.minor == 2 include("generate.jl") From e4f97431b51b9821548c925e3cf5a412ae4364a6 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sat, 31 Aug 2019 21:22:38 +0700 Subject: [PATCH 17/81] Fix a Winows test bug, delete some CI jobs --- .travis.yml | 19 ------------------- docs/Manifest.toml | 8 ++++---- .../AllPlugins/docs/Manifest.toml.txt | 4 ++-- test/{generate.jl => reference.jl} | 0 test/runtests.jl | 6 ++++-- test/template.jl | 2 +- 6 files changed, 11 insertions(+), 28 deletions(-) rename test/{generate.jl => reference.jl} (100%) diff --git a/.travis.yml b/.travis.yml index e4d9dcec..8a37dac2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ os: - windows julia: - 1.0 - - 1.1 - 1.2 - 1.3 - nightly @@ -26,24 +25,6 @@ matrix: - os: windows arch: x86 julia: 1.0 - - os: linux - arch: x86 - julia: 1.1 - - os: windows - arch: x86 - julia: 1.1 - - os: linux - arch: x86 - julia: 1.2 - - os: windows - arch: x86 - julia: 1.2 - - os: linux - arch: x86 - julia: nightly - - os: windows - arch: x86 - julia: nightly - stage: Documentation julia: 1.0 script: julia --project=docs -e ' diff --git a/docs/Manifest.toml b/docs/Manifest.toml index bf9d220a..fe717470 100644 --- a/docs/Manifest.toml +++ b/docs/Manifest.toml @@ -19,9 +19,9 @@ version = "0.8.0" [[Documenter]] deps = ["Base64", "DocStringExtensions", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"] -git-tree-sha1 = "c61d6eedbc3c4323c08b64af12d29c8ee0fcbb5f" +git-tree-sha1 = "1b6ae3796f60311e39cd1770566140d2c056e87f" uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4" -version = "0.23.2" +version = "0.23.3" [[InteractiveUtils]] deps = ["Markdown"] @@ -48,9 +48,9 @@ uuid = "a63ad114-7e13-5084-954f-fe012c677804" [[Parsers]] deps = ["Dates", "Test"] -git-tree-sha1 = "db2b35dedab3c0e46dc15996d170af07a5ab91c9" +git-tree-sha1 = "ef0af6c8601db18c282d092ccbd2f01f3f0cd70b" uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" -version = "0.3.6" +version = "0.3.7" [[Pkg]] deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] diff --git a/test/fixtures/AllPlugins/docs/Manifest.toml.txt b/test/fixtures/AllPlugins/docs/Manifest.toml.txt index f1332b5d..fe717470 100644 --- a/test/fixtures/AllPlugins/docs/Manifest.toml.txt +++ b/test/fixtures/AllPlugins/docs/Manifest.toml.txt @@ -48,9 +48,9 @@ uuid = "a63ad114-7e13-5084-954f-fe012c677804" [[Parsers]] deps = ["Dates", "Test"] -git-tree-sha1 = "db2b35dedab3c0e46dc15996d170af07a5ab91c9" +git-tree-sha1 = "ef0af6c8601db18c282d092ccbd2f01f3f0cd70b" uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" -version = "0.3.6" +version = "0.3.7" [[Pkg]] deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] diff --git a/test/generate.jl b/test/reference.jl similarity index 100% rename from test/generate.jl rename to test/reference.jl diff --git a/test/runtests.jl b/test/runtests.jl index 5d97feb8..0075aec9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,3 +1,5 @@ +using Base.Filesystem: path_separator + using Pkg: Pkg using Random: Random using Test: @test, @testset, @test_throws @@ -23,9 +25,9 @@ tpl(; kwargs...) = Template(; user=USER, kwargs...) # Quite a bit of output depends on the Julia version, # and the test fixtures are generated with Julia 1.2. if VERSION.major == 1 && VERSION.minor == 2 - include("generate.jl") + include("reference.jl") else - @info "Skipping reference tests (Julia = $VERSION)" + @info "Skipping reference tests" julia=VERSION end finally popfirst!(DEPOT_PATH) diff --git a/test/template.jl b/test/template.jl index 95ffa552..e23014ba 100644 --- a/test/template.jl +++ b/test/template.jl @@ -19,7 +19,7 @@ end @testset "dir" begin - @test tpl(; dir="/foo/bar").dir == "/foo/bar" + @test tpl(; dir="/foo/bar").dir == joinpath(path_separator, "foo", "bar") @test tpl(; dir="foo").dir == abspath("foo") @test tpl(; dir="~/foo").dir == abspath(expanduser("~/foo")) end From b70d3c9cf8372cdaee585eccbb04d6290ee6382c Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sun, 1 Sep 2019 08:36:33 +0700 Subject: [PATCH 18/81] A few more tests --- src/plugin.jl | 22 +++++++++++----------- src/plugins/defaults.jl | 2 +- test/fixtures/AllPlugins/README.md.txt | 4 ++-- test/plugin.jl | 26 ++++++++++++++++++++++++++ test/reference.jl | 11 ++++------- test/runtests.jl | 18 +++++++++++++++--- 6 files changed, 59 insertions(+), 24 deletions(-) create mode 100644 test/plugin.jl diff --git a/src/plugin.jl b/src/plugin.jl index ae331027..187fcdac 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -1,5 +1,16 @@ const DEFAULTS_DIR = normpath(joinpath(@__DIR__, "..", "defaults")) +badge_order() = [ + Documenter{GitLabCI}, + Documenter{TravisCI}, + GitLabCI, + TravisCI, + AppVeyor, + CirrusCI, + Codecov, + Coveralls, +] + """ A simple plugin that, in general, manages a single file. For example, most CI services reply on one configuration file. @@ -151,14 +162,3 @@ include(joinpath("plugins", "coverage.jl")) include(joinpath("plugins", "ci.jl")) include(joinpath("plugins", "citation.jl")) include(joinpath("plugins", "documenter.jl")) - -const BADGE_ORDER = [ - Documenter{GitLabCI}, - Documenter{TravisCI}, - TravisCI, - AppVeyor, - GitLabCI, - CirrusCI, - Codecov, - Coveralls, -] diff --git a/src/plugins/defaults.jl b/src/plugins/defaults.jl index 2c4d5968..c66e8b4f 100644 --- a/src/plugins/defaults.jl +++ b/src/plugins/defaults.jl @@ -27,7 +27,7 @@ function view(p::Readme, t::Template, pkg::AbstractString) # Explicitly ordered badges go first. strings = String[] done = DataType[] - foreach(BADGE_ORDER) do T + foreach(badge_order()) do T if hasplugin(t, T) bs = badges(t.plugins[T], t, pkg) append!(strings, badges(t.plugins[T], t, pkg)) diff --git a/test/fixtures/AllPlugins/README.md.txt b/test/fixtures/AllPlugins/README.md.txt index 603070b1..35d94a0f 100644 --- a/test/fixtures/AllPlugins/README.md.txt +++ b/test/fixtures/AllPlugins/README.md.txt @@ -1,9 +1,9 @@ # AllPlugins -[![Build Status](https://travis-ci.com/tester/AllPlugins.jl.svg?branch=master)](https://travis-ci.com/tester/AllPlugins.jl) -[![Build Status](https://ci.appveyor.com/api/projects/status/github/tester/AllPlugins.jl?svg=true)](https://ci.appveyor.com/project/tester/AllPlugins-jl) [![Build Status](https://gitlab.com/tester/AllPlugins.jl/badges/master/build.svg)](https://gitlab.com/tester/AllPlugins.jl/pipelines) [![Coverage](https://gitlab.com/tester/AllPlugins.jl/badges/master/coverage.svg)](https://gitlab.com/tester/AllPlugins.jl/commits/master) +[![Build Status](https://travis-ci.com/tester/AllPlugins.jl.svg?branch=master)](https://travis-ci.com/tester/AllPlugins.jl) +[![Build Status](https://ci.appveyor.com/api/projects/status/github/tester/AllPlugins.jl?svg=true)](https://ci.appveyor.com/project/tester/AllPlugins-jl) [![Build Status](https://api.cirrus-ci.com/github/tester/.jl.svg)](https://cirrus-ci.com/github/tester/AllPlugins.jl) [![Coverage](https://codecov.io/gh//.jl/branch/master/graph/badge.svg)](https://codecov.io/gh//.jl) [![Coverage](https://coveralls.io/repos/github//.jl/badge.svg?branch=master)](https://coveralls.io/github//.jl?branch=master) diff --git a/test/plugin.jl b/test/plugin.jl new file mode 100644 index 00000000..92ec338d --- /dev/null +++ b/test/plugin.jl @@ -0,0 +1,26 @@ +# Don't move this line from the top, please. {{X}} {{Y}} {{Z}} + +struct BasicTest <: PT.BasicPlugin end + +PT.gitignore(::BasicTest) = ["a", "aa", "aaa"] +PT.source(::BasicTest) = @__FILE__ +PT.destination(::BasicTest) = "foo.txt" +PT.badges(::BasicTest) = PT.Badge("{{X}}", "{{Y}}", "{{Z}}") +PT.view(::BasicTest, ::Template, ::AbstractString) = Dict("X" => 0, "Y" => 2) +PT.user_view(::BasicTest, ::Template, ::AbstractString) = Dict("X" => 1, "Z" => 3) + +@testset "BasicPlugin" begin + p = BasicTest() + t = tpl(; plugins=[p]) + + # The X from user_view should override the X from view. + s = PT.render_plugin(p, t, "") + @test occursin("1 2 3", first(split(s, "\n"))) + + with_pkg(t) do pkg + pkg_dir = joinpath(t.dir, pkg) + badge = string(PT.Badge("1", "2", "3")) + @test occursin(badge, read(joinpath(pkg_dir, "README.md"), String)) + @test read(joinpath(pkg_dir, "foo.txt"), String) == s + end +end diff --git a/test/reference.jl b/test/reference.jl index bd31ea5f..bafe07ad 100644 --- a/test/reference.jl +++ b/test/reference.jl @@ -6,26 +6,23 @@ end function test_all(pkg::AbstractString; kwargs...) t = tpl(; kwargs...) - pkg_dir = joinpath(t.dir, pkg) - t(pkg) - try + with_pkg(t, pkg) do pkg + pkg_dir = joinpath(t.dir, pkg) foreach(readlines(`git -C $pkg_dir ls-files`)) do f # All fixture files are .txt so that ReferenceTests can handle them. reference = joinpath(@__DIR__, "fixtures", pkg, f * ".txt") observed = read(joinpath(pkg_dir, f), String) @test_reference reference observed end - finally - rm(pkg_dir; recursive=true, force=true) end end @testset "Default package" begin - test_all("Basic"; authors=USER, develop=false, manifest=true) + test_all("Basic"; authors=USER, manifest=true) end @testset "All plugins" begin - test_all("AllPlugins"; authors=USER, develop=false, manifest=true, plugins=[ + test_all("AllPlugins"; authors=USER, manifest=true, plugins=[ AppVeyor(), CirrusCI(), Citation(), Codecov(), Coveralls(), Documenter(), GitLabCI(), TravisCI(), ]) diff --git a/test/runtests.jl b/test/runtests.jl index 0075aec9..21210399 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -9,22 +9,34 @@ using ReferenceTests: @test_reference using PkgTemplates const PT = PkgTemplates +const PKG = "TestPkg" const USER = "tester" Random.seed!(1) tpl(; kwargs...) = Template(; user=USER, kwargs...) +function with_pkg(f::Function, t::Template, pkg::AbstractString=PKG) + t(pkg) + try + f(pkg) + finally + haskey(Pkg.installed(), pkg) && Pkg.rm(pkg) + rm(joinpath(t.dir, pkg); recursive=true, force=true) + end +end + @testset "PkgTemplates.jl" begin mktempdir() do dir Pkg.activate(dir) pushfirst!(DEPOT_PATH, dir) try include("template.jl") + include("plugin.jl") - # Quite a bit of output depends on the Julia version, - # and the test fixtures are generated with Julia 1.2. - if VERSION.major == 1 && VERSION.minor == 2 + # Quite a bit of output depends on the Julia version, and the test fixtures are + # made with Julia 1.2. Also, Windows uses CRLF which breaks everything. + if !Sys.iswindows() && VERSION.major == 1 && VERSION.minor == 2 include("reference.jl") else @info "Skipping reference tests" julia=VERSION From d5a341c5dd53f7b8b35eadc90ddb1f90bc9b8361 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sun, 1 Sep 2019 08:36:42 +0700 Subject: [PATCH 19/81] Delete the outdated interactive code for now --- src/interactive.jl | 154 ---------------------------------------- src/plugins/citation.jl | 5 -- 2 files changed, 159 deletions(-) delete mode 100644 src/interactive.jl diff --git a/src/interactive.jl b/src/interactive.jl deleted file mode 100644 index c6d5f677..00000000 --- a/src/interactive.jl +++ /dev/null @@ -1,154 +0,0 @@ -# TODO ::IO APIs for easier testing - -# Printing utils. -const TAB = repeat(' ', 4) -const HALFTAB = repeat(' ', 2) -const DOT = "• " -const ARROW = "→ " -const PLUGIN_TYPES = let - leaves(T::Type) = isabstracttype(T) ? vcat(map(leaves, subtypes(T))...) : [T] - leaves(Plugin) -end - -yesno(x::Bool) = x ? "Yes" : "No" - -maybe_string(s::AbstractString) = isempty(s) ? "None" : string(s) - -""" - interactive(T::Type{<:Plugin}) -> T - -Interactively create a plugin of type `T`. -When this method is implemented for a type, it becomes available to [`Template`](@ref)s created with `interactive=true`. -""" -function interactive end - -function make_template(::Val{true}; kwargs...) - @info "Default values are shown in [brackets]" - - opts = Dict{Symbol, Any}() - fast = get(kwargs, :fast, false) - - opts[:user] = get(kwargs, :user) do - default = defaultkw(:user) - default = isempty(default) ? nothing : default - prompt_string("Username", default) - end - - git = opts[:git] = get(kwargs, :git) do - default = defaultkw(:git) - fast ? default : prompt_bool("Create Git repositories for packages", default) - end - - opts[:host] = get(kwargs, :host) do - default = defaultkw(:host) - if fast || !git - default - else - prompt_string("Code hosting service", default) - end - end - - opts[:license] = get(kwargs, :license) do - default = defaultkw(:license) - if fast - default - else - # TODO: Break this out into something reusable? - choices = String["None"; split(sprint(available_licenses), "\n")] - licenses = ["" => "", pairs(LICENSES)...] - menu = RadioMenu(choices) - first(licenses[request("License:", menu)]) - end - end - - opts[:authors] = get(kwargs, :authors) do - default = defaultkw(:authors) - if fast || !git - default - else - prompt_string("Package author(s)", isempty(default) ? "None" : default) - end - end - - opts[:dir] = get(kwargs, :dir) do - default = defaultkw(:dir) - fast ? default : prompt_string("Path to package directory", default) - end - - opts[:julia_version] = get(kwargs, :julia_version) do - default = defaultkw(:julia_version) - if fast - default - else - VersionNumber(prompt_string("Minimum Julia version", string(default))) - end - end - - opts[:ssh] = get(kwargs, :ssh) do - default = defaultkw(:ssh) - fast || !git ? default : prompt_bool("Set remote to SSH", default) - end - - opts[:manifest] = get(kwargs, :manifest) do - default = defaultkw(:manifest) - fast || !git ? default : prompt_bool("Commit Manifest.toml", default) - end - - opts[:develop] = get(kwargs, :develop) do - default = defaultkw(:develop) - fast || !git ? default : prompt_bool("Develop generated packages", default) - end - - opts[:plugins] = get(kwargs, :plugins) do - # TODO: Break this out into something reusable? - types = filter(T -> applicable(interactive, T), PLUGIN_TYPES) - menu = MultiSelectMenu(map(string ∘ nameof, types)) - selected = types[collect(request("Plugins:", menu))] - map(interactive, selected) - end - - return make_template(Val(false); opts...) -end - -prompt_string(s::AbstractString, default=nothing) = prompt(string, s, default) - -function prompt_bool(s::AbstractString, default=nothing) - return prompt(s, default) do answer - answer = lowercase(answer) - if answer in ["yes", "true", "y", "t"] - true - elseif answer in ["no", "false", "n", "f"] - false - else - throw(ArgumentError("Invalid yes/no response")) - end - end -end - -function prompt(f::Function, s::AbstractString, default) - required = default === nothing - default_display = default isa Bool ? yesno(default) : default - print(s, " [", required ? "REQUIRED" : default_display, "]: ") - answer = readline() - return if isempty(answer) - required && throw(ArgumentError("This argument is required")) - default - else - f(answer) - end -end - -function prompt_config(T::Type{<:BasicPlugin}) - s = "$(nameof(T)): Source file template path" - default = source(T) - default === nothing && (s *= " (\"None\" for no file)") - answer = prompt_string(s, default === nothing ? "None" : contractuser(default)) - - return if lowercase(answer) == "none" - nothing - elseif isempty(answer) - default - else - answer - end -end diff --git a/src/plugins/citation.jl b/src/plugins/citation.jl index 82e27080..deabe8a6 100644 --- a/src/plugins/citation.jl +++ b/src/plugins/citation.jl @@ -21,8 +21,3 @@ view(::Citation, t::Template, pkg::AbstractString) = Dict( "URL" => "https://$(t.host)/$(t.user)/$pkg.jl", "YEAR" => year(today()), ) - -function interactive(::Type{Citation}) - readme = prompt_bool("Citation: Add a section to the README", false) - return Citation(; readme_section=readme) -end From 9b68d22aad06e6343e75d080b38a372e00557458 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sun, 1 Sep 2019 08:56:01 +0700 Subject: [PATCH 20/81] Add coverage back --- .travis.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8a37dac2..8dd65735 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,8 +28,13 @@ matrix: - stage: Documentation julia: 1.0 script: julia --project=docs -e ' - using Pkg; - Pkg.develop(PackageSpec(; path=pwd())); - Pkg.instantiate(); - include("docs/make.jl");' + using Pkg; + Pkg.develop(PackageSpec(; path=pwd())); + Pkg.instantiate(); + include("docs/make.jl");' after_success: skip +after_success: julia -e ' + using Pkg; + Pkg.add("Coverage"); + using Coverage; + Codecov.submit(process_folder());' From f61253b0100a835441b83e3ad3669eab8be90b6e Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sun, 1 Sep 2019 09:48:01 +0700 Subject: [PATCH 21/81] Trim the readme, hopefully fix another Windows test bug --- README.md | 154 ++++++++----------------------------------------- test/plugin.jl | 5 +- 2 files changed, 29 insertions(+), 130 deletions(-) diff --git a/README.md b/README.md index 00a30c10..e6927d38 100644 --- a/README.md +++ b/README.md @@ -1,146 +1,42 @@ # PkgTemplates [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://invenia.github.io/PkgTemplates.jl/stable) -[![Latest](https://img.shields.io/badge/docs-latest-blue.svg)](https://invenia.github.io/PkgTemplates.jl/latest) +[![Dev](https://img.shields.io/badge/docs-latest-blue.svg)](https://invenia.github.io/PkgTemplates.jl/dev) [![Build Status](https://travis-ci.org/invenia/PkgTemplates.jl.svg?branch=master)](https://travis-ci.org/invenia/PkgTemplates.jl) -[![Build Status](https://ci.appveyor.com/api/projects/status/r24xamruqlm88uti/branch/master?svg=true)](https://ci.appveyor.com/project/christopher-dG/pkgtemplates-jl/branch/master) [![Codecov](https://codecov.io/gh/invenia/PkgTemplates.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/invenia/PkgTemplates.jl) -**PkgTemplates is a Julia package for creating new Julia packages in an easy, -repeatable, and customizable way.** - -## Installation - -```julia -pkg> add PkgTemplates -``` - -## Plugins - -`PkgTemplates` is based on plugins which handle the setup of individual package components. -The available plugins are: - -* Continuous Integration (CI) - * [Travis CI](https://travis-ci.com) (Linux, MacOS) - * [AppVeyor](https://appveyor.com) (Windows) - * [GitLabCI](https://gitlab.com) (Linux) - * [CirrusCI](https://cirrus-ci.org) (FreeBSD) -* Code Coverage - * [Codecov](https://codecov.io) - * [Coveralls](https://coveralls.io) -* Documentation - * [GitHubPages](https://pages.github.com) -* Citation +**PkgTemplates creates new Julia packages in an easy, repeatable, and customizable way.** ## Usage -Assuming you have the relatively standard Git options `user.name`, `user.email` and `github.user` set up globally with `git config --global`, the simplest template requires no arguments: - -```julia -julia> using PkgTemplates - -julia> t = Template() -Template: - → User: christopher-dG - → Host: github.com - → License: MIT (Chris de Graaf 2018) - → Package directory: ~/.julia/dev - → Minimum Julia version: v1.0 - → SSH remote: No - → Commit Manifest.toml: No - → Plugins: None +Assuming you have the relatively standard Git options `user.name`, `user.email` and `github.user` set up globally with `git config --global`, creating a `Template` is as simple as: -julia> generate("MyPkg", t) - -julia> run(`git -C $(joinpath(t.dir, "MyPkg")) ls-files`); -.gitignore -LICENSE -Manifest.toml -Project.toml -README.md -REQUIRE -src/MyPkg.jl -test/runtests.jl +```jl +using PkgTemplates +t = Template() ``` -However, we can also configure a number of keyword arguments to `Template`: - -```julia -julia> t = Template(; - user="myusername", - license="ISC", - authors=["Chris de Graaf", "Invenia Technical Computing Corporation"], - dir="~/code", - julia_version=v"0.7", - plugins=[ - TravisCI(), - Codecov(), - Coveralls(), - AppVeyor(), - GitHubPages(), - CirrusCI(), - ], - ) -Template: - → User: myusername - → Host: github.com - → License: ISC (Chris de Graaf, Invenia Technical Computing Corporation 2018) - → Package directory: ~/code - → Minimum Julia version: v0.7 - → SSH remote: No - → Commit Manifest.toml: No - → Plugins: - • AppVeyor: - → Config file: Default - → 0 gitignore entries - • Codecov: - → Config file: None - → 3 gitignore entries: "*.jl.cov", "*.jl.*.cov", "*.jl.mem" - • Coveralls: - → Config file: None - → 3 gitignore entries: "*.jl.cov", "*.jl.*.cov", "*.jl.mem" - • GitHubPages: - → 0 asset files - → 2 gitignore entries: "/docs/build/", "/docs/site/" - • TravisCI: - → Config file: Default - → 0 gitignore entries - -julia> generate(t, "MyPkg2") - -julia> run(`git -C $(joinpath(t.dir, "MyPkg2")) ls-files`); -.appveyor.yml -.gitignore -.travis.yml -LICENSE -Project.toml -README.md -REQUIRE -docs/Manifest.toml -docs/Project.toml -docs/make.jl -docs/src/index.md -src/MyPkg2.jl -test/runtests.jl +However, it's probably desirable to customize the template to your liking with various options and plugins: + +```jl +t = Template(; + dir="~/code", + ssh=true, + manifest=true, + plugins=[ + Codecov(), + TravisCI(; x86=true), + Documenter{TravisCI}(), + ], +) ``` -Information on each keyword as well as plugin types can be found in the -[documentation](https://invenia.github.io/PkgTemplates.jl/stable). +Once you have a `Template`, yoy can createa packages with ease: -If that looks like a lot of work, you can also create templates interactively -with `interactive_template`: - -[![asciicast](https://asciinema.org/a/31bZqW9u8h5RHpd7gtsemioRV.png)](https://asciinema.org/a/31bZqW9u8h5RHpd7gtsemioRV) - -And if that's **still** too much work for you, you can call -`interactive_template` with `fast=true` to use default values for everything -but username and plugin selection. - -You can also use `generate_interactive` to interactively generate a template and then -immediately use it to create a new package. +```jl +t("MyPkg") +``` -## Contributing +--- -It's extremely easy to extend `PkgTemplates` with new plugins. To get started, -check out the -[plugin development guide](https://invenia.github.io/PkgTemplates.jl/stable/pages/plugin_development.html). +For a much more detailled overview, please see the documentation. diff --git a/test/plugin.jl b/test/plugin.jl index 92ec338d..b55a47ed 100644 --- a/test/plugin.jl +++ b/test/plugin.jl @@ -21,6 +21,9 @@ PT.user_view(::BasicTest, ::Template, ::AbstractString) = Dict("X" => 1, "Z" => pkg_dir = joinpath(t.dir, pkg) badge = string(PT.Badge("1", "2", "3")) @test occursin(badge, read(joinpath(pkg_dir, "README.md"), String)) - @test read(joinpath(pkg_dir, "foo.txt"), String) == s + observed = read(joinpath(pkg_dir, "foo.txt"), String) + # On Travis, everything works with CRLF. + Sys.iswindows() && (observed = replace(observed, "\r\n" => "\n")) + @test observed == s end end From 493c54a948522bbd9242b367f7bfcded02c3f24b Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sun, 1 Sep 2019 16:10:40 +0700 Subject: [PATCH 22/81] More tests, more Windows fiddling Cassette is cool! --- .gitattributes | 1 + Project.toml | 4 +- src/generate.jl | 11 ++++- test/git.jl | 55 ++++++++++++++++++++++++ test/plugin.jl | 27 ++++++------ test/reference.jl | 18 ++++---- test/runtests.jl | 39 +++++++++++------ test/template.jl | 107 ++++++++++++++++++++++++++++------------------ 8 files changed, 182 insertions(+), 80 deletions(-) create mode 100644 .gitattributes create mode 100644 test/git.jl diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..fae8897c --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* eol=lf diff --git a/Project.toml b/Project.toml index 5e069c6f..e1ac7d43 100644 --- a/Project.toml +++ b/Project.toml @@ -16,9 +16,11 @@ REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" julia = "1" [extras] +Cassette = "7057c7e9-c182-5462-911a-8362d720325c" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf" +Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Random", "ReferenceTests", "Test"] +test = ["Cassette", "Suppressor", "Random", "ReferenceTests", "Test"] diff --git a/src/generate.jl b/src/generate.jl index cc5404ad..669685be 100644 --- a/src/generate.jl +++ b/src/generate.jl @@ -6,6 +6,8 @@ Generate a package named `pkg` from a [`Template`](@ref). function (t::Template)(pkg::AbstractString) endswith(pkg, ".jl") && (pkg = pkg[1:end-3]) pkg_dir = joinpath(t.dir, pkg) + ispath(pkg_dir) && throw(ArgumentError("$pkg_dir already exists")) + repo = nothing try # Create the directory with some boilerplate inside. @@ -24,12 +26,15 @@ function (t::Template)(pkg::AbstractString) # Initialize the repo, make a commit, and set the remote. repo = LibGit2.init(pkg_dir) LibGit2.commit(repo, "Initial commit") - rmt = if t.ssh + url = if t.ssh "git@$(t.host):$(t.user)/$pkg.jl.git" else "https://$(t.host)/$(t.user)/$pkg.jl" end - close(LibGit2.GitRemote(repo, "origin", rmt)) + remote = LibGit2.GitRemote(repo, "origin", url) + # TODO: `git pull` still requires some Git branch config. + LibGit2.add_push!(repo, remote, "refs/heads/master") + close(remote) end # Generate the files. @@ -56,6 +61,8 @@ function (t::Template)(pkg::AbstractString) catch rm(pkg_dir; recursive=true, force=true) rethrow() + finally + repo === nothing || close(repo) end end diff --git a/test/git.jl b/test/git.jl new file mode 100644 index 00000000..4b149693 --- /dev/null +++ b/test/git.jl @@ -0,0 +1,55 @@ +@context PTIsInstalled +function Cassette.posthook(::PTIsInstalled, result::Dict, ::typeof(Pkg.installed)) + result["PkgTemplates"] = v"1.2.3" + return result +end + +@testset "Git repositories" begin + @testset "Does not create Git repo" begin + t = tpl(; git=false) + with_pkg(t) do pkg + pkg_dir = joinpath(t.dir, pkg) + @test !isdir(joinpath(pkg_dir, ".git")) + end + end + + @testset "Creates Git repo" begin + t = tpl(; git=true) + with_pkg(t) do pkg + pkg_dir = joinpath(t.dir, pkg) + @test isdir(joinpath(pkg_dir, ".git")) + end + end + + @testset "With HTTPS" begin + t = tpl(; git=true, ssh=false) + with_pkg(t) do pkg + LibGit2.with(GitRepo(joinpath(t.dir, pkg))) do repo + remote = LibGit2.get(GitRemote, repo, "origin") + @test startswith(LibGit2.url(remote), "https://") + end + end + end + + @testset "With SSH" begin + t = tpl(; git=true, ssh=true) + with_pkg(t) do pkg + LibGit2.with(GitRepo(joinpath(t.dir, pkg))) do repo + remote = LibGit2.get(GitRemote, repo, "origin") + @test startswith(LibGit2.url(remote), "git@") + end + end + end + + @testset "Adds version to commit message" begin + # We're careful to avoid a Pkg.update as it triggers Cassette#130. + t = tpl(; git=true, develop=false, disable_defaults=[Tests]) + @overdub PTIsInstalled() with_pkg(t) do pkg + pkg_dir = joinpath(t.dir, pkg) + LibGit2.with(GitRepo(pkg_dir)) do repo + commit = GitCommit(repo, "HEAD") + @test occursin("PkgTemplates version: 1.2.3", LibGit2.message(commit)) + end + end + end +end diff --git a/test/plugin.jl b/test/plugin.jl index b55a47ed..05639f1e 100644 --- a/test/plugin.jl +++ b/test/plugin.jl @@ -9,21 +9,20 @@ PT.badges(::BasicTest) = PT.Badge("{{X}}", "{{Y}}", "{{Z}}") PT.view(::BasicTest, ::Template, ::AbstractString) = Dict("X" => 0, "Y" => 2) PT.user_view(::BasicTest, ::Template, ::AbstractString) = Dict("X" => 1, "Z" => 3) -@testset "BasicPlugin" begin - p = BasicTest() - t = tpl(; plugins=[p]) +@testset "Plugins" begin + @testset "BasicPlugin" begin + p = BasicTest() + t = tpl(; plugins=[p]) - # The X from user_view should override the X from view. - s = PT.render_plugin(p, t, "") - @test occursin("1 2 3", first(split(s, "\n"))) + # The X from user_view should override the X from view. + s = PT.render_plugin(p, t, "") + @test occursin("1 2 3", first(split(s, "\n"))) - with_pkg(t) do pkg - pkg_dir = joinpath(t.dir, pkg) - badge = string(PT.Badge("1", "2", "3")) - @test occursin(badge, read(joinpath(pkg_dir, "README.md"), String)) - observed = read(joinpath(pkg_dir, "foo.txt"), String) - # On Travis, everything works with CRLF. - Sys.iswindows() && (observed = replace(observed, "\r\n" => "\n")) - @test observed == s + with_pkg(t) do pkg + pkg_dir = joinpath(t.dir, pkg) + badge = string(PT.Badge("1", "2", "3")) + @test occursin(badge, read(joinpath(pkg_dir, "README.md"), String)) + @test read(joinpath(pkg_dir, "foo.txt"), String) == s + end end end diff --git a/test/reference.jl b/test/reference.jl index bafe07ad..3a1eaecd 100644 --- a/test/reference.jl +++ b/test/reference.jl @@ -17,13 +17,15 @@ function test_all(pkg::AbstractString; kwargs...) end end -@testset "Default package" begin - test_all("Basic"; authors=USER, manifest=true) -end +@testset "Reference tests" begin + @testset "Default package" begin + test_all("Basic"; authors=USER, manifest=true) + end -@testset "All plugins" begin - test_all("AllPlugins"; authors=USER, manifest=true, plugins=[ - AppVeyor(), CirrusCI(), Citation(), Codecov(), - Coveralls(), Documenter(), GitLabCI(), TravisCI(), - ]) + @testset "All plugins" begin + test_all("AllPlugins"; authors=USER, manifest=true, plugins=[ + AppVeyor(), CirrusCI(), Citation(), Codecov(), + Coveralls(), Documenter(), GitLabCI(), TravisCI(), + ]) + end end diff --git a/test/runtests.jl b/test/runtests.jl index 21210399..94312f97 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,48 +1,59 @@ using Base.Filesystem: path_separator +using LibGit2: LibGit2, GitCommit, GitRemote, GitRepo using Pkg: Pkg using Random: Random using Test: @test, @testset, @test_throws +using Cassette: Cassette, @context, @overdub using ReferenceTests: @test_reference +using Suppressor: @suppress using PkgTemplates const PT = PkgTemplates -const PKG = "TestPkg" const USER = "tester" Random.seed!(1) +# Creata a template that won't error because of a missing username. tpl(; kwargs...) = Template(; user=USER, kwargs...) -function with_pkg(f::Function, t::Template, pkg::AbstractString=PKG) - t(pkg) +const pkg_name = Ref("A") + +# Generate an unused package name. +pkgname() = pkg_name[] *= "a" + +# Create a randomly named package with a template, and delete it afterwards. +function with_pkg(f::Function, t::Template, pkg::AbstractString=pkgname()) + @suppress t(pkg) try f(pkg) finally - haskey(Pkg.installed(), pkg) && Pkg.rm(pkg) + haskey(Pkg.installed(), pkg) && @suppress Pkg.rm(pkg) rm(joinpath(t.dir, pkg); recursive=true, force=true) end end -@testset "PkgTemplates.jl" begin - mktempdir() do dir - Pkg.activate(dir) - pushfirst!(DEPOT_PATH, dir) - try +mktempdir() do dir + Pkg.activate(dir) + pushfirst!(DEPOT_PATH, dir) + try + @testset "PkgTemplates.jl" begin include("template.jl") include("plugin.jl") + include("git.jl") - # Quite a bit of output depends on the Julia version, and the test fixtures are - # made with Julia 1.2. Also, Windows uses CRLF which breaks everything. - if !Sys.iswindows() && VERSION.major == 1 && VERSION.minor == 2 + # Quite a bit of output depends on the Julia version, + # and the test fixtures are made with Julia 1.2. + # TODO: Keep this on the latest stable Julia version. + if VERSION.major == 1 && VERSION.minor == 2 include("reference.jl") else @info "Skipping reference tests" julia=VERSION end - finally - popfirst!(DEPOT_PATH) end + finally + popfirst!(DEPOT_PATH) end end diff --git a/test/template.jl b/test/template.jl index e23014ba..8ddf5d72 100644 --- a/test/template.jl +++ b/test/template.jl @@ -1,52 +1,77 @@ -@testset "Template constructor" begin - @testset "user" begin - if isempty(PT.default_user()) - @test_throws ArgumentError Template() - haskey(ENV, "CI") && run(`git config --global github.user $USER`) +@testset "Template" begin + @testset "Template constructor" begin + @testset "user" begin + if isempty(PT.default_user()) + @test_throws ArgumentError Template() + haskey(ENV, "CI") && run(`git config --global github.user $USER`) + end + @test Template().user == PT.default_user() end - @test Template().user == PT.default_user() - end - @testset "authors" begin - @test tpl(; authors=["a"]).authors == ["a"] - @test tpl(; authors="a").authors == ["a"] - @test tpl(; authors="a,b").authors == ["a", "b"] - @test tpl(; authors="a, b").authors == ["a", "b"] - end + @testset "authors" begin + @test tpl(; authors=["a"]).authors == ["a"] + @test tpl(; authors="a").authors == ["a"] + @test tpl(; authors="a,b").authors == ["a", "b"] + @test tpl(; authors="a, b").authors == ["a", "b"] + end - @testset "host" begin - @test tpl(; host="https://foo.com").host == "foo.com" - end + @testset "host" begin + @test tpl(; host="https://foo.com").host == "foo.com" + end - @testset "dir" begin - @test tpl(; dir="/foo/bar").dir == joinpath(path_separator, "foo", "bar") - @test tpl(; dir="foo").dir == abspath("foo") - @test tpl(; dir="~/foo").dir == abspath(expanduser("~/foo")) - end + @testset "dir" begin + @test tpl(; dir="/foo/bar").dir == joinpath(path_separator, "foo", "bar") + @test tpl(; dir="foo").dir == abspath("foo") + @test tpl(; dir="~/foo").dir == abspath(expanduser("~/foo")) + end + + @testset "plugins / disabled_defaults" begin + function test_plugins(plugins, expected, disabled=DataType[]) + t = tpl(; plugins=plugins, disable_defaults=disabled) + @test issetequal(values(t.plugins), expected) + end - @testset "plugins / disabled_defaults" begin - function test_plugins(plugins, expected, disabled=DataType[]) - t = tpl(; plugins=plugins, disable_defaults=disabled) - @test issetequal(values(t.plugins), expected) + defaults = PT.default_plugins() + test_plugins([], defaults) + test_plugins([Citation()], union(defaults, [Citation()])) + # Overriding a default plugin. + gi = Gitignore(; dev=false) + test_plugins([gi], union(setdiff(defaults, [Gitignore()]), [gi])) + # Disabling a default plugin. + test_plugins([], setdiff(defaults, [Gitignore()]), [Gitignore]) end + end - defaults = PT.default_plugins() - test_plugins([], defaults) - test_plugins([Citation()], union(defaults, [Citation()])) - # Overriding a default plugin. - gi = Gitignore(; dev=false) - test_plugins([gi], union(setdiff(defaults, [Gitignore()]), [gi])) - # Disabling a default plugin. - test_plugins([], setdiff(defaults, [Gitignore()]), [Gitignore]) + @testset "hasplugin" begin + t = tpl(; plugins=[Documenter{TravisCI}()]) + @test PT.hasplugin(t, typeof(first(PT.default_plugins()))) + @test PT.hasplugin(t, Documenter) + @test PT.hasplugin(t, _ -> true) + @test !PT.hasplugin(t, _ -> false) + @test !PT.hasplugin(t, Citation) + @test !PT.hasplugin(t, PT.is_ci) end end -@testset "hasplugin" begin - t = tpl(; plugins=[Documenter{TravisCI}()]) - @test PT.hasplugin(t, typeof(first(PT.default_plugins()))) - @test PT.hasplugin(t, Documenter) - @test PT.hasplugin(t, _ -> true) - @test !PT.hasplugin(t, _ -> false) - @test !PT.hasplugin(t, Citation) - @test !PT.hasplugin(t, PT.is_ci) +@context ErrorOnRepoInit +function Cassette.prehook(::ErrorOnRepoInit, ::typeof(LibGit2.init), pkg_dir) + @test isdir(pkg_dir) + error() +end + +@testset "Package generation errors" begin + mktempdir() do dir + t = tpl(; dir=dirname(dir)) + @test_throws ArgumentError t(basename(dir)) + end + + mktemp() do f, _io + t = tpl(; dir=dirname(f)) + @test_throws ArgumentError t(basename(f)) + end + + t = tpl() + pkg = pkgname() + @test_throws ErrorException @overdub ErrorOnRepoInit() @suppress t(pkg) + @test !isdir(joinpath(t.dir, pkg)) end From 65f5eff29bc40f7fd84a25ef975f25693c79d656 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sun, 1 Sep 2019 21:03:19 +0700 Subject: [PATCH 23/81] Lots of documentation Still WIP though. --- .travis.yml | 14 +++-- README.md | 6 +-- docs/make.jl | 5 +- docs/src/developer.md | 31 +++++++++++ docs/src/index.md | 8 --- docs/src/user.md | 67 +++++++++++++++++++++++ src/PkgTemplates.jl | 1 - src/plugin.jl | 73 ++++++++++++++++++++++--- src/plugins/ci.jl | 110 ++++++++++++++++++++++++++++++++++---- src/plugins/citation.jl | 12 +++-- src/plugins/coverage.jl | 22 ++++++++ src/plugins/defaults.jl | 46 ++++++++++++++++ src/plugins/documenter.jl | 24 ++++----- src/template.jl | 4 +- 14 files changed, 369 insertions(+), 54 deletions(-) create mode 100644 docs/src/developer.md delete mode 100644 docs/src/index.md create mode 100644 docs/src/user.md diff --git a/.travis.yml b/.travis.yml index 8dd65735..7246a9f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,11 +27,15 @@ matrix: julia: 1.0 - stage: Documentation julia: 1.0 - script: julia --project=docs -e ' - using Pkg; - Pkg.develop(PackageSpec(; path=pwd())); - Pkg.instantiate(); - include("docs/make.jl");' + script: + - git config --global user.name Your-Name + - git config --global user.email your-email + - git config --global github.user your-username + - julia --project=docs -e ' + using Pkg; + Pkg.develop(PackageSpec(; path=pwd())); + Pkg.instantiate(); + include("docs/make.jl");' after_success: skip after_success: julia -e ' using Pkg; diff --git a/README.md b/README.md index e6927d38..26ab9b1d 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,12 @@ # PkgTemplates [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://invenia.github.io/PkgTemplates.jl/stable) -[![Dev](https://img.shields.io/badge/docs-latest-blue.svg)](https://invenia.github.io/PkgTemplates.jl/dev) +[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://invenia.github.io/PkgTemplates.jl/dev) [![Build Status](https://travis-ci.org/invenia/PkgTemplates.jl.svg?branch=master)](https://travis-ci.org/invenia/PkgTemplates.jl) [![Codecov](https://codecov.io/gh/invenia/PkgTemplates.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/invenia/PkgTemplates.jl) **PkgTemplates creates new Julia packages in an easy, repeatable, and customizable way.** -## Usage - Assuming you have the relatively standard Git options `user.name`, `user.email` and `github.user` set up globally with `git config --global`, creating a `Template` is as simple as: ```jl @@ -31,7 +29,7 @@ t = Template(; ) ``` -Once you have a `Template`, yoy can createa packages with ease: +Once you have a template, you can create packages with ease: ```jl t("MyPkg") diff --git a/docs/make.jl b/docs/make.jl index b80a9130..3d6900b5 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,5 +1,5 @@ using Documenter -using PkgTemplates +using PkgTemplates: PkgTemplates makedocs(; modules=[PkgTemplates], @@ -11,7 +11,8 @@ makedocs(; assets=String[], ), pages=[ - "Home" => "index.md", + "Home" => "user.md", + "Developer Guide" => "developer.md", ], ) diff --git a/docs/src/developer.md b/docs/src/developer.md new file mode 100644 index 00000000..1f9666c2 --- /dev/null +++ b/docs/src/developer.md @@ -0,0 +1,31 @@ +```@meta +CurrentModule = PkgTemplates +``` + +# PkgTemplates Developer Guide + +PkgTemplates can be easily extended by adding new [`Plugin`](@ref)s. + +## The `Plugin` Interface + +```@docs +gen_plugin +gitignore +badges +Badge +view +user_view +combined_view +tags +``` + +## The `BasicPlugin` Interface + +While subtyping [`Plugin`](@ref) gives you complete freedom, it's not always necessary. +For more constrained cases, a simpler API exists. + +```@docs +BasicPlugin +source +destination +``` diff --git a/docs/src/index.md b/docs/src/index.md deleted file mode 100644 index d819939e..00000000 --- a/docs/src/index.md +++ /dev/null @@ -1,8 +0,0 @@ -# PkgTemplates - -```@index -``` - -```@autodocs -Modules = [PkgTemplates] -``` diff --git a/docs/src/user.md b/docs/src/user.md new file mode 100644 index 00000000..3d7c85f6 --- /dev/null +++ b/docs/src/user.md @@ -0,0 +1,67 @@ +```@meta +CurrentModule = PkgTemplates +``` + +# PkgTemplates User Guide + +Using PkgTemplates is straightforward. +Just create a [`Template`](@ref), and call it on a package name to generate that package. + +## Template + +```@docs +Template +``` + +## Plugins + +Plugins are PkgTemplates' source of customization and extensibility. +Add plugins to your templates to enable extra pieces of repository setup. + +```@docs +Plugin +``` + +### Defaults + +These plugins are included in [`Template`](@ref)s by default. +They can be overridden by supplying another value via the `plugins` keyword, or disabled by supplying the type via the `disable_defaults` keyword. + +```@docs +Gitignore +License +Readme +Tests +``` + +### Continuous Integration (CI) + +These plugins will create the configuration files of common CI services for you. + +```@docs +AppVeyor +CirrusCI +GitLabCI +TravisCI +``` + +### Code Coverage + +These plugins will enable code coverage reporting from CI. + +```@docs +Codecov +Coveralls +``` + +### Documentation + +```@docs +Documenter +``` + +### Miscellaneous + +```@docs +Citation +``` diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index 801958b0..5fd5e062 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -35,6 +35,5 @@ abstract type Plugin end include("template.jl") include("generate.jl") include("plugin.jl") -# include("interactive.jl") end diff --git a/src/plugin.jl b/src/plugin.jl index 187fcdac..695e80b7 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -12,10 +12,16 @@ badge_order() = [ ] """ -A simple plugin that, in general, manages a single file. -For example, most CI services reply on one configuration file. +A simple plugin that, in general, creates a single file. -TODO: Dev guide. +You needn't implement [`gen_plugin`](@ref) for your subtypes. +Instead, you're left to implement a couple of much simpler functions: + +- [`source`](@ref) +- [`destination`](@ref) + +For examples, see the plugins in the [Continuous Integration (CI)](@ref) and [Code Coverage](@ref) sections. +For an example of a plugin that creates a file and then does some additional work, see [`Tests`](@ref). """ abstract type BasicPlugin <: Plugin end @@ -25,16 +31,40 @@ default_file(paths::AbstractString...) = joinpath(DEFAULTS_DIR, paths...) """ view(::Plugin, ::Template, pkg::AbstractString) -> Dict{String, Any} -Return the string replacements to be made for this plugin. +Return the view to be passed to the text templating engine for this plugin. `pkg` is the name of the package being generated. + +For [`BasicPlugin`](@ref)s, this is used for both the plugin badges (see [`badges`](@ref)) and the template file (see [`source`](@ref)). +For other [`Plugin`](@ref)s, it is used only for badges, but you can always call it yourself as part of your [`gen_plugin`](@ref) implementation. + +By default, an empty `Dict` is returned. + +!!! note + For more information on templating with Mustache, see the [Mustache.jl](https://github.com/jverzani/Mustache.jl) documentation. """ view(::Plugin, ::Template, ::AbstractString) = Dict{String, Any}() """ user_view(::Plugin, ::Template, pkg::AbstractString) -> Dict{String, Any} -The same as [`view`](@ref), but for use only by package *users* for extension. -TODO better explanation +The same as [`view`](@ref), but for use by package *users* for extension. + +For example, suppose you were using the [`Readme`](@ref) with a custom template file that looked like this: + +```md +# {{PKG}} + +Created on *{{TODAY}}*. +``` + +The [`view`](@ref) function supplies a value for `PKG`, but it does not supply a value for `TODAY`. +Rather than override [`view`](@ref), we can implement this function to get both the default values and whatever else we need to add. + +```julia +user_view(::Readme, ::Template, ::AbstractString) = Dict("TODAY" => today()) +``` + +Values returned by this function will override those from [`view`](@ref) when the keys are the same. """ user_view(::Plugin, ::Template, ::AbstractString) = Dict{String, Any}() @@ -42,6 +72,9 @@ user_view(::Plugin, ::Template, ::AbstractString) = Dict{String, Any}() tags(::Plugin) -> Tuple{String, String} Return the tags used for Mustache templating. +See the [`Citation`](@ref) plugin for a rare case where changing the tags is necessary. + +By default, the tags are `"{{"` and `"}}"`. """ tags(::Plugin) = ("{{", "}}") @@ -49,6 +82,9 @@ tags(::Plugin) = ("{{", "}}") gitignore(::Plugin) -> Vector{String} Return patterns that should be added to `.gitignore`. +These are used by the [`Gitignore`](@ref) plugin. + +By default, an empty list is returned. """ gitignore(::Plugin) = String[] @@ -56,13 +92,18 @@ gitignore(::Plugin) = String[] badges(::Plugin) -> Union{Badge, Vector{Badge}} Return a list of [`Badge`](@ref)s, or just one, to be added to `README.md`. +These are used by the [`Readme`](@ref) plugin to add badges to the README. + +By default, an empty list is returned. """ badges(::Plugin) = Badge[] """ source(::BasicPlugin) -> Union{String, Nothing} -Return the path to a plugin's configuration file template, or `nothing` to indicate no file. +Return the path to a plugin's template file, or `nothing` to indicate no file. + +By default, `nothing` is returned. """ source(::BasicPlugin) = nothing @@ -70,6 +111,8 @@ source(::BasicPlugin) = nothing destination(::BasicPlugin) -> String Return the destination, relative to the package root, of a plugin's configuration file. + +This function **must** be implemented. """ function destination end @@ -77,7 +120,7 @@ function destination end Badge(hover::AbstractString, image::AbstractString, link::AbstractString) -> Badge Container for Markdown badge data. -Each argument can contain placeholders. +Each argument can contain placeholders (which will be filled in with values from [`combined_view`](@ref)). ## Arguments * `hover::AbstractString`: Text to appear when the mouse is hovered over the badge. @@ -104,6 +147,11 @@ end Perform any work associated with a plugin. `pkg` is the name of the package being generated. + +For [`Plugin`](@ref)s that are not [`BasicPlugin`](@ref)s, this is the only function that really needs to be implemented. +If you want your plugin to do anything at all during package generation, you should implement it here. + +You should **not** implement this function for `BasicPlugin`s. """ gen_plugin(::Plugin, ::Template, ::AbstractString) = nothing @@ -120,6 +168,15 @@ function render_plugin(p::BasicPlugin, t::Template, pkg::AbstractString) return render_file(source(p), combined_view(p, t, pkg), tags(p)) end +""" + combined_view(::Plugin, ::Template, pkg::AbstractString) -> Dict{String, Any} + +This function combines [`view`](@ref) and [`user_view`](@ref) for use in text templating. +If you're doing manual creation (i.e. writing [`Plugin`](@ref)s that are not [`BasicPlugin`](@ref)s, then you should use this function rather than either of the former two. + +!!! note + You should **not** implement this function yourself. +""" function combined_view(p::Plugin, t::Template, pkg::AbstractString) return merge(view(p, t, pkg), user_view(p, t, pkg)) end diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index e83c1c64..d71a5fb8 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -1,15 +1,45 @@ -const VersionsOrStrings = Vector{Union{VersionNumber, String}} -const ALLOWED_FAILURES = ["1.3", "nightly"] # TODO: Update this list with new RCs. -const DEFAULT_CI_VERSIONS = VersionsOrStrings([VERSION, default_version(), "nightly"]) - +# Strip everything but the major and minor release from a version number. format_version(v::VersionNumber) = "$(v.major).$(v.minor)" format_version(v::AbstractString) = string(v) +const ALLOWED_FAILURES = ["1.3", "nightly"] # TODO: Update this list with new RCs. +const DEFAULT_CI_VERSIONS = map(format_version, [default_version(), VERSION, "nightly"]) +const EXTRA_VERSIONS_DOC = "- `extra_versions::Vector`: Extra Julia versions to test, as strings or `VersionNumber`s." + + +""" + collect_versions(t::Template, versions::Vector) -> Vector{String} + +Combine the [`Template`](@ref)'s Julia version and some other versions, and format them as `major.minor`. +This is useful for creating lists of versions to be included in CI configurations. +""" function collect_versions(t::Template, versions::Vector) vs = map(format_version, [t.julia_version, versions...]) return sort(unique(vs)) end +""" + TravisCI(; + file="$(contractuser(default_file("travis.yml")))", + linux=true, + osx=true, + windows=true, + x86=false, + coverage=true, + extra_versions=$DEFAULT_CI_VERSIONS, + ) -> TravisCI + +Integrates your packages with [Travis CI](https://travis-ci.com). + +## Keyword Arguments +- `file::AbstractString`: Template file for `.travis.yml`. +- `linux::Bool`: Whether or not to run builds on Linux. +- `osx::Bool`: Whether or not to run builds on OSX (MacOS). +- `windows::Bool`: Whether or not to run builds on Windows. +- `x86::Bool`: Whether or not to run builds on 32-bit systems, in addition to the default 64-bit builds. +- `coverage::Bool`: Whether or not to publish code coverage (another code coverage plugin such as [`Codecov`](@ref) must also be included). +$EXTRA_VERSIONS_DOC +""" @with_kw struct TravisCI <: BasicPlugin file::String = default_file("travis.yml") linux::Bool = true @@ -17,7 +47,7 @@ end windows::Bool = true x86::Bool = false coverage::Bool = true - extra_versions::VersionsOrStrings = DEFAULT_CI_VERSIONS + extra_versions::Vector = DEFAULT_CI_VERSIONS end source(p::TravisCI) = p.file @@ -35,7 +65,6 @@ function view(p::TravisCI, t::Template, pkg::AbstractString) p.osx && push!(os, "osx") p.windows && push!(os, "windows") - versions = collect_versions(t, p.extra_versions) allow_failures = filter(in(versions), ALLOWED_FAILURES) @@ -64,11 +93,27 @@ function view(p::TravisCI, t::Template, pkg::AbstractString) ) end +""" + AppVeyor(; + file="$(contractuser(default_file("appveyor.yml")))", + x86=false, + coverage=true, + extra_versions=$DEFAULT_CI_VERSIONS, + ) -> AppVeyor + +Integrates your packages with [AppVeyor](https://appveyor.com) via [AppVeyor.jl](https://github.com/JuliaCI/Appveyor.jl). + +## Keyword Arguments +- `file::AbstractString`: Template file for `.appveyor.yml`. +- `x86::Bool`: Whether or not to run builds on 32-bit systems, in addition to the default 64-bit builds. +- `coverage::Bool`: Whether or not to publish code coverage ([`Codecov`](@ref) must also be included). +$EXTRA_VERSIONS_DOC +""" @with_kw struct AppVeyor <: BasicPlugin file::String = default_file("appveyor.yml") x86::Bool = false coverage::Bool = true - extra_versions::VersionsOrStrings = DEFAULT_CI_VERSIONS + extra_versions::Vector = DEFAULT_CI_VERSIONS end source(p::AppVeyor) = p.file @@ -98,11 +143,30 @@ function view(p::AppVeyor, t::Template, pkg::AbstractString) ) end +""" + CirrusCI(; + file="$(contractuser(default_file("cirrus.yml")))", + image="freebsd-12-0-release-amd64", + coverage=true, + extra_versions=$DEFAULT_CI_VERSIONS, + ) -> CirrusCI + +Integrates your packages with [Cirrus CI](https://cirrus-ci.org) via [CirrusCI.jl](https://github.com/ararslan/CirrusCI.jl). + +## Keyword Arguments +- `file::AbstractString`: Template file for `.cirrus.yml`. +- `image::AbstractString`: The FreeBSD image to be used. +- `coverage::Bool`: Whether or not to publish code coverage ([`Codecov`](@ref) must also be included). +$EXTRA_VERSIONS_DOC + +!!! note + Code coverage submission from Cirrus CI is not yet supported by [Coverage.jl](https://github.com/JuliaCI/Coverage.jl). +""" @with_kw struct CirrusCI <: BasicPlugin file::String = default_file("cirrus.yml") image::String = "freebsd-12-0-release-amd64" coverage::Bool = true - extra_versions::VersionsOrStrings = DEFAULT_CI_VERSIONS + extra_versions::Vector = DEFAULT_CI_VERSIONS end source(p::CirrusCI) = p.file @@ -126,11 +190,32 @@ function view(p::CirrusCI, t::Template, pkg::AbstractString) ) end +""" + GitLabCI(; + file="$(contractuser(default_file("gitlab-ci.yml")))", + coverage=true, + extra_versions=$DEFAULT_CI_VERSIONS, + ) -> GitLabCI + +Integrates your packages with [GitLab CI](https://docs.gitlab.com/ce/ci/). + +## Keyword Arguments +- `file::AbstractString`: Template file for `.gitlab-ci.yml`. +- `coverage::Bool`: Whether or not to compute code coverage. +$EXTRA_VERSIONS_DOC + +## GitLab Pages +Documentation can be generated by including a `Documenter{GitLabCI}` plugin. +See [`Documenter`](@ref) for more information. + +!!! note + Nightly Julia is not supported. +""" @with_kw struct GitLabCI <: BasicPlugin file::String = default_file("gitlab-ci.yml") coverage::Bool = true # Nightly has no Docker image. - extra_versions::VersionsOrStrings = [VERSION, default_version()] + extra_versions::Vector = map(format_version, [default_version(), VERSION]) end gitignore(p::GitLabCI) = p.coverage ? COVERAGE_GITIGNORE : String[] @@ -163,5 +248,12 @@ function view(p::GitLabCI, t::Template, pkg::AbstractString) ) end + +""" + is_ci(::Type{T}) -> Bool + +Determine whether or not `T` is a CI plugin. +If you are adding a CI plugin, you should implement this function and return `true`. +""" is_ci(::Type) = false is_ci(::Type{<:Union{AppVeyor, TravisCI, CirrusCI, GitLabCI}}) = true diff --git a/src/plugins/citation.jl b/src/plugins/citation.jl index deabe8a6..eb1f6a16 100644 --- a/src/plugins/citation.jl +++ b/src/plugins/citation.jl @@ -1,8 +1,14 @@ """ - Citation(; readme_section::Bool=false) -> Citation + Citation(; + file="$(contractuser(default_file("CITATION.bib")))", + readme=false, + ) -> Citation -Add `Citation` to a [`Template`](@ref)'s plugin list to generate a `CITATION.bib` file. -If `readme` is set, then `README.md` will contain a section about citing. +Creates a `CITATION.bib` file for citing package repositories. + +## Keyword Arguments +- `file::AbstractString`: Template file for `CITATION.bib`. +- `readme::Bool`: Whether or not to include a section about citing in the README. """ @with_kw struct Citation <: BasicPlugin file::String = default_file("CITATION.bib") diff --git a/src/plugins/coverage.jl b/src/plugins/coverage.jl index 4025be0c..064b8296 100644 --- a/src/plugins/coverage.jl +++ b/src/plugins/coverage.jl @@ -1,5 +1,13 @@ const COVERAGE_GITIGNORE = ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] +""" + Codecov(; file=nothing) -> Codecov + +Sets up code coverage submission from CI to [Codecov](https://codecov.io). + +## Keyword Arguments +- `file::Union{AbstractString, Nothing}`: Template file for `.codecov.yml`, or `nothing` to create no file. +""" @with_kw struct Codecov <: BasicPlugin file::Union{String, Nothing} = nothing end @@ -13,6 +21,14 @@ badges(::Codecov) = Badge( "https://codecov.io/gh/{{USER}}/{{PKG}}.jl", ) +""" + Coveralls(; file=nothing) -> Coverallls + +Sets up code coverage submission from CI to [Coveralls](https://coveralls.io). + +## Keyword Arguments +- `file::Union{AbstractString, Nothing}`: Template file for `.coveralls.yml`, or `nothing` to create no file. +""" @with_kw struct Coveralls <: BasicPlugin file::Union{String, Nothing} = nothing end @@ -28,5 +44,11 @@ badges(::Coveralls) = Badge( gitignore(::Union{Codecov, Coveralls}) = COVERAGE_GITIGNORE +""" + is_coverage(::Type{T}) -> Bool + +Determine whether or not `T` is a coverage plugin. +If you are adding a coverage plugin, you should implement this function and return `true`. +""" is_coverage(::Type) = false is_coverage(::Type{<:Union{Codecov, Coveralls}}) = true diff --git a/src/plugins/defaults.jl b/src/plugins/defaults.jl index c66e8b4f..794479ea 100644 --- a/src/plugins/defaults.jl +++ b/src/plugins/defaults.jl @@ -14,6 +14,22 @@ const LICENSES = Dict( "EUPL-1.2+" => "European Union Public Licence, Version 1.2+", ) +""" + Readme(; + file="$(contractuser(default_file("README.md")))", + destination="README.md", + inline_badges=false, + ) -> Readme, + +Creates a `README` file. +By default, it includes badges for other included plugins + +## Keyword Arguments +- `file::AbstractString`: Template file for the `README`. +- `destination::AbstractString`: File destination, relative to the repository root. + For example, values of `"README"` or `"README.rst"` might be desired. +- `inline_badges::Bool`: Whether or not to put the badges on the same line as the package name. +""" @with_kw struct Readme <: BasicPlugin file::String = default_file("README.md") destination::String = "README.md" @@ -47,6 +63,17 @@ function view(p::Readme, t::Template, pkg::AbstractString) ) end +""" + License(; name="MIT", destination="LICENSE") -> License + +Creates a license file. + +## Keyword Arguments +- `name::AbstractString`: Name of the desired license. + Available licenses can be seen [here](https://github.com/invenia/PkgTemplates.jl/tree/master/licenses). +- `destination::AbstractString`: File destination, relative to the repository root. + For example, `"LICENSE.md"` might be desired. +""" struct License <: Plugin path::String destination::String @@ -56,12 +83,14 @@ struct License <: Plugin end end +# Look up a license and throw an error if it doesn't exist. function license_path(license::AbstractString) path = joinpath(LICENSE_DIR, license) isfile(path) || throw(ArgumentError("License '$license' is not available")) return path end +# Read a license's text. read_license(license::AbstractString) = string(readchomp(license_path(license))) function render_plugin(p::License, t::Template) @@ -76,6 +105,15 @@ function gen_plugin(p::License, t::Template, pkg_dir::AbstractString) gen_file(joinpath(pkg_dir, p.destination), render_plugin(p, t)) end +""" + Gitignore(; ds_store=true, dev=true) -> Gitignore + +Creates a `.gitignore` file. + +## Keyword Arguments +- `ds_store::Bool`: Whether or not to ignore MacOS's `.DS_Store` files. +- `dev::Bool`: Whether or not to ignore the directory of locally-developed packages. +""" @with_kw struct Gitignore <: Plugin ds_store::Bool = true dev::Bool = true @@ -96,6 +134,14 @@ function gen_plugin(p::Gitignore, t::Template, pkg_dir::AbstractString) t.git && gen_file(joinpath(pkg_dir, ".gitignore"), render_plugin(p, t)) end +""" + Tests(; file="$(contractuser(default_file("runtests.jl")))" -> Tests + +Sets up testing for packages. + +## Keyword Arguments +- `file::AbstractString`: Template file for the `runtests.jl`. +""" @with_kw struct Tests <: BasicPlugin file::String = default_file("runtests.jl") end diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index 70c5618f..8a4950ee 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -2,23 +2,23 @@ const DOCUMENTER_UUID = "e30172f5-a6a5-5a46-863b-614d45cd2de4" """ Documenter{T<:Union{TravisCI, GitLabCI, Nothing}}(; - assets::Vector{<:AbstractString}=String[], - makedocs_kwargs::Dict{Symbol}=Dict(), - canonical_url::Union{Function, Nothing}=nothing, - make_jl::AbstractString="$(contractuser(default_file("make.jl")))", - index_md::AbstractString="$(contractuser(default_file("index.md")))", + make_jl="$(contractuser(default_file("make.jl")))", + index_md="$(contractuser(default_file("index.md")))", + assets=String[], + canonical_url=, + makedocs_kwargs=Dict{Symbol, Any}(), ) -> Documenter{T} -The `Documenter` plugin adds support for documentation generation via [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl). +Sets up documentation generation via [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl). Documentation deployment depends on `T`, where `T` is some supported CI plugin, or `Nothing` to only support local documentation builds. ## Keyword Arguments -TODO -- `assets::Vector{<:AbstractString}=String[]`: -- `makedocs_kwargs::Dict{Symbol}=Dict{Symbol, Any}()`: -- `canonical_url::Union{Function, Nothing}=nothing`: -- `index_md::AbstractString` -- `make_jl::AbstractString` +- `make_jl::AbstractString`: Template file for `make.jl`. +- `index_md::AbstractString`: Template file for `index.md`. +- `assets::Vector{<:AbstractString}`: Extra assets for the generated site. +- `canonical_url::Union{Function, Nothing}`: A function to generate the documentation site's canonical URL. + The default value will compute GitHub Pages and GitLab Pages URLs for [`TravisCI`](@ref) and [`GitLabCI`](@ref), respectively. +- `makedocs_kwargs::Dict{Symbol}`: Extra keyword arguments to be inserted into `makedocs`. !!! note If deploying documentation with Travis CI, don't forget to complete the required configuration. diff --git a/src/template.jl b/src/template.jl index 72dc581e..37ccdb3a 100644 --- a/src/template.jl +++ b/src/template.jl @@ -10,9 +10,9 @@ function default_authors() end """ - Template(; interactive::Bool=false, kwargs...) -> Template + Template(; kwargs...) -> Template -Records common information used to generate a package. +A configuration used to generate packages. ## Keyword Arguments From 481d8430e6f4ba4c065cf3edbffd178c4685584a Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Mon, 2 Sep 2019 21:20:33 +0700 Subject: [PATCH 24/81] Add show methods --- docs/src/user.md | 16 +++++++++++++++ src/PkgTemplates.jl | 3 ++- src/interactive.jl | 32 +++++++++++++++++++++++++++++ src/plugins/ci.jl | 8 ++++---- src/plugins/citation.jl | 2 +- src/plugins/coverage.jl | 4 ++-- src/plugins/defaults.jl | 6 +++--- src/plugins/documenter.jl | 2 +- test/runtests.jl | 3 ++- test/show.jl | 42 +++++++++++++++++++++++++++++++++++++++ 10 files changed, 105 insertions(+), 13 deletions(-) create mode 100644 src/interactive.jl create mode 100644 test/show.jl diff --git a/docs/src/user.md b/docs/src/user.md index 3d7c85f6..0d00db2b 100644 --- a/docs/src/user.md +++ b/docs/src/user.md @@ -65,3 +65,19 @@ Documenter ```@docs Citation ``` + +## Saving Templates + +One of the main reasons for PkgTemplates' existence is for new packages to be consistent. +This means using the same template more than once, so we want a way to save a template to be used later. + +Here's my recommendation for loading a template whenever it's needed: + +```julia +function template() + @eval using PkgTemplates + Template(; #= ... =#) +end +``` + +Add this to your `startup.jl`, and you can create your template from anywhere, without incurring any startup cost. diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index 5fd5e062..81a4a389 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -10,7 +10,7 @@ using Pkg: Pkg, TOML, PackageSpec using REPL.TerminalMenus: MultiSelectMenu, RadioMenu, request using Mustache: entityMap, render -using Parameters: @with_kw +using Parameters: @with_kw_noshow export Template, @@ -35,5 +35,6 @@ abstract type Plugin end include("template.jl") include("generate.jl") include("plugin.jl") +include("interactive.jl") end diff --git a/src/interactive.jl b/src/interactive.jl new file mode 100644 index 00000000..8b80e01e --- /dev/null +++ b/src/interactive.jl @@ -0,0 +1,32 @@ +# const PLUGIN_TYPES = let +# leaves(T::Type) = isconcretetype(T) ? [T] : vcat(map(leaves, subtypes(T))...) +# leaves(Plugin) +# end + +function Base.show(io::IO, p::T) where T <: Plugin + indent = get(io, :indent, 0) + print(io, repeat(' ', indent), T, ":") + foreach(fieldnames(T)) do n + println(io) + print(io, repeat(' ', indent + 2), n, ": ", show_field(getfield(p, n))) + end +end + +show_field(x) = repr(x) +show_field(x::AbstractString) = repr(contractuser(x)) + +function Base.show(io::IO, t::Template) + println(io, "Template:") + foreach(fieldnames(Template)) do n + n === :plugins || println(io, repeat(' ', 2), n, ": ", show_field(getfield(t, n))) + end + if isempty(t.plugins) + print(io, " plugins: None") + else + print(io, repeat(' ', 2), "plugins:") + foreach(values(t.plugins)) do p + println(io) + show(IOContext(io, :indent => 4), p) + end + end +end diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index d71a5fb8..9a43bc5f 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -40,7 +40,7 @@ Integrates your packages with [Travis CI](https://travis-ci.com). - `coverage::Bool`: Whether or not to publish code coverage (another code coverage plugin such as [`Codecov`](@ref) must also be included). $EXTRA_VERSIONS_DOC """ -@with_kw struct TravisCI <: BasicPlugin +@with_kw_noshow struct TravisCI <: BasicPlugin file::String = default_file("travis.yml") linux::Bool = true osx::Bool = true @@ -109,7 +109,7 @@ Integrates your packages with [AppVeyor](https://appveyor.com) via [AppVeyor.jl] - `coverage::Bool`: Whether or not to publish code coverage ([`Codecov`](@ref) must also be included). $EXTRA_VERSIONS_DOC """ -@with_kw struct AppVeyor <: BasicPlugin +@with_kw_noshow struct AppVeyor <: BasicPlugin file::String = default_file("appveyor.yml") x86::Bool = false coverage::Bool = true @@ -162,7 +162,7 @@ $EXTRA_VERSIONS_DOC !!! note Code coverage submission from Cirrus CI is not yet supported by [Coverage.jl](https://github.com/JuliaCI/Coverage.jl). """ -@with_kw struct CirrusCI <: BasicPlugin +@with_kw_noshow struct CirrusCI <: BasicPlugin file::String = default_file("cirrus.yml") image::String = "freebsd-12-0-release-amd64" coverage::Bool = true @@ -211,7 +211,7 @@ See [`Documenter`](@ref) for more information. !!! note Nightly Julia is not supported. """ -@with_kw struct GitLabCI <: BasicPlugin +@with_kw_noshow struct GitLabCI <: BasicPlugin file::String = default_file("gitlab-ci.yml") coverage::Bool = true # Nightly has no Docker image. diff --git a/src/plugins/citation.jl b/src/plugins/citation.jl index eb1f6a16..a52469cd 100644 --- a/src/plugins/citation.jl +++ b/src/plugins/citation.jl @@ -10,7 +10,7 @@ Creates a `CITATION.bib` file for citing package repositories. - `file::AbstractString`: Template file for `CITATION.bib`. - `readme::Bool`: Whether or not to include a section about citing in the README. """ -@with_kw struct Citation <: BasicPlugin +@with_kw_noshow struct Citation <: BasicPlugin file::String = default_file("CITATION.bib") readme::Bool = false end diff --git a/src/plugins/coverage.jl b/src/plugins/coverage.jl index 064b8296..8d030ef2 100644 --- a/src/plugins/coverage.jl +++ b/src/plugins/coverage.jl @@ -8,7 +8,7 @@ Sets up code coverage submission from CI to [Codecov](https://codecov.io). ## Keyword Arguments - `file::Union{AbstractString, Nothing}`: Template file for `.codecov.yml`, or `nothing` to create no file. """ -@with_kw struct Codecov <: BasicPlugin +@with_kw_noshow struct Codecov <: BasicPlugin file::Union{String, Nothing} = nothing end @@ -29,7 +29,7 @@ Sets up code coverage submission from CI to [Coveralls](https://coveralls.io). ## Keyword Arguments - `file::Union{AbstractString, Nothing}`: Template file for `.coveralls.yml`, or `nothing` to create no file. """ -@with_kw struct Coveralls <: BasicPlugin +@with_kw_noshow struct Coveralls <: BasicPlugin file::Union{String, Nothing} = nothing end diff --git a/src/plugins/defaults.jl b/src/plugins/defaults.jl index 794479ea..53ea0863 100644 --- a/src/plugins/defaults.jl +++ b/src/plugins/defaults.jl @@ -30,7 +30,7 @@ By default, it includes badges for other included plugins For example, values of `"README"` or `"README.rst"` might be desired. - `inline_badges::Bool`: Whether or not to put the badges on the same line as the package name. """ -@with_kw struct Readme <: BasicPlugin +@with_kw_noshow struct Readme <: BasicPlugin file::String = default_file("README.md") destination::String = "README.md" inline_badges::Bool = false @@ -114,7 +114,7 @@ Creates a `.gitignore` file. - `ds_store::Bool`: Whether or not to ignore MacOS's `.DS_Store` files. - `dev::Bool`: Whether or not to ignore the directory of locally-developed packages. """ -@with_kw struct Gitignore <: Plugin +@with_kw_noshow struct Gitignore <: Plugin ds_store::Bool = true dev::Bool = true end @@ -142,7 +142,7 @@ Sets up testing for packages. ## Keyword Arguments - `file::AbstractString`: Template file for the `runtests.jl`. """ -@with_kw struct Tests <: BasicPlugin +@with_kw_noshow struct Tests <: BasicPlugin file::String = default_file("runtests.jl") end diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index 8a4950ee..cf002a9e 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -31,7 +31,7 @@ struct Documenter{T<:Union{TravisCI, GitLabCI, Nothing}} <: Plugin make_jl::String index_md::String - # Can't use @with_kw due to some weird precompilation issues. + # Can't use @with_kw_noshow due to some weird precompilation issues. function Documenter{T}(; assets::Vector{<:AbstractString}=String[], makedocs_kwargs::Dict{Symbol}=Dict{Symbol, Any}(), diff --git a/test/runtests.jl b/test/runtests.jl index 94312f97..0f3dfec1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,4 @@ -using Base.Filesystem: path_separator +using Base.Filesystem: contractuser, path_separator using LibGit2: LibGit2, GitCommit, GitRemote, GitRepo using Pkg: Pkg @@ -43,6 +43,7 @@ mktempdir() do dir include("template.jl") include("plugin.jl") include("git.jl") + include("show.jl") # Quite a bit of output depends on the Julia version, # and the test fixtures are made with Julia 1.2. diff --git a/test/show.jl b/test/show.jl new file mode 100644 index 00000000..54b9cac4 --- /dev/null +++ b/test/show.jl @@ -0,0 +1,42 @@ +const DEFAULTS_DIR = contractuser(PT.DEFAULTS_DIR) +const LICENSE_DIR = contractuser(PT.LICENSE_DIR) + +@testset "Show methods" begin + @testset "Plugins" begin + expected = """ + Readme: + file: "$DEFAULTS_DIR/README.md" + destination: "README.md" + inline_badges: false + """ + @test sprint(show, Readme()) == rstrip(expected) + end + + @testset "Template" begin + expected = """ + Template: + authors: ["$USER"] + develop: true + dir: "$(Pkg.devdir())" + git: true + host: "github.com" + julia_version: v"1.0.0" + manifest: false + ssh: false + user: "$USER" + plugins: + Readme: + file: "$DEFAULTS_DIR/README.md" + destination: "README.md" + inline_badges: false + Tests: + file: "$DEFAULTS_DIR/runtests.jl" + Gitignore: + ds_store: true + dev: true + License: + path: "$LICENSE_DIR/MIT" + destination: "LICENSE" + """ + end +end From 2d7c851fcaaef6b14c2df6db5f3ae285e6d29148 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Tue, 3 Sep 2019 18:15:53 +0700 Subject: [PATCH 25/81] Only use custom show methods for plaintext display Thanks Lyndon: https://github.com/invenia/PkgTemplates.jl/issues/80#issuecomment-527351832 --- src/interactive.jl | 8 ++++---- test/show.jl | 24 ++++++++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/interactive.jl b/src/interactive.jl index 8b80e01e..a7d513f9 100644 --- a/src/interactive.jl +++ b/src/interactive.jl @@ -3,7 +3,7 @@ # leaves(Plugin) # end -function Base.show(io::IO, p::T) where T <: Plugin +function Base.show(io::IO, ::MIME"text/plain", p::T) where T <: Plugin indent = get(io, :indent, 0) print(io, repeat(' ', indent), T, ":") foreach(fieldnames(T)) do n @@ -15,7 +15,7 @@ end show_field(x) = repr(x) show_field(x::AbstractString) = repr(contractuser(x)) -function Base.show(io::IO, t::Template) +function Base.show(io::IO, m::MIME"text/plain", t::Template) println(io, "Template:") foreach(fieldnames(Template)) do n n === :plugins || println(io, repeat(' ', 2), n, ": ", show_field(getfield(t, n))) @@ -24,9 +24,9 @@ function Base.show(io::IO, t::Template) print(io, " plugins: None") else print(io, repeat(' ', 2), "plugins:") - foreach(values(t.plugins)) do p + foreach(sort(collect(values(t.plugins)); by=string)) do p println(io) - show(IOContext(io, :indent => 4), p) + show(IOContext(io, :indent => 4), m, p) end end end diff --git a/test/show.jl b/test/show.jl index 54b9cac4..b51aba8f 100644 --- a/test/show.jl +++ b/test/show.jl @@ -9,7 +9,7 @@ const LICENSE_DIR = contractuser(PT.LICENSE_DIR) destination: "README.md" inline_badges: false """ - @test sprint(show, Readme()) == rstrip(expected) + @test sprint(show, MIME("text/plain"), Readme()) == rstrip(expected) end @testset "Template" begin @@ -17,7 +17,7 @@ const LICENSE_DIR = contractuser(PT.LICENSE_DIR) Template: authors: ["$USER"] develop: true - dir: "$(Pkg.devdir())" + dir: "$(contractuser(Pkg.devdir()))" git: true host: "github.com" julia_version: v"1.0.0" @@ -25,18 +25,26 @@ const LICENSE_DIR = contractuser(PT.LICENSE_DIR) ssh: false user: "$USER" plugins: - Readme: - file: "$DEFAULTS_DIR/README.md" - destination: "README.md" - inline_badges: false - Tests: - file: "$DEFAULTS_DIR/runtests.jl" Gitignore: ds_store: true dev: true License: path: "$LICENSE_DIR/MIT" destination: "LICENSE" + Readme: + file: "$DEFAULTS_DIR/README.md" + destination: "README.md" + inline_badges: false + Tests: + file: "$DEFAULTS_DIR/runtests.jl" """ + @test sprint(show, MIME("text/plain"), tpl(; authors=USER)) == rstrip(expected) + end + + @testset "show as serialization" begin + # Equality is not implemented for Template, so check the string form. + t1 = tpl() + t2 = eval(Meta.parse(sprint(show, t1))) + @test sprint(show, t1) == sprint(show, t2) end end From 7a2a43f3f485b28efd42682f93831771297ce1a7 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Wed, 18 Sep 2019 21:22:04 +0700 Subject: [PATCH 26/81] Lots of documentation changes --- .travis.yml | 6 +- docs/make.jl | 5 +- docs/src/developer.md | 223 ++++++++++++++++++++++++++++++++++++-- docs/src/index.md | 25 +++++ docs/src/user.md | 114 +++++++++++++++++-- src/PkgTemplates.jl | 7 +- src/generate.jl | 16 ++- src/plugin.jl | 92 ++++++---------- src/plugins/ci.jl | 18 +-- src/plugins/citation.jl | 2 +- src/plugins/coverage.jl | 4 +- src/plugins/defaults.jl | 24 ++-- src/plugins/documenter.jl | 2 +- src/template.jl | 14 ++- test/plugin.jl | 1 + 15 files changed, 447 insertions(+), 106 deletions(-) create mode 100644 docs/src/index.md diff --git a/.travis.yml b/.travis.yml index 7246a9f1..a9fdc1ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,9 +28,9 @@ matrix: - stage: Documentation julia: 1.0 script: - - git config --global user.name Your-Name - - git config --global user.email your-email - - git config --global github.user your-username + - git config --global user.name name + - git config --global user.email email + - git config --global github.user username - julia --project=docs -e ' using Pkg; Pkg.develop(PackageSpec(; path=pwd())); diff --git a/docs/make.jl b/docs/make.jl index 3d6900b5..66168486 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,4 +1,4 @@ -using Documenter +using Documenter: Documenter, makedocs, deploydocs using PkgTemplates: PkgTemplates makedocs(; @@ -11,7 +11,8 @@ makedocs(; assets=String[], ), pages=[ - "Home" => "user.md", + "Home" => "index.md", + "User Guide" => "user.md", "Developer Guide" => "developer.md", ], ) diff --git a/docs/src/developer.md b/docs/src/developer.md index 1f9666c2..06a4013f 100644 --- a/docs/src/developer.md +++ b/docs/src/developer.md @@ -4,28 +4,237 @@ CurrentModule = PkgTemplates # PkgTemplates Developer Guide +```@contents +Pages = ["developer.md"] +``` + PkgTemplates can be easily extended by adding new [`Plugin`](@ref)s. -## The `Plugin` Interface +There are two types of plugins: [`Plugin`](@ref) and [`BasicPlugin`](@ref). + +```@docs +Plugin +BasicPlugin +``` + +## `Plugin` Walkthrough + +Concrete types that subtype [`Plugin`](@ref) directly are free to do almost anything. +To understand how they're implemented, let's look at a simplified version of [`Documenter`](@ref): + +```julia +@with_kw_noshow struct Documenter <: Plugin + make_jl::String = default_file("make.jl") + index_md::String = default_file("index.md") +end + +gitignore(::Documenter) = ["/docs/build/", "/docs/site/"] + +badges(::Documenter) = [ + Badge( + "Stable", + "https://img.shields.io/badge/docs-stable-blue.svg", + "https://{{USER}}.github.io/{{PKG}}.jl/stable", + ), + Badge( + "Dev", + "https://img.shields.io/badge/docs-dev-blue.svg", + "https://{{USER}}.github.io/{{PKG}}.jl/dev", + ), +] + +view(p::Documenter, t::Template, pkg::AbstractString) = Dict( + "AUTHORS" => join(t.authors, ", "), + "PKG" => pkg, + "REPO" => "$(t.host)/$(t.user)/$pkg.jl", + "USER" => t.user, +) + +function gen_plugin(p::Documenter, t::Template, pkg_dir::AbstractString) + pkg = basename(pkg_dir) + docs_dir = joinpath(pkg_dir, "docs") + + make = render_file(p.make_jl, combined_view(p, t, pkg), tags(p)) + gen_file(joinpath(docs_dir, "make.jl"), make) + + index = render_file(p.index_md, combined_view(p, t, pkg), tags(p)) + gen_file(joinpath(docs_dir, "src", "index.md"), index) + + # What this function does is not relevant here. + create_documentation_project() +end +``` + +First of all, `@with_kw_noshow` comes from [Parameters.jl](https://github.com/mauro3/Parameters.jl), and it just defines a nice keyword constructor for us. +The default values for our type are using [`default_file`](@ref) to point to files in this repository. + +```@docs +default_file +``` + +The first method we implement for `Documenter` is [`gitignore`](@ref), so that packages created with this plugin ignore documentation build artifacts. ```@docs -gen_plugin gitignore +``` + +Second, we implement [`badges`](@ref) to add a couple of badges to new packages' README files. + +```@docs badges Badge +``` + +Third, we implement [`view`](@ref), which is used to fill placeholders in badges and rendered files. + +```@docs view -user_view +``` + +Finally, we implement [`gen_plugin`](@ref), which is the real workhorse for the plugin. + +```@docs +gen_plugin +``` + +Inside of this function, we call a few more functions, which help us with text templating. + +```@docs +render_file +render_text +gen_file combined_view tags ``` -## The `BasicPlugin` Interface +todo more + +## `BasicPlugin` Walkthrough + +Plugins that subtype [`BasicPlugin`](@ref) perform a much more limited task. +In general, they just generate one templated file. + +To illustrate, let's look at the [`Citation`](@ref) plugin, which creates a `CITATION.bib` file. + +```julia +@with_kw_noshow struct Citation <: BasicPlugin + file::String = default_file("CITATION.bib") +end + +source(p::Citation) = p.file +destination(::Citation) = "CITATION.bib" + +tags(::Citation) = "<<", ">>" + +view(::Citation, t::Template, pkg::AbstractString) = Dict( + "AUTHORS" => join(t.authors, ", "), + "MONTH" => month(today()), + "PKG" => pkg, + "URL" => "https://$(t.host)/$(t.user)/$pkg.jl", + "YEAR" => year(today()), +) +``` + +Similar to the `Documenter` example above, we're defining a keyword constructor, and assigning a default template file from this repository. +This plugin adds nothing to `.gitignore`, and it doesn't add any badges, so implementations for [`gitignore`](@ref) and [`badges`](@ref) are omitted. -While subtyping [`Plugin`](@ref) gives you complete freedom, it's not always necessary. -For more constrained cases, a simpler API exists. +First, we implement [`source`](@ref) and [`destination`](@ref) to define where the template file comes from, and where it goes. +These functions are specific to [`BasicPlugin`](@ref)s, and have no effect on regular [`Plugin`](@ref)s by default. ```@docs -BasicPlugin source destination ``` + +Next, we implement [`tags`](@ref). +We briefly saw this function earlier, but in this case it's necessary to change its behaviour from the default. +To see why, it might help to see the template file in its entirety: + +``` +@misc{<>.jl, + author = {<>}, + title = {<>.jl}, + url = {<>}, + version = {v0.1.0}, + year = {<>}, + month = {<>} +} +``` + +Because the file contains its own `{}` delimiters, we need to use different ones for templating to work properly. + +Finally, we implement [`view`](@ref) to fill in the placeholders that we saw in the template file. + +## Doing Extra Work With `BasicPlugin`s + +Notice that we didn't have to implement [`gen_plugin`](@ref) for our plugin. +It's implemented for all [`BasicPlugin`](@ref)s, like so: + +```julia +function render_plugin(p::BasicPlugin, t::Template, pkg::AbstractString) + return render_file(source(p), combined_view(p, t, pkg), tags(p)) +end + +function gen_plugin(p::BasicPlugin, t::Template, pkg_dir::AbstractString) + source(p) === nothing && return + pkg = basename(pkg_dir) + path = joinpath(pkg_dir, destination(p)) + text = render_plugin(p, t, pkg) + gen_file(path, text) +end +``` + +But what if we want to do a little more than just generate one file? + +A good example of this is the [`Tests`](@ref) plugin. +It creates `runtests.jl`, but it also modifies the `Project.toml` to include the `Test` dependency. + +Of course, we could use a normal [`Plugin`](@ref), but it turns out there's a way to avoid that while still getting the extra capbilities that we want. + +The plugin implements its own `gen_plugin`, but uses `invoke` to avoid duplicating the file creation code: + +```julia +@with_kw_noshow struct Tests <: BasicPlugin + file::String = default_file("runtests.jl") +end + +source(p::Tests) = p.file +destination(::Tests) = joinpath("test", "runtests.jl") +view(::Tests, ::Template, pkg::AbstractString) = Dict("PKG" => pkg) + +function gen_plugin(p::Tests, t::Template, pkg_dir::AbstractString) + # Do the normal BasicPlugin behaviour to create the test script. + invoke(gen_plugin, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) + # Do some other work. + add_test_dependency() +end +``` + +For more examples, see the plugins in the [Continuous Integration (CI)](@ref) and [Code Coverage](@ref) sections. + +## Miscellaneous Tips + +### Writing Template Files + +For an overview of writing template files for Mustache.jl, see [Custom Template Files](@ref) in the user guide. + +### Traits + +There are a few traits for plugin types that are occassionally used to answer questions like "does this `Template` have any code coverage plugins?". +If you're implementing a plugin that fits into one of the following categories, it would be wise to implement the corresponding trait function to return `true` for your type. + +```@docs +is_ci +is_coverage +``` + +### Formatting Version Numbers + +When writing configuration files for CI services, working with version numbers is often needed. +There are a few convenience functions that can be used to make this a little bit easier. + +```@docs +compat_version +format_version +collect_versions +``` diff --git a/docs/src/index.md b/docs/src/index.md new file mode 100644 index 00000000..9b996991 --- /dev/null +++ b/docs/src/index.md @@ -0,0 +1,25 @@ +```@meta +CurrentModule = PkgTemplates +``` + +# PkgTemplates + +**PkgTemplates creates new Julia packages in an easy, repeatable, and customizable way.** + +### Foreword: Templating vs. Template + +This documentation refers plenty to [`Template`](@ref)s, the package's main type. +But it also refers to "template files" and "text templating", which are plaintext files with placeholders to be filled with data, and the technique of filling those placeholders with data, respectively. + +These concepts should be familiar if you've used [Jinja](https://palletsprojects.com/p/jinja) or [Mustache](https://mustache.github.io) (Mustache is the particular flavour used by PkgTemplates, via [Mustache.jl](https://github.com/jverzani/Mustache.jl)). + +### Documentation + +If you're looking to **create new packages**, see the [User Guide](user.md). + +If you want to **create new plugins**, see the [Developer Guide](developer.md). + +### Index + +```@index +``` diff --git a/docs/src/user.md b/docs/src/user.md index 0d00db2b..c811086e 100644 --- a/docs/src/user.md +++ b/docs/src/user.md @@ -4,6 +4,10 @@ CurrentModule = PkgTemplates # PkgTemplates User Guide +```@contents +Pages = ["user.md"] +``` + Using PkgTemplates is straightforward. Just create a [`Template`](@ref), and call it on a package name to generate that package. @@ -15,16 +19,12 @@ Template ## Plugins -Plugins are PkgTemplates' source of customization and extensibility. -Add plugins to your templates to enable extra pieces of repository setup. - -```@docs -Plugin -``` +Plugins add functionality to `Template`s. +There are a number of plugins available to automate common boilerplate tasks. ### Defaults -These plugins are included in [`Template`](@ref)s by default. +These plugins are included by default. They can be overridden by supplying another value via the `plugins` keyword, or disabled by supplying the type via the `disable_defaults` keyword. ```@docs @@ -66,6 +66,106 @@ Documenter Citation ``` +## Custom Template Files + +Many plugins support a `file` argument or similar, which sets the path to the template file to be used for generating files. +Each plugin has a sensible default that should make sense for most people, but you might have a specialized workflow that requires a totally different template file. + +If that's the case, a basic understanding of [Mustache](https://mustache.github.io)'s syntax is required. +Here's an example template file: + +``` +Hello, {{name}}. + +{{#weather}} +It's {{weather}} outside. +{{/weather}} +{{^weather}} +I don't know what the weather outside is. +{{/weather}} + +{{#has_things}} +I have the following things: +{{/has_things}} +{{#things}} +- Here's a thing: {{.}} +{{/things}} + +{{#people}} +- {{name}} is {{mood}} +{{/people}} +``` + +In the first section, `name` is a key, and its value replaces `{{name}}`. + +In the second section, `weather`'s value may or may not exist. +If it does exist, then "It's $weather outside" is printed. +Otherwise, "I don't know what the weather outside is" is printed. +Mustache uses a notion of "truthiness" similar to Python or JavaScript, where values of `nothing`, `false`, or empty collections are all considered to not exist. + +In the third section, `has_things`' value is printed if it's truthy. +Then, if the `things` list is truthy (i.e. not empty), its values are each printed on their own line. +The reason that we have two separate keys is that `{{#things}}` iterates over the whole `things` list, even when there are no `{{.}}` placeholders, which would duplicate "I have the following things:" `n` times. + +The fourth section iterates over the `people` list, but instead of using the `{{.}}` placeholder, we have `name` and `mood`, which are keys or fields of the list elements. +Most types are supported here, including `Dict`s and structs. +`NamedTuple`s require you to use `{{:name}}` instead of the normal `{{name}}`, though. + +Assuming the following view: + +```julia +struct Person; name::String; mood::String; end +things = ["a", "b", "c"] +view = Dict( + "name" => "Chris", + "weather" => "sunny", + "has_things" => !isempty(things), + "things" => things, + "people" => [Person("John", "happy"), Person("Jane", "sad")], +) +``` + +Our example template would produce this: + +``` +Hello, Chris. + +It's sunny outside. + +I have the following things: +- Here's a thing: a +- Here's a thing: b +- Here's a thing: c + +- John is happy +- Jane is sad +``` + +## Extending Existing Plugins + +Most of the existing plugins generate a file from a template file. +If you want to use custom template files, you may run into situations where the data passed into the templating engine is not sufficient. +In this case, you can look into implementing [`user_view`](@ref) to supply whatever data is necessary for your use case. + +```@docs +user_view +``` + +For example, suppose you were using the [`Readme`](@ref) plugin with a custom template file that looked like this: + +```md +# {{PKG}} + +Created on *{{TODAY}}*. +``` + +The [`view`](@ref) function supplies a value for `PKG`, but it does not supply a value for `TODAY`. +Rather than override [`view`](@ref), we can implement this function to get both the default values and whatever else we need to add. + +```julia +user_view(::Readme, ::Template, ::AbstractString) = Dict("TODAY" => today()) +``` + ## Saving Templates One of the main reasons for PkgTemplates' existence is for new packages to be consistent. diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index 81a4a389..d6769d0e 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -5,7 +5,7 @@ using Base.Filesystem: contractuser using Dates: month, today, year using InteractiveUtils: subtypes -using LibGit2: LibGit2 +using LibGit2: LibGit2, GitRemote using Pkg: Pkg, TOML, PackageSpec using REPL.TerminalMenus: MultiSelectMenu, RadioMenu, request @@ -28,7 +28,10 @@ export TravisCI """ -A plugin to be added to a [`Template`](@ref), which adds some functionality or integration. +Plugins are PkgTemplates' source of customization and extensibility. +Add plugins to your [`Template`](@ref)s to enable extra pieces of repository setup. + +When implementing a new plugin, subtype this type to have full control over its behaviour. """ abstract type Plugin end diff --git a/src/generate.jl b/src/generate.jl index 669685be..7a1716d5 100644 --- a/src/generate.jl +++ b/src/generate.jl @@ -31,10 +31,10 @@ function (t::Template)(pkg::AbstractString) else "https://$(t.host)/$(t.user)/$pkg.jl" end - remote = LibGit2.GitRemote(repo, "origin", url) - # TODO: `git pull` still requires some Git branch config. - LibGit2.add_push!(repo, remote, "refs/heads/master") - close(remote) + LibGit2.with(GitRemote(repo, "origin", url)) do remote + # TODO: `git pull` still requires some Git branch config. + LibGit2.add_push!(repo, remote, "refs/heads/master") + end end # Generate the files. @@ -66,10 +66,14 @@ function (t::Template)(pkg::AbstractString) end end -# Format the version to be included in Project.toml's [compat] section. +""" + compat_version(v::VersionNumber) -> String + +Format a `VersionNumber` to exclude trailing zero components. +""" function compat_version(v::VersionNumber) return if v.patch == 0 && v.minor == 0 - string(v.major) + "$(v.major)" elseif v.patch == 0 "$(v.major).$(v.minor)" else diff --git a/src/plugin.jl b/src/plugin.jl index 695e80b7..7d48e503 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -1,31 +1,15 @@ const DEFAULTS_DIR = normpath(joinpath(@__DIR__, "..", "defaults")) -badge_order() = [ - Documenter{GitLabCI}, - Documenter{TravisCI}, - GitLabCI, - TravisCI, - AppVeyor, - CirrusCI, - Codecov, - Coveralls, -] - """ A simple plugin that, in general, creates a single file. - -You needn't implement [`gen_plugin`](@ref) for your subtypes. -Instead, you're left to implement a couple of much simpler functions: - -- [`source`](@ref) -- [`destination`](@ref) - -For examples, see the plugins in the [Continuous Integration (CI)](@ref) and [Code Coverage](@ref) sections. -For an example of a plugin that creates a file and then does some additional work, see [`Tests`](@ref). """ abstract type BasicPlugin <: Plugin end -# Compute the path to a default template file in this repository. +""" + default_file(paths::AbstractString...) -> String + +Return a path relative to the default template file directory (`$(contractuser(DEFAULTS_DIR))`). +""" default_file(paths::AbstractString...) = joinpath(DEFAULTS_DIR, paths...) """ @@ -38,9 +22,6 @@ For [`BasicPlugin`](@ref)s, this is used for both the plugin badges (see [`badge For other [`Plugin`](@ref)s, it is used only for badges, but you can always call it yourself as part of your [`gen_plugin`](@ref) implementation. By default, an empty `Dict` is returned. - -!!! note - For more information on templating with Mustache, see the [Mustache.jl](https://github.com/jverzani/Mustache.jl) documentation. """ view(::Plugin, ::Template, ::AbstractString) = Dict{String, Any}() @@ -49,34 +30,34 @@ view(::Plugin, ::Template, ::AbstractString) = Dict{String, Any}() The same as [`view`](@ref), but for use by package *users* for extension. -For example, suppose you were using the [`Readme`](@ref) with a custom template file that looked like this: - -```md -# {{PKG}} - -Created on *{{TODAY}}*. -``` +Values returned by this function will override those from [`view`](@ref) when the keys are the same. +""" +user_view(::Plugin, ::Template, ::AbstractString) = Dict{String, Any}() -The [`view`](@ref) function supplies a value for `PKG`, but it does not supply a value for `TODAY`. -Rather than override [`view`](@ref), we can implement this function to get both the default values and whatever else we need to add. +""" + combined_view(::Plugin, ::Template, pkg::AbstractString) -> Dict{String, Any} -```julia -user_view(::Readme, ::Template, ::AbstractString) = Dict("TODAY" => today()) -``` +This function combines [`view`](@ref) and [`user_view`](@ref) for use in text templating. +If you're doing manual file creation or text templating (i.e. writing [`Plugin`](@ref)s that are not [`BasicPlugin`](@ref)s), then you should use this function rather than either of the former two. -Values returned by this function will override those from [`view`](@ref) when the keys are the same. +!!! note + Do not implement this function yourself! + If you're implementing a plugin, you should implement [`view`](@ref). + If you're customizing a plugin as a user, you should implement [`user_view`](@ref). """ -user_view(::Plugin, ::Template, ::AbstractString) = Dict{String, Any}() +function combined_view(p::Plugin, t::Template, pkg::AbstractString) + return merge(view(p, t, pkg), user_view(p, t, pkg)) +end """ tags(::Plugin) -> Tuple{String, String} -Return the tags used for Mustache templating. +Return the delimiters used for text templating. See the [`Citation`](@ref) plugin for a rare case where changing the tags is necessary. By default, the tags are `"{{"` and `"}}"`. """ -tags(::Plugin) = ("{{", "}}") +tags(::Plugin) = "{{", "}}" """ gitignore(::Plugin) -> Vector{String} @@ -117,7 +98,7 @@ This function **must** be implemented. function destination end """ - Badge(hover::AbstractString, image::AbstractString, link::AbstractString) -> Badge + Badge(hover::AbstractString, image::AbstractString, link::AbstractString) Container for Markdown badge data. Each argument can contain placeholders (which will be filled in with values from [`combined_view`](@ref)). @@ -164,24 +145,9 @@ function gen_plugin(p::BasicPlugin, t::Template, pkg_dir::AbstractString) end function render_plugin(p::BasicPlugin, t::Template, pkg::AbstractString) - # TODO template rendering code return render_file(source(p), combined_view(p, t, pkg), tags(p)) end -""" - combined_view(::Plugin, ::Template, pkg::AbstractString) -> Dict{String, Any} - -This function combines [`view`](@ref) and [`user_view`](@ref) for use in text templating. -If you're doing manual creation (i.e. writing [`Plugin`](@ref)s that are not [`BasicPlugin`](@ref)s, then you should use this function rather than either of the former two. - -!!! note - You should **not** implement this function yourself. -""" -function combined_view(p::Plugin, t::Template, pkg::AbstractString) - return merge(view(p, t, pkg), user_view(p, t, pkg)) -end - - """ gen_file(file::AbstractString, text::AbstractString) @@ -194,12 +160,22 @@ function gen_file(file::AbstractString, text::AbstractString) write(file, text) end -# Render text from a file. +""" + render_file(file::AbstractString view::Dict{<:AbstractString}, tags) -> String + +Render a template file with the data in `view`. +`tags` should be a tuple of two strings, which are the opening and closing delimiters, or `nothing` to use the default delimiters. +""" function render_file(file::AbstractString, view::Dict{<:AbstractString}, tags) render_text(read(file, String), view, tags) end -# Render text using Mustache's templating system. HTML escaping is disabled. +""" + render_text(text::AbstractString, view::Dict{<:AbstractString}, tags=nothing) -> String + +Render some text with the data in `view`. +`tags` should be a tuple of two strings, which are the opening and closing delimiters, or `nothing` to use the default delimiters. +""" function render_text(text::AbstractString, view::Dict{<:AbstractString}, tags=nothing) saved = copy(entityMap) empty!(entityMap) diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index 9a43bc5f..9628a1a2 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -1,4 +1,9 @@ -# Strip everything but the major and minor release from a version number. +""" + format_version(v::Union{VersionNumber, AbstractString}) -> String + +Strip everything but the major and minor release from a `VersionNumber`. +Strings are left in their original form. +""" format_version(v::VersionNumber) = "$(v.major).$(v.minor)" format_version(v::AbstractString) = string(v) @@ -6,11 +11,10 @@ const ALLOWED_FAILURES = ["1.3", "nightly"] # TODO: Update this list with new R const DEFAULT_CI_VERSIONS = map(format_version, [default_version(), VERSION, "nightly"]) const EXTRA_VERSIONS_DOC = "- `extra_versions::Vector`: Extra Julia versions to test, as strings or `VersionNumber`s." - """ collect_versions(t::Template, versions::Vector) -> Vector{String} -Combine the [`Template`](@ref)'s Julia version and some other versions, and format them as `major.minor`. +Combine `t`'s Julia version with `versions`, and format them as `major.minor`. This is useful for creating lists of versions to be included in CI configurations. """ function collect_versions(t::Template, versions::Vector) @@ -27,7 +31,7 @@ end x86=false, coverage=true, extra_versions=$DEFAULT_CI_VERSIONS, - ) -> TravisCI + ) Integrates your packages with [Travis CI](https://travis-ci.com). @@ -99,7 +103,7 @@ end x86=false, coverage=true, extra_versions=$DEFAULT_CI_VERSIONS, - ) -> AppVeyor + ) Integrates your packages with [AppVeyor](https://appveyor.com) via [AppVeyor.jl](https://github.com/JuliaCI/Appveyor.jl). @@ -149,7 +153,7 @@ end image="freebsd-12-0-release-amd64", coverage=true, extra_versions=$DEFAULT_CI_VERSIONS, - ) -> CirrusCI + ) Integrates your packages with [Cirrus CI](https://cirrus-ci.org) via [CirrusCI.jl](https://github.com/ararslan/CirrusCI.jl). @@ -195,7 +199,7 @@ end file="$(contractuser(default_file("gitlab-ci.yml")))", coverage=true, extra_versions=$DEFAULT_CI_VERSIONS, - ) -> GitLabCI + ) Integrates your packages with [GitLab CI](https://docs.gitlab.com/ce/ci/). diff --git a/src/plugins/citation.jl b/src/plugins/citation.jl index a52469cd..1f45196c 100644 --- a/src/plugins/citation.jl +++ b/src/plugins/citation.jl @@ -2,7 +2,7 @@ Citation(; file="$(contractuser(default_file("CITATION.bib")))", readme=false, - ) -> Citation + ) Creates a `CITATION.bib` file for citing package repositories. diff --git a/src/plugins/coverage.jl b/src/plugins/coverage.jl index 8d030ef2..04002947 100644 --- a/src/plugins/coverage.jl +++ b/src/plugins/coverage.jl @@ -1,7 +1,7 @@ const COVERAGE_GITIGNORE = ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] """ - Codecov(; file=nothing) -> Codecov + Codecov(; file=nothing) Sets up code coverage submission from CI to [Codecov](https://codecov.io). @@ -22,7 +22,7 @@ badges(::Codecov) = Badge( ) """ - Coveralls(; file=nothing) -> Coverallls + Coveralls(; file=nothing) Sets up code coverage submission from CI to [Coveralls](https://coveralls.io). diff --git a/src/plugins/defaults.jl b/src/plugins/defaults.jl index 53ea0863..fdc14191 100644 --- a/src/plugins/defaults.jl +++ b/src/plugins/defaults.jl @@ -14,12 +14,23 @@ const LICENSES = Dict( "EUPL-1.2+" => "European Union Public Licence, Version 1.2+", ) +badge_order() = [ + Documenter{GitLabCI}, + Documenter{TravisCI}, + GitLabCI, + TravisCI, + AppVeyor, + CirrusCI, + Codecov, + Coveralls, +] + """ Readme(; file="$(contractuser(default_file("README.md")))", destination="README.md", inline_badges=false, - ) -> Readme, + ) Creates a `README` file. By default, it includes badges for other included plugins @@ -57,14 +68,14 @@ function view(p::Readme, t::Template, pkg::AbstractString) return Dict( "BADGES" => strings, - "HAS_CITATION" => hasplugin(t, Citation), - "HAS_INLINE_BADGES" => !isempty(strings) && p.inline_badges, + "HAS_CITATION" => hasplugin(t, Citation) && t.plugins[Citation].readme, + "HAS_INLINE_BADGES" => !isempty(strings) && p.inline_badges, "PKG" => pkg, ) end """ - License(; name="MIT", destination="LICENSE") -> License + License(; name="MIT", destination="LICENSE") Creates a license file. @@ -90,9 +101,6 @@ function license_path(license::AbstractString) return path end -# Read a license's text. -read_license(license::AbstractString) = string(readchomp(license_path(license))) - function render_plugin(p::License, t::Template) date = year(today()) authors = join(t.authors, ", ") @@ -106,7 +114,7 @@ function gen_plugin(p::License, t::Template, pkg_dir::AbstractString) end """ - Gitignore(; ds_store=true, dev=true) -> Gitignore + Gitignore(; ds_store=true, dev=true) Creates a `.gitignore` file. diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index cf002a9e..dc61dd01 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -7,7 +7,7 @@ const DOCUMENTER_UUID = "e30172f5-a6a5-5a46-863b-614d45cd2de4" assets=String[], canonical_url=, makedocs_kwargs=Dict{Symbol, Any}(), - ) -> Documenter{T} + ) Sets up documentation generation via [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl). Documentation deployment depends on `T`, where `T` is some supported CI plugin, or `Nothing` to only support local documentation builds. diff --git a/src/template.jl b/src/template.jl index 37ccdb3a..8ef31542 100644 --- a/src/template.jl +++ b/src/template.jl @@ -10,7 +10,7 @@ function default_authors() end """ - Template(; kwargs...) -> Template + Template(; kwargs...) A configuration used to generate packages. @@ -25,13 +25,13 @@ A configuration used to generate packages. Like `user`, it takes its default value from the global Git config (`user.name` and `user.email`). ### Package Options -- `host::AbstractString="github.com"`: URL to the code hosting service where packages will reside. - `dir::AbstractString="$(contractuser(Pkg.devdir()))"`: Directory to place packages in. - `julia_version::VersionNumber=$(repr(default_version()))`: Minimum allowed Julia version. - `develop::Bool=true`: Whether or not to `develop` new packages in the active environment. ### Git Options - `git::Bool=true`: Whether or not to create a Git repository for new packages. +- `host::AbstractString="github.com"`: URL to the code hosting service where packages will reside. - `ssh::Bool=false`: Whether or not to use SSH for the Git remote. If left unset, HTTPS will be used. - `manifest::Bool=false`: Whether or not to commit the `Manifest.toml`. @@ -44,6 +44,16 @@ A configuration used to generate packages. ### Interactive Usage - `interactive::Bool=false`: When set, the template is created interactively, filling unset keywords with user input. + +--- + +To create a package from a `Template`, use the following syntax: + +```julia +julia> t = Template(); + +julia> t("PkgName") +``` """ struct Template authors::Vector{String} diff --git a/test/plugin.jl b/test/plugin.jl index 05639f1e..c76efa07 100644 --- a/test/plugin.jl +++ b/test/plugin.jl @@ -21,6 +21,7 @@ PT.user_view(::BasicTest, ::Template, ::AbstractString) = Dict("X" => 1, "Z" => with_pkg(t) do pkg pkg_dir = joinpath(t.dir, pkg) badge = string(PT.Badge("1", "2", "3")) + @test occursin("a\naa\naaa", read(joinpath(pkg_dir, ".gitignore"), String)) @test occursin(badge, read(joinpath(pkg_dir, "README.md"), String)) @test read(joinpath(pkg_dir, "foo.txt"), String) == s end From f6272e110f195beafeb564941a820298ae0d0935 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Wed, 18 Sep 2019 21:25:48 +0700 Subject: [PATCH 27/81] Add option to create test/Project.toml (#95) --- src/PkgTemplates.jl | 11 +++++++++ src/generate.jl | 7 ++++++ src/plugins/defaults.jl | 33 ++++++++++++++++++-------- src/plugins/documenter.jl | 13 ++++------ src/template.jl | 10 +++++++- test/fixtures/AllPlugins/README.md.txt | 4 ---- test/show.jl | 1 + 7 files changed, 56 insertions(+), 23 deletions(-) diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index d6769d0e..d8a0312d 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -40,4 +40,15 @@ include("generate.jl") include("plugin.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 diff --git a/src/generate.jl b/src/generate.jl index 7a1716d5..0c240e81 100644 --- a/src/generate.jl +++ b/src/generate.jl @@ -57,6 +57,13 @@ function (t::Template)(pkg::AbstractString) Pkg.develop(PackageSpec(; path=pkg_dir)) 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" catch rm(pkg_dir; recursive=true, force=true) diff --git a/src/plugins/defaults.jl b/src/plugins/defaults.jl index fdc14191..e69ecf9c 100644 --- a/src/plugins/defaults.jl +++ b/src/plugins/defaults.jl @@ -1,4 +1,5 @@ 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 LICENSES = Dict( "MIT" => "MIT \"Expat\" License", @@ -143,15 +144,21 @@ function gen_plugin(p::Gitignore, t::Template, pkg_dir::AbstractString) end """ - Tests(; file="$(contractuser(default_file("runtests.jl")))" -> Tests + Tests(; file="$(contractuser(default_file("runtests.jl")))", project=false) Sets up testing for packages. ## Keyword Arguments - `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 file::String = default_file("runtests.jl") + project::Bool = false end 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. 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") toml = TOML.parsefile(path) get!(toml, "extras", Dict())["Test"] = TEST_UUID get!(toml, "targets", Dict())["test"] = ["Test"] 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. touch(joinpath(pkg_dir, "Manifest.toml")) # File must exist to be modified by Pkg. - proj = current_project() - try - Pkg.activate(pkg_dir) - Pkg.update() - finally - proj === nothing ? Pkg.activate() : Pkg.activate(proj) - end + with_project(Pkg.update, pkg_dir) end diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index dc61dd01..3ff2ac18 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -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}}(; @@ -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) # Create the documentation project. - proj = current_project() - try - Pkg.activate(docs_dir) - Pkg.add(PackageSpec(; name="Documenter", uuid=DOCUMENTER_UUID)) - finally - proj === nothing ? Pkg.activate() : Pkg.activate(proj) - end + with_project(() -> Pkg.add(DOCUMENTER_DEP), docs_dir) end github_pages_url(t::Template, pkg::AbstractString) = "https://$(t.user).github.io/$pkg.jl" diff --git a/src/template.jl b/src/template.jl index 8ef31542..da175bf2 100644 --- a/src/template.jl +++ b/src/template.jl @@ -89,13 +89,21 @@ function Template(::Val{false}; kwargs...) # which means that default plugins get replaced by user values. 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( authors, getkw(kwargs, :develop), dir, getkw(kwargs, :git), host, - getkw(kwargs, :julia_version), + julia, getkw(kwargs, :manifest), plugins, getkw(kwargs, :ssh), diff --git a/test/fixtures/AllPlugins/README.md.txt b/test/fixtures/AllPlugins/README.md.txt index 35d94a0f..44735f9f 100644 --- a/test/fixtures/AllPlugins/README.md.txt +++ b/test/fixtures/AllPlugins/README.md.txt @@ -7,7 +7,3 @@ [![Build Status](https://api.cirrus-ci.com/github/tester/.jl.svg)](https://cirrus-ci.com/github/tester/AllPlugins.jl) [![Coverage](https://codecov.io/gh//.jl/branch/master/graph/badge.svg)](https://codecov.io/gh//.jl) [![Coverage](https://coveralls.io/repos/github//.jl/badge.svg?branch=master)](https://coveralls.io/github//.jl?branch=master) - -## Citing - -See [`CITATION.bib`](CITATION.bib) for the relevant reference(s). diff --git a/test/show.jl b/test/show.jl index b51aba8f..b48fe7ff 100644 --- a/test/show.jl +++ b/test/show.jl @@ -37,6 +37,7 @@ const LICENSE_DIR = contractuser(PT.LICENSE_DIR) inline_badges: false Tests: file: "$DEFAULTS_DIR/runtests.jl" + project: false """ @test sprint(show, MIME("text/plain"), tpl(; authors=USER)) == rstrip(expected) end From 358c213b876b4073234ac8aa6a0a5276dfa4d71b Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Wed, 18 Sep 2019 22:27:16 +0700 Subject: [PATCH 28/81] Escape HTML the right way --- defaults/CITATION.bib | 12 ++++++------ defaults/README.md | 4 ++-- defaults/appveyor.yml | 6 +++--- defaults/cirrus.yml | 4 ++-- defaults/gitlab-ci.yml | 10 +++++----- defaults/index.md | 4 ++-- defaults/make.jl | 18 +++++++++--------- defaults/runtests.jl | 4 ++-- defaults/travis.yml | 12 ++++++------ docs/src/user.md | 21 +++++++++++++-------- src/PkgTemplates.jl | 2 +- src/plugin.jl | 14 ++------------ src/plugins/ci.jl | 20 ++++++++++---------- src/plugins/coverage.jl | 8 ++++---- src/plugins/documenter.jl | 6 +++--- test/fixtures/AllPlugins/README.md.txt | 2 +- 16 files changed, 71 insertions(+), 76 deletions(-) diff --git a/defaults/CITATION.bib b/defaults/CITATION.bib index b49e5ea9..6579e314 100644 --- a/defaults/CITATION.bib +++ b/defaults/CITATION.bib @@ -1,8 +1,8 @@ -@misc{<>.jl, - author = {<>}, - title = {<>.jl}, - url = {<>}, +@misc{<<&PKG>>.jl, + author = {<<&AUTHORS>>}, + title = {<<&PKG>>.jl}, + url = {<<&URL>>}, version = {v0.1.0}, - year = {<>}, - month = {<>} + year = {<<&YEAR>>}, + month = {<<&MONTH>>} } diff --git a/defaults/README.md b/defaults/README.md index 230e5a50..980a7bb2 100644 --- a/defaults/README.md +++ b/defaults/README.md @@ -1,8 +1,8 @@ -# {{PKG}}{{#HAS_INLINE_BADGES}} {{#BADGES}}{{.}} {{/BADGES}}{{/HAS_INLINE_BADGES}} +# {{{PKG}}}{{#HAS_INLINE_BADGES}} {{#BADGES}}{{{.}}} {{/BADGES}}{{/HAS_INLINE_BADGES}} {{^HAS_INLINE_BADGES}} {{#BADGES}} -{{.}} +{{{.}}} {{/BADGES}} {{/HAS_INLINE_BADGES}} {{#HAS_CITATION}} diff --git a/defaults/appveyor.yml b/defaults/appveyor.yml index 2d4682bb..4535a46e 100644 --- a/defaults/appveyor.yml +++ b/defaults/appveyor.yml @@ -2,17 +2,17 @@ environment: matrix: {{#VERSIONS}} - - julia_version: {{.}} + - julia_version: {{{.}}} {{/VERSIONS}} platform: {{#PLATFORMS}} - - {{.}} + - {{{.}}} {{/PLATFORMS}} {{#HAS_ALLOW_FAILURES}} matrix: allow_failures: {{#ALLOW_FAILURES}} - - julia_version: {{.}} + - julia_version: {{{.}}} {{/ALLOW_FAILURES}} {{/HAS_ALLOW_FAILURES}} branches: diff --git a/defaults/cirrus.yml b/defaults/cirrus.yml index 1e182e2e..8c296cc9 100644 --- a/defaults/cirrus.yml +++ b/defaults/cirrus.yml @@ -1,10 +1,10 @@ freebsd_instance: - image: {{IMAGE}} + image: {{{IMAGE}}} task: name: FreeBSD env: {{#VERSIONS}} - JULIA_VERSION: {{.}} + JULIA_VERSION: {{{.}}} {{/VERSIONS}} install_script: - sh -c "$(fetch https://raw.githubusercontent.com/ararslan/CirrusCI.jl/master/bin/install.sh -o -)" diff --git a/defaults/gitlab-ci.yml b/defaults/gitlab-ci.yml index d9f965d5..774b2180 100644 --- a/defaults/gitlab-ci.yml +++ b/defaults/gitlab-ci.yml @@ -18,16 +18,16 @@ @printf "Test coverage %.2f%%\n" 100c / t;' {{/HAS_COVERAGE}} {{#VERSIONS}} -Julia {{.}}: - image: julia:{{.}} +Julia {{{.}}}: + image: julia:{{{.}}} <<: *script - {{#HAS_COVERAGE}} +{{#HAS_COVERAGE}} <<: *coverage - {{/HAS_COVERAGE}} +{{/HAS_COVERAGE}} {{/VERSIONS}} {{#HAS_DOCUMENTER}} pages: - image: julia:{{VERSION}} + image: julia:{{{VERSION}}} stage: deploy script: - julia --project=docs -e ' diff --git a/defaults/index.md b/defaults/index.md index e5e882f3..949e9c9c 100644 --- a/defaults/index.md +++ b/defaults/index.md @@ -1,8 +1,8 @@ -# {{PKG}} +# {{{PKG}}} ```@index ``` ```@autodocs -Modules = [{{PKG}}] +Modules = [{{{PKG}}}] ``` diff --git a/defaults/make.jl b/defaults/make.jl index 26dd48f8..366e5a8f 100644 --- a/defaults/make.jl +++ b/defaults/make.jl @@ -1,18 +1,18 @@ -using {{PKG}} +using {{{PKG}}} using Documenter makedocs(; - modules=[{{PKG}}], - authors="{{AUTHORS}}", - repo="https://{{REPO}}/blob/{commit}{path}#L{line}", - sitename="{{PKG}}.jl", + modules=[{{{PKG}}}], + authors="{{{AUTHORS}}}", + repo="https://{{{REPO}}}/blob/{commit}{path}#L{line}", + sitename="{{{PKG}}}.jl", format=Documenter.HTML(; {{#CANONICAL}} - canonical="{{CANONICAL}}", + canonical="{{{CANONICAL}}}", {{/CANONICAL}} assets={{^HAS_ASSETS}}String{{/HAS_ASSETS}}[{{^HAS_ASSETS}}],{{/HAS_ASSETS}} {{#ASSETS}} - "{{.}}", + "{{{.}}}", {{/ASSETS}} {{#HAS_ASSETS}} ], @@ -22,12 +22,12 @@ makedocs(; "Home" => "index.md", ], {{#MAKEDOCS_KWARGS}} - {{first}}={{second}}, + {{{first}}}={{{second}}}, {{/MAKEDOCS_KWARGS}} ) {{#HAS_DEPLOY}} deploydocs(; - repo="{{REPO}}", + repo="{{{REPO}}}", ) {{/HAS_DEPLOY}} diff --git a/defaults/runtests.jl b/defaults/runtests.jl index 072ffb37..7cc1ecbe 100644 --- a/defaults/runtests.jl +++ b/defaults/runtests.jl @@ -1,6 +1,6 @@ -using {{PKG}} +using {{{PKG}}} using Test -@testset "{{PKG}}.jl" begin +@testset "{{{PKG}}}.jl" begin # Write your tests here. end diff --git a/defaults/travis.yml b/defaults/travis.yml index 1100682d..accf0d2a 100644 --- a/defaults/travis.yml +++ b/defaults/travis.yml @@ -4,11 +4,11 @@ notifications: email: false julia: {{#VERSIONS}} - - {{.}} + - {{{.}}} {{/VERSIONS}} os: {{#OS}} - - {{.}} + - {{{.}}} {{/OS}} jobs: fast_finish: true @@ -16,19 +16,19 @@ jobs: allow_failures: {{/HAS_ALLOW_FAILURES}} {{#ALLOW_FAILURES}} - - julia: {{.}} + - julia: {{{.}}} {{/ALLOW_FAILURES}} {{#HAS_JOBS}} include: {{/HAS_JOBS}} {{#X86}} - - julia: {{JULIA}} - os: {{OS}} + - julia: {{{JULIA}}} + os: {{{OS}}} arch: x86 {{/X86}} {{#HAS_DOCUMENTER}} - stage: Documentation - julia: {{VERSION}} + julia: {{{VERSION}}} script: julia --project=docs -e ' using Pkg; Pkg.develop(PackageSpec(; path=pwd())); diff --git a/docs/src/user.md b/docs/src/user.md index c811086e..4c86cd06 100644 --- a/docs/src/user.md +++ b/docs/src/user.md @@ -75,10 +75,10 @@ If that's the case, a basic understanding of [Mustache](https://mustache.github. Here's an example template file: ``` -Hello, {{name}}. +Hello, {{{name}}}. {{#weather}} -It's {{weather}} outside. +It's {{{weather}}} outside. {{/weather}} {{^weather}} I don't know what the weather outside is. @@ -88,15 +88,15 @@ I don't know what the weather outside is. I have the following things: {{/has_things}} {{#things}} -- Here's a thing: {{.}} +- Here's a thing: {{{.}}} {{/things}} {{#people}} -- {{name}} is {{mood}} +- {{{name}}} is {{{mood}}} {{/people}} ``` -In the first section, `name` is a key, and its value replaces `{{name}}`. +In the first section, `name` is a key, and its value replaces `{{{name}}}`. In the second section, `weather`'s value may or may not exist. If it does exist, then "It's $weather outside" is printed. @@ -105,11 +105,16 @@ Mustache uses a notion of "truthiness" similar to Python or JavaScript, where va In the third section, `has_things`' value is printed if it's truthy. Then, if the `things` list is truthy (i.e. not empty), its values are each printed on their own line. -The reason that we have two separate keys is that `{{#things}}` iterates over the whole `things` list, even when there are no `{{.}}` placeholders, which would duplicate "I have the following things:" `n` times. +The reason that we have two separate keys is that `{{#things}}` iterates over the whole `things` list, even when there are no `{{{.}}}` placeholders, which would duplicate "I have the following things:" `n` times. -The fourth section iterates over the `people` list, but instead of using the `{{.}}` placeholder, we have `name` and `mood`, which are keys or fields of the list elements. +The fourth section iterates over the `people` list, but instead of using the `{{{.}}}` placeholder, we have `name` and `mood`, which are keys or fields of the list elements. Most types are supported here, including `Dict`s and structs. -`NamedTuple`s require you to use `{{:name}}` instead of the normal `{{name}}`, though. +`NamedTuple`s require you to use `{{{:name}}}` instead of the normal `{{{name}}}`, though. + +You might notice that some curlies are in groups of two (`{{key}}`), and some are in groups of three (`{{{key}}}`). +Whenever we want to subtitute in a value, using the triple curlies disables HTML escaping, which we rarely want for the types of files we're creating. +If you do want escaping, just use the double curlies. +And if you're using different delimiters, for example `<>`, use `<<&foo>>` to disable escaping. Assuming the following view: diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index d8a0312d..15173c88 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -9,7 +9,7 @@ using LibGit2: LibGit2, GitRemote using Pkg: Pkg, TOML, PackageSpec using REPL.TerminalMenus: MultiSelectMenu, RadioMenu, request -using Mustache: entityMap, render +using Mustache: render using Parameters: @with_kw_noshow export diff --git a/src/plugin.jl b/src/plugin.jl index 7d48e503..e76f4f04 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -167,7 +167,7 @@ Render a template file with the data in `view`. `tags` should be a tuple of two strings, which are the opening and closing delimiters, or `nothing` to use the default delimiters. """ function render_file(file::AbstractString, view::Dict{<:AbstractString}, tags) - render_text(read(file, String), view, tags) + return render_text(read(file, String), view, tags) end """ @@ -177,17 +177,7 @@ Render some text with the data in `view`. `tags` should be a tuple of two strings, which are the opening and closing delimiters, or `nothing` to use the default delimiters. """ function render_text(text::AbstractString, view::Dict{<:AbstractString}, tags=nothing) - saved = copy(entityMap) - empty!(entityMap) - return try - if tags === nothing - render(text, view) - else - render(text, view; tags=tags) - end - finally - append!(entityMap, saved) - end + return tags === nothing ? render(text, view) : render(text, view; tags=tags) end include(joinpath("plugins", "defaults.jl")) diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index 9628a1a2..be82caea 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -59,8 +59,8 @@ destination(::TravisCI) = ".travis.yml" badges(::TravisCI) = Badge( "Build Status", - "https://travis-ci.com/{{USER}}/{{PKG}}.jl.svg?branch=master", - "https://travis-ci.com/{{USER}}/{{PKG}}.jl", + "https://travis-ci.com/{{{USER}}}/{{{PKG}}}.jl.svg?branch=master", + "https://travis-ci.com/{{{USER}}}/{{{PKG}}}.jl", ) function view(p::TravisCI, t::Template, pkg::AbstractString) @@ -125,8 +125,8 @@ destination(::AppVeyor) = ".appveyor.yml" badges(::AppVeyor) = Badge( "Build Status", - "https://ci.appveyor.com/api/projects/status/github/{{USER}}/{{PKG}}.jl?svg=true", - "https://ci.appveyor.com/project/{{USER}}/{{PKG}}-jl", + "https://ci.appveyor.com/api/projects/status/github/{{{USER}}}/{{{PKG}}}.jl?svg=true", + "https://ci.appveyor.com/project/{{{USER}}}/{{{PKG}}}-jl", ) function view(p::AppVeyor, t::Template, pkg::AbstractString) @@ -178,8 +178,8 @@ destination(::CirrusCI) = ".cirrus.yml" badges(::CirrusCI) = Badge( "Build Status", - "https://api.cirrus-ci.com/github/{{USER}}/{{PACKAGE}}.jl.svg", - "https://cirrus-ci.com/github/{{USER}}/{{PKG}}.jl", + "https://api.cirrus-ci.com/github/{{{USER}}}/{{{PKG}}}.jl.svg", + "https://cirrus-ci.com/github/{{{USER}}}/{{{PKG}}}.jl", ) function view(p::CirrusCI, t::Template, pkg::AbstractString) @@ -230,13 +230,13 @@ destination(::GitLabCI) = ".gitlab-ci.yml" function badges(p::GitLabCI) ci = Badge( "Build Status", - "https://gitlab.com/{{USER}}/{{PKG}}.jl/badges/master/build.svg", - "https://gitlab.com/{{USER}}/{{PKG}}.jl/pipelines", + "https://gitlab.com/{{{USER}}}/{{{PKG}}}.jl/badges/master/build.svg", + "https://gitlab.com/{{{USER}}}/{{{PKG}}}.jl/pipelines", ) cov = Badge( "Coverage", - "https://gitlab.com/{{USER}}/{{PKG}}.jl/badges/master/coverage.svg", - "https://gitlab.com/{{USER}}/{{PKG}}.jl/commits/master", + "https://gitlab.com/{{{USER}}}/{{{PKG}}}.jl/badges/master/coverage.svg", + "https://gitlab.com/{{{USER}}}/{{{PKG}}}.jl/commits/master", ) return p.coverage ? [ci, cov] : [ci] end diff --git a/src/plugins/coverage.jl b/src/plugins/coverage.jl index 04002947..359c312d 100644 --- a/src/plugins/coverage.jl +++ b/src/plugins/coverage.jl @@ -17,8 +17,8 @@ destination(::Codecov) = ".codecov.yml" badges(::Codecov) = Badge( "Coverage", - "https://codecov.io/gh/{{USER}}/{{PKG}}.jl/branch/master/graph/badge.svg", - "https://codecov.io/gh/{{USER}}/{{PKG}}.jl", + "https://codecov.io/gh/{{{USER}}}/{{{PKG}}}.jl/branch/master/graph/badge.svg", + "https://codecov.io/gh/{{{USER}}}/{{{PKG}}}.jl", ) """ @@ -38,8 +38,8 @@ destination(::Coveralls) = ".coveralls.yml" badges(::Coveralls) = Badge( "Coverage", - "https://coveralls.io/repos/github/{{USER}}/{{PKG}}.jl/badge.svg?branch=master", - "https://coveralls.io/github/{{USER}}/{{PKG}}.jl?branch=master", + "https://coveralls.io/repos/github/{{{USER}}}/{{{PKG}}}.jl/badge.svg?branch=master", + "https://coveralls.io/github/{{{USER}}}/{{{PKG}}}.jl?branch=master", ) gitignore(::Union{Codecov, Coveralls}) = COVERAGE_GITIGNORE diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index 3ff2ac18..dc66a5b5 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -55,18 +55,18 @@ badges(::Documenter{TravisCI}) = [ Badge( "Stable", "https://img.shields.io/badge/docs-stable-blue.svg", - "https://{{USER}}.github.io/{{PKG}}.jl/stable", + "https://{{{USER}}}.github.io/{{{PKG}}}.jl/stable", ), Badge( "Dev", "https://img.shields.io/badge/docs-dev-blue.svg", - "https://{{USER}}.github.io/{{PKG}}.jl/dev", + "https://{{{USER}}}.github.io/{{{PKG}}}.jl/dev", ), ] badges(::Documenter{GitLabCI}) = Badge( "Dev", "https://img.shields.io/badge/docs-dev-blue.svg", - "https://{{USER}}.gitlab.io/{{PKG}}.jl/dev", + "https://{{{USER}}}.gitlab.io/{{{PKG}}}.jl/dev", ) view(p::Documenter, t::Template, pkg::AbstractString) = Dict( diff --git a/test/fixtures/AllPlugins/README.md.txt b/test/fixtures/AllPlugins/README.md.txt index 44735f9f..adbba2f3 100644 --- a/test/fixtures/AllPlugins/README.md.txt +++ b/test/fixtures/AllPlugins/README.md.txt @@ -4,6 +4,6 @@ [![Coverage](https://gitlab.com/tester/AllPlugins.jl/badges/master/coverage.svg)](https://gitlab.com/tester/AllPlugins.jl/commits/master) [![Build Status](https://travis-ci.com/tester/AllPlugins.jl.svg?branch=master)](https://travis-ci.com/tester/AllPlugins.jl) [![Build Status](https://ci.appveyor.com/api/projects/status/github/tester/AllPlugins.jl?svg=true)](https://ci.appveyor.com/project/tester/AllPlugins-jl) -[![Build Status](https://api.cirrus-ci.com/github/tester/.jl.svg)](https://cirrus-ci.com/github/tester/AllPlugins.jl) +[![Build Status](https://api.cirrus-ci.com/github/tester/AllPlugins.jl.svg)](https://cirrus-ci.com/github/tester/AllPlugins.jl) [![Coverage](https://codecov.io/gh//.jl/branch/master/graph/badge.svg)](https://codecov.io/gh//.jl) [![Coverage](https://coveralls.io/repos/github//.jl/badge.svg?branch=master)](https://coveralls.io/github//.jl?branch=master) From 4e1247c504bc88d54c62f00151eef0f5137cc220 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Thu, 19 Sep 2019 07:58:48 +0700 Subject: [PATCH 29/81] Fix a Windows test, maybe --- src/interactive.jl | 6 +++++- src/template.jl | 2 +- test/show.jl | 8 ++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/interactive.jl b/src/interactive.jl index a7d513f9..9b343567 100644 --- a/src/interactive.jl +++ b/src/interactive.jl @@ -13,7 +13,11 @@ function Base.show(io::IO, ::MIME"text/plain", p::T) where T <: Plugin end show_field(x) = repr(x) -show_field(x::AbstractString) = repr(contractuser(x)) +if Sys.iswindows() + show_field(x::AbstractString) = replace(repr(contractuser(x)), "\\\\" => "\\") +else + show_field(x::AbstractString) = repr(contractuser(x)) +end function Base.show(io::IO, m::MIME"text/plain", t::Template) println(io, "Template:") diff --git a/src/template.jl b/src/template.jl index da175bf2..7350a991 100644 --- a/src/template.jl +++ b/src/template.jl @@ -90,7 +90,7 @@ function Template(::Val{false}; kwargs...) 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. + # to be optionally implemented 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)", diff --git a/test/show.jl b/test/show.jl index b48fe7ff..b97c3afe 100644 --- a/test/show.jl +++ b/test/show.jl @@ -5,7 +5,7 @@ const LICENSE_DIR = contractuser(PT.LICENSE_DIR) @testset "Plugins" begin expected = """ Readme: - file: "$DEFAULTS_DIR/README.md" + file: "$(joinpath(DEFAULTS_DIR, "README.md"))" destination: "README.md" inline_badges: false """ @@ -29,14 +29,14 @@ const LICENSE_DIR = contractuser(PT.LICENSE_DIR) ds_store: true dev: true License: - path: "$LICENSE_DIR/MIT" + path: "$(joinpath(LICENSE_DIR, "MIT"))" destination: "LICENSE" Readme: - file: "$DEFAULTS_DIR/README.md" + file: "$(joinpath(DEFAULTS_DIR, "README.md"))" destination: "README.md" inline_badges: false Tests: - file: "$DEFAULTS_DIR/runtests.jl" + file: "$(joinpath(DEFAULTS_DIR, "runtests.jl"))" project: false """ @test sprint(show, MIME("text/plain"), tpl(; authors=USER)) == rstrip(expected) From 3b9714c8a8f3f15a41dc9ddf7f52fc9f59aad34b Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Thu, 19 Sep 2019 12:51:04 +0700 Subject: [PATCH 30/81] Move around the template files, update the licenses Hopefully the licenses are detected better by Licensee. Also they can be templated now which is nice. --- licenses/BSD3 | 12 - licenses/EUPL-1.2+ | 191 ------ licenses/LGPL-3.0+ | 182 ------ licenses/MPL | 363 ----------- src/plugin.jl | 2 +- src/plugins/defaults.jl | 50 +- src/plugins/documenter.jl | 10 +- {defaults => templates}/CITATION.bib | 0 {defaults => templates}/README.md | 0 {defaults => templates}/appveyor.yml | 0 {defaults => templates}/cirrus.yml | 0 {defaults => templates/docs}/index.md | 0 {defaults => templates/docs}/make.jl | 0 {defaults => templates}/gitlab-ci.yml | 0 {licenses => templates/licenses}/ASL | 3 +- {licenses => templates/licenses}/BSD2 | 12 +- templates/licenses/BSD3 | 29 + templates/licenses/EUPL-1.2+ | 274 +++++++++ {licenses => templates/licenses}/GPL-2.0+ | 75 ++- {licenses => templates/licenses}/GPL-3.0+ | 67 +- {licenses => templates/licenses}/ISC | 3 + {licenses => templates/licenses}/LGPL-2.1+ | 62 +- templates/licenses/LGPL-3.0+ | 674 +++++++++++++++++++++ {licenses => templates/licenses}/MIT | 3 + templates/licenses/MPL | 373 ++++++++++++ {defaults => templates/test}/runtests.jl | 0 {defaults => templates}/travis.yml | 0 test/fixtures/AllPlugins/LICENSE.txt | 2 + test/fixtures/Basic/LICENSE.txt | 2 + test/show.jl | 4 +- 30 files changed, 1559 insertions(+), 834 deletions(-) delete mode 100644 licenses/BSD3 delete mode 100644 licenses/EUPL-1.2+ delete mode 100644 licenses/LGPL-3.0+ delete mode 100644 licenses/MPL rename {defaults => templates}/CITATION.bib (100%) rename {defaults => templates}/README.md (100%) rename {defaults => templates}/appveyor.yml (100%) rename {defaults => templates}/cirrus.yml (100%) rename {defaults => templates/docs}/index.md (100%) rename {defaults => templates/docs}/make.jl (100%) rename {defaults => templates}/gitlab-ci.yml (100%) rename {licenses => templates/licenses}/ASL (99%) rename {licenses => templates/licenses}/BSD2 (69%) create mode 100644 templates/licenses/BSD3 create mode 100644 templates/licenses/EUPL-1.2+ rename {licenses => templates/licenses}/GPL-2.0+ (84%) rename {licenses => templates/licenses}/GPL-3.0+ (92%) rename {licenses => templates/licenses}/ISC (92%) rename {licenses => templates/licenses}/LGPL-2.1+ (92%) create mode 100644 templates/licenses/LGPL-3.0+ rename {licenses => templates/licenses}/MIT (95%) create mode 100644 templates/licenses/MPL rename {defaults => templates/test}/runtests.jl (100%) rename {defaults => templates}/travis.yml (100%) diff --git a/licenses/BSD3 b/licenses/BSD3 deleted file mode 100644 index bd84765d..00000000 --- a/licenses/BSD3 +++ /dev/null @@ -1,12 +0,0 @@ - -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/licenses/EUPL-1.2+ b/licenses/EUPL-1.2+ deleted file mode 100644 index 6603aeb5..00000000 --- a/licenses/EUPL-1.2+ +++ /dev/null @@ -1,191 +0,0 @@ - -EUROPEAN UNION PUBLIC LICENCE v. 1.2 -EUPL © the European Union 2007, 2016 - -This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined below) which is provided under the -terms of this Licence. Any use of the Work, other than as authorised under this Licence is prohibited (to the extent such -use is covered by a right of the copyright holder of the Work). -The Work is provided under the terms of this Licence when the Licensor (as defined below) has placed the following -notice immediately following the copyright notice for the Work: - Licensed under the EUPL -or has expressed by any other means his willingness to license under the EUPL. - -1.Definitions -In this Licence, the following terms have the following meaning: -— ‘The Licence’:this Licence. -— ‘The Original Work’:the work or software distributed or communicated by the Licensor under this Licence, available -as Source Code and also as Executable Code as the case may be. -— ‘Derivative Works’:the works or software that could be created by the Licensee, based upon the Original Work or -modifications thereof. This Licence does not define the extent of modification or dependence on the Original Work -required in order to classify a work as a Derivative Work; this extent is determined by copyright law applicable in -the country mentioned in Article 15. -— ‘The Work’:the Original Work or its Derivative Works. -— ‘The Source Code’:the human-readable form of the Work which is the most convenient for people to study and -modify. -— ‘The Executable Code’:any code which has generally been compiled and which is meant to be interpreted by -a computer as a program. -— ‘The Licensor’:the natural or legal person that distributes or communicates the Work under the Licence. -— ‘Contributor(s)’:any natural or legal person who modifies the Work under the Licence, or otherwise contributes to -the creation of a Derivative Work. -— ‘The Licensee’ or ‘You’:any natural or legal person who makes any usage of the Work under the terms of the -Licence. -— ‘Distribution’ or ‘Communication’:any act of selling, giving, lending, renting, distributing, communicating, -transmitting, or otherwise making available, online or offline, copies of the Work or providing access to its essential -functionalities at the disposal of any other natural or legal person. - -2.Scope of the rights granted by the Licence -The Licensor hereby grants You a worldwide, royalty-free, non-exclusive, sublicensable licence to do the following, for -the duration of copyright vested in the Original Work: -— use the Work in any circumstance and for all usage, -— reproduce the Work, -— modify the Work, and make Derivative Works based upon the Work, -— communicate to the public, including the right to make available or display the Work or copies thereof to the public -and perform publicly, as the case may be, the Work, -— distribute the Work or copies thereof, -— lend and rent the Work or copies thereof, -— sublicense rights in the Work or copies thereof. -Those rights can be exercised on any media, supports and formats, whether now known or later invented, as far as the -applicable law permits so. -In the countries where moral rights apply, the Licensor waives his right to exercise his moral right to the extent allowed -by law in order to make effective the licence of the economic rights here above listed. -The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to any patents held by the Licensor, to the -extent necessary to make use of the rights granted on the Work under this Licence. - -3.Communication of the Source Code -The Licensor may provide the Work either in its Source Code form, or as Executable Code. If the Work is provided as -Executable Code, the Licensor provides in addition a machine-readable copy of the Source Code of the Work along with -each copy of the Work that the Licensor distributes or indicates, in a notice following the copyright notice attached to -the Work, a repository where the Source Code is easily and freely accessible for as long as the Licensor continues to -distribute or communicate the Work. - -4.Limitations on copyright -Nothing in this Licence is intended to deprive the Licensee of the benefits from any exception or limitation to the -exclusive rights of the rights owners in the Work, of the exhaustion of those rights or of other applicable limitations -thereto. - -5.Obligations of the Licensee -The grant of the rights mentioned above is subject to some restrictions and obligations imposed on the Licensee. Those -obligations are the following: - -Attribution right: The Licensee shall keep intact all copyright, patent or trademarks notices and all notices that refer to -the Licence and to the disclaimer of warranties. The Licensee must include a copy of such notices and a copy of the -Licence with every copy of the Work he/she distributes or communicates. The Licensee must cause any Derivative Work -to carry prominent notices stating that the Work has been modified and the date of modification. - -Copyleft clause: If the Licensee distributes or communicates copies of the Original Works or Derivative Works, this -Distribution or Communication will be done under the terms of this Licence or of a later version of this Licence unless -the Original Work is expressly distributed only under this version of the Licence — for example by communicating -‘EUPL v. 1.2 only’. The Licensee (becoming Licensor) cannot offer or impose any additional terms or conditions on the -Work or Derivative Work that alter or restrict the terms of the Licence. - -Compatibility clause: If the Licensee Distributes or Communicates Derivative Works or copies thereof based upon both -the Work and another work licensed under a Compatible Licence, this Distribution or Communication can be done -under the terms of this Compatible Licence. For the sake of this clause, ‘Compatible Licence’ refers to the licences listed -in the appendix attached to this Licence. Should the Licensee's obligations under the Compatible Licence conflict with -his/her obligations under this Licence, the obligations of the Compatible Licence shall prevail. - -Provision of Source Code: When distributing or communicating copies of the Work, the Licensee will provide -a machine-readable copy of the Source Code or indicate a repository where this Source will be easily and freely available -for as long as the Licensee continues to distribute or communicate the Work. -Legal Protection: This Licence does not grant permission to use the trade names, trademarks, service marks, or names -of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and -reproducing the content of the copyright notice. - -6.Chain of Authorship -The original Licensor warrants that the copyright in the Original Work granted hereunder is owned by him/her or -licensed to him/her and that he/she has the power and authority to grant the Licence. -Each Contributor warrants that the copyright in the modifications he/she brings to the Work are owned by him/her or -licensed to him/her and that he/she has the power and authority to grant the Licence. -Each time You accept the Licence, the original Licensor and subsequent Contributors grant You a licence to their contributions -to the Work, under the terms of this Licence. - -7.Disclaimer of Warranty -The Work is a work in progress, which is continuously improved by numerous Contributors. It is not a finished work -and may therefore contain defects or ‘bugs’ inherent to this type of development. -For the above reason, the Work is provided under the Licence on an ‘as is’ basis and without warranties of any kind -concerning the Work, including without limitation merchantability, fitness for a particular purpose, absence of defects or -errors, accuracy, non-infringement of intellectual property rights other than copyright as stated in Article 6 of this -Licence. -This disclaimer of warranty is an essential part of the Licence and a condition for the grant of any rights to the Work. - -8.Disclaimer of Liability -Except in the cases of wilful misconduct or damages directly caused to natural persons, the Licensor will in no event be -liable for any direct or indirect, material or moral, damages of any kind, arising out of the Licence or of the use of the -Work, including without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, loss -of data or any commercial damage, even if the Licensor has been advised of the possibility of such damage. However, -the Licensor will be liable under statutory product liability laws as far such laws apply to the Work. - -9.Additional agreements -While distributing the Work, You may choose to conclude an additional agreement, defining obligations or services -consistent with this Licence. However, if accepting obligations, You may act only on your own behalf and on your sole -responsibility, not on behalf of the original Licensor or any other Contributor, and only if You agree to indemnify, -defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against such Contributor by -the fact You have accepted any warranty or additional liability. - -10.Acceptance of the Licence -The provisions of this Licence can be accepted by clicking on an icon ‘I agree’ placed under the bottom of a window -displaying the text of this Licence or by affirming consent in any other similar way, in accordance with the rules of -applicable law. Clicking on that icon indicates your clear and irrevocable acceptance of this Licence and all of its terms -and conditions. -Similarly, you irrevocably accept this Licence and all of its terms and conditions by exercising any rights granted to You -by Article 2 of this Licence, such as the use of the Work, the creation by You of a Derivative Work or the Distribution -or Communication by You of the Work or copies thereof. - -11.Information to the public -In case of any Distribution or Communication of the Work by means of electronic communication by You (for example, -by offering to download the Work from a remote location) the distribution channel or media (for example, a website) -must at least provide to the public the information requested by the applicable law regarding the Licensor, the Licence -and the way it may be accessible, concluded, stored and reproduced by the Licensee. - -12.Termination of the Licence -The Licence and the rights granted hereunder will terminate automatically upon any breach by the Licensee of the terms -of the Licence. -Such a termination will not terminate the licences of any person who has received the Work from the Licensee under -the Licence, provided such persons remain in full compliance with the Licence. - -13.Miscellaneous -Without prejudice of Article 9 above, the Licence represents the complete agreement between the Parties as to the -Work. -If any provision of the Licence is invalid or unenforceable under applicable law, this will not affect the validity or -enforceability of the Licence as a whole. Such provision will be construed or reformed so as necessary to make it valid -and enforceable. -The European Commission may publish other linguistic versions or new versions of this Licence or updated versions of -the Appendix, so far this is required and reasonable, without reducing the scope of the rights granted by the Licence. -New versions of the Licence will be published with a unique version number. -All linguistic versions of this Licence, approved by the European Commission, have identical value. Parties can take -advantage of the linguistic version of their choice. - -14.Jurisdiction -Without prejudice to specific agreement between parties, -— any litigation resulting from the interpretation of this License, arising between the European Union institutions, -bodies, offices or agencies, as a Licensor, and any Licensee, will be subject to the jurisdiction of the Court of Justice -of the European Union, as laid down in article 272 of the Treaty on the Functioning of the European Union, -— any litigation arising between other parties and resulting from the interpretation of this License, will be subject to -the exclusive jurisdiction of the competent court where the Licensor resides or conducts its primary business. - -15.Applicable Law -Without prejudice to specific agreement between parties, -— this Licence shall be governed by the law of the European Union Member State where the Licensor has his seat, -resides or has his registered office, -— this licence shall be governed by Belgian law if the Licensor has no seat, residence or registered office inside -a European Union Member State. - - - Appendix - -‘Compatible Licences’ according to Article 5 EUPL are: -— GNU General Public License (GPL) v. 2, v. 3 -— GNU Affero General Public License (AGPL) v. 3 -— Open Software License (OSL) v. 2.1, v. 3.0 -— Eclipse Public License (EPL) v. 1.0 -— CeCILL v. 2.0, v. 2.1 -— Mozilla Public Licence (MPL) v. 2 -— GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3 -— Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for works other than software -— European Union Public Licence (EUPL) v. 1.1, v. 1.2 -— Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong Reciprocity (LiLiQ-R+). - -The European Commission may update this Appendix to later versions of the above licences without producing -a new version of the EUPL, as long as they provide the rights granted in Article 2 of this Licence and protect the -covered Source Code from exclusive appropriation. -All other changes or additions to this Appendix require the production of a new EUPL version. diff --git a/licenses/LGPL-3.0+ b/licenses/LGPL-3.0+ deleted file mode 100644 index 52a81ac9..00000000 --- a/licenses/LGPL-3.0+ +++ /dev/null @@ -1,182 +0,0 @@ - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 3 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. - - END OF TERMS AND CONDITIONS diff --git a/licenses/MPL b/licenses/MPL deleted file mode 100644 index 7be29a13..00000000 --- a/licenses/MPL +++ /dev/null @@ -1,363 +0,0 @@ - -Mozilla Public License, version 2.0 - -1. Definitions - -1.1. "Contributor" - - means each individual or legal entity that creates, contributes to the - creation of, or owns Covered Software. - -1.2. "Contributor Version" - - means the combination of the Contributions of others (if any) used by a - Contributor and that particular Contributor's Contribution. - -1.3. "Contribution" - - means Covered Software of a particular Contributor. - -1.4. "Covered Software" - - means Source Code Form to which the initial Contributor has attached the - notice in Exhibit A, the Executable Form of such Source Code Form, and - Modifications of such Source Code Form, in each case including portions - thereof. - -1.5. "Incompatible With Secondary Licenses" - means - - a. that the initial Contributor has attached the notice described in - Exhibit B to the Covered Software; or - - b. that the Covered Software was made available under the terms of - version 1.1 or earlier of the License, but not also under the terms of - a Secondary License. - -1.6. "Executable Form" - - means any form of the work other than Source Code Form. - -1.7. "Larger Work" - - means a work that combines Covered Software with other material, in a - separate file or files, that is not Covered Software. - -1.8. "License" - - means this document. - -1.9. "Licensable" - - means having the right to grant, to the maximum extent possible, whether - at the time of the initial grant or subsequently, any and all of the - rights conveyed by this License. - -1.10. "Modifications" - - means any of the following: - - a. any file in Source Code Form that results from an addition to, - deletion from, or modification of the contents of Covered Software; or - - b. any new file in Source Code Form that contains any Covered Software. - -1.11. "Patent Claims" of a Contributor - - means any patent claim(s), including without limitation, method, - process, and apparatus claims, in any patent Licensable by such - Contributor that would be infringed, but for the grant of the License, - by the making, using, selling, offering for sale, having made, import, - or transfer of either its Contributions or its Contributor Version. - -1.12. "Secondary License" - - means either the GNU General Public License, Version 2.0, the GNU Lesser - General Public License, Version 2.1, the GNU Affero General Public - License, Version 3.0, or any later versions of those licenses. - -1.13. "Source Code Form" - - means the form of the work preferred for making modifications. - -1.14. "You" (or "Your") - - means an individual or a legal entity exercising rights under this - License. For legal entities, "You" includes any entity that controls, is - controlled by, or is under common control with You. For purposes of this - definition, "control" means (a) the power, direct or indirect, to cause - the direction or management of such entity, whether by contract or - otherwise, or (b) ownership of more than fifty percent (50%) of the - outstanding shares or beneficial ownership of such entity. - - -2. License Grants and Conditions - -2.1. Grants - - Each Contributor hereby grants You a world-wide, royalty-free, - non-exclusive license: - - a. under intellectual property rights (other than patent or trademark) - Licensable by such Contributor to use, reproduce, make available, - modify, display, perform, distribute, and otherwise exploit its - Contributions, either on an unmodified basis, with Modifications, or - as part of a Larger Work; and - - b. under Patent Claims of such Contributor to make, use, sell, offer for - sale, have made, import, and otherwise transfer either its - Contributions or its Contributor Version. - -2.2. Effective Date - - The licenses granted in Section 2.1 with respect to any Contribution - become effective for each Contribution on the date the Contributor first - distributes such Contribution. - -2.3. Limitations on Grant Scope - - The licenses granted in this Section 2 are the only rights granted under - this License. No additional rights or licenses will be implied from the - distribution or licensing of Covered Software under this License. - Notwithstanding Section 2.1(b) above, no patent license is granted by a - Contributor: - - a. for any code that a Contributor has removed from Covered Software; or - - b. for infringements caused by: (i) Your and any other third party's - modifications of Covered Software, or (ii) the combination of its - Contributions with other software (except as part of its Contributor - Version); or - - c. under Patent Claims infringed by Covered Software in the absence of - its Contributions. - - This License does not grant any rights in the trademarks, service marks, - or logos of any Contributor (except as may be necessary to comply with - the notice requirements in Section 3.4). - -2.4. Subsequent Licenses - - No Contributor makes additional grants as a result of Your choice to - distribute the Covered Software under a subsequent version of this - License (see Section 10.2) or under the terms of a Secondary License (if - permitted under the terms of Section 3.3). - -2.5. Representation - - Each Contributor represents that the Contributor believes its - Contributions are its original creation(s) or it has sufficient rights to - grant the rights to its Contributions conveyed by this License. - -2.6. Fair Use - - This License is not intended to limit any rights You have under - applicable copyright doctrines of fair use, fair dealing, or other - equivalents. - -2.7. Conditions - - Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in - Section 2.1. - - -3. Responsibilities - -3.1. Distribution of Source Form - - All distribution of Covered Software in Source Code Form, including any - Modifications that You create or to which You contribute, must be under - the terms of this License. You must inform recipients that the Source - Code Form of the Covered Software is governed by the terms of this - License, and how they can obtain a copy of this License. You may not - attempt to alter or restrict the recipients' rights in the Source Code - Form. - -3.2. Distribution of Executable Form - - If You distribute Covered Software in Executable Form then: - - a. such Covered Software must also be made available in Source Code Form, - as described in Section 3.1, and You must inform recipients of the - Executable Form how they can obtain a copy of such Source Code Form by - reasonable means in a timely manner, at a charge no more than the cost - of distribution to the recipient; and - - b. You may distribute such Executable Form under the terms of this - License, or sublicense it under different terms, provided that the - license for the Executable Form does not attempt to limit or alter the - recipients' rights in the Source Code Form under this License. - -3.3. Distribution of a Larger Work - - You may create and distribute a Larger Work under terms of Your choice, - provided that You also comply with the requirements of this License for - the Covered Software. If the Larger Work is a combination of Covered - Software with a work governed by one or more Secondary Licenses, and the - Covered Software is not Incompatible With Secondary Licenses, this - License permits You to additionally distribute such Covered Software - under the terms of such Secondary License(s), so that the recipient of - the Larger Work may, at their option, further distribute the Covered - Software under the terms of either this License or such Secondary - License(s). - -3.4. Notices - - You may not remove or alter the substance of any license notices - (including copyright notices, patent notices, disclaimers of warranty, or - limitations of liability) contained within the Source Code Form of the - Covered Software, except that You may alter any license notices to the - extent required to remedy known factual inaccuracies. - -3.5. Application of Additional Terms - - You may choose to offer, and to charge a fee for, warranty, support, - indemnity or liability obligations to one or more recipients of Covered - Software. However, You may do so only on Your own behalf, and not on - behalf of any Contributor. You must make it absolutely clear that any - such warranty, support, indemnity, or liability obligation is offered by - You alone, and You hereby agree to indemnify every Contributor for any - liability incurred by such Contributor as a result of warranty, support, - indemnity or liability terms You offer. You may include additional - disclaimers of warranty and limitations of liability specific to any - jurisdiction. - -4. Inability to Comply Due to Statute or Regulation - - If it is impossible for You to comply with any of the terms of this License - with respect to some or all of the Covered Software due to statute, - judicial order, or regulation then You must: (a) comply with the terms of - this License to the maximum extent possible; and (b) describe the - limitations and the code they affect. Such description must be placed in a - text file included with all distributions of the Covered Software under - this License. Except to the extent prohibited by statute or regulation, - such description must be sufficiently detailed for a recipient of ordinary - skill to be able to understand it. - -5. Termination - -5.1. The rights granted under this License will terminate automatically if You - fail to comply with any of its terms. However, if You become compliant, - then the rights granted under this License from a particular Contributor - are reinstated (a) provisionally, unless and until such Contributor - explicitly and finally terminates Your grants, and (b) on an ongoing - basis, if such Contributor fails to notify You of the non-compliance by - some reasonable means prior to 60 days after You have come back into - compliance. Moreover, Your grants from a particular Contributor are - reinstated on an ongoing basis if such Contributor notifies You of the - non-compliance by some reasonable means, this is the first time You have - received notice of non-compliance with this License from such - Contributor, and You become compliant prior to 30 days after Your receipt - of the notice. - -5.2. If You initiate litigation against any entity by asserting a patent - infringement claim (excluding declaratory judgment actions, - counter-claims, and cross-claims) alleging that a Contributor Version - directly or indirectly infringes any patent, then the rights granted to - You by any and all Contributors for the Covered Software under Section - 2.1 of this License shall terminate. - -5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user - license agreements (excluding distributors and resellers) which have been - validly granted by You or Your distributors under this License prior to - termination shall survive termination. - -6. Disclaimer of Warranty - - Covered Software is provided under this License on an "as is" basis, - without warranty of any kind, either expressed, implied, or statutory, - including, without limitation, warranties that the Covered Software is free - of defects, merchantable, fit for a particular purpose or non-infringing. - The entire risk as to the quality and performance of the Covered Software - is with You. Should any Covered Software prove defective in any respect, - You (not any Contributor) assume the cost of any necessary servicing, - repair, or correction. This disclaimer of warranty constitutes an essential - part of this License. No use of any Covered Software is authorized under - this License except under this disclaimer. - -7. Limitation of Liability - - Under no circumstances and under no legal theory, whether tort (including - negligence), contract, or otherwise, shall any Contributor, or anyone who - distributes Covered Software as permitted above, be liable to You for any - direct, indirect, special, incidental, or consequential damages of any - character including, without limitation, damages for lost profits, loss of - goodwill, work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses, even if such party shall have been - informed of the possibility of such damages. This limitation of liability - shall not apply to liability for death or personal injury resulting from - such party's negligence to the extent applicable law prohibits such - limitation. Some jurisdictions do not allow the exclusion or limitation of - incidental or consequential damages, so this exclusion and limitation may - not apply to You. - -8. Litigation - - Any litigation relating to this License may be brought only in the courts - of a jurisdiction where the defendant maintains its principal place of - business and such litigation shall be governed by laws of that - jurisdiction, without reference to its conflict-of-law provisions. Nothing - in this Section shall prevent a party's ability to bring cross-claims or - counter-claims. - -9. Miscellaneous - - This License represents the complete agreement concerning the subject - matter hereof. If any provision of this License is held to be - unenforceable, such provision shall be reformed only to the extent - necessary to make it enforceable. Any law or regulation which provides that - the language of a contract shall be construed against the drafter shall not - be used to construe this License against a Contributor. - - -10. Versions of the License - -10.1. New Versions - - Mozilla Foundation is the license steward. Except as provided in Section - 10.3, no one other than the license steward has the right to modify or - publish new versions of this License. Each version will be given a - distinguishing version number. - -10.2. Effect of New Versions - - You may distribute the Covered Software under the terms of the version - of the License under which You originally received the Covered Software, - or under the terms of any subsequent version published by the license - steward. - -10.3. Modified Versions - - If you create software not governed by this License, and you want to - create a new license for such software, you may create and use a - modified version of this License if you rename the license and remove - any references to the name of the license steward (except to note that - such modified license differs from this License). - -10.4. Distributing Source Code Form that is Incompatible With Secondary - Licenses If You choose to distribute Source Code Form that is - Incompatible With Secondary Licenses under the terms of this version of - the License, the notice described in Exhibit B of this License must be - attached. - -Exhibit A - Source Code Form License Notice - - This Source Code Form is subject to the - terms of the Mozilla Public License, v. - 2.0. If a copy of the MPL was not - distributed with this file, You can - obtain one at - http://mozilla.org/MPL/2.0/. - -If it is not possible or desirable to put the notice in a particular file, -then You may include the notice in a location (such as a LICENSE file in a -relevant directory) where a recipient would be likely to look for such a -notice. - -You may add additional accurate notices of copyright ownership. - -Exhibit B - "Incompatible With Secondary Licenses" Notice - - This Source Code Form is "Incompatible - With Secondary Licenses", as defined by - the Mozilla Public License, v. 2.0. diff --git a/src/plugin.jl b/src/plugin.jl index e76f4f04..d45e6cb4 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -1,4 +1,4 @@ -const DEFAULTS_DIR = normpath(joinpath(@__DIR__, "..", "defaults")) +const DEFAULTS_DIR = normpath(joinpath(@__DIR__, "..", "templates")) """ A simple plugin that, in general, creates a single file. diff --git a/src/plugins/defaults.jl b/src/plugins/defaults.jl index e69ecf9c..e0bf7509 100644 --- a/src/plugins/defaults.jl +++ b/src/plugins/defaults.jl @@ -1,6 +1,5 @@ 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 LICENSES = Dict( "MIT" => "MIT \"Expat\" License", "BSD2" => "Simplified \"2-clause\" BSD License", @@ -76,43 +75,42 @@ function view(p::Readme, t::Template, pkg::AbstractString) end """ - License(; name="MIT", destination="LICENSE") + License(; name="MIT", path=nothing, destination="LICENSE") Creates a license file. ## Keyword Arguments -- `name::AbstractString`: Name of the desired license. - Available licenses can be seen [here](https://github.com/invenia/PkgTemplates.jl/tree/master/licenses). +- `name::AbstractString`: Name of a license supported by PkgTemplates. + Available licenses can be seen [here](https://github.com/invenia/PkgTemplates.jl/tree/master/templates/licenses). +- `path::Union{AbstractString, Nothing}`: Path to a custom license file. + This keyword takes priority over `name`. - `destination::AbstractString`: File destination, relative to the repository root. For example, `"LICENSE.md"` might be desired. """ -struct License <: Plugin +struct License <: BasicPlugin path::String destination::String +end - function License(name::AbstractString="MIT", destination::AbstractString="LICENSE") - return new(license_path(name), destination) +function License( + name::AbstractString="MIT", + path::Union{AbstractString, Nothing}=nothing, + destination::AbstractString="LICENSE", +) + if path === nothing + path = default_file("licenses", name) + isfile(path) || throw(ArgumentError("License '$(basename(path))' is not available")) end + return License(path, destination) end -# Look up a license and throw an error if it doesn't exist. -function license_path(license::AbstractString) - path = joinpath(LICENSE_DIR, license) - isfile(path) || throw(ArgumentError("License '$license' is not available")) - return path -end -function render_plugin(p::License, t::Template) - date = year(today()) - authors = join(t.authors, ", ") - text = "Copyright (c) $date $authors\n\n" - license = strip(read(p.path, String)) - return text * license -end - -function gen_plugin(p::License, t::Template, pkg_dir::AbstractString) - gen_file(joinpath(pkg_dir, p.destination), render_plugin(p, t)) -end +source(p::License) = p.path +destination(p::License) = p.destination +view(::License, t::Template, ::AbstractString) = Dict( + "AUTHORS" => join(t.authors, ", "), + "YEAR" => year(today()), +) """ Gitignore(; ds_store=true, dev=true) @@ -144,7 +142,7 @@ function gen_plugin(p::Gitignore, t::Template, pkg_dir::AbstractString) end """ - Tests(; file="$(contractuser(default_file("runtests.jl")))", project=false) + Tests(; file="$(contractuser(default_file("test", "runtests.jl")))", project=false) Sets up testing for packages. @@ -157,7 +155,7 @@ Sets up testing for packages. Managing test dependencies with `test/Project.toml` is only supported in Julia 1.2 and later. """ @with_kw_noshow struct Tests <: BasicPlugin - file::String = default_file("runtests.jl") + file::String = default_file("test", "runtests.jl") project::Bool = false end diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index dc66a5b5..aa87ab5e 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -5,10 +5,10 @@ const DOCUMENTER_DEP = PackageSpec(; """ Documenter{T<:Union{TravisCI, GitLabCI, Nothing}}(; - make_jl="$(contractuser(default_file("make.jl")))", - index_md="$(contractuser(default_file("index.md")))", + make_jl="$(contractuser(default_file("docs", "make.jl")))", + index_md="$(contractuser(default_file("docs", "index.md")))", assets=String[], - canonical_url=, + canonical_url=make_canonical(T), makedocs_kwargs=Dict{Symbol, Any}(), ) @@ -39,8 +39,8 @@ struct Documenter{T<:Union{TravisCI, GitLabCI, Nothing}} <: Plugin assets::Vector{<:AbstractString}=String[], makedocs_kwargs::Dict{Symbol}=Dict{Symbol, Any}(), canonical_url::Union{Function, Nothing}=make_canonical(T), - make_jl::AbstractString=default_file("make.jl"), - index_md::AbstractString=default_file("index.md"), + make_jl::AbstractString=default_file("docs", "make.jl"), + index_md::AbstractString=default_file("docs", "index.md"), ) where T <: Union{TravisCI, GitLabCI, Nothing} return new(assets, makedocs_kwargs, canonical_url, make_jl, index_md) end diff --git a/defaults/CITATION.bib b/templates/CITATION.bib similarity index 100% rename from defaults/CITATION.bib rename to templates/CITATION.bib diff --git a/defaults/README.md b/templates/README.md similarity index 100% rename from defaults/README.md rename to templates/README.md diff --git a/defaults/appveyor.yml b/templates/appveyor.yml similarity index 100% rename from defaults/appveyor.yml rename to templates/appveyor.yml diff --git a/defaults/cirrus.yml b/templates/cirrus.yml similarity index 100% rename from defaults/cirrus.yml rename to templates/cirrus.yml diff --git a/defaults/index.md b/templates/docs/index.md similarity index 100% rename from defaults/index.md rename to templates/docs/index.md diff --git a/defaults/make.jl b/templates/docs/make.jl similarity index 100% rename from defaults/make.jl rename to templates/docs/make.jl diff --git a/defaults/gitlab-ci.yml b/templates/gitlab-ci.yml similarity index 100% rename from defaults/gitlab-ci.yml rename to templates/gitlab-ci.yml diff --git a/licenses/ASL b/templates/licenses/ASL similarity index 99% rename from licenses/ASL rename to templates/licenses/ASL index e5aa8110..6f756351 100644 --- a/licenses/ASL +++ b/templates/licenses/ASL @@ -1,4 +1,3 @@ - Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -187,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [year] [fullname] + Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/licenses/BSD2 b/templates/licenses/BSD2 similarity index 69% rename from licenses/BSD2 rename to templates/licenses/BSD2 index f2692064..319c6007 100644 --- a/licenses/BSD2 +++ b/templates/licenses/BSD2 @@ -1,15 +1,17 @@ +BSD 2-Clause License +Copyright (c) {{{YEAR}}}, {{{AUTHORS}}} All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE diff --git a/templates/licenses/BSD3 b/templates/licenses/BSD3 new file mode 100644 index 00000000..7461e50b --- /dev/null +++ b/templates/licenses/BSD3 @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) {{{YEAR}}}, {{{AUTHORS}}} +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/templates/licenses/EUPL-1.2+ b/templates/licenses/EUPL-1.2+ new file mode 100644 index 00000000..a74f0443 --- /dev/null +++ b/templates/licenses/EUPL-1.2+ @@ -0,0 +1,274 @@ +European Union Public Licence +V. 1.2 + +EUPL © the European Union 2007, 2016 + +This European Union Public Licence (the ‘EUPL’) applies to the Work (as +defined below) which is provided under the terms of this Licence. Any use of +the Work, other than as authorised under this Licence is prohibited (to the +extent such use is covered by a right of the copyright holder of the Work). + +The Work is provided under the terms of this Licence when the Licensor (as +defined below) has placed the following notice immediately following the +copyright notice for the Work: “Licensed under the EUPL”, or has expressed by +any other means his willingness to license under the EUPL. + +1. Definitions + +In this Licence, the following terms have the following meaning: +— ‘The Licence’: this Licence. +— ‘The Original Work’: the work or software distributed or communicated by the + ‘Licensor under this Licence, available as Source Code and also as + ‘Executable Code as the case may be. +— ‘Derivative Works’: the works or software that could be created by the + ‘Licensee, based upon the Original Work or modifications thereof. This + ‘Licence does not define the extent of modification or dependence on the + ‘Original Work required in order to classify a work as a Derivative Work; + ‘this extent is determined by copyright law applicable in the country + ‘mentioned in Article 15. +— ‘The Work’: the Original Work or its Derivative Works. +— ‘The Source Code’: the human-readable form of the Work which is the most + convenient for people to study and modify. + +— ‘The Executable Code’: any code which has generally been compiled and which + is meant to be interpreted by a computer as a program. +— ‘The Licensor’: the natural or legal person that distributes or communicates + the Work under the Licence. +— ‘Contributor(s)’: any natural or legal person who modifies the Work under + the Licence, or otherwise contributes to the creation of a Derivative Work. +— ‘The Licensee’ or ‘You’: any natural or legal person who makes any usage of + the Work under the terms of the Licence. +— ‘Distribution’ or ‘Communication’: any act of selling, giving, lending, + renting, distributing, communicating, transmitting, or otherwise making + available, online or offline, copies of the Work or providing access to its + essential functionalities at the disposal of any other natural or legal + person. + +2. Scope of the rights granted by the Licence + +The Licensor hereby grants You a worldwide, royalty-free, non-exclusive, +sublicensable licence to do the following, for the duration of copyright +vested in the Original Work: + +— use the Work in any circumstance and for all usage, +— reproduce the Work, +— modify the Work, and make Derivative Works based upon the Work, +— communicate to the public, including the right to make available or display + the Work or copies thereof to the public and perform publicly, as the case + may be, the Work, +— distribute the Work or copies thereof, +— lend and rent the Work or copies thereof, +— sublicense rights in the Work or copies thereof. + +Those rights can be exercised on any media, supports and formats, whether now +known or later invented, as far as the applicable law permits so. + +In the countries where moral rights apply, the Licensor waives his right to +exercise his moral right to the extent allowed by law in order to make +effective the licence of the economic rights here above listed. + +The Licensor grants to the Licensee royalty-free, non-exclusive usage rights +to any patents held by the Licensor, to the extent necessary to make use of +the rights granted on the Work under this Licence. + +3. Communication of the Source Code + +The Licensor may provide the Work either in its Source Code form, or as +Executable Code. If the Work is provided as Executable Code, the Licensor +provides in addition a machine-readable copy of the Source Code of the Work +along with each copy of the Work that the Licensor distributes or indicates, +in a notice following the copyright notice attached to the Work, a repository +where the Source Code is easily and freely accessible for as long as the +Licensor continues to distribute or communicate the Work. + +4. Limitations on copyright + +Nothing in this Licence is intended to deprive the Licensee of the benefits +from any exception or limitation to the exclusive rights of the rights owners +in the Work, of the exhaustion of those rights or of other applicable +limitations thereto. + +5. Obligations of the Licensee + +The grant of the rights mentioned above is subject to some restrictions and +obligations imposed on the Licensee. Those obligations are the following: + +Attribution right: The Licensee shall keep intact all copyright, patent or +trademarks notices and all notices that refer to the Licence and to the +disclaimer of warranties. The Licensee must include a copy of such notices and +a copy of the Licence with every copy of the Work he/she distributes or +communicates. The Licensee must cause any Derivative Work to carry prominent +notices stating that the Work has been modified and the date of modification. + +Copyleft clause: If the Licensee distributes or communicates copies of the +Original Works or Derivative Works, this Distribution or Communication will be +done under the terms of this Licence or of a later version of this Licence +unless the Original Work is expressly distributed only under this version of +the Licence — for example by communicating ‘EUPL v. 1.2 only’. The Licensee +(becoming Licensor) cannot offer or impose any additional terms or conditions +on the Work or Derivative Work that alter or restrict the terms of the +Licence. + +Compatibility clause: If the Licensee Distributes or Communicates Derivative +Works or copies thereof based upon both the Work and another work licensed +under a Compatible Licence, this Distribution or Communication can be done +under the terms of this Compatible Licence. For the sake of this clause, +‘Compatible Licence’ refers to the licences listed in the appendix attached to +this Licence. Should the Licensee's obligations under the Compatible Licence +conflict with his/her obligations under this Licence, the obligations of the +Compatible Licence shall prevail. + +Provision of Source Code: When distributing or communicating copies of the +Work, the Licensee will provide a machine-readable copy of the Source Code or +indicate a repository where this Source will be easily and freely available +for as long as the Licensee continues to distribute or communicate the Work. + +Legal Protection: This Licence does not grant permission to use the trade +names, trademarks, service marks, or names of the Licensor, except as required +for reasonable and customary use in describing the origin of the Work and +reproducing the content of the copyright notice. + +6. Chain of Authorship + +The original Licensor warrants that the copyright in the Original Work granted +hereunder is owned by him/her or licensed to him/her and that he/she has the +power and authority to grant the Licence. + +Each Contributor warrants that the copyright in the modifications he/she +brings to the Work are owned by him/her or licensed to him/her and that he/she +has the power and authority to grant the Licence. + +Each time You accept the Licence, the original Licensor and subsequent +Contributors grant You a licence to their contributions to the Work, under the +terms of this Licence. + +7. Disclaimer of Warranty + +The Work is a work in progress, which is continuously improved by numerous +Contributors. It is not a finished work and may therefore contain defects or +‘bugs’ inherent to this type of development. + +For the above reason, the Work is provided under the Licence on an ‘as is’ +basis and without warranties of any kind concerning the Work, including +without limitation merchantability, fitness for a particular purpose, absence +of defects or errors, accuracy, non-infringement of intellectual property +rights other than copyright as stated in Article 6 of this Licence. + +This disclaimer of warranty is an essential part of the Licence and a +condition for the grant of any rights to the Work. + +8. Disclaimer of Liability + +Except in the cases of wilful misconduct or damages directly caused to natural +persons, the Licensor will in no event be liable for any direct or indirect, +material or moral, damages of any kind, arising out of the Licence or of the +use of the Work, including without limitation, damages for loss of goodwill, +work stoppage, computer failure or malfunction, loss of data or any commercial +damage, even if the Licensor has been advised of the possibility of such +damage. However, the Licensor will be liable under statutory product liability +laws as far such laws apply to the Work. + +9. Additional agreements + +While distributing the Work, You may choose to conclude an additional +agreement, defining obligations or services consistent with this Licence. +However, if accepting obligations, You may act only on your own behalf and on +your sole responsibility, not on behalf of the original Licensor or any other +Contributor, and only if You agree to indemnify, defend, and hold each +Contributor harmless for any liability incurred by, or claims asserted against +such Contributor by the fact You have accepted any warranty or additional +liability. + +10. Acceptance of the Licence + +The provisions of this Licence can be accepted by clicking on an icon ‘I +agree’ placed under the bottom of a window displaying the text of this Licence +or by affirming consent in any other similar way, in accordance with the rules +of applicable law. Clicking on that icon indicates your clear and irrevocable +acceptance of this Licence and all of its terms and conditions. + +Similarly, you irrevocably accept this Licence and all of its terms and +conditions by exercising any rights granted to You by Article 2 of this +Licence, such as the use of the Work, the creation by You of a Derivative Work +or the Distribution or Communication by You of the Work or copies thereof. + +11. Information to the public + +In case of any Distribution or Communication of the Work by means of +electronic communication by You (for example, by offering to download the Work +from a remote location) the distribution channel or media (for example, a +website) must at least provide to the public the information requested by the +applicable law regarding the Licensor, the Licence and the way it may be +accessible, concluded, stored and reproduced by the Licensee. + +12. Termination of the Licence + +The Licence and the rights granted hereunder will terminate automatically upon +any breach by the Licensee of the terms of the Licence. Such a termination +will not terminate the licences of any person who has received the Work from +the Licensee under the Licence, provided such persons remain in full +compliance with the Licence. + +13. Miscellaneous + +Without prejudice of Article 9 above, the Licence represents the complete +agreement between the Parties as to the Work. + +If any provision of the Licence is invalid or unenforceable under applicable +law, this will not affect the validity or enforceability of the Licence as a +whole. Such provision will be construed or reformed so as necessary to make it +valid and enforceable. + +The European Commission may publish other linguistic versions or new versions +of this Licence or updated versions of the Appendix, so far this is required +and reasonable, without reducing the scope of the rights granted by the +Licence. New versions of the Licence will be published with a unique version +number. + +All linguistic versions of this Licence, approved by the European Commission, +have identical value. Parties can take advantage of the linguistic version of +their choice. + +14. Jurisdiction + +Without prejudice to specific agreement between parties, +— any litigation resulting from the interpretation of this License, arising + between the European Union institutions, bodies, offices or agencies, as a + Licensor, and any Licensee, will be subject to the jurisdiction of the Court + of Justice of the European Union, as laid down in article 272 of the Treaty + on the Functioning of the European Union, +— any litigation arising between other parties and resulting from the + interpretation of this License, will be subject to the exclusive + jurisdiction of the competent court where the Licensor resides or conducts + its primary business. + +15. Applicable Law + +Without prejudice to specific agreement between parties, +— this Licence shall be governed by the law of the European Union Member State + where the Licensor has his seat, resides or has his registered office, +— this licence shall be governed by Belgian law if the Licensor has no seat, + residence or registered office inside a European Union Member State. + +Appendix + +‘Compatible Licences’ according to Article 5 EUPL are: +— GNU General Public License (GPL) v. 2, v. 3 +— GNU Affero General Public License (AGPL) v. 3 +— Open Software License (OSL) v. 2.1, v. 3.0 +— Eclipse Public License (EPL) v. 1.0 +— CeCILL v. 2.0, v. 2.1 +— Mozilla Public Licence (MPL) v. 2 +— GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3 +— Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for + works other than software +— European Union Public Licence (EUPL) v. 1.1, v. 1.2 +— Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or + Strong Reciprocity (LiLiQ-R+) + +— The European Commission may update this Appendix to later versions of the + above licences without producing a new version of the EUPL, as long as they + provide the rights granted in Article 2 of this Licence and protect the + covered Source Code from exclusive appropriation. +— All other changes or additions to this Appendix require the production of a + new EUPL version. diff --git a/licenses/GPL-2.0+ b/templates/licenses/GPL-2.0+ similarity index 84% rename from licenses/GPL-2.0+ rename to templates/licenses/GPL-2.0+ index 1d90c9be..d159169d 100644 --- a/licenses/GPL-2.0+ +++ b/templates/licenses/GPL-2.0+ @@ -1,19 +1,3 @@ - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - GNU GENERAL PUBLIC LICENSE Version 2, June 1991 @@ -294,3 +278,62 @@ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/licenses/GPL-3.0+ b/templates/licenses/GPL-3.0+ similarity index 92% rename from licenses/GPL-3.0+ rename to templates/licenses/GPL-3.0+ index c22be353..f288702d 100644 --- a/licenses/GPL-3.0+ +++ b/templates/licenses/GPL-3.0+ @@ -1,19 +1,7 @@ - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - - GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @@ -631,3 +619,56 @@ Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/licenses/ISC b/templates/licenses/ISC similarity index 92% rename from licenses/ISC rename to templates/licenses/ISC index 07e276db..eeb89fc3 100644 --- a/licenses/ISC +++ b/templates/licenses/ISC @@ -1,3 +1,6 @@ +ISC License + +Copyright (c) {{{YEAR}}}, {{{AUTHORS}}} Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/licenses/LGPL-2.1+ b/templates/licenses/LGPL-2.1+ similarity index 92% rename from licenses/LGPL-2.1+ rename to templates/licenses/LGPL-2.1+ index d391bace..8000a6fa 100644 --- a/licenses/LGPL-2.1+ +++ b/templates/licenses/LGPL-2.1+ @@ -1,19 +1,3 @@ - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 @@ -472,3 +456,49 @@ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/templates/licenses/LGPL-3.0+ b/templates/licenses/LGPL-3.0+ new file mode 100644 index 00000000..f288702d --- /dev/null +++ b/templates/licenses/LGPL-3.0+ @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/licenses/MIT b/templates/licenses/MIT similarity index 95% rename from licenses/MIT rename to templates/licenses/MIT index 6bf41db9..775ba1de 100644 --- a/licenses/MIT +++ b/templates/licenses/MIT @@ -1,3 +1,6 @@ +MIT License + +Copyright (c) {{{YEAR}}} {{{AUTHORS}}} Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/templates/licenses/MPL b/templates/licenses/MPL new file mode 100644 index 00000000..a612ad98 --- /dev/null +++ b/templates/licenses/MPL @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/defaults/runtests.jl b/templates/test/runtests.jl similarity index 100% rename from defaults/runtests.jl rename to templates/test/runtests.jl diff --git a/defaults/travis.yml b/templates/travis.yml similarity index 100% rename from defaults/travis.yml rename to templates/travis.yml diff --git a/test/fixtures/AllPlugins/LICENSE.txt b/test/fixtures/AllPlugins/LICENSE.txt index 9ce1e635..b7731085 100644 --- a/test/fixtures/AllPlugins/LICENSE.txt +++ b/test/fixtures/AllPlugins/LICENSE.txt @@ -1,3 +1,5 @@ +MIT License + Copyright (c) 2019 tester Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/fixtures/Basic/LICENSE.txt b/test/fixtures/Basic/LICENSE.txt index 9ce1e635..b7731085 100644 --- a/test/fixtures/Basic/LICENSE.txt +++ b/test/fixtures/Basic/LICENSE.txt @@ -1,3 +1,5 @@ +MIT License + Copyright (c) 2019 tester Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/show.jl b/test/show.jl index b97c3afe..324c1adf 100644 --- a/test/show.jl +++ b/test/show.jl @@ -1,5 +1,5 @@ const DEFAULTS_DIR = contractuser(PT.DEFAULTS_DIR) -const LICENSE_DIR = contractuser(PT.LICENSE_DIR) +const LICENSE_DIR = contractuser(joinpath(PT.DEFAULTS_DIR, "licenses")) @testset "Show methods" begin @testset "Plugins" begin @@ -36,7 +36,7 @@ const LICENSE_DIR = contractuser(PT.LICENSE_DIR) destination: "README.md" inline_badges: false Tests: - file: "$(joinpath(DEFAULTS_DIR, "runtests.jl"))" + file: "$(joinpath(DEFAULTS_DIR, "test", "runtests.jl"))" project: false """ @test sprint(show, MIME("text/plain"), tpl(; authors=USER)) == rstrip(expected) From 12fcc121fa8ba0323bf5582e69387b5abc04386a Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Thu, 19 Sep 2019 17:18:12 +0700 Subject: [PATCH 31/81] Remove .txt suffix from reference test files --- test/fixtures/AllPlugins/{.appveyor.yml.txt => .appveyor.yml} | 0 test/fixtures/AllPlugins/{.cirrus.yml.txt => .cirrus.yml} | 0 test/fixtures/AllPlugins/{.gitignore.txt => .gitignore} | 0 .../fixtures/AllPlugins/{.gitlab-ci.yml.txt => .gitlab-ci.yml} | 0 test/fixtures/AllPlugins/{.travis.yml.txt => .travis.yml} | 0 test/fixtures/AllPlugins/{CITATION.bib.txt => CITATION.bib} | 0 test/fixtures/AllPlugins/{LICENSE.txt => LICENSE} | 0 test/fixtures/AllPlugins/{Manifest.toml.txt => Manifest.toml} | 0 test/fixtures/AllPlugins/{Project.toml.txt => Project.toml} | 0 test/fixtures/AllPlugins/{README.md.txt => README.md} | 0 .../AllPlugins/docs/{Manifest.toml.txt => Manifest.toml} | 0 .../AllPlugins/docs/{Project.toml.txt => Project.toml} | 0 test/fixtures/AllPlugins/docs/{make.jl.txt => make.jl} | 0 test/fixtures/AllPlugins/docs/src/{index.md.txt => index.md} | 0 .../AllPlugins/src/{AllPlugins.jl.txt => AllPlugins.jl} | 0 test/fixtures/AllPlugins/test/{runtests.jl.txt => runtests.jl} | 0 test/fixtures/Basic/{.gitignore.txt => .gitignore} | 0 test/fixtures/Basic/{LICENSE.txt => LICENSE} | 0 test/fixtures/Basic/{Manifest.toml.txt => Manifest.toml} | 0 test/fixtures/Basic/{Project.toml.txt => Project.toml} | 0 test/fixtures/Basic/{README.md.txt => README.md} | 0 test/fixtures/Basic/src/{Basic.jl.txt => Basic.jl} | 0 test/fixtures/Basic/test/{runtests.jl.txt => runtests.jl} | 0 test/reference.jl | 3 +-- 24 files changed, 1 insertion(+), 2 deletions(-) rename test/fixtures/AllPlugins/{.appveyor.yml.txt => .appveyor.yml} (100%) rename test/fixtures/AllPlugins/{.cirrus.yml.txt => .cirrus.yml} (100%) rename test/fixtures/AllPlugins/{.gitignore.txt => .gitignore} (100%) rename test/fixtures/AllPlugins/{.gitlab-ci.yml.txt => .gitlab-ci.yml} (100%) rename test/fixtures/AllPlugins/{.travis.yml.txt => .travis.yml} (100%) rename test/fixtures/AllPlugins/{CITATION.bib.txt => CITATION.bib} (100%) rename test/fixtures/AllPlugins/{LICENSE.txt => LICENSE} (100%) rename test/fixtures/AllPlugins/{Manifest.toml.txt => Manifest.toml} (100%) rename test/fixtures/AllPlugins/{Project.toml.txt => Project.toml} (100%) rename test/fixtures/AllPlugins/{README.md.txt => README.md} (100%) rename test/fixtures/AllPlugins/docs/{Manifest.toml.txt => Manifest.toml} (100%) rename test/fixtures/AllPlugins/docs/{Project.toml.txt => Project.toml} (100%) rename test/fixtures/AllPlugins/docs/{make.jl.txt => make.jl} (100%) rename test/fixtures/AllPlugins/docs/src/{index.md.txt => index.md} (100%) rename test/fixtures/AllPlugins/src/{AllPlugins.jl.txt => AllPlugins.jl} (100%) rename test/fixtures/AllPlugins/test/{runtests.jl.txt => runtests.jl} (100%) rename test/fixtures/Basic/{.gitignore.txt => .gitignore} (100%) rename test/fixtures/Basic/{LICENSE.txt => LICENSE} (100%) rename test/fixtures/Basic/{Manifest.toml.txt => Manifest.toml} (100%) rename test/fixtures/Basic/{Project.toml.txt => Project.toml} (100%) rename test/fixtures/Basic/{README.md.txt => README.md} (100%) rename test/fixtures/Basic/src/{Basic.jl.txt => Basic.jl} (100%) rename test/fixtures/Basic/test/{runtests.jl.txt => runtests.jl} (100%) diff --git a/test/fixtures/AllPlugins/.appveyor.yml.txt b/test/fixtures/AllPlugins/.appveyor.yml similarity index 100% rename from test/fixtures/AllPlugins/.appveyor.yml.txt rename to test/fixtures/AllPlugins/.appveyor.yml diff --git a/test/fixtures/AllPlugins/.cirrus.yml.txt b/test/fixtures/AllPlugins/.cirrus.yml similarity index 100% rename from test/fixtures/AllPlugins/.cirrus.yml.txt rename to test/fixtures/AllPlugins/.cirrus.yml diff --git a/test/fixtures/AllPlugins/.gitignore.txt b/test/fixtures/AllPlugins/.gitignore similarity index 100% rename from test/fixtures/AllPlugins/.gitignore.txt rename to test/fixtures/AllPlugins/.gitignore diff --git a/test/fixtures/AllPlugins/.gitlab-ci.yml.txt b/test/fixtures/AllPlugins/.gitlab-ci.yml similarity index 100% rename from test/fixtures/AllPlugins/.gitlab-ci.yml.txt rename to test/fixtures/AllPlugins/.gitlab-ci.yml diff --git a/test/fixtures/AllPlugins/.travis.yml.txt b/test/fixtures/AllPlugins/.travis.yml similarity index 100% rename from test/fixtures/AllPlugins/.travis.yml.txt rename to test/fixtures/AllPlugins/.travis.yml diff --git a/test/fixtures/AllPlugins/CITATION.bib.txt b/test/fixtures/AllPlugins/CITATION.bib similarity index 100% rename from test/fixtures/AllPlugins/CITATION.bib.txt rename to test/fixtures/AllPlugins/CITATION.bib diff --git a/test/fixtures/AllPlugins/LICENSE.txt b/test/fixtures/AllPlugins/LICENSE similarity index 100% rename from test/fixtures/AllPlugins/LICENSE.txt rename to test/fixtures/AllPlugins/LICENSE diff --git a/test/fixtures/AllPlugins/Manifest.toml.txt b/test/fixtures/AllPlugins/Manifest.toml similarity index 100% rename from test/fixtures/AllPlugins/Manifest.toml.txt rename to test/fixtures/AllPlugins/Manifest.toml diff --git a/test/fixtures/AllPlugins/Project.toml.txt b/test/fixtures/AllPlugins/Project.toml similarity index 100% rename from test/fixtures/AllPlugins/Project.toml.txt rename to test/fixtures/AllPlugins/Project.toml diff --git a/test/fixtures/AllPlugins/README.md.txt b/test/fixtures/AllPlugins/README.md similarity index 100% rename from test/fixtures/AllPlugins/README.md.txt rename to test/fixtures/AllPlugins/README.md diff --git a/test/fixtures/AllPlugins/docs/Manifest.toml.txt b/test/fixtures/AllPlugins/docs/Manifest.toml similarity index 100% rename from test/fixtures/AllPlugins/docs/Manifest.toml.txt rename to test/fixtures/AllPlugins/docs/Manifest.toml diff --git a/test/fixtures/AllPlugins/docs/Project.toml.txt b/test/fixtures/AllPlugins/docs/Project.toml similarity index 100% rename from test/fixtures/AllPlugins/docs/Project.toml.txt rename to test/fixtures/AllPlugins/docs/Project.toml diff --git a/test/fixtures/AllPlugins/docs/make.jl.txt b/test/fixtures/AllPlugins/docs/make.jl similarity index 100% rename from test/fixtures/AllPlugins/docs/make.jl.txt rename to test/fixtures/AllPlugins/docs/make.jl diff --git a/test/fixtures/AllPlugins/docs/src/index.md.txt b/test/fixtures/AllPlugins/docs/src/index.md similarity index 100% rename from test/fixtures/AllPlugins/docs/src/index.md.txt rename to test/fixtures/AllPlugins/docs/src/index.md diff --git a/test/fixtures/AllPlugins/src/AllPlugins.jl.txt b/test/fixtures/AllPlugins/src/AllPlugins.jl similarity index 100% rename from test/fixtures/AllPlugins/src/AllPlugins.jl.txt rename to test/fixtures/AllPlugins/src/AllPlugins.jl diff --git a/test/fixtures/AllPlugins/test/runtests.jl.txt b/test/fixtures/AllPlugins/test/runtests.jl similarity index 100% rename from test/fixtures/AllPlugins/test/runtests.jl.txt rename to test/fixtures/AllPlugins/test/runtests.jl diff --git a/test/fixtures/Basic/.gitignore.txt b/test/fixtures/Basic/.gitignore similarity index 100% rename from test/fixtures/Basic/.gitignore.txt rename to test/fixtures/Basic/.gitignore diff --git a/test/fixtures/Basic/LICENSE.txt b/test/fixtures/Basic/LICENSE similarity index 100% rename from test/fixtures/Basic/LICENSE.txt rename to test/fixtures/Basic/LICENSE diff --git a/test/fixtures/Basic/Manifest.toml.txt b/test/fixtures/Basic/Manifest.toml similarity index 100% rename from test/fixtures/Basic/Manifest.toml.txt rename to test/fixtures/Basic/Manifest.toml diff --git a/test/fixtures/Basic/Project.toml.txt b/test/fixtures/Basic/Project.toml similarity index 100% rename from test/fixtures/Basic/Project.toml.txt rename to test/fixtures/Basic/Project.toml diff --git a/test/fixtures/Basic/README.md.txt b/test/fixtures/Basic/README.md similarity index 100% rename from test/fixtures/Basic/README.md.txt rename to test/fixtures/Basic/README.md diff --git a/test/fixtures/Basic/src/Basic.jl.txt b/test/fixtures/Basic/src/Basic.jl similarity index 100% rename from test/fixtures/Basic/src/Basic.jl.txt rename to test/fixtures/Basic/src/Basic.jl diff --git a/test/fixtures/Basic/test/runtests.jl.txt b/test/fixtures/Basic/test/runtests.jl similarity index 100% rename from test/fixtures/Basic/test/runtests.jl.txt rename to test/fixtures/Basic/test/runtests.jl diff --git a/test/reference.jl b/test/reference.jl index 3a1eaecd..305c1408 100644 --- a/test/reference.jl +++ b/test/reference.jl @@ -9,8 +9,7 @@ function test_all(pkg::AbstractString; kwargs...) with_pkg(t, pkg) do pkg pkg_dir = joinpath(t.dir, pkg) foreach(readlines(`git -C $pkg_dir ls-files`)) do f - # All fixture files are .txt so that ReferenceTests can handle them. - reference = joinpath(@__DIR__, "fixtures", pkg, f * ".txt") + reference = joinpath(@__DIR__, "fixtures", pkg, f) observed = read(joinpath(pkg_dir, f), String) @test_reference reference observed end From 146c1bdbe5700e386331d191b8acd0672587402f Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Fri, 20 Sep 2019 00:21:06 +0700 Subject: [PATCH 32/81] Add prehooks/posthooks for more fine-grained plugin control --- Manifest.toml | 4 +- Project.toml | 1 + docs/src/developer.md | 16 ++-- docs/src/user.md | 9 +- src/PkgTemplates.jl | 9 +- src/plugin.jl | 40 +++++++-- src/plugins/defaults.jl | 179 +++++++++++++++++++++++++++++++------- src/plugins/develop.jl | 11 +++ src/plugins/documenter.jl | 4 +- src/template.jl | 71 +++++++-------- templates/src/module.jl | 5 ++ 11 files changed, 252 insertions(+), 97 deletions(-) create mode 100644 src/plugins/develop.jl create mode 100644 templates/src/module.jl diff --git a/Manifest.toml b/Manifest.toml index afff9f01..bffdf4c8 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -61,9 +61,9 @@ version = "1.1.0" [[Parameters]] deps = ["OrderedCollections"] -git-tree-sha1 = "1dfd7cd50a8eb06ef693a4c2bbe945943cd000c5" +git-tree-sha1 = "b62b2558efb1eef1fa44e4be5ff58a515c287e38" uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a" -version = "0.11.0" +version = "0.12.0" [[Pkg]] deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] diff --git a/Project.toml b/Project.toml index e1ac7d43..339b5309 100644 --- a/Project.toml +++ b/Project.toml @@ -11,6 +11,7 @@ Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" +UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [compat] julia = "1" diff --git a/docs/src/developer.md b/docs/src/developer.md index 06a4013f..7e074566 100644 --- a/docs/src/developer.md +++ b/docs/src/developer.md @@ -50,7 +50,7 @@ view(p::Documenter, t::Template, pkg::AbstractString) = Dict( "USER" => t.user, ) -function gen_plugin(p::Documenter, t::Template, pkg_dir::AbstractString) +function hook(p::Documenter, t::Template, pkg_dir::AbstractString) pkg = basename(pkg_dir) docs_dir = joinpath(pkg_dir, "docs") @@ -91,10 +91,10 @@ Third, we implement [`view`](@ref), which is used to fill placeholders in badges view ``` -Finally, we implement [`gen_plugin`](@ref), which is the real workhorse for the plugin. +Finally, we implement [`hook`](@ref), which is the real workhorse for the plugin. ```@docs -gen_plugin +hook ``` Inside of this function, we call a few more functions, which help us with text templating. @@ -167,7 +167,7 @@ Finally, we implement [`view`](@ref) to fill in the placeholders that we saw in ## Doing Extra Work With `BasicPlugin`s -Notice that we didn't have to implement [`gen_plugin`](@ref) for our plugin. +Notice that we didn't have to implement [`hook`](@ref) for our plugin. It's implemented for all [`BasicPlugin`](@ref)s, like so: ```julia @@ -175,7 +175,7 @@ function render_plugin(p::BasicPlugin, t::Template, pkg::AbstractString) return render_file(source(p), combined_view(p, t, pkg), tags(p)) end -function gen_plugin(p::BasicPlugin, t::Template, pkg_dir::AbstractString) +function hook(p::BasicPlugin, t::Template, pkg_dir::AbstractString) source(p) === nothing && return pkg = basename(pkg_dir) path = joinpath(pkg_dir, destination(p)) @@ -191,7 +191,7 @@ It creates `runtests.jl`, but it also modifies the `Project.toml` to include the Of course, we could use a normal [`Plugin`](@ref), but it turns out there's a way to avoid that while still getting the extra capbilities that we want. -The plugin implements its own `gen_plugin`, but uses `invoke` to avoid duplicating the file creation code: +The plugin implements its own `hook`, but uses `invoke` to avoid duplicating the file creation code: ```julia @with_kw_noshow struct Tests <: BasicPlugin @@ -202,9 +202,9 @@ source(p::Tests) = p.file destination(::Tests) = joinpath("test", "runtests.jl") view(::Tests, ::Template, pkg::AbstractString) = Dict("PKG" => pkg) -function gen_plugin(p::Tests, t::Template, pkg_dir::AbstractString) +function hook(p::Tests, t::Template, pkg_dir::AbstractString) # Do the normal BasicPlugin behaviour to create the test script. - invoke(gen_plugin, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) + invoke(hook, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) # Do some other work. add_test_dependency() end diff --git a/docs/src/user.md b/docs/src/user.md index 4c86cd06..5e92a158 100644 --- a/docs/src/user.md +++ b/docs/src/user.md @@ -28,10 +28,12 @@ These plugins are included by default. They can be overridden by supplying another value via the `plugins` keyword, or disabled by supplying the type via the `disable_defaults` keyword. ```@docs -Gitignore -License -Readme +ProjectFile +SrcDir Tests +Readme +License +Git ``` ### Continuous Integration (CI) @@ -63,6 +65,7 @@ Documenter ### Miscellaneous ```@docs +Develop Citation ``` diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index 15173c88..e86d1aa7 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -5,9 +5,10 @@ using Base.Filesystem: contractuser using Dates: month, today, year using InteractiveUtils: subtypes -using LibGit2: LibGit2, GitRemote +using LibGit2: LibGit2, GitRemote, GitRepo using Pkg: Pkg, TOML, PackageSpec using REPL.TerminalMenus: MultiSelectMenu, RadioMenu, request +using UUIDs: uuid4 using Mustache: render using Parameters: @with_kw_noshow @@ -19,11 +20,14 @@ export Citation, Codecov, Coveralls, + Develop, Documenter, - Gitignore, + Git, GitLabCI, License, + ProjectFile, Readme, + SrcDir, Tests, TravisCI @@ -36,7 +40,6 @@ When implementing a new plugin, subtype this type to have full control over its abstract type Plugin end include("template.jl") -include("generate.jl") include("plugin.jl") include("interactive.jl") diff --git a/src/plugin.jl b/src/plugin.jl index d45e6cb4..da2be5f8 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -19,7 +19,7 @@ Return the view to be passed to the text templating engine for this plugin. `pkg` is the name of the package being generated. For [`BasicPlugin`](@ref)s, this is used for both the plugin badges (see [`badges`](@ref)) and the template file (see [`source`](@ref)). -For other [`Plugin`](@ref)s, it is used only for badges, but you can always call it yourself as part of your [`gen_plugin`](@ref) implementation. +For other [`Plugin`](@ref)s, it is used only for badges, but you can always call it yourself as part of your [`hook`](@ref) implementation. By default, an empty `Dict` is returned. """ @@ -124,19 +124,44 @@ function badges(p::Plugin, t::Template, pkg::AbstractString) end """ - gen_plugin(::Plugin, ::Template, pkg::AbstractString) + prehook(::Plugin, ::Template, pkg_dir::AbstractString) + +Do some work associated with a plugin **before** any files are generated. +At this point, `pkg_dir` is an empty directory that will eventually contain the package. +""" +prehook(::Plugin, ::Template, ::AbstractString) = nothing + +function prehook(p::T, ::Template, ::AbstractString) where T <: BasicPlugin + src = source(p) + src === nothing && return + isfile(src) || throw(ArgumentError("$(nameof(T)): The file $src does not exist")) +end + +""" + posthook(::Plugin, ::Template, pkg_dir::AbstractString) + +Do some work associated with a plugin **after** after files have been generated. +""" +posthook(::Plugin, ::Template, ::AbstractString) = nothing + +""" + hook(::Plugin, ::Template, pkg_dir::AbstractString) Perform any work associated with a plugin. -`pkg` is the name of the package being generated. +`pkg_dir` is the directory in which the package is being generated (so `basename(pkg_dir)` is the package name). For [`Plugin`](@ref)s that are not [`BasicPlugin`](@ref)s, this is the only function that really needs to be implemented. -If you want your plugin to do anything at all during package generation, you should implement it here. +If you want your plugin to do something during the main phase of package generation, you should implement it here. + +See also: [`prehook`](@ref) and [`posthook`](@ref). -You should **not** implement this function for `BasicPlugin`s. +!!! note + You usually shouldn't implement this function for [`BasicPlugin`](@ref)s. + If you do, it should probably `invoke` the generic method (otherwise, there's no reason to subtype `BasicPlugin`). """ -gen_plugin(::Plugin, ::Template, ::AbstractString) = nothing +hook(::Plugin, ::Template, ::AbstractString) = nothing -function gen_plugin(p::BasicPlugin, t::Template, pkg_dir::AbstractString) +function hook(p::BasicPlugin, t::Template, pkg_dir::AbstractString) source(p) === nothing && return pkg = basename(pkg_dir) path = joinpath(pkg_dir, destination(p)) @@ -184,4 +209,5 @@ include(joinpath("plugins", "defaults.jl")) include(joinpath("plugins", "coverage.jl")) include(joinpath("plugins", "ci.jl")) include(joinpath("plugins", "citation.jl")) +include(joinpath("plugins", "develop.jl")) include(joinpath("plugins", "documenter.jl")) diff --git a/src/plugins/defaults.jl b/src/plugins/defaults.jl index e0bf7509..82dbf8af 100644 --- a/src/plugins/defaults.jl +++ b/src/plugins/defaults.jl @@ -1,18 +1,5 @@ const TEST_UUID = "8dfed614-e22c-5e08-85e1-65c5234f0b40" const TEST_DEP = PackageSpec(; name="Test", uuid=TEST_UUID) -const LICENSES = Dict( - "MIT" => "MIT \"Expat\" License", - "BSD2" => "Simplified \"2-clause\" BSD License", - "BSD3" => "Modified \"3-clause\" BSD License", - "ISC" => "Internet Systems Consortium License", - "ASL" => "Apache License, Version 2.0", - "MPL" => "Mozilla Public License, Version 2.0", - "GPL-2.0+" => "GNU Public License, Version 2.0+", - "GPL-3.0+" => "GNU Public License, Version 3.0+", - "LGPL-2.1+" => "Lesser GNU Public License, Version 2.1+", - "LGPL-3.0+" => "Lesser GNU Public License, Version 3.0+", - "EUPL-1.2+" => "European Union Public Licence, Version 1.2+", -) badge_order() = [ Documenter{GitLabCI}, @@ -25,6 +12,67 @@ badge_order() = [ Coveralls, ] +""" + ProjectFile() + +Creates a `Project.toml`. +""" +struct ProjectFile <: Plugin end + +# Create Project.toml in the prehook because other hooks might depend on it. +function prehook(::ProjectFile, t::Template, pkg_dir::AbstractString) + toml = Dict( + "name" => basename(pkg_dir), + "uuid" => uuid4(), + "authors" => t.authors, + "compat" => Dict("julia" => compat_version(t.julia_version)), + ) + open(io -> TOML.print(io, toml), joinpath(pkg_dir, "Project.toml"), "w") +end + +""" + compat_version(v::VersionNumber) -> String + +Format a `VersionNumber` to exclude trailing zero components. +""" +function compat_version(v::VersionNumber) + return if v.patch == 0 && v.minor == 0 + "$(v.major)" + elseif v.patch == 0 + "$(v.major).$(v.minor)" + else + "$(v.major).$(v.minor).$(v.patch)" + end +end + +""" + SrcDir(; file="$(contractuser(default_file("src", "module.jl")))") + +Creates a module entrypoint. +""" +@with_kw_noshow mutable struct SrcDir <: BasicPlugin + file::String = default_file("src", "module.jl") + destination::String = joinpath("src", ".jl") +end + +# Don't display the destination field. +function Base.show(io::IO, ::MIME"text/plain", p::SrcDir) + indent = get(io, :indent, 0) + print(io, repeat(' ', indent), "SrcDir:") + print(io, "\n", repeat(' ', indent + 2), "file: ", show_field(p.file)) +end + +source(p::SrcDir) = p.file +destination(p::SrcDir) = p.destination +view(::SrcDir, ::Template, pkg::AbstractString) = Dict("PKG" => pkg) + +# Update the destination now that we know the package name. +# Kind of hacky, but oh well. +function prehook(p::SrcDir, t::Template, pkg_dir::AbstractString) + invoke(prehook, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) + p.destination = joinpath("src", basename(pkg_dir) * ".jl") +end + """ Readme(; file="$(contractuser(default_file("README.md")))", @@ -113,32 +161,88 @@ view(::License, t::Template, ::AbstractString) = Dict( ) """ - Gitignore(; ds_store=true, dev=true) + Git(; ignore=String[], ssh=false, manifest=false, gpgsign=false) -Creates a `.gitignore` file. +Creates a Git repository and a `.gitignore` file. ## Keyword Arguments -- `ds_store::Bool`: Whether or not to ignore MacOS's `.DS_Store` files. -- `dev::Bool`: Whether or not to ignore the directory of locally-developed packages. +- `ignore::Vector{<:AbstractString}`: Patterns to add to the `.gitignore`. + See also: [`gitignore`](@ref). +- `ssh::Bool`: Whether or not to use SSH for the remote. + If left unset, HTTPS is used. +- `manifest::Bool`: Whether or not to commit `Manifest.toml`. +- `gpgsign::Bool`: Whether or not to sign commits with your GPG key. + This option requires that the Git CLI is installed. """ -@with_kw_noshow struct Gitignore <: Plugin - ds_store::Bool = true - dev::Bool = true +@with_kw_noshow struct Git <: Plugin + ignore::Vector{String} = [] + ssh::Bool = false + manifest::Bool = false + gpgsign::Bool = false end -function render_plugin(p::Gitignore, t::Template) - init = String[] - p.ds_store && push!(init, ".DS_Store") - p.dev && push!(init, "/dev/") - entries = mapreduce(gitignore, append!, values(t.plugins); init=init) - # Only ignore manifests at the repo root. - t.manifest || "Manifest.toml" in entries || push!(entries, "/Manifest.toml") - unique!(sort!(entries)) - return join(entries, "\n") +gitignore(p::Git) = p.ignore + +# Set up the Git repository. +function prehook(p::Git, t::Template, pkg_dir::AbstractString) + if p.gpgsign && try run(pipeline(`git --version`; stdout=devnull)); false catch; true end + throw(ArgumentError("Git: gpgsign is set but the Git CLI is not installed")) + end + LibGit2.with(LibGit2.init(pkg_dir)) do repo + commit(p, repo, pkg_dir, "Initial commit") + pkg = basename(pkg_dir) + url = if p.ssh + "git@$(t.host):$(t.user)/$pkg.jl.git" + else + "https://$(t.host)/$(t.user)/$pkg.jl" + end + LibGit2.with(GitRemote(repo, "origin", url)) do remote + # TODO: `git pull` still requires some Git branch config. + LibGit2.add_push!(repo, remote, "refs/heads/master") + end + end end -function gen_plugin(p::Gitignore, t::Template, pkg_dir::AbstractString) - t.git && gen_file(joinpath(pkg_dir, ".gitignore"), render_plugin(p, t)) +# Create the .gitignore. +function hook(p::Git, t::Template, pkg_dir::AbstractString) + gen_file(joinpath(pkg_dir, ".gitignore"), render_plugin(p, t)) +end + +# Commit the files +function posthook(p::Git, t::Template, pkg_dir::AbstractString) + # Ensure that the manifest exists if it's going to be committed. + manifest = joinpath(pkg_dir, "Manifest.toml") + if p.manifest && !isfile(manifest) + touch(manifest) + with_project(Pkg.update, pkg_dir) + end + + LibGit2.with(GitRepo(pkg_dir)) do repo + LibGit2.add!(repo, ".") + msg = "Files generated by PkgTemplates" + installed = Pkg.installed() + if haskey(installed, "PkgTemplates") + ver = string(installed["PkgTemplates"]) + msg *= "\n\nPkgTemplates version: $ver" + end + commit(p, repo, pkg_dir, msg) + end +end + +function commit(p::Git, repo::GitRepo, pkg_dir::AbstractString, msg::AbstractString) + if p.gpgsign + run(pipeline(`git -C $pkg_dir commit -S --allow-empty -m $msg`; stdout=devnull)) + else + LibGit2.commit(repo, msg) + end +end + +function render_plugin(p::Git, t::Template) + ignore = mapreduce(gitignore, append!, values(t.plugins)) + # Only ignore manifests at the repo root. + p.manifest || "Manifest.toml" in ignore || push!(ignore, "/Manifest.toml") + unique!(sort!(ignore)) + return join(ignore, "\n") end """ @@ -163,9 +267,18 @@ source(p::Tests) = p.file destination(::Tests) = joinpath("test", "runtests.jl") view(::Tests, ::Template, pkg::AbstractString) = Dict("PKG" => pkg) -function gen_plugin(p::Tests, t::Template, pkg_dir::AbstractString) +function prehook(p::Tests, t::Template, pkg_dir::AbstractString) + invoke(prehook, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) + p.project && t.julia_version < v"1.2" && @warn string( + "Tests: The project option is set to create a project (supported in Julia 1.2 and later) ", + "but a Julia version older than 1.2 is supported by the Template.", + ) +end + + +function hook(p::Tests, t::Template, pkg_dir::AbstractString) # Do the normal BasicPlugin behaviour to create the test script. - invoke(gen_plugin, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) + invoke(hook, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) # Then set up the test depdendency in the chosen way. f = p.project ? make_test_project : add_test_dependency diff --git a/src/plugins/develop.jl b/src/plugins/develop.jl new file mode 100644 index 00000000..467a82c5 --- /dev/null +++ b/src/plugins/develop.jl @@ -0,0 +1,11 @@ +""" + Develop() + +Adds generated packages to the current environment by `dev`ing them. +See [here](https://julialang.github.io/Pkg.jl/v1/managing-packages/#Developing-packages-1) for more details. +""" +struct Develop <: Plugin end + +function posthook(::Develop, ::Template, pkg_dir::AbstractString) + Pkg.develop(PackageSpec(; path=pkg_dir)) +end diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index aa87ab5e..1623878f 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -85,14 +85,14 @@ function view(p::Documenter{TravisCI}, t::Template, pkg::AbstractString) return merge(base, Dict("HAS_DEPLOY" => true)) end -function gen_plugin(p::Documenter, t::Template, pkg_dir::AbstractString) +function hook(p::Documenter, t::Template, pkg_dir::AbstractString) pkg = basename(pkg_dir) docs_dir = joinpath(pkg_dir, "docs") # Generate files. make = render_file(p.make_jl, combined_view(p, t, pkg), tags(p)) - gen_file(joinpath(docs_dir, "make.jl"), make) index = render_file(p.index_md, combined_view(p, t, pkg), tags(p)) + gen_file(joinpath(docs_dir, "make.jl"), make) gen_file(joinpath(docs_dir, "src", "index.md"), index) # Copy over any assets. diff --git a/src/template.jl b/src/template.jl index 7350a991..aeb888dd 100644 --- a/src/template.jl +++ b/src/template.jl @@ -1,4 +1,4 @@ -default_plugins() = [Gitignore(), License(), Readme(), Tests()] +default_plugins() = [ProjectFile(), SrcDir(), Git(), License(), Readme(), Tests()] default_user() = LibGit2.getconfig("github.user", "") default_version() = VersionNumber(VERSION.major) @@ -26,20 +26,14 @@ A configuration used to generate packages. ### Package Options - `dir::AbstractString="$(contractuser(Pkg.devdir()))"`: Directory to place packages in. +- `host::AbstractString="github.com"`: URL to the code hosting service where packages will reside. - `julia_version::VersionNumber=$(repr(default_version()))`: Minimum allowed Julia version. - `develop::Bool=true`: Whether or not to `develop` new packages in the active environment. -### Git Options -- `git::Bool=true`: Whether or not to create a Git repository for new packages. -- `host::AbstractString="github.com"`: URL to the code hosting service where packages will reside. -- `ssh::Bool=false`: Whether or not to use SSH for the Git remote. - If left unset, HTTPS will be used. -- `manifest::Bool=false`: Whether or not to commit the `Manifest.toml`. - ### Template Plugins - `plugins::Vector{<:Plugin}=Plugin[]`: A list of [`Plugin`](@ref)s used by the template. - `disable_defaults::Vector{DataType}=DataType[]`: Default plugins to disable. - The default plugins are [`Readme`](@ref), [`License`](@ref), [`Tests`](@ref), and [`Gitignore`](@ref). + The default plugins are [`ProjectFile`](@ref), [`SrcDir`](@ref), [`Tests`](@ref), [`Readme`](@ref), [`License`](@ref), and [`Git`](@ref). To override a default plugin instead of disabling it altogether, supply it via `plugins`. ### Interactive Usage @@ -57,14 +51,10 @@ julia> t("PkgName") """ struct Template authors::Vector{String} - develop::Bool dir::String - git::Bool host::String julia_version::VersionNumber - manifest::Bool plugins::Dict{DataType, <:Plugin} - ssh::Bool user::String end @@ -78,9 +68,9 @@ function Template(::Val{false}; kwargs...) authors = getkw(kwargs, :authors) authors isa Vector || (authors = map(strip, split(authors, ","))) - host = replace(getkw(kwargs, :host), r".*://" => "") - dir = abspath(expanduser(getkw(kwargs, :dir))) + host = replace(getkw(kwargs, :host), r".*://" => "") + julia_version = getkw(kwargs, :julia_version) disabled = getkw(kwargs, :disable_defaults) enabled = filter(p -> !(typeof(p) in disabled), default_plugins()) @@ -89,26 +79,7 @@ function Template(::Val{false}; kwargs...) # which means that default plugins get replaced by user values. 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 implemented 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( - authors, - getkw(kwargs, :develop), - dir, - getkw(kwargs, :git), - host, - julia, - getkw(kwargs, :manifest), - plugins, - getkw(kwargs, :ssh), - user, - ) + return Template(authors, dir, host, julia_version, plugins, user) end # Does the template have a plugin that satisfies some predicate? @@ -121,13 +92,35 @@ getkw(kwargs, k) = get(() -> defaultkw(k), kwargs, k) # Default Template keyword values. defaultkw(s::Symbol) = defaultkw(Val(s)) defaultkw(::Val{:authors}) = default_authors() -defaultkw(::Val{:develop}) = true defaultkw(::Val{:dir}) = Pkg.devdir() defaultkw(::Val{:disable_defaults}) = DataType[] -defaultkw(::Val{:git}) = true defaultkw(::Val{:host}) = "github.com" defaultkw(::Val{:julia_version}) = default_version() -defaultkw(::Val{:manifest}) = false defaultkw(::Val{:plugins}) = Plugin[] -defaultkw(::Val{:ssh}) = false defaultkw(::Val{:user}) = default_user() + +""" + (::Template)(pkg::AbstractString) + +Generate a package named `pkg` from a [`Template`](@ref). +""" +function (t::Template)(pkg::AbstractString) + endswith(pkg, ".jl") && (pkg = pkg[1:end-3]) + pkg_dir = joinpath(t.dir, pkg) + ispath(pkg_dir) && throw(ArgumentError("$pkg_dir already exists")) + mkpath(pkg_dir) + + try + foreach((prehook, hook, posthook)) do h + @info "Running $(h)s" + foreach(values(t.plugins)) do p + h(p, t, pkg_dir) + end + end + catch + rm(pkg_dir; recursive=true, force=true) + rethrow() + end + + @info "New package is at $pkg_dir" +end diff --git a/templates/src/module.jl b/templates/src/module.jl new file mode 100644 index 00000000..f07318fc --- /dev/null +++ b/templates/src/module.jl @@ -0,0 +1,5 @@ +module {{{PKG}}} + +# Write your package code here. + +end From 2a5fb5ccc87aa51fc3c1e954372de845c35e1ac3 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Fri, 20 Sep 2019 01:06:13 +0700 Subject: [PATCH 33/81] Move the default plugins into their own files, fix some bugs --- src/plugin.jl | 15 +- src/plugins/defaults.jl | 306 --------------------- src/plugins/git.jl | 87 ++++++ src/plugins/license.jl | 37 +++ src/plugins/project_file.jl | 33 +++ src/plugins/readme.jl | 59 ++++ src/plugins/src_dir.jl | 29 ++ src/plugins/tests.jl | 62 +++++ test/fixtures/AllPlugins/.gitignore | 3 +- test/fixtures/AllPlugins/src/AllPlugins.jl | 4 +- test/fixtures/Basic/.gitignore | 3 +- test/fixtures/Basic/src/Basic.jl | 4 +- test/git.jl | 10 +- test/reference.jl | 8 +- test/runtests.jl | 4 +- test/show.jl | 37 ++- test/template.jl | 7 +- 17 files changed, 364 insertions(+), 344 deletions(-) delete mode 100644 src/plugins/defaults.jl create mode 100644 src/plugins/git.jl create mode 100644 src/plugins/license.jl create mode 100644 src/plugins/project_file.jl create mode 100644 src/plugins/readme.jl create mode 100644 src/plugins/src_dir.jl create mode 100644 src/plugins/tests.jl diff --git a/src/plugin.jl b/src/plugin.jl index da2be5f8..9bb7f221 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -1,4 +1,4 @@ -const DEFAULTS_DIR = normpath(joinpath(@__DIR__, "..", "templates")) +const TEMPLATES_DIR = normpath(joinpath(@__DIR__, "..", "templates")) """ A simple plugin that, in general, creates a single file. @@ -8,9 +8,9 @@ abstract type BasicPlugin <: Plugin end """ default_file(paths::AbstractString...) -> String -Return a path relative to the default template file directory (`$(contractuser(DEFAULTS_DIR))`). +Return a path relative to the default template file directory (`$(contractuser(TEMPLATES_DIR))`). """ -default_file(paths::AbstractString...) = joinpath(DEFAULTS_DIR, paths...) +default_file(paths::AbstractString...) = joinpath(TEMPLATES_DIR, paths...) """ view(::Plugin, ::Template, pkg::AbstractString) -> Dict{String, Any} @@ -205,9 +205,14 @@ function render_text(text::AbstractString, view::Dict{<:AbstractString}, tags=no return tags === nothing ? render(text, view) : render(text, view; tags=tags) end -include(joinpath("plugins", "defaults.jl")) +include(joinpath("plugins", "project_file.jl")) +include(joinpath("plugins", "src_dir.jl")) +include(joinpath("plugins", "tests.jl")) +include(joinpath("plugins", "readme.jl")) +include(joinpath("plugins", "license.jl")) +include(joinpath("plugins", "git.jl")) +include(joinpath("plugins", "develop.jl")) include(joinpath("plugins", "coverage.jl")) include(joinpath("plugins", "ci.jl")) include(joinpath("plugins", "citation.jl")) -include(joinpath("plugins", "develop.jl")) include(joinpath("plugins", "documenter.jl")) diff --git a/src/plugins/defaults.jl b/src/plugins/defaults.jl deleted file mode 100644 index 82dbf8af..00000000 --- a/src/plugins/defaults.jl +++ /dev/null @@ -1,306 +0,0 @@ -const TEST_UUID = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -const TEST_DEP = PackageSpec(; name="Test", uuid=TEST_UUID) - -badge_order() = [ - Documenter{GitLabCI}, - Documenter{TravisCI}, - GitLabCI, - TravisCI, - AppVeyor, - CirrusCI, - Codecov, - Coveralls, -] - -""" - ProjectFile() - -Creates a `Project.toml`. -""" -struct ProjectFile <: Plugin end - -# Create Project.toml in the prehook because other hooks might depend on it. -function prehook(::ProjectFile, t::Template, pkg_dir::AbstractString) - toml = Dict( - "name" => basename(pkg_dir), - "uuid" => uuid4(), - "authors" => t.authors, - "compat" => Dict("julia" => compat_version(t.julia_version)), - ) - open(io -> TOML.print(io, toml), joinpath(pkg_dir, "Project.toml"), "w") -end - -""" - compat_version(v::VersionNumber) -> String - -Format a `VersionNumber` to exclude trailing zero components. -""" -function compat_version(v::VersionNumber) - return if v.patch == 0 && v.minor == 0 - "$(v.major)" - elseif v.patch == 0 - "$(v.major).$(v.minor)" - else - "$(v.major).$(v.minor).$(v.patch)" - end -end - -""" - SrcDir(; file="$(contractuser(default_file("src", "module.jl")))") - -Creates a module entrypoint. -""" -@with_kw_noshow mutable struct SrcDir <: BasicPlugin - file::String = default_file("src", "module.jl") - destination::String = joinpath("src", ".jl") -end - -# Don't display the destination field. -function Base.show(io::IO, ::MIME"text/plain", p::SrcDir) - indent = get(io, :indent, 0) - print(io, repeat(' ', indent), "SrcDir:") - print(io, "\n", repeat(' ', indent + 2), "file: ", show_field(p.file)) -end - -source(p::SrcDir) = p.file -destination(p::SrcDir) = p.destination -view(::SrcDir, ::Template, pkg::AbstractString) = Dict("PKG" => pkg) - -# Update the destination now that we know the package name. -# Kind of hacky, but oh well. -function prehook(p::SrcDir, t::Template, pkg_dir::AbstractString) - invoke(prehook, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) - p.destination = joinpath("src", basename(pkg_dir) * ".jl") -end - -""" - Readme(; - file="$(contractuser(default_file("README.md")))", - destination="README.md", - inline_badges=false, - ) - -Creates a `README` file. -By default, it includes badges for other included plugins - -## Keyword Arguments -- `file::AbstractString`: Template file for the `README`. -- `destination::AbstractString`: File destination, relative to the repository root. - For example, values of `"README"` or `"README.rst"` might be desired. -- `inline_badges::Bool`: Whether or not to put the badges on the same line as the package name. -""" -@with_kw_noshow struct Readme <: BasicPlugin - file::String = default_file("README.md") - destination::String = "README.md" - inline_badges::Bool = false -end - -source(p::Readme) = p.file -destination(p::Readme) = p.destination - -function view(p::Readme, t::Template, pkg::AbstractString) - # Explicitly ordered badges go first. - strings = String[] - done = DataType[] - foreach(badge_order()) do T - if hasplugin(t, T) - bs = badges(t.plugins[T], t, pkg) - append!(strings, badges(t.plugins[T], t, pkg)) - push!(done, T) - end - end - foreach(setdiff(keys(t.plugins), done)) do T - bs = badges(t.plugins[T], t, pkg) - append!(strings, badges(t.plugins[T], t, pkg)) - end - - return Dict( - "BADGES" => strings, - "HAS_CITATION" => hasplugin(t, Citation) && t.plugins[Citation].readme, - "HAS_INLINE_BADGES" => !isempty(strings) && p.inline_badges, - "PKG" => pkg, - ) -end - -""" - License(; name="MIT", path=nothing, destination="LICENSE") - -Creates a license file. - -## Keyword Arguments -- `name::AbstractString`: Name of a license supported by PkgTemplates. - Available licenses can be seen [here](https://github.com/invenia/PkgTemplates.jl/tree/master/templates/licenses). -- `path::Union{AbstractString, Nothing}`: Path to a custom license file. - This keyword takes priority over `name`. -- `destination::AbstractString`: File destination, relative to the repository root. - For example, `"LICENSE.md"` might be desired. -""" -struct License <: BasicPlugin - path::String - destination::String -end - -function License( - name::AbstractString="MIT", - path::Union{AbstractString, Nothing}=nothing, - destination::AbstractString="LICENSE", -) - if path === nothing - path = default_file("licenses", name) - isfile(path) || throw(ArgumentError("License '$(basename(path))' is not available")) - end - return License(path, destination) -end - - -source(p::License) = p.path -destination(p::License) = p.destination -view(::License, t::Template, ::AbstractString) = Dict( - "AUTHORS" => join(t.authors, ", "), - "YEAR" => year(today()), -) - -""" - Git(; ignore=String[], ssh=false, manifest=false, gpgsign=false) - -Creates a Git repository and a `.gitignore` file. - -## Keyword Arguments -- `ignore::Vector{<:AbstractString}`: Patterns to add to the `.gitignore`. - See also: [`gitignore`](@ref). -- `ssh::Bool`: Whether or not to use SSH for the remote. - If left unset, HTTPS is used. -- `manifest::Bool`: Whether or not to commit `Manifest.toml`. -- `gpgsign::Bool`: Whether or not to sign commits with your GPG key. - This option requires that the Git CLI is installed. -""" -@with_kw_noshow struct Git <: Plugin - ignore::Vector{String} = [] - ssh::Bool = false - manifest::Bool = false - gpgsign::Bool = false -end - -gitignore(p::Git) = p.ignore - -# Set up the Git repository. -function prehook(p::Git, t::Template, pkg_dir::AbstractString) - if p.gpgsign && try run(pipeline(`git --version`; stdout=devnull)); false catch; true end - throw(ArgumentError("Git: gpgsign is set but the Git CLI is not installed")) - end - LibGit2.with(LibGit2.init(pkg_dir)) do repo - commit(p, repo, pkg_dir, "Initial commit") - pkg = basename(pkg_dir) - url = if p.ssh - "git@$(t.host):$(t.user)/$pkg.jl.git" - else - "https://$(t.host)/$(t.user)/$pkg.jl" - end - LibGit2.with(GitRemote(repo, "origin", url)) do remote - # TODO: `git pull` still requires some Git branch config. - LibGit2.add_push!(repo, remote, "refs/heads/master") - end - end -end - -# Create the .gitignore. -function hook(p::Git, t::Template, pkg_dir::AbstractString) - gen_file(joinpath(pkg_dir, ".gitignore"), render_plugin(p, t)) -end - -# Commit the files -function posthook(p::Git, t::Template, pkg_dir::AbstractString) - # Ensure that the manifest exists if it's going to be committed. - manifest = joinpath(pkg_dir, "Manifest.toml") - if p.manifest && !isfile(manifest) - touch(manifest) - with_project(Pkg.update, pkg_dir) - end - - LibGit2.with(GitRepo(pkg_dir)) do repo - LibGit2.add!(repo, ".") - msg = "Files generated by PkgTemplates" - installed = Pkg.installed() - if haskey(installed, "PkgTemplates") - ver = string(installed["PkgTemplates"]) - msg *= "\n\nPkgTemplates version: $ver" - end - commit(p, repo, pkg_dir, msg) - end -end - -function commit(p::Git, repo::GitRepo, pkg_dir::AbstractString, msg::AbstractString) - if p.gpgsign - run(pipeline(`git -C $pkg_dir commit -S --allow-empty -m $msg`; stdout=devnull)) - else - LibGit2.commit(repo, msg) - end -end - -function render_plugin(p::Git, t::Template) - ignore = mapreduce(gitignore, append!, values(t.plugins)) - # Only ignore manifests at the repo root. - p.manifest || "Manifest.toml" in ignore || push!(ignore, "/Manifest.toml") - unique!(sort!(ignore)) - return join(ignore, "\n") -end - -""" - Tests(; file="$(contractuser(default_file("test", "runtests.jl")))", project=false) - -Sets up testing for packages. - -## Keyword Arguments -- `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 - file::String = default_file("test", "runtests.jl") - project::Bool = false -end - -source(p::Tests) = p.file -destination(::Tests) = joinpath("test", "runtests.jl") -view(::Tests, ::Template, pkg::AbstractString) = Dict("PKG" => pkg) - -function prehook(p::Tests, t::Template, pkg_dir::AbstractString) - invoke(prehook, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) - p.project && t.julia_version < v"1.2" && @warn string( - "Tests: The project option is set to create a project (supported in Julia 1.2 and later) ", - "but a Julia version older than 1.2 is supported by the Template.", - ) -end - - -function hook(p::Tests, t::Template, pkg_dir::AbstractString) - # Do the normal BasicPlugin behaviour to create the test script. - invoke(hook, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) - - # 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") - toml = TOML.parsefile(path) - get!(toml, "extras", Dict())["Test"] = TEST_UUID - get!(toml, "targets", Dict())["test"] = ["Test"] - open(io -> TOML.print(io, toml), path, "w") - - # Generate the manifest by updating the project. - # 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. - with_project(Pkg.update, pkg_dir) -end diff --git a/src/plugins/git.jl b/src/plugins/git.jl new file mode 100644 index 00000000..8126944d --- /dev/null +++ b/src/plugins/git.jl @@ -0,0 +1,87 @@ +""" + Git(; ignore=String[], ssh=false, manifest=false, gpgsign=false) + +Creates a Git repository and a `.gitignore` file. + +## Keyword Arguments +- `ignore::Vector{<:AbstractString}`: Patterns to add to the `.gitignore`. + See also: [`gitignore`](@ref). +- `manifest::Bool`: Whether or not to commit `Manifest.toml`. +- `ssh::Bool`: Whether or not to use SSH for the remote. + If left unset, HTTPS is used. +- `gpgsign::Bool`: Whether or not to sign commits with your GPG key. + This option requires that the Git CLI is installed. +""" +@with_kw_noshow struct Git <: Plugin + ignore::Vector{String} = [] + ssh::Bool = false + manifest::Bool = false + gpgsign::Bool = false + ignore_manifest::Bool = true +end + +Base.:(==)(a::Git, b::Git) = all(map(n -> getfield(a, n) == getfield(b, n), fieldnames(Git))) + +function gitignore(p::Git) + ignore = copy(p.ignore) + p.manifest || push!(ignore, "Manifest.toml") + return ignore +end + +# Set up the Git repository. +function prehook(p::Git, t::Template, pkg_dir::AbstractString) + if p.gpgsign && try run(pipeline(`git --version`; stdout=devnull)); false catch; true end + throw(ArgumentError("Git: gpgsign is set but the Git CLI is not installed")) + end + LibGit2.with(LibGit2.init(pkg_dir)) do repo + commit(p, repo, pkg_dir, "Initial commit") + pkg = basename(pkg_dir) + url = if p.ssh + "git@$(t.host):$(t.user)/$pkg.jl.git" + else + "https://$(t.host)/$(t.user)/$pkg.jl" + end + LibGit2.with(GitRemote(repo, "origin", url)) do remote + # TODO: `git pull` still requires some Git branch config. + LibGit2.add_push!(repo, remote, "refs/heads/master") + end + end +end + +# Create the .gitignore. +function hook(p::Git, t::Template, pkg_dir::AbstractString) + ignore = mapreduce(gitignore, append!, values(t.plugins)) + # Only ignore manifests at the repo root. + p.manifest || "Manifest.toml" in ignore || push!(ignore, "/Manifest.toml") + unique!(sort!(ignore)) + gen_file(joinpath(pkg_dir, ".gitignore"), join(ignore, "\n")) +end + +# Commit the files +function posthook(p::Git, t::Template, pkg_dir::AbstractString) + # Ensure that the manifest exists if it's going to be committed. + manifest = joinpath(pkg_dir, "Manifest.toml") + if p.manifest && !isfile(manifest) + touch(manifest) + with_project(Pkg.update, pkg_dir) + end + + LibGit2.with(GitRepo(pkg_dir)) do repo + LibGit2.add!(repo, ".") + msg = "Files generated by PkgTemplates" + installed = Pkg.installed() + if haskey(installed, "PkgTemplates") + ver = string(installed["PkgTemplates"]) + msg *= "\n\nPkgTemplates version: $ver" + end + commit(p, repo, pkg_dir, msg) + end +end + +function commit(p::Git, repo::GitRepo, pkg_dir::AbstractString, msg::AbstractString) + if p.gpgsign + run(pipeline(`git -C $pkg_dir commit -S --allow-empty -m $msg`; stdout=devnull)) + else + LibGit2.commit(repo, msg) + end +end diff --git a/src/plugins/license.jl b/src/plugins/license.jl new file mode 100644 index 00000000..f6bf72ca --- /dev/null +++ b/src/plugins/license.jl @@ -0,0 +1,37 @@ +""" + License(; name="MIT", path=nothing, destination="LICENSE") + +Creates a license file. + +## Keyword Arguments +- `name::AbstractString`: Name of a license supported by PkgTemplates. + Available licenses can be seen [here](https://github.com/invenia/PkgTemplates.jl/tree/master/templates/licenses). +- `path::Union{AbstractString, Nothing}`: Path to a custom license file. + This keyword takes priority over `name`. +- `destination::AbstractString`: File destination, relative to the repository root. + For example, `"LICENSE.md"` might be desired. +""" +struct License <: BasicPlugin + path::String + destination::String +end + +function License( + name::AbstractString="MIT", + path::Union{AbstractString, Nothing}=nothing, + destination::AbstractString="LICENSE", +) + if path === nothing + path = default_file("licenses", name) + isfile(path) || throw(ArgumentError("License '$(basename(path))' is not available")) + end + return License(path, destination) +end + + +source(p::License) = p.path +destination(p::License) = p.destination +view(::License, t::Template, ::AbstractString) = Dict( + "AUTHORS" => join(t.authors, ", "), + "YEAR" => year(today()), +) diff --git a/src/plugins/project_file.jl b/src/plugins/project_file.jl new file mode 100644 index 00000000..68c3651e --- /dev/null +++ b/src/plugins/project_file.jl @@ -0,0 +1,33 @@ +""" + ProjectFile() + +Creates a `Project.toml`. +""" +struct ProjectFile <: Plugin end + +# Create Project.toml in the prehook because other hooks might depend on it. +function prehook(::ProjectFile, t::Template, pkg_dir::AbstractString) + toml = Dict( + "name" => basename(pkg_dir), + "uuid" => uuid4(), + "authors" => t.authors, + "version" => "0.1.0", + "compat" => Dict("julia" => compat_version(t.julia_version)), + ) + open(io -> TOML.print(io, toml), joinpath(pkg_dir, "Project.toml"), "w") +end + +""" + compat_version(v::VersionNumber) -> String + +Format a `VersionNumber` to exclude trailing zero components. +""" +function compat_version(v::VersionNumber) + return if v.patch == 0 && v.minor == 0 + "$(v.major)" + elseif v.patch == 0 + "$(v.major).$(v.minor)" + else + "$(v.major).$(v.minor).$(v.patch)" + end +end diff --git a/src/plugins/readme.jl b/src/plugins/readme.jl new file mode 100644 index 00000000..8e166763 --- /dev/null +++ b/src/plugins/readme.jl @@ -0,0 +1,59 @@ +""" + Readme(; + file="$(contractuser(default_file("README.md")))", + destination="README.md", + inline_badges=false, + ) + +Creates a `README` file. +By default, it includes badges for other included plugins + +## Keyword Arguments +- `file::AbstractString`: Template file for the `README`. +- `destination::AbstractString`: File destination, relative to the repository root. + For example, values of `"README"` or `"README.rst"` might be desired. +- `inline_badges::Bool`: Whether or not to put the badges on the same line as the package name. +""" +@with_kw_noshow struct Readme <: BasicPlugin + file::String = default_file("README.md") + destination::String = "README.md" + inline_badges::Bool = false +end + +source(p::Readme) = p.file +destination(p::Readme) = p.destination + +function view(p::Readme, t::Template, pkg::AbstractString) + # Explicitly ordered badges go first. + strings = String[] + done = DataType[] + foreach(badge_order()) do T + if hasplugin(t, T) + bs = badges(t.plugins[T], t, pkg) + append!(strings, badges(t.plugins[T], t, pkg)) + push!(done, T) + end + end + foreach(setdiff(keys(t.plugins), done)) do T + bs = badges(t.plugins[T], t, pkg) + append!(strings, badges(t.plugins[T], t, pkg)) + end + + return Dict( + "BADGES" => strings, + "HAS_CITATION" => hasplugin(t, Citation) && t.plugins[Citation].readme, + "HAS_INLINE_BADGES" => !isempty(strings) && p.inline_badges, + "PKG" => pkg, + ) +end + +badge_order() = [ + Documenter{GitLabCI}, + Documenter{TravisCI}, + GitLabCI, + TravisCI, + AppVeyor, + CirrusCI, + Codecov, + Coveralls, +] diff --git a/src/plugins/src_dir.jl b/src/plugins/src_dir.jl new file mode 100644 index 00000000..fbbdad37 --- /dev/null +++ b/src/plugins/src_dir.jl @@ -0,0 +1,29 @@ +""" + SrcDir(; file="$(contractuser(default_file("src", "module.jl")))") + +Creates a module entrypoint. +""" +@with_kw_noshow mutable struct SrcDir <: BasicPlugin + file::String = default_file("src", "module.jl") + destination::String = joinpath("src", ".jl") +end + +Base.:(==)(a::SrcDir, b::SrcDir) = a.file == b.file + +# Don't display the destination field. +function Base.show(io::IO, ::MIME"text/plain", p::SrcDir) + indent = get(io, :indent, 0) + print(io, repeat(' ', indent), "SrcDir:") + print(io, "\n", repeat(' ', indent + 2), "file: ", show_field(p.file)) +end + +source(p::SrcDir) = p.file +destination(p::SrcDir) = p.destination +view(::SrcDir, ::Template, pkg::AbstractString) = Dict("PKG" => pkg) + +# Update the destination now that we know the package name. +# Kind of hacky, but oh well. +function prehook(p::SrcDir, t::Template, pkg_dir::AbstractString) + invoke(prehook, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) + p.destination = joinpath("src", basename(pkg_dir) * ".jl") +end diff --git a/src/plugins/tests.jl b/src/plugins/tests.jl new file mode 100644 index 00000000..156cebdb --- /dev/null +++ b/src/plugins/tests.jl @@ -0,0 +1,62 @@ +const TEST_UUID = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +const TEST_DEP = PackageSpec(; name="Test", uuid=TEST_UUID) + +""" + Tests(; file="$(contractuser(default_file("test", "runtests.jl")))", project=false) + +Sets up testing for packages. + +## Keyword Arguments +- `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 + file::String = default_file("test", "runtests.jl") + project::Bool = false +end + +source(p::Tests) = p.file +destination(::Tests) = joinpath("test", "runtests.jl") +view(::Tests, ::Template, pkg::AbstractString) = Dict("PKG" => pkg) + +function prehook(p::Tests, t::Template, pkg_dir::AbstractString) + invoke(prehook, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) + p.project && t.julia_version < v"1.2" && @warn string( + "Tests: The project option is set to create a project (supported in Julia 1.2 and later) ", + "but a Julia version older than 1.2 is supported by the Template.", + ) +end + + +function hook(p::Tests, t::Template, pkg_dir::AbstractString) + # Do the normal BasicPlugin behaviour to create the test script. + invoke(hook, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) + + # 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") + toml = TOML.parsefile(path) + get!(toml, "extras", Dict())["Test"] = TEST_UUID + get!(toml, "targets", Dict())["test"] = ["Test"] + open(io -> TOML.print(io, toml), path, "w") + + # Generate the manifest by updating the project. + # 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. + with_project(Pkg.update, pkg_dir) +end diff --git a/test/fixtures/AllPlugins/.gitignore b/test/fixtures/AllPlugins/.gitignore index f1338cfb..0cdd26b9 100644 --- a/test/fixtures/AllPlugins/.gitignore +++ b/test/fixtures/AllPlugins/.gitignore @@ -1,7 +1,6 @@ *.jl.*.cov *.jl.cov *.jl.mem -.DS_Store -/dev/ /docs/build/ /docs/site/ +Manifest.toml diff --git a/test/fixtures/AllPlugins/src/AllPlugins.jl b/test/fixtures/AllPlugins/src/AllPlugins.jl index 44ba550a..41b2489c 100644 --- a/test/fixtures/AllPlugins/src/AllPlugins.jl +++ b/test/fixtures/AllPlugins/src/AllPlugins.jl @@ -1,5 +1,5 @@ module AllPlugins -greet() = print("Hello World!") +# Write your package code here. -end # module +end diff --git a/test/fixtures/Basic/.gitignore b/test/fixtures/Basic/.gitignore index 37719915..ba39cc53 100644 --- a/test/fixtures/Basic/.gitignore +++ b/test/fixtures/Basic/.gitignore @@ -1,2 +1 @@ -.DS_Store -/dev/ +Manifest.toml diff --git a/test/fixtures/Basic/src/Basic.jl b/test/fixtures/Basic/src/Basic.jl index 5c9a3d6f..42332aa3 100644 --- a/test/fixtures/Basic/src/Basic.jl +++ b/test/fixtures/Basic/src/Basic.jl @@ -1,5 +1,5 @@ module Basic -greet() = print("Hello World!") +# Write your package code here. -end # module +end diff --git a/test/git.jl b/test/git.jl index 4b149693..3840a66b 100644 --- a/test/git.jl +++ b/test/git.jl @@ -6,7 +6,7 @@ end @testset "Git repositories" begin @testset "Does not create Git repo" begin - t = tpl(; git=false) + t = tpl(; disable_defaults=[Git]) with_pkg(t) do pkg pkg_dir = joinpath(t.dir, pkg) @test !isdir(joinpath(pkg_dir, ".git")) @@ -14,7 +14,7 @@ end end @testset "Creates Git repo" begin - t = tpl(; git=true) + t = tpl(; plugins=[Git()]) with_pkg(t) do pkg pkg_dir = joinpath(t.dir, pkg) @test isdir(joinpath(pkg_dir, ".git")) @@ -22,7 +22,7 @@ end end @testset "With HTTPS" begin - t = tpl(; git=true, ssh=false) + t = tpl(; plugins=[Git(; ssh=false)]) with_pkg(t) do pkg LibGit2.with(GitRepo(joinpath(t.dir, pkg))) do repo remote = LibGit2.get(GitRemote, repo, "origin") @@ -32,7 +32,7 @@ end end @testset "With SSH" begin - t = tpl(; git=true, ssh=true) + t = tpl(; plugins=[Git(; ssh=true)]) with_pkg(t) do pkg LibGit2.with(GitRepo(joinpath(t.dir, pkg))) do repo remote = LibGit2.get(GitRemote, repo, "origin") @@ -43,7 +43,7 @@ end @testset "Adds version to commit message" begin # We're careful to avoid a Pkg.update as it triggers Cassette#130. - t = tpl(; git=true, develop=false, disable_defaults=[Tests]) + t = tpl(; disable_defaults=[Tests], plugins=[Git()]) @overdub PTIsInstalled() with_pkg(t) do pkg pkg_dir = joinpath(t.dir, pkg) LibGit2.with(GitRepo(pkg_dir)) do repo diff --git a/test/reference.jl b/test/reference.jl index 305c1408..325a1768 100644 --- a/test/reference.jl +++ b/test/reference.jl @@ -23,8 +23,12 @@ end @testset "All plugins" begin test_all("AllPlugins"; authors=USER, manifest=true, plugins=[ - AppVeyor(), CirrusCI(), Citation(), Codecov(), - Coveralls(), Documenter(), GitLabCI(), TravisCI(), + AppVeyor(), CirrusCI(), Citation(), Codecov(), Coveralls(), + Develop(), Documenter(), GitLabCI(), TravisCI(), ]) end + + @testset "Wacky options" begin + # TODO + end end diff --git a/test/runtests.jl b/test/runtests.jl index 0f3dfec1..81997d50 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -19,10 +19,10 @@ Random.seed!(1) # Creata a template that won't error because of a missing username. tpl(; kwargs...) = Template(; user=USER, kwargs...) -const pkg_name = Ref("A") +const PKG = Ref("A") # Generate an unused package name. -pkgname() = pkg_name[] *= "a" +pkgname() = PKG[] *= "a" # Create a randomly named package with a template, and delete it afterwards. function with_pkg(f::Function, t::Template, pkg::AbstractString=pkgname()) diff --git a/test/show.jl b/test/show.jl index 324c1adf..044cd8c5 100644 --- a/test/show.jl +++ b/test/show.jl @@ -1,11 +1,11 @@ -const DEFAULTS_DIR = contractuser(PT.DEFAULTS_DIR) -const LICENSE_DIR = contractuser(joinpath(PT.DEFAULTS_DIR, "licenses")) +const TEMPLATES_DIR = contractuser(PT.TEMPLATES_DIR) +const LICENSES_DIR = joinpath(TEMPLATES_DIR, "licenses") @testset "Show methods" begin @testset "Plugins" begin expected = """ Readme: - file: "$(joinpath(DEFAULTS_DIR, "README.md"))" + file: "$(joinpath(TEMPLATES_DIR, "README.md"))" destination: "README.md" inline_badges: false """ @@ -13,30 +13,41 @@ const LICENSE_DIR = contractuser(joinpath(PT.DEFAULTS_DIR, "licenses")) end @testset "Template" begin + expected = """ + Template: + authors: ["Chris de Graaf "] + dir: "~/.local/share/julia/dev" + host: "github.com" + julia_version: v"1.0.0" + user: "$USER" + plugins: + """ expected = """ Template: authors: ["$USER"] - develop: true dir: "$(contractuser(Pkg.devdir()))" - git: true host: "github.com" julia_version: v"1.0.0" - manifest: false - ssh: false user: "$USER" plugins: - Gitignore: - ds_store: true - dev: true + Git: + ignore: String[] + ssh: false + manifest: false + gpgsign: false + ignore_manifest: true License: - path: "$(joinpath(LICENSE_DIR, "MIT"))" + path: "$(joinpath(LICENSES_DIR, "MIT"))" destination: "LICENSE" + ProjectFile: Readme: - file: "$(joinpath(DEFAULTS_DIR, "README.md"))" + file: "$(joinpath(TEMPLATES_DIR, "README.md"))" destination: "README.md" inline_badges: false + SrcDir: + file: "$(joinpath(TEMPLATES_DIR, "src", "module.jl"))" Tests: - file: "$(joinpath(DEFAULTS_DIR, "test", "runtests.jl"))" + file: "$(joinpath(TEMPLATES_DIR, "test", "runtests.jl"))" project: false """ @test sprint(show, MIME("text/plain"), tpl(; authors=USER)) == rstrip(expected) diff --git a/test/template.jl b/test/template.jl index 8ddf5d72..a91589f4 100644 --- a/test/template.jl +++ b/test/template.jl @@ -35,10 +35,11 @@ test_plugins([], defaults) test_plugins([Citation()], union(defaults, [Citation()])) # Overriding a default plugin. - gi = Gitignore(; dev=false) - test_plugins([gi], union(setdiff(defaults, [Gitignore()]), [gi])) + default_g = defaults[findfirst(p -> p isa Git, defaults)] + g = Git(; ssh=true) + test_plugins([g], union(setdiff(defaults, [default_g]), [g])) # Disabling a default plugin. - test_plugins([], setdiff(defaults, [Gitignore()]), [Gitignore]) + test_plugins([], setdiff(defaults, [default_g]), [Git]) end end From 980452fde3d6180819ce59d856297812a507bc5b Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Fri, 20 Sep 2019 01:14:57 +0700 Subject: [PATCH 34/81] Tweak docs --- docs/src/developer.md | 6 +++++- src/plugin.jl | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/src/developer.md b/docs/src/developer.md index 7e074566..87853ed3 100644 --- a/docs/src/developer.md +++ b/docs/src/developer.md @@ -93,8 +93,12 @@ view Finally, we implement [`hook`](@ref), which is the real workhorse for the plugin. +TODO prehook and posthook in examples + ```@docs +prehook hook +posthook ``` Inside of this function, we call a few more functions, which help us with text templating. @@ -107,7 +111,7 @@ combined_view tags ``` -todo more +TODO more ## `BasicPlugin` Walkthrough diff --git a/src/plugin.jl b/src/plugin.jl index 9bb7f221..06ba8270 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -63,7 +63,7 @@ tags(::Plugin) = "{{", "}}" gitignore(::Plugin) -> Vector{String} Return patterns that should be added to `.gitignore`. -These are used by the [`Gitignore`](@ref) plugin. +These are used by the [`Git`](@ref) plugin. By default, an empty list is returned. """ @@ -128,6 +128,10 @@ end Do some work associated with a plugin **before** any files are generated. At this point, `pkg_dir` is an empty directory that will eventually contain the package. + +!!! note + `pkg_dir` only stays empty until the first plugin chooses to create a file. + Don't count on the order in which the plugins are sorted! """ prehook(::Plugin, ::Template, ::AbstractString) = nothing @@ -140,7 +144,7 @@ end """ posthook(::Plugin, ::Template, pkg_dir::AbstractString) -Do some work associated with a plugin **after** after files have been generated. +Do some work associated with a plugin **after** files have been generated. """ posthook(::Plugin, ::Template, ::AbstractString) = nothing From 0cf6d47ada51c6c1c725921114abb9efea021da7 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Fri, 20 Sep 2019 09:31:56 +0700 Subject: [PATCH 35/81] Add execution priority to plugins --- README.md | 3 +- docs/src/developer.md | 1 + src/interactive.jl | 8 ++++-- src/plugin.jl | 11 +++++++- src/plugins/ci.jl | 8 +++--- src/plugins/coverage.jl | 8 +++--- src/plugins/git.jl | 2 +- src/plugins/project_file.jl | 6 ++-- src/plugins/readme.jl | 11 ++++---- src/template.jl | 55 +++++++++++++++++++++---------------- test/show.jl | 2 +- test/template.jl | 2 +- 12 files changed, 68 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 26ab9b1d..f4d0acf0 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,8 @@ However, it's probably desirable to customize the template to your liking with v ```jl t = Template(; dir="~/code", - ssh=true, - manifest=true, plugins=[ + Git(; manifest=true, ssh=true), Codecov(), TravisCI(; x86=true), Documenter{TravisCI}(), diff --git a/docs/src/developer.md b/docs/src/developer.md index 87853ed3..ca3fbaa3 100644 --- a/docs/src/developer.md +++ b/docs/src/developer.md @@ -94,6 +94,7 @@ view Finally, we implement [`hook`](@ref), which is the real workhorse for the plugin. TODO prehook and posthook in examples +TODO priority ```@docs prehook diff --git a/src/interactive.jl b/src/interactive.jl index 9b343567..2da39cfb 100644 --- a/src/interactive.jl +++ b/src/interactive.jl @@ -5,8 +5,10 @@ function Base.show(io::IO, ::MIME"text/plain", p::T) where T <: Plugin indent = get(io, :indent, 0) - print(io, repeat(' ', indent), T, ":") - foreach(fieldnames(T)) do n + print(io, repeat(' ', indent), T) + ns = fieldnames(T) + isempty(ns) || print(io, ":") + foreach(ns) do n println(io) print(io, repeat(' ', indent + 2), n, ": ", show_field(getfield(p, n))) end @@ -28,7 +30,7 @@ function Base.show(io::IO, m::MIME"text/plain", t::Template) print(io, " plugins: None") else print(io, repeat(' ', 2), "plugins:") - foreach(sort(collect(values(t.plugins)); by=string)) do p + foreach(sort(t.plugins; by=string)) do p println(io) show(IOContext(io, :indent => 4), m, p) end diff --git a/src/plugin.jl b/src/plugin.jl index 06ba8270..c5846498 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -1,4 +1,5 @@ const TEMPLATES_DIR = normpath(joinpath(@__DIR__, "..", "templates")) +const DEFAULT_PRIORITY = 1000 """ A simple plugin that, in general, creates a single file. @@ -59,6 +60,14 @@ By default, the tags are `"{{"` and `"}}"`. """ tags(::Plugin) = "{{", "}}" +""" + priority(::Plugin) -> Int + +Determines the order in which plugins are processed (higher goes first). +The default priority (`DEFAULT_PRIORITY`), is `$DEFAULT_PRIORITY`. +""" +priority(::Plugin) = DEFAULT_PRIORITY + """ gitignore(::Plugin) -> Vector{String} @@ -131,7 +140,7 @@ At this point, `pkg_dir` is an empty directory that will eventually contain the !!! note `pkg_dir` only stays empty until the first plugin chooses to create a file. - Don't count on the order in which the plugins are sorted! + See also: [`priority`](@ref). """ prehook(::Plugin, ::Template, ::AbstractString) = nothing diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index be82caea..1228ee83 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -254,10 +254,10 @@ end """ - is_ci(::Type{T}) -> Bool + is_ci(::Plugin) -> Bool -Determine whether or not `T` is a CI plugin. +Determine whether or not a plugin is a CI plugin. If you are adding a CI plugin, you should implement this function and return `true`. """ -is_ci(::Type) = false -is_ci(::Type{<:Union{AppVeyor, TravisCI, CirrusCI, GitLabCI}}) = true +is_ci(::Plugin) = false +is_ci(::Union{AppVeyor, TravisCI, CirrusCI, GitLabCI}) = true diff --git a/src/plugins/coverage.jl b/src/plugins/coverage.jl index 359c312d..358ab244 100644 --- a/src/plugins/coverage.jl +++ b/src/plugins/coverage.jl @@ -45,10 +45,10 @@ badges(::Coveralls) = Badge( gitignore(::Union{Codecov, Coveralls}) = COVERAGE_GITIGNORE """ - is_coverage(::Type{T}) -> Bool + is_coverage(::Plugin) -> Bool -Determine whether or not `T` is a coverage plugin. +Determine whether or not a plugin is a coverage plugin. If you are adding a coverage plugin, you should implement this function and return `true`. """ -is_coverage(::Type) = false -is_coverage(::Type{<:Union{Codecov, Coveralls}}) = true +is_coverage(::Plugin) = false +is_coverage(::Union{Codecov, Coveralls}) = true diff --git a/src/plugins/git.jl b/src/plugins/git.jl index 8126944d..fa867b37 100644 --- a/src/plugins/git.jl +++ b/src/plugins/git.jl @@ -50,7 +50,7 @@ end # Create the .gitignore. function hook(p::Git, t::Template, pkg_dir::AbstractString) - ignore = mapreduce(gitignore, append!, values(t.plugins)) + ignore = mapreduce(gitignore, append!, t.plugins) # Only ignore manifests at the repo root. p.manifest || "Manifest.toml" in ignore || push!(ignore, "/Manifest.toml") unique!(sort!(ignore)) diff --git a/src/plugins/project_file.jl b/src/plugins/project_file.jl index 68c3651e..a8cdf5a3 100644 --- a/src/plugins/project_file.jl +++ b/src/plugins/project_file.jl @@ -5,8 +5,10 @@ Creates a `Project.toml`. """ struct ProjectFile <: Plugin end -# Create Project.toml in the prehook because other hooks might depend on it. -function prehook(::ProjectFile, t::Template, pkg_dir::AbstractString) +# Other plugins like Tests will modify this file. +priority(::ProjectFile) = typemax(Int) - DEFAULT_PRIORITY + 1 + +function hook(::ProjectFile, t::Template, pkg_dir::AbstractString) toml = Dict( "name" => basename(pkg_dir), "uuid" => uuid4(), diff --git a/src/plugins/readme.jl b/src/plugins/readme.jl index 8e166763..d4aca5b9 100644 --- a/src/plugins/readme.jl +++ b/src/plugins/readme.jl @@ -29,19 +29,18 @@ function view(p::Readme, t::Template, pkg::AbstractString) done = DataType[] foreach(badge_order()) do T if hasplugin(t, T) - bs = badges(t.plugins[T], t, pkg) - append!(strings, badges(t.plugins[T], t, pkg)) + append!(strings, badges(getplugin(t, T), t, pkg)) push!(done, T) end end - foreach(setdiff(keys(t.plugins), done)) do T - bs = badges(t.plugins[T], t, pkg) - append!(strings, badges(t.plugins[T], t, pkg)) + # And the rest go after, in no particular order. + foreach(setdiff(map(typeof, t.plugins), done)) do T + append!(strings, badges(getplugin(t, T), t, pkg)) end return Dict( "BADGES" => strings, - "HAS_CITATION" => hasplugin(t, Citation) && t.plugins[Citation].readme, + "HAS_CITATION" => hasplugin(t, Citation) && getplugin(t, Citation).readme, "HAS_INLINE_BADGES" => !isempty(strings) && p.inline_badges, "PKG" => pkg, ) diff --git a/src/template.jl b/src/template.jl index aeb888dd..77d5b028 100644 --- a/src/template.jl +++ b/src/template.jl @@ -54,7 +54,7 @@ struct Template dir::String host::String julia_version::VersionNumber - plugins::Dict{DataType, <:Plugin} + plugins::Vector{<:Plugin} user::String end @@ -72,33 +72,17 @@ function Template(::Val{false}; kwargs...) host = replace(getkw(kwargs, :host), r".*://" => "") julia_version = getkw(kwargs, :julia_version) + # User-supplied plugins come first, so that deduping the list will remove the defaults. + plugins = Plugin[] + append!(plugins, getkw(kwargs, :plugins)) disabled = getkw(kwargs, :disable_defaults) - enabled = filter(p -> !(typeof(p) in disabled), default_plugins()) - append!(enabled, getkw(kwargs, :plugins)) - # This comprehension resolves duplicate plugin types by overwriting, - # which means that default plugins get replaced by user values. - plugins = Dict(typeof(p) => p for p in enabled) + append!(plugins, filter(p -> !(typeof(p) in disabled), default_plugins())) + plugins = unique(typeof, plugins) + sort!(plugins; by=priority, rev=true) return Template(authors, dir, host, julia_version, plugins, user) end -# Does the template have a plugin that satisfies some predicate? -hasplugin(t::Template, f::Function) = any(f, keys(t.plugins)) -hasplugin(t::Template, ::Type{T}) where T <: Plugin = hasplugin(t, U -> U <: T) - -# Get a keyword, or compute some default value. -getkw(kwargs, k) = get(() -> defaultkw(k), kwargs, k) - -# Default Template keyword values. -defaultkw(s::Symbol) = defaultkw(Val(s)) -defaultkw(::Val{:authors}) = default_authors() -defaultkw(::Val{:dir}) = Pkg.devdir() -defaultkw(::Val{:disable_defaults}) = DataType[] -defaultkw(::Val{:host}) = "github.com" -defaultkw(::Val{:julia_version}) = default_version() -defaultkw(::Val{:plugins}) = Plugin[] -defaultkw(::Val{:user}) = default_user() - """ (::Template)(pkg::AbstractString) @@ -113,7 +97,7 @@ function (t::Template)(pkg::AbstractString) try foreach((prehook, hook, posthook)) do h @info "Running $(h)s" - foreach(values(t.plugins)) do p + foreach(t.plugins) do p h(p, t, pkg_dir) end end @@ -124,3 +108,26 @@ function (t::Template)(pkg::AbstractString) @info "New package is at $pkg_dir" end + +# Does the template have a plugin that satisfies some predicate? +hasplugin(t::Template, f::Function) = any(f, t.plugins) +hasplugin(t::Template, ::Type{T}) where T <: Plugin = hasplugin(t, p -> p isa T) + +# Get a plugin by type. +function getplugin(t::Template, ::Type{T}) where T <: Plugin + i = findfirst(p -> p isa T, t.plugins) + i === nothing ? nothing : t.plugins[i] +end + +# Get a keyword, or compute some default value. +getkw(kwargs, k) = get(() -> defaultkw(k), kwargs, k) + +# Default Template keyword values. +defaultkw(s::Symbol) = defaultkw(Val(s)) +defaultkw(::Val{:authors}) = default_authors() +defaultkw(::Val{:dir}) = Pkg.devdir() +defaultkw(::Val{:disable_defaults}) = DataType[] +defaultkw(::Val{:host}) = "github.com" +defaultkw(::Val{:julia_version}) = default_version() +defaultkw(::Val{:plugins}) = Plugin[] +defaultkw(::Val{:user}) = default_user() diff --git a/test/show.jl b/test/show.jl index 044cd8c5..bbd7cd33 100644 --- a/test/show.jl +++ b/test/show.jl @@ -39,7 +39,7 @@ const LICENSES_DIR = joinpath(TEMPLATES_DIR, "licenses") License: path: "$(joinpath(LICENSES_DIR, "MIT"))" destination: "LICENSE" - ProjectFile: + ProjectFile Readme: file: "$(joinpath(TEMPLATES_DIR, "README.md"))" destination: "README.md" diff --git a/test/template.jl b/test/template.jl index a91589f4..6fde029d 100644 --- a/test/template.jl +++ b/test/template.jl @@ -28,7 +28,7 @@ @testset "plugins / disabled_defaults" begin function test_plugins(plugins, expected, disabled=DataType[]) t = tpl(; plugins=plugins, disable_defaults=disabled) - @test issetequal(values(t.plugins), expected) + @test issetequal(t.plugins, expected) end defaults = PT.default_plugins() From 89e0ed5356389482ab760a07cd273dc88c9c1e23 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Fri, 20 Sep 2019 10:23:56 +0700 Subject: [PATCH 36/81] Fixes for 1.0 --- src/plugins/project_file.jl | 2 +- src/template.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/project_file.jl b/src/plugins/project_file.jl index a8cdf5a3..ab310d38 100644 --- a/src/plugins/project_file.jl +++ b/src/plugins/project_file.jl @@ -11,7 +11,7 @@ priority(::ProjectFile) = typemax(Int) - DEFAULT_PRIORITY + 1 function hook(::ProjectFile, t::Template, pkg_dir::AbstractString) toml = Dict( "name" => basename(pkg_dir), - "uuid" => uuid4(), + "uuid" => string(uuid4()), "authors" => t.authors, "version" => "0.1.0", "compat" => Dict("julia" => compat_version(t.julia_version)), diff --git a/src/template.jl b/src/template.jl index 77d5b028..f88bd6b5 100644 --- a/src/template.jl +++ b/src/template.jl @@ -96,7 +96,7 @@ function (t::Template)(pkg::AbstractString) try foreach((prehook, hook, posthook)) do h - @info "Running $(h)s" + @info "Running $(nameof(h))s" foreach(t.plugins) do p h(p, t, pkg_dir) end From 6a49bd72f018018c7867c4126f106fa7fa8bce4d Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Fri, 20 Sep 2019 13:43:29 +0700 Subject: [PATCH 37/81] Fix some tests on 1.3+ --- test/template.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/template.jl b/test/template.jl index 6fde029d..ab39b2a5 100644 --- a/test/template.jl +++ b/test/template.jl @@ -28,7 +28,7 @@ @testset "plugins / disabled_defaults" begin function test_plugins(plugins, expected, disabled=DataType[]) t = tpl(; plugins=plugins, disable_defaults=disabled) - @test issetequal(t.plugins, expected) + @test all(map(==, sort(t.plugins; by=string), sort(expected; by=string))) end defaults = PT.default_plugins() From 63f1f762a6328380ca28c1e7560868291a15e1ca Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Tue, 24 Sep 2019 13:31:31 +0700 Subject: [PATCH 38/81] Fix some oversights --- src/plugins/git.jl | 1 - templates/docs/index.md | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/plugins/git.jl b/src/plugins/git.jl index fa867b37..92c58112 100644 --- a/src/plugins/git.jl +++ b/src/plugins/git.jl @@ -17,7 +17,6 @@ Creates a Git repository and a `.gitignore` file. ssh::Bool = false manifest::Bool = false gpgsign::Bool = false - ignore_manifest::Bool = true end Base.:(==)(a::Git, b::Git) = all(map(n -> getfield(a, n) == getfield(b, n), fieldnames(Git))) diff --git a/templates/docs/index.md b/templates/docs/index.md index 949e9c9c..602f9ac6 100644 --- a/templates/docs/index.md +++ b/templates/docs/index.md @@ -1,3 +1,7 @@ +```@meta +CurrentModule = {{{PKG}}} +``` + # {{{PKG}}} ```@index From 5e843dadbb437a471265fc43c68506d4a57ae479 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Tue, 24 Sep 2019 13:48:00 +0700 Subject: [PATCH 39/81] Replace Cassette mocking with SimpleMock FYI: CI should fail until SimpleMock is finished being registered. --- Project.toml | 4 ++-- test/git.jl | 18 +++++++----------- test/runtests.jl | 3 ++- test/template.jl | 10 +++------- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/Project.toml b/Project.toml index 339b5309..58aa3f7c 100644 --- a/Project.toml +++ b/Project.toml @@ -17,11 +17,11 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" julia = "1" [extras] -Cassette = "7057c7e9-c182-5462-911a-8362d720325c" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf" +SimpleMock = "a896ed2c-15a5-4479-b61d-a0e88e2a1d25" Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Cassette", "Suppressor", "Random", "ReferenceTests", "Test"] +test = ["Suppressor", "Random", "ReferenceTests", "SimpleMock", "Test"] diff --git a/test/git.jl b/test/git.jl index 3840a66b..5fc0c303 100644 --- a/test/git.jl +++ b/test/git.jl @@ -1,9 +1,3 @@ -@context PTIsInstalled -function Cassette.posthook(::PTIsInstalled, result::Dict, ::typeof(Pkg.installed)) - result["PkgTemplates"] = v"1.2.3" - return result -end - @testset "Git repositories" begin @testset "Does not create Git repo" begin t = tpl(; disable_defaults=[Git]) @@ -44,11 +38,13 @@ end @testset "Adds version to commit message" begin # We're careful to avoid a Pkg.update as it triggers Cassette#130. t = tpl(; disable_defaults=[Tests], plugins=[Git()]) - @overdub PTIsInstalled() with_pkg(t) do pkg - pkg_dir = joinpath(t.dir, pkg) - LibGit2.with(GitRepo(pkg_dir)) do repo - commit = GitCommit(repo, "HEAD") - @test occursin("PkgTemplates version: 1.2.3", LibGit2.message(commit)) + mock(CTX, Pkg.installed => () -> Dict("PkgTemplates" => v"1.2.3")) do _pi + with_pkg(t) do pkg + pkg_dir = joinpath(t.dir, pkg) + LibGit2.with(GitRepo(pkg_dir)) do repo + commit = GitCommit(repo, "HEAD") + @test occursin("PkgTemplates version: 1.2.3", LibGit2.message(commit)) + end end end end diff --git a/test/runtests.jl b/test/runtests.jl index 81997d50..2a5de84e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,8 +5,8 @@ using Pkg: Pkg using Random: Random using Test: @test, @testset, @test_throws -using Cassette: Cassette, @context, @overdub using ReferenceTests: @test_reference +using SimpleMock: Mock, mock using Suppressor: @suppress using PkgTemplates @@ -20,6 +20,7 @@ Random.seed!(1) tpl(; kwargs...) = Template(; user=USER, kwargs...) const PKG = Ref("A") +const CTX = gensym() # Generate an unused package name. pkgname() = PKG[] *= "a" diff --git a/test/template.jl b/test/template.jl index ab39b2a5..c13c3b35 100644 --- a/test/template.jl +++ b/test/template.jl @@ -54,12 +54,6 @@ end end -@context ErrorOnRepoInit -function Cassette.prehook(::ErrorOnRepoInit, ::typeof(LibGit2.init), pkg_dir) - @test isdir(pkg_dir) - error() -end - @testset "Package generation errors" begin mktempdir() do dir t = tpl(; dir=dirname(dir)) @@ -73,6 +67,8 @@ end t = tpl() pkg = pkgname() - @test_throws ErrorException @overdub ErrorOnRepoInit() @suppress t(pkg) + mock(CTX, LibGit2.init => dir -> (@test isdir(dir); error())) do _init + @test_throws ErrorException @suppress t(pkg) + end @test !isdir(joinpath(t.dir, pkg)) end From 6d95bf78a02f956184bd462d8c9540a24f6ebae2 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Tue, 24 Sep 2019 15:07:57 +0700 Subject: [PATCH 40/81] Enable priority per-hook --- src/plugin.jl | 6 ++++-- src/plugins/git.jl | 3 +++ src/plugins/project_file.jl | 2 +- src/template.jl | 5 ++--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/plugin.jl b/src/plugin.jl index c5846498..16543248 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -61,12 +61,14 @@ By default, the tags are `"{{"` and `"}}"`. tags(::Plugin) = "{{", "}}" """ - priority(::Plugin) -> Int + priority(::Plugin, ::Union{typeof(prehook), typeof(hook), typeof(posthook)}) -> Int Determines the order in which plugins are processed (higher goes first). The default priority (`DEFAULT_PRIORITY`), is `$DEFAULT_PRIORITY`. + +You can implement this function per-stage (by using `::typeof(hook)`, for example), or for all stages by simply using `::Function`. """ -priority(::Plugin) = DEFAULT_PRIORITY +priority(::Plugin, ::Function) = DEFAULT_PRIORITY """ gitignore(::Plugin) -> Vector{String} diff --git a/src/plugins/git.jl b/src/plugins/git.jl index 92c58112..d9d93e88 100644 --- a/src/plugins/git.jl +++ b/src/plugins/git.jl @@ -19,6 +19,9 @@ Creates a Git repository and a `.gitignore` file. gpgsign::Bool = false end +# Try to make sure that no files are created after we commit. +priority(::Git, ::typeof(posthook)) = 5 + Base.:(==)(a::Git, b::Git) = all(map(n -> getfield(a, n) == getfield(b, n), fieldnames(Git))) function gitignore(p::Git) diff --git a/src/plugins/project_file.jl b/src/plugins/project_file.jl index ab310d38..91714c0c 100644 --- a/src/plugins/project_file.jl +++ b/src/plugins/project_file.jl @@ -6,7 +6,7 @@ Creates a `Project.toml`. struct ProjectFile <: Plugin end # Other plugins like Tests will modify this file. -priority(::ProjectFile) = typemax(Int) - DEFAULT_PRIORITY + 1 +priority(::ProjectFile, ::typeof(hook)) = typemax(Int) - 5 function hook(::ProjectFile, t::Template, pkg_dir::AbstractString) toml = Dict( diff --git a/src/template.jl b/src/template.jl index f88bd6b5..84e9ee1b 100644 --- a/src/template.jl +++ b/src/template.jl @@ -77,8 +77,7 @@ function Template(::Val{false}; kwargs...) append!(plugins, getkw(kwargs, :plugins)) disabled = getkw(kwargs, :disable_defaults) append!(plugins, filter(p -> !(typeof(p) in disabled), default_plugins())) - plugins = unique(typeof, plugins) - sort!(plugins; by=priority, rev=true) + plugins = sort(unique(typeof, plugins); by=string) return Template(authors, dir, host, julia_version, plugins, user) end @@ -97,7 +96,7 @@ function (t::Template)(pkg::AbstractString) try foreach((prehook, hook, posthook)) do h @info "Running $(nameof(h))s" - foreach(t.plugins) do p + foreach(sort(t.plugins; by=p -> priority(p, h), rev=true)) do p h(p, t, pkg_dir) end end From d53fb0b1191c19ca71851c309deded3da59d8516 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Tue, 24 Sep 2019 15:34:24 +0700 Subject: [PATCH 41/81] More docs! --- docs/src/developer.md | 112 +++++++++++++++++++++++++++++++++++------- docs/src/index.md | 2 + src/plugins/git.jl | 5 +- 3 files changed, 98 insertions(+), 21 deletions(-) diff --git a/docs/src/developer.md b/docs/src/developer.md index ca3fbaa3..04b0b6a7 100644 --- a/docs/src/developer.md +++ b/docs/src/developer.md @@ -17,10 +17,47 @@ Plugin BasicPlugin ``` +## Package Generation Pipeline + +The package generation process looks basically like this: + +``` +- create directory for the package +- for each plugin, ordered by priority: + - run plugin prehook +- for each plugin, ordered by priority: + - run plugin hook +- for each plugin, ordered by priority: + - run plugin posthook +``` + +That's it! +As you can tell, plugins play a central role in setting up a package. + +The three main entrypoints for plugins to do work are the [`prehook`](@ref), the [`hook`](@ref), and the [`posthook`](@ref). +As the names might imply, they basically mean "before the main stage", "the main stage", and "after the main stage", respectively. + +Each stage is basically identical, since the functions take the exact same arguments. +However, the multiple stages allow us to depend on artifacts of the previous stages. +For example, the [`Git`](@ref) plugin uses [`posthook`](@ref) to commit all generated files, but it wouldn't make sense to do that before the files are generated. + +But what about dependencies within the same stage? +In this case, we have [`priority`](@ref) to define which plugins go when. +The [`Git`](@ref) plugin also uses this function to lower its priority, so that even if other plugins generate files in their posthooks, they still get committed. + +```@docs +prehook +hook +posthook +priority +``` + ## `Plugin` Walkthrough Concrete types that subtype [`Plugin`](@ref) directly are free to do almost anything. -To understand how they're implemented, let's look at a simplified version of [`Documenter`](@ref): +To understand how they're implemented, let's look at simplified versions of two plugins: [`Documenter`](@ref) to explore templating, and [`Git`](@ref) to further clarify the multi-stage pipeline. + +### Example: `Documenter` ```julia @with_kw_noshow struct Documenter <: Plugin @@ -85,6 +122,9 @@ badges Badge ``` +These two functions, [`gitignore`](@ref) and [`badges`](@ref), are currently the only "special" functions for cross-plugin interactions. +In other cases, you can still access the [`Template`](@ref)'s plugins to depend on the presence/properties of other plugins, although that's less powerful. + Third, we implement [`view`](@ref), which is used to fill placeholders in badges and rendered files. ```@docs @@ -92,17 +132,7 @@ view ``` Finally, we implement [`hook`](@ref), which is the real workhorse for the plugin. - -TODO prehook and posthook in examples -TODO priority - -```@docs -prehook -hook -posthook -``` - -Inside of this function, we call a few more functions, which help us with text templating. +Inside of this function, we generate a couple of files with the help of a few more text templating functions. ```@docs render_file @@ -112,10 +142,51 @@ combined_view tags ``` -TODO more +For more information on text templating, see the [`BasicPlugin` Walkthrough](@ref) and the section on [Custom Template Files](@ref). + +### Example: `Git` + +``` +struct Git <: Plugin end + +priority(::Git, ::typeof(posthook)) = 5 + +function prehook(::Git, t::Template, pkg_dir::AbstractString) + LibGit2.with(LibGit2.init(pkg_dir)) do repo + LibGit2.commit(repo, "Initial commit") + pkg = basename(pkg_dir) + url = "https://$(t.host)/$(t.user)/$pkg.jl" + close(GitRemote(repo, "origin", url)) + end +end + +function hook(::Git, t::Template, pkg_dir::AbstractString) + ignore = mapreduce(gitignore, append!, t.plugins) + unique!(sort!(ignore)) + gen_file(joinpath(pkg_dir, ".gitignore"), join(ignore, "\n")) +end + +function posthook(::Git, ::Template, pkg_dir::AbstractString) + LibGit2.with(GitRepo(pkg_dir)) do repo + LibGit2.add!(repo, ".") + LibGit2.commit(repo, "Files generated by PkgTemplates") + end +end +``` + +As previously mentioned, we use [`priority`](@ref) to make sure that we commit all generated files. + +Then, all three hooks are implemented: + +- [`prehook`](@ref) creates the Git repository for the package +- [`hook`](@ref) generates the `.gitignore` file, using the special [`gitignore`](@ref) function +- [`posthook`](@ref) adds and commits all generated files + +Hopefully, this demonstrates the level of control you have over the package generation process when developing plugins. ## `BasicPlugin` Walkthrough +Most of the time, you don't really need all of the control that we showed off above. Plugins that subtype [`BasicPlugin`](@ref) perform a much more limited task. In general, they just generate one templated file. @@ -156,13 +227,13 @@ We briefly saw this function earlier, but in this case it's necessary to change To see why, it might help to see the template file in its entirety: ``` -@misc{<>.jl, - author = {<>}, - title = {<>.jl}, - url = {<>}, +@misc{<<&PKG>>.jl, + author = {<<&AUTHORS>>}, + title = {<<&PKG>>.jl}, + url = {<<&URL>>}, version = {v0.1.0}, - year = {<>}, - month = {<>} + year = {<<&YEAR>>}, + month = {<<&MONTH>>} } ``` @@ -215,6 +286,9 @@ function hook(p::Tests, t::Template, pkg_dir::AbstractString) end ``` +There is also a default [`prehook`](@ref) implementation for [`BasicPlugin`](@ref)s, which checks that the plugin's [`source`](@ref) file exists, and throws an `ArgumentError` otherwise. +If you want to extend the prehook but keep the file existence check, use the `invoke` method as described above. + For more examples, see the plugins in the [Continuous Integration (CI)](@ref) and [Code Coverage](@ref) sections. ## Miscellaneous Tips diff --git a/docs/src/index.md b/docs/src/index.md index 9b996991..54238d68 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -13,6 +13,8 @@ But it also refers to "template files" and "text templating", which are plaintex These concepts should be familiar if you've used [Jinja](https://palletsprojects.com/p/jinja) or [Mustache](https://mustache.github.io) (Mustache is the particular flavour used by PkgTemplates, via [Mustache.jl](https://github.com/jverzani/Mustache.jl)). +Please keep the difference between these two things in mind when reading this documentation! + ### Documentation If you're looking to **create new packages**, see the [User Guide](user.md). diff --git a/src/plugins/git.jl b/src/plugins/git.jl index d9d93e88..ba1b3e29 100644 --- a/src/plugins/git.jl +++ b/src/plugins/git.jl @@ -59,8 +59,8 @@ function hook(p::Git, t::Template, pkg_dir::AbstractString) gen_file(joinpath(pkg_dir, ".gitignore"), join(ignore, "\n")) end -# Commit the files -function posthook(p::Git, t::Template, pkg_dir::AbstractString) +# Commit the files. +function posthook(p::Git, ::Template, pkg_dir::AbstractString) # Ensure that the manifest exists if it's going to be committed. manifest = joinpath(pkg_dir, "Manifest.toml") if p.manifest && !isfile(manifest) @@ -71,6 +71,7 @@ function posthook(p::Git, t::Template, pkg_dir::AbstractString) LibGit2.with(GitRepo(pkg_dir)) do repo LibGit2.add!(repo, ".") msg = "Files generated by PkgTemplates" + # TODO: Newer versions of Julia will not have Pkg.installed. installed = Pkg.installed() if haskey(installed, "PkgTemplates") ver = string(installed["PkgTemplates"]) From a941b96e1d44949df942c79587dec2a01b733eac Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Tue, 24 Sep 2019 15:37:06 +0700 Subject: [PATCH 42/81] Fix some docs and comments --- src/plugins/git.jl | 2 +- src/template.jl | 1 - test/reference.jl | 2 -- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/plugins/git.jl b/src/plugins/git.jl index ba1b3e29..a94c855b 100644 --- a/src/plugins/git.jl +++ b/src/plugins/git.jl @@ -6,9 +6,9 @@ Creates a Git repository and a `.gitignore` file. ## Keyword Arguments - `ignore::Vector{<:AbstractString}`: Patterns to add to the `.gitignore`. See also: [`gitignore`](@ref). -- `manifest::Bool`: Whether or not to commit `Manifest.toml`. - `ssh::Bool`: Whether or not to use SSH for the remote. If left unset, HTTPS is used. +- `manifest::Bool`: Whether or not to commit `Manifest.toml`. - `gpgsign::Bool`: Whether or not to sign commits with your GPG key. This option requires that the Git CLI is installed. """ diff --git a/src/template.jl b/src/template.jl index 84e9ee1b..327a03dc 100644 --- a/src/template.jl +++ b/src/template.jl @@ -28,7 +28,6 @@ A configuration used to generate packages. - `dir::AbstractString="$(contractuser(Pkg.devdir()))"`: Directory to place packages in. - `host::AbstractString="github.com"`: URL to the code hosting service where packages will reside. - `julia_version::VersionNumber=$(repr(default_version()))`: Minimum allowed Julia version. -- `develop::Bool=true`: Whether or not to `develop` new packages in the active environment. ### Template Plugins - `plugins::Vector{<:Plugin}=Plugin[]`: A list of [`Plugin`](@ref)s used by the template. diff --git a/test/reference.jl b/test/reference.jl index 325a1768..942248ff 100644 --- a/test/reference.jl +++ b/test/reference.jl @@ -1,5 +1,3 @@ -# TODO: License fixtures need to be updated every year because they don't use Mustache. - function PT.user_view(::Citation, ::Template, ::AbstractString) return Dict("MONTH" => 8, "YEAR" => 2019) end From 57765374134abbedeeae073367759deaadc3fa65 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Tue, 24 Sep 2019 22:07:31 +0700 Subject: [PATCH 43/81] Minor bug/doc fixes --- docs/src/developer.md | 18 +++++----- src/plugin.jl | 42 +++++++++++----------- src/plugins/ci.jl | 2 +- src/plugins/citation.jl | 5 +-- src/template.jl | 1 - test/fixtures/AllPlugins/docs/src/index.md | 4 +++ test/git.jl | 2 +- test/runtests.jl | 1 - test/show.jl | 1 - test/template.jl | 2 +- 10 files changed, 37 insertions(+), 41 deletions(-) diff --git a/docs/src/developer.md b/docs/src/developer.md index 04b0b6a7..54bab832 100644 --- a/docs/src/developer.md +++ b/docs/src/developer.md @@ -22,7 +22,7 @@ BasicPlugin The package generation process looks basically like this: ``` -- create directory for the package +- create empty directory for the package - for each plugin, ordered by priority: - run plugin prehook - for each plugin, ordered by priority: @@ -43,7 +43,7 @@ For example, the [`Git`](@ref) plugin uses [`posthook`](@ref) to commit all gene But what about dependencies within the same stage? In this case, we have [`priority`](@ref) to define which plugins go when. -The [`Git`](@ref) plugin also uses this function to lower its priority, so that even if other plugins generate files in their posthooks, they still get committed. +The [`Git`](@ref) plugin also uses this function to lower its posthook's priority, so that even if other plugins generate files in their posthooks, they still get committed (provided that those plugins didn't set an even lower priority). ```@docs prehook @@ -146,7 +146,7 @@ For more information on text templating, see the [`BasicPlugin` Walkthrough](@re ### Example: `Git` -``` +```julia struct Git <: Plugin end priority(::Git, ::typeof(posthook)) = 5 @@ -174,15 +174,15 @@ function posthook(::Git, ::Template, pkg_dir::AbstractString) end ``` -As previously mentioned, we use [`priority`](@ref) to make sure that we commit all generated files. +All three hooks are implemented: -Then, all three hooks are implemented: +- [`prehook`](@ref) creates the Git repository for the package. +- [`hook`](@ref) generates the `.gitignore` file, using the special [`gitignore`](@ref) function. +- [`posthook`](@ref) adds and commits all the generated files. -- [`prehook`](@ref) creates the Git repository for the package -- [`hook`](@ref) generates the `.gitignore` file, using the special [`gitignore`](@ref) function -- [`posthook`](@ref) adds and commits all generated files +As previously mentioned, we use [`priority`](@ref) to make sure that we wait until all other plugins are finished their work before committing files. -Hopefully, this demonstrates the level of control you have over the package generation process when developing plugins. +Hopefully, this demonstrates the level of control you have over the package generation process when developing plugins, and when it makes sense to exercise that power! ## `BasicPlugin` Walkthrough diff --git a/src/plugin.jl b/src/plugin.jl index 16543248..f202a9d0 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -137,8 +137,8 @@ end """ prehook(::Plugin, ::Template, pkg_dir::AbstractString) -Do some work associated with a plugin **before** any files are generated. -At this point, `pkg_dir` is an empty directory that will eventually contain the package. +Stage 1 of the package generation process (the "before" stage, in general). +At this point, `pkg_dir` is an empty directory that will eventually contain the package, and neither the [`hook`](@ref)s nor the [`posthook`](@ref)s have run. !!! note `pkg_dir` only stays empty until the first plugin chooses to create a file. @@ -146,36 +146,34 @@ At this point, `pkg_dir` is an empty directory that will eventually contain the """ prehook(::Plugin, ::Template, ::AbstractString) = nothing -function prehook(p::T, ::Template, ::AbstractString) where T <: BasicPlugin - src = source(p) - src === nothing && return - isfile(src) || throw(ArgumentError("$(nameof(T)): The file $src does not exist")) -end - -""" - posthook(::Plugin, ::Template, pkg_dir::AbstractString) - -Do some work associated with a plugin **after** files have been generated. -""" -posthook(::Plugin, ::Template, ::AbstractString) = nothing - """ hook(::Plugin, ::Template, pkg_dir::AbstractString) -Perform any work associated with a plugin. -`pkg_dir` is the directory in which the package is being generated (so `basename(pkg_dir)` is the package name). - -For [`Plugin`](@ref)s that are not [`BasicPlugin`](@ref)s, this is the only function that really needs to be implemented. -If you want your plugin to do something during the main phase of package generation, you should implement it here. +Stage 2 of the package generation pipeline (the "main" stage, in general). +At this point, the [`prehook`](@ref)s have run, but not the [`posthook`](@ref)s. -See also: [`prehook`](@ref) and [`posthook`](@ref). +`pkg_dir` is the directory in which the package is being generated (so `basename(pkg_dir)` is the package name). !!! note You usually shouldn't implement this function for [`BasicPlugin`](@ref)s. - If you do, it should probably `invoke` the generic method (otherwise, there's no reason to subtype `BasicPlugin`). + If you do, it should probably `invoke` the generic method (otherwise, there's not much reason to subtype `BasicPlugin`). """ hook(::Plugin, ::Template, ::AbstractString) = nothing +""" + posthook(::Plugin, ::Template, pkg_dir::AbstractString) + +Stage 3 of the package generation pipeline (the "after" stage, in general). +At this point, both the [`prehook`](@ref)s and [`hook`](@ref)s have run. +""" +posthook(::Plugin, ::Template, ::AbstractString) = nothing + +function prehook(p::T, ::Template, ::AbstractString) where T <: BasicPlugin + src = source(p) + src === nothing && return + isfile(src) || throw(ArgumentError("$(nameof(T)): The file $src does not exist")) +end + function hook(p::BasicPlugin, t::Template, pkg_dir::AbstractString) source(p) === nothing && return pkg = basename(pkg_dir) diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index 1228ee83..7a743879 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -198,7 +198,7 @@ end GitLabCI(; file="$(contractuser(default_file("gitlab-ci.yml")))", coverage=true, - extra_versions=$DEFAULT_CI_VERSIONS, + extra_versions=$(map(format_version, [default_version(), VERSION])), ) Integrates your packages with [GitLab CI](https://docs.gitlab.com/ce/ci/). diff --git a/src/plugins/citation.jl b/src/plugins/citation.jl index 1f45196c..abd8ba9d 100644 --- a/src/plugins/citation.jl +++ b/src/plugins/citation.jl @@ -1,8 +1,5 @@ """ - Citation(; - file="$(contractuser(default_file("CITATION.bib")))", - readme=false, - ) + Citation(; file="$(contractuser(default_file("CITATION.bib")))", readme=false) Creates a `CITATION.bib` file for citing package repositories. diff --git a/src/template.jl b/src/template.jl index 327a03dc..89569471 100644 --- a/src/template.jl +++ b/src/template.jl @@ -21,7 +21,6 @@ A configuration used to generate packages. The default value comes from the global Git config (`github.user`). If no value is obtained, an `ArgumentError` is thrown. - `authors::Union{AbstractString, Vector{<:AbstractString}}="$(default_authors())"`: Package authors. - Supply a string for one author or an array for multiple. Like `user`, it takes its default value from the global Git config (`user.name` and `user.email`). ### Package Options diff --git a/test/fixtures/AllPlugins/docs/src/index.md b/test/fixtures/AllPlugins/docs/src/index.md index 744bc7e8..b1afe2bb 100644 --- a/test/fixtures/AllPlugins/docs/src/index.md +++ b/test/fixtures/AllPlugins/docs/src/index.md @@ -1,3 +1,7 @@ +```@meta +CurrentModule = AllPlugins +``` + # AllPlugins ```@index diff --git a/test/git.jl b/test/git.jl index 5fc0c303..d87870d9 100644 --- a/test/git.jl +++ b/test/git.jl @@ -38,7 +38,7 @@ @testset "Adds version to commit message" begin # We're careful to avoid a Pkg.update as it triggers Cassette#130. t = tpl(; disable_defaults=[Tests], plugins=[Git()]) - mock(CTX, Pkg.installed => () -> Dict("PkgTemplates" => v"1.2.3")) do _pi + mock(Pkg.installed => () -> Dict("PkgTemplates" => v"1.2.3")) do _pi with_pkg(t) do pkg pkg_dir = joinpath(t.dir, pkg) LibGit2.with(GitRepo(pkg_dir)) do repo diff --git a/test/runtests.jl b/test/runtests.jl index 2a5de84e..6c93fb18 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -20,7 +20,6 @@ Random.seed!(1) tpl(; kwargs...) = Template(; user=USER, kwargs...) const PKG = Ref("A") -const CTX = gensym() # Generate an unused package name. pkgname() = PKG[] *= "a" diff --git a/test/show.jl b/test/show.jl index bbd7cd33..2e67fd49 100644 --- a/test/show.jl +++ b/test/show.jl @@ -35,7 +35,6 @@ const LICENSES_DIR = joinpath(TEMPLATES_DIR, "licenses") ssh: false manifest: false gpgsign: false - ignore_manifest: true License: path: "$(joinpath(LICENSES_DIR, "MIT"))" destination: "LICENSE" diff --git a/test/template.jl b/test/template.jl index c13c3b35..a28b76f2 100644 --- a/test/template.jl +++ b/test/template.jl @@ -67,7 +67,7 @@ end t = tpl() pkg = pkgname() - mock(CTX, LibGit2.init => dir -> (@test isdir(dir); error())) do _init + mock(LibGit2.init => dir -> (@test isdir(dir); error())) do _init @test_throws ErrorException @suppress t(pkg) end @test !isdir(joinpath(t.dir, pkg)) From e05e5bec0ac2b042e27461583ef04fb2b6903dc5 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Tue, 24 Sep 2019 22:07:54 +0700 Subject: [PATCH 44/81] Add a basic migration guide --- docs/make.jl | 1 + docs/src/index.md | 2 ++ docs/src/migrating.md | 65 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 docs/src/migrating.md diff --git a/docs/make.jl b/docs/make.jl index 66168486..830e6462 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -14,6 +14,7 @@ makedocs(; "Home" => "index.md", "User Guide" => "user.md", "Developer Guide" => "developer.md", + "Migrating To 0.7+" => "migrating.md", ], ) diff --git a/docs/src/index.md b/docs/src/index.md index 54238d68..9e6c04a6 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -21,6 +21,8 @@ If you're looking to **create new packages**, see the [User Guide](user.md). If you want to **create new plugins**, see the [Developer Guide](developer.md). +if you're trying to **migrate from an older version of PkgTemplates**, see [Migrating To 0.7+](migrating.md). + ### Index ```@index diff --git a/docs/src/migrating.md b/docs/src/migrating.md new file mode 100644 index 00000000..177c47ef --- /dev/null +++ b/docs/src/migrating.md @@ -0,0 +1,65 @@ +```@meta +CurrentModule = PkgTemplates +``` + +# Migrating To PkgTemplates 0.7+ + +PkgTemplates 0.7 is a ground-up rewrite of the package with similar functionality but with updated APIs and internals. +Here is a summary of things that existed in older versions but have been moved elsewhere or removed. +However, it might be easier to just read the [User Guide](user.md). + +## Template keywords + +The recurring theme is "everything is a plugin now". + +| Old | New | +| :-: | :-: | +| `license="ISC"` | `plugins=[License(; name="ISC")]` | +| `develop=true` * | `plugins=[Develop()]` | +| `git=false` | `disable_defaults=[Git]` | +| `ssh=true` | `plugins=[Git(; ssh=true)]` | +| `manifest=true` | `plugins=[Git(; manifest=true)]` | + +\* `develop=true` was the default setting. + +## Plugins + +Aside from renamings, basically every plugin has had their constructors reworked. +So if you are using anything non-default, you should consult the new docstring. + +| Old | New | +| :-----------: | :--------------------: | +| `GitHubPages` | `Documenter{TravisCI}` | +| `GitLabPages` | `Documenter{GitLabCI}` | + +## Package Generation + +One less name to remember! + +| Old | New | +| :-----------------------------------------: | :---------------------------------: | +| `generate(::Template, pkg::AbstractString)` | `(::Template)(pkg::AbstractString)` | + +## Interactive Templates + +Two less names to remember! + +| Old | New | +| :--------------------: | :---------------------------------: | +| `interactive_template` | `Template(; interactive=true)` | +| `generate_interactive` | `Template(; interactive=true)(pkg)` | + +## Other Functions + +Another two less names to remember! +Although it's unlikely that anyone used these. + +| Old | New | +| :------------------: | :---------------------------------------------------------------------------------: | +| `available_licenses` | [GitHub](https://github.com/invenia/PkgTemplates.jl/tree/master/templates/licenses) | +| `show_license` | [GitHub](https://github.com/invenia/PkgTemplates.jl/tree/master/templates/licenses) | + +## Custom Plugins + +In addition to the changes in usage, custom plugins from older versions of PkgTemplates will not work in 0.7+. +See the [Developer Guide](developer.md) for more information on the new extension API. From cd40cb4b7edcb875c6d6a3eeb28d5032b390c18d Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Wed, 25 Sep 2019 09:45:08 +0700 Subject: [PATCH 45/81] Allow empty username when it's not used --- docs/src/developer.md | 7 ++++--- src/plugin.jl | 8 ++++++++ src/plugins/ci.jl | 2 ++ src/plugins/citation.jl | 2 ++ src/plugins/coverage.jl | 2 ++ src/plugins/documenter.jl | 2 ++ src/plugins/git.jl | 2 ++ src/template.jl | 20 ++++++++++++++------ test/template.jl | 8 +++++--- 9 files changed, 41 insertions(+), 12 deletions(-) diff --git a/docs/src/developer.md b/docs/src/developer.md index 54bab832..96cdf5f2 100644 --- a/docs/src/developer.md +++ b/docs/src/developer.md @@ -297,12 +297,13 @@ For more examples, see the plugins in the [Continuous Integration (CI)](@ref) an For an overview of writing template files for Mustache.jl, see [Custom Template Files](@ref) in the user guide. -### Traits +### Predicates -There are a few traits for plugin types that are occassionally used to answer questions like "does this `Template` have any code coverage plugins?". -If you're implementing a plugin that fits into one of the following categories, it would be wise to implement the corresponding trait function to return `true` for your type. +There are a few predicate functions for plugins that are occasionally used to answer questions like "does this `Template` have any code coverage plugins?". +If you're implementing a plugin that fits into one of the following categories, it would be wise to implement the corresponding predicate function to return `true` for instances of your type. ```@docs +needs_username is_ci is_coverage ``` diff --git a/src/plugin.jl b/src/plugin.jl index f202a9d0..88c76fb4 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -218,6 +218,14 @@ function render_text(text::AbstractString, view::Dict{<:AbstractString}, tags=no return tags === nothing ? render(text, view) : render(text, view; tags=tags) end +""" + needs_username(::Plugin) -> Bool + +Determine whether or not a plugin needs a Git hosting service username to function correctly. +If you are implementing a plugin that uses the `user` field of a [`Template`](@ref), you should implement this function and return `true`. +""" +needs_username(::Plugin) = false + include(joinpath("plugins", "project_file.jl")) include(joinpath("plugins", "src_dir.jl")) include(joinpath("plugins", "tests.jl")) diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index 7a743879..d582e153 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -261,3 +261,5 @@ If you are adding a CI plugin, you should implement this function and return `tr """ is_ci(::Plugin) = false is_ci(::Union{AppVeyor, TravisCI, CirrusCI, GitLabCI}) = true + +needs_username(::Union{AppVeyor, TravisCI, CirrusCI, GitLabCI}) = true diff --git a/src/plugins/citation.jl b/src/plugins/citation.jl index abd8ba9d..805d446b 100644 --- a/src/plugins/citation.jl +++ b/src/plugins/citation.jl @@ -24,3 +24,5 @@ view(::Citation, t::Template, pkg::AbstractString) = Dict( "URL" => "https://$(t.host)/$(t.user)/$pkg.jl", "YEAR" => year(today()), ) + +needs_username(::Citation) = true diff --git a/src/plugins/coverage.jl b/src/plugins/coverage.jl index 358ab244..448cc36d 100644 --- a/src/plugins/coverage.jl +++ b/src/plugins/coverage.jl @@ -52,3 +52,5 @@ If you are adding a coverage plugin, you should implement this function and retu """ is_coverage(::Plugin) = false is_coverage(::Union{Codecov, Coveralls}) = true + +needs_username(::Union{Codecov, Coveralls}) = true diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index 1623878f..0963bfca 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -110,3 +110,5 @@ gitlab_pages_url(t::Template, pkg::AbstractString) = "https://$(t.user).gitlab.i make_canonical(::Type{TravisCI}) = github_pages_url make_canonical(::Type{GitLabCI}) = gitlab_pages_url make_canonical(::Type{Nothing}) = nothing + +needs_username(::Documenter) = true diff --git a/src/plugins/git.jl b/src/plugins/git.jl index a94c855b..5b413ab8 100644 --- a/src/plugins/git.jl +++ b/src/plugins/git.jl @@ -88,3 +88,5 @@ function commit(p::Git, repo::GitRepo, pkg_dir::AbstractString, msg::AbstractStr LibGit2.commit(repo, msg) end end + +needs_username(::Git) = true diff --git a/src/template.jl b/src/template.jl index 89569471..93d39d6c 100644 --- a/src/template.jl +++ b/src/template.jl @@ -19,7 +19,7 @@ A configuration used to generate packages. ### User Options - `user::AbstractString="$(default_user())"`: GitHub (or other code hosting service) username. The default value comes from the global Git config (`github.user`). - If no value is obtained, an `ArgumentError` is thrown. + If no value is obtained, many plugins that use this value will not work. - `authors::Union{AbstractString, Vector{<:AbstractString}}="$(default_authors())"`: Package authors. Like `user`, it takes its default value from the global Git config (`user.name` and `user.email`). @@ -61,15 +61,13 @@ Template(; interactive::Bool=false, kwargs...) = Template(Val(interactive); kwar # Non-interactive constructor. function Template(::Val{false}; kwargs...) user = getkw(kwargs, :user) - isempty(user) && throw(ArgumentError("No user set, please pass user=username")) - - authors = getkw(kwargs, :authors) - authors isa Vector || (authors = map(strip, split(authors, ","))) - dir = abspath(expanduser(getkw(kwargs, :dir))) host = replace(getkw(kwargs, :host), r".*://" => "") julia_version = getkw(kwargs, :julia_version) + authors = getkw(kwargs, :authors) + authors isa Vector || (authors = map(strip, split(authors, ","))) + # User-supplied plugins come first, so that deduping the list will remove the defaults. plugins = Plugin[] append!(plugins, getkw(kwargs, :plugins)) @@ -77,6 +75,16 @@ function Template(::Val{false}; kwargs...) append!(plugins, filter(p -> !(typeof(p) in disabled), default_plugins())) plugins = sort(unique(typeof, plugins); by=string) + if isempty(user) + foreach(plugins) do p + if needs_username(p) + T = nameof(typeof(p)) + s = "$T: Git hosting service username is required, supply user=username" + throw(ArgumentError(s)) + end + end + end + return Template(authors, dir, host, julia_version, plugins, user) end diff --git a/test/template.jl b/test/template.jl index a28b76f2..b4b583cf 100644 --- a/test/template.jl +++ b/test/template.jl @@ -1,11 +1,13 @@ @testset "Template" begin @testset "Template constructor" begin @testset "user" begin - if isempty(PT.default_user()) + mock(PT.default_user => () -> "") do _du @test_throws ArgumentError Template() - haskey(ENV, "CI") && run(`git config --global github.user $USER`) + @test isempty(Template(; disable_defaults=[Git]).user) + end + mock(PT.default_user => () -> "username") do _du + @test Template().user == PT.default_user() end - @test Template().user == PT.default_user() end @testset "authors" begin From 2b0e4bc987b5cead0fbbe67b0c16f6999a7bd935 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Wed, 25 Sep 2019 20:48:39 +0700 Subject: [PATCH 46/81] Rename julia_version -> julia --- docs/src/migrating.md | 15 ++++++++------- src/plugins/ci.jl | 6 +++--- src/plugins/project_file.jl | 2 +- src/plugins/tests.jl | 5 ++--- src/template.jl | 10 +++++----- test/show.jl | 4 ++-- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/docs/src/migrating.md b/docs/src/migrating.md index 177c47ef..40cc7c82 100644 --- a/docs/src/migrating.md +++ b/docs/src/migrating.md @@ -12,13 +12,14 @@ However, it might be easier to just read the [User Guide](user.md). The recurring theme is "everything is a plugin now". -| Old | New | -| :-: | :-: | -| `license="ISC"` | `plugins=[License(; name="ISC")]` | -| `develop=true` * | `plugins=[Develop()]` | -| `git=false` | `disable_defaults=[Git]` | -| `ssh=true` | `plugins=[Git(; ssh=true)]` | -| `manifest=true` | `plugins=[Git(; manifest=true)]` | +| Old | New | +| :------------------: | :-------------------------------: | +| `license="ISC"` | `plugins=[License(; name="ISC")]` | +| `develop=true` * | `plugins=[Develop()]` | +| `git=false` | `disable_defaults=[Git]` | +| `julia_version=v"1"` | `julia=v"1"` | +| `ssh=true` | `plugins=[Git(; ssh=true)]` | +| `manifest=true` | `plugins=[Git(; manifest=true)]` | \* `develop=true` was the default setting. diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index d582e153..825448ad 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -18,7 +18,7 @@ Combine `t`'s Julia version with `versions`, and format them as `major.minor`. This is useful for creating lists of versions to be included in CI configurations. """ function collect_versions(t::Template, versions::Vector) - vs = map(format_version, [t.julia_version, versions...]) + vs = map(format_version, [t.julia, versions...]) return sort(unique(vs)) end @@ -91,7 +91,7 @@ function view(p::TravisCI, t::Template, pkg::AbstractString) "OS" => os, "PKG" => pkg, "USER" => t.user, - "VERSION" => format_version(t.julia_version), + "VERSION" => format_version(t.julia), "VERSIONS" => versions, "X86" => x86, ) @@ -247,7 +247,7 @@ function view(p::GitLabCI, t::Template, pkg::AbstractString) "HAS_DOCUMENTER" => hasplugin(t, Documenter{GitLabCI}), "PKG" => pkg, "USER" => t.user, - "VERSION" => format_version(t.julia_version), + "VERSION" => format_version(t.julia), "VERSIONS" => collect_versions(t, p.extra_versions), ) end diff --git a/src/plugins/project_file.jl b/src/plugins/project_file.jl index 91714c0c..15ea375c 100644 --- a/src/plugins/project_file.jl +++ b/src/plugins/project_file.jl @@ -14,7 +14,7 @@ function hook(::ProjectFile, t::Template, pkg_dir::AbstractString) "uuid" => string(uuid4()), "authors" => t.authors, "version" => "0.1.0", - "compat" => Dict("julia" => compat_version(t.julia_version)), + "compat" => Dict("julia" => compat_version(t.julia)), ) open(io -> TOML.print(io, toml), joinpath(pkg_dir, "Project.toml"), "w") end diff --git a/src/plugins/tests.jl b/src/plugins/tests.jl index 156cebdb..796c6b58 100644 --- a/src/plugins/tests.jl +++ b/src/plugins/tests.jl @@ -25,13 +25,12 @@ view(::Tests, ::Template, pkg::AbstractString) = Dict("PKG" => pkg) function prehook(p::Tests, t::Template, pkg_dir::AbstractString) invoke(prehook, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) - p.project && t.julia_version < v"1.2" && @warn string( + p.project && t.julia < v"1.2" && @warn string( "Tests: The project option is set to create a project (supported in Julia 1.2 and later) ", "but a Julia version older than 1.2 is supported by the Template.", ) end - function hook(p::Tests, t::Template, pkg_dir::AbstractString) # Do the normal BasicPlugin behaviour to create the test script. invoke(hook, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) @@ -56,7 +55,7 @@ function add_test_dependency(pkg_dir::AbstractString) open(io -> TOML.print(io, toml), path, "w") # 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. with_project(Pkg.update, pkg_dir) end diff --git a/src/template.jl b/src/template.jl index 93d39d6c..164cbfde 100644 --- a/src/template.jl +++ b/src/template.jl @@ -26,7 +26,7 @@ A configuration used to generate packages. ### Package Options - `dir::AbstractString="$(contractuser(Pkg.devdir()))"`: Directory to place packages in. - `host::AbstractString="github.com"`: URL to the code hosting service where packages will reside. -- `julia_version::VersionNumber=$(repr(default_version()))`: Minimum allowed Julia version. +- `julia::VersionNumber=$(repr(default_version()))`: Minimum allowed Julia version. ### Template Plugins - `plugins::Vector{<:Plugin}=Plugin[]`: A list of [`Plugin`](@ref)s used by the template. @@ -51,7 +51,7 @@ struct Template authors::Vector{String} dir::String host::String - julia_version::VersionNumber + julia::VersionNumber plugins::Vector{<:Plugin} user::String end @@ -63,7 +63,7 @@ function Template(::Val{false}; kwargs...) user = getkw(kwargs, :user) dir = abspath(expanduser(getkw(kwargs, :dir))) host = replace(getkw(kwargs, :host), r".*://" => "") - julia_version = getkw(kwargs, :julia_version) + julia = getkw(kwargs, :julia) authors = getkw(kwargs, :authors) authors isa Vector || (authors = map(strip, split(authors, ","))) @@ -85,7 +85,7 @@ function Template(::Val{false}; kwargs...) end end - return Template(authors, dir, host, julia_version, plugins, user) + return Template(authors, dir, host, julia, plugins, user) end """ @@ -133,6 +133,6 @@ defaultkw(::Val{:authors}) = default_authors() defaultkw(::Val{:dir}) = Pkg.devdir() defaultkw(::Val{:disable_defaults}) = DataType[] defaultkw(::Val{:host}) = "github.com" -defaultkw(::Val{:julia_version}) = default_version() +defaultkw(::Val{:julia}) = default_version() defaultkw(::Val{:plugins}) = Plugin[] defaultkw(::Val{:user}) = default_user() diff --git a/test/show.jl b/test/show.jl index 2e67fd49..8683f436 100644 --- a/test/show.jl +++ b/test/show.jl @@ -18,7 +18,7 @@ const LICENSES_DIR = joinpath(TEMPLATES_DIR, "licenses") authors: ["Chris de Graaf "] dir: "~/.local/share/julia/dev" host: "github.com" - julia_version: v"1.0.0" + julia: v"1.0.0" user: "$USER" plugins: """ @@ -27,7 +27,7 @@ const LICENSES_DIR = joinpath(TEMPLATES_DIR, "licenses") authors: ["$USER"] dir: "$(contractuser(Pkg.devdir()))" host: "github.com" - julia_version: v"1.0.0" + julia: v"1.0.0" user: "$USER" plugins: Git: From 385195c6b57c2d3e018b140c9416e0bca17e430b Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Wed, 25 Sep 2019 21:56:00 +0700 Subject: [PATCH 47/81] Improve documentation clarity --- README.md | 30 ++++++++++++++++++++++++++---- docs/make.jl | 2 +- docs/src/index.md | 15 +++------------ docs/src/migrating.md | 11 ++++++----- docs/src/user.md | 16 ++++++++++++++-- src/plugins/develop.jl | 2 +- src/plugins/documenter.jl | 8 ++++++-- src/template.jl | 2 +- 8 files changed, 58 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index f4d0acf0..d2c04c3b 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,35 @@ **PkgTemplates creates new Julia packages in an easy, repeatable, and customizable way.** -Assuming you have the relatively standard Git options `user.name`, `user.email` and `github.user` set up globally with `git config --global`, creating a `Template` is as simple as: +## Installation + +Install with Pkg, just like any other registered Julia package: + +```jl +pkg> add PkgTemplates # Press ']' to enter te Pkg REPL mode. +``` + +## Usage + +Creating a `Template` is as simple as: ```jl using PkgTemplates t = Template() ``` +The no-keywords constructor assumes the existence of some preexisting Git configuration (set with `git config --global`): + +- `user.name`: Your real name, e.g. John Smith. +- `user.email`: Your email address, eg. john.smith@acme.corp. +- `github.user`: Your GitHub username: e.g. john-smith. + +Once you have a `Template`, use it to generate a package: + +```jl +t("MyPkg") +``` + However, it's probably desirable to customize the template to your liking with various options and plugins: ```jl @@ -24,14 +46,14 @@ t = Template(; Codecov(), TravisCI(; x86=true), Documenter{TravisCI}(), - ], +o ], ) ``` -Once you have a template, you can create packages with ease: +You can also create a `Template` interactively by following a set of prompts: ```jl -t("MyPkg") +julia> t = Template(; interactive=true) ``` --- diff --git a/docs/make.jl b/docs/make.jl index 830e6462..622e8953 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -14,7 +14,7 @@ makedocs(; "Home" => "index.md", "User Guide" => "user.md", "Developer Guide" => "developer.md", - "Migrating To 0.7+" => "migrating.md", + "Migrating To PkgTemplates 0.7+" => "migrating.md", ], ) diff --git a/docs/src/index.md b/docs/src/index.md index 9e6c04a6..924afa83 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -6,24 +6,15 @@ CurrentModule = PkgTemplates **PkgTemplates creates new Julia packages in an easy, repeatable, and customizable way.** -### Foreword: Templating vs. Template - -This documentation refers plenty to [`Template`](@ref)s, the package's main type. -But it also refers to "template files" and "text templating", which are plaintext files with placeholders to be filled with data, and the technique of filling those placeholders with data, respectively. - -These concepts should be familiar if you've used [Jinja](https://palletsprojects.com/p/jinja) or [Mustache](https://mustache.github.io) (Mustache is the particular flavour used by PkgTemplates, via [Mustache.jl](https://github.com/jverzani/Mustache.jl)). - -Please keep the difference between these two things in mind when reading this documentation! - -### Documentation +## Documentation If you're looking to **create new packages**, see the [User Guide](user.md). If you want to **create new plugins**, see the [Developer Guide](developer.md). -if you're trying to **migrate from an older version of PkgTemplates**, see [Migrating To 0.7+](migrating.md). +if you're trying to **migrate from an older version of PkgTemplates**, see [Migrating To PkgTemplates 0.7+](migrating.md). -### Index +## Index ```@index ``` diff --git a/docs/src/migrating.md b/docs/src/migrating.md index 40cc7c82..a003078b 100644 --- a/docs/src/migrating.md +++ b/docs/src/migrating.md @@ -21,7 +21,7 @@ The recurring theme is "everything is a plugin now". | `ssh=true` | `plugins=[Git(; ssh=true)]` | | `manifest=true` | `plugins=[Git(; manifest=true)]` | -\* `develop=true` was the default setting. +\* `develop=true` was the default setting, but it is no longer the default in PkgTemplates 0.7+. ## Plugins @@ -55,10 +55,11 @@ Two less names to remember! Another two less names to remember! Although it's unlikely that anyone used these. -| Old | New | -| :------------------: | :---------------------------------------------------------------------------------: | -| `available_licenses` | [GitHub](https://github.com/invenia/PkgTemplates.jl/tree/master/templates/licenses) | -| `show_license` | [GitHub](https://github.com/invenia/PkgTemplates.jl/tree/master/templates/licenses) | +| Old | New | +| :------------------: | :--------------------------------------------------------------------------------------------------: | +| `available_licenses` | [View licenses on GitHub](https://github.com/invenia/PkgTemplates.jl/tree/master/templates/licenses) | +| `show_license` | [View licenses on GitHub](https://github.com/invenia/PkgTemplates.jl/tree/master/templates/licenses) | +| | | ## Custom Plugins diff --git a/docs/src/user.md b/docs/src/user.md index 5e92a158..6d344209 100644 --- a/docs/src/user.md +++ b/docs/src/user.md @@ -9,7 +9,13 @@ Pages = ["user.md"] ``` Using PkgTemplates is straightforward. -Just create a [`Template`](@ref), and call it on a package name to generate that package. +Just create a [`Template`](@ref), and call it on a package name to generate that package: + +```julia +using PkgTemplates +t = Template() +t("MyPkg") +``` ## Template @@ -22,7 +28,7 @@ Template Plugins add functionality to `Template`s. There are a number of plugins available to automate common boilerplate tasks. -### Defaults +### Default Plugins These plugins are included by default. They can be overridden by supplying another value via the `plugins` keyword, or disabled by supplying the type via the `disable_defaults` keyword. @@ -71,6 +77,12 @@ Citation ## Custom Template Files +!!! note "Templates vs Templating" + This documentation refers plenty to [`Template`](@ref)s, the package's main type, but it also refers to "template files" and "text templating", which are plaintext files with placeholders to be filled with data, and the technique of filling those placeholders with data, respectively. + + These concepts should be familiar if you've used [Jinja](https://palletsprojects.com/p/jinja) or [Mustache](https://mustache.github.io) (Mustache is the particular flavour used by PkgTemplates, via [Mustache.jl](https://github.com/jverzani/Mustache.jl)). + Please keep the difference between these two things in mind! + Many plugins support a `file` argument or similar, which sets the path to the template file to be used for generating files. Each plugin has a sensible default that should make sense for most people, but you might have a specialized workflow that requires a totally different template file. diff --git a/src/plugins/develop.jl b/src/plugins/develop.jl index 467a82c5..a06fef74 100644 --- a/src/plugins/develop.jl +++ b/src/plugins/develop.jl @@ -2,7 +2,7 @@ Develop() Adds generated packages to the current environment by `dev`ing them. -See [here](https://julialang.github.io/Pkg.jl/v1/managing-packages/#Developing-packages-1) for more details. +See the Pkg documentation [here](https://julialang.github.io/Pkg.jl/v1/managing-packages/#Developing-packages-1) for more details. """ struct Develop <: Plugin end diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index 0963bfca..6fb9f5c2 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -15,6 +15,11 @@ const DOCUMENTER_DEP = PackageSpec(; Sets up documentation generation via [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl). Documentation deployment depends on `T`, where `T` is some supported CI plugin, or `Nothing` to only support local documentation builds. +## Supported Type Parameters +- `TravisCI`: Deploys documentation to [GitHub Pages](https://pages.github.com) with the help of [`TravisCI`](@ref). +- `GitLabCI`: Deploys documentation to [GitLab Pages](https://pages.gitlab.com) with the help of [`GitLabCI`](@ref). +- `Nothing` (default): Does not set up documentation deployment. + ## Keyword Arguments - `make_jl::AbstractString`: Template file for `make.jl`. - `index_md::AbstractString`: Template file for `index.md`. @@ -24,8 +29,7 @@ Documentation deployment depends on `T`, where `T` is some supported CI plugin, - `makedocs_kwargs::Dict{Symbol}`: Extra keyword arguments to be inserted into `makedocs`. !!! note - If deploying documentation with Travis CI, don't forget to complete the required configuration. - See [here](https://juliadocs.github.io/Documenter.jl/stable/man/hosting/#SSH-Deploy-Keys-1). + If deploying documentation with Travis CI, don't forget to complete [the required configuration](https://juliadocs.github.io/Documenter.jl/stable/man/hosting/#SSH-Deploy-Keys-1). """ struct Documenter{T<:Union{TravisCI, GitLabCI, Nothing}} <: Plugin assets::Vector{String} diff --git a/src/template.jl b/src/template.jl index 164cbfde..d15873d3 100644 --- a/src/template.jl +++ b/src/template.jl @@ -79,7 +79,7 @@ function Template(::Val{false}; kwargs...) foreach(plugins) do p if needs_username(p) T = nameof(typeof(p)) - s = "$T: Git hosting service username is required, supply user=username" + s = """$T: Git hosting service username is required, set one with keyword `user=""`""" throw(ArgumentError(s)) end end From fd995a05bccc757bb9852c218de09c6929b99d94 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Wed, 25 Sep 2019 23:26:03 +0700 Subject: [PATCH 48/81] Add per-plugin validation at template construction time --- docs/src/developer.md | 36 ++++++++++++++++++++++++++++++------ src/plugin.jl | 11 ++++++++++- src/plugins/documenter.jl | 10 ++++++++++ src/plugins/git.jl | 13 +++++++++++-- src/plugins/src_dir.jl | 1 - src/plugins/tests.jl | 4 ++-- src/template.jl | 4 +++- test/template.jl | 10 ++++++++-- 8 files changed, 74 insertions(+), 15 deletions(-) diff --git a/docs/src/developer.md b/docs/src/developer.md index 96cdf5f2..7a92c15e 100644 --- a/docs/src/developer.md +++ b/docs/src/developer.md @@ -17,9 +17,25 @@ Plugin BasicPlugin ``` -## Package Generation Pipeline +## Template + Package Creation Pipeline -The package generation process looks basically like this: + +The [`Template`](@ref) constructor basically does this: + +``` +- extract values from keyword arguments +- create a Template from the values +- validate each plugin against the constructed Template +``` + +The plugin validation step uses the [`validate`](@ref) function. +It lets us catch mistakes before we try to generate packages. + +```@docs +validate +``` + +The package generation process looks like this: ``` - create empty directory for the package @@ -31,7 +47,6 @@ The package generation process looks basically like this: - run plugin posthook ``` -That's it! As you can tell, plugins play a central role in setting up a package. The three main entrypoints for plugins to do work are the [`prehook`](@ref), the [`hook`](@ref), and the [`posthook`](@ref). @@ -151,6 +166,14 @@ struct Git <: Plugin end priority(::Git, ::typeof(posthook)) = 5 +function validate(::Git, ::Template) + foreach(("user.name", "user.email")) do k + if isempty(LibGit2.getconfig(k, "")) + throw(ArgumentError("Git: Global Git config is missing required value '$k'")) + end + end +end + function prehook(::Git, t::Template, pkg_dir::AbstractString) LibGit2.with(LibGit2.init(pkg_dir)) do repo LibGit2.commit(repo, "Initial commit") @@ -174,8 +197,9 @@ function posthook(::Git, ::Template, pkg_dir::AbstractString) end ``` -All three hooks are implemented: +Validation and all three hooks are implemented: +- [`validate`](@ref) makes sure that all required Git configuration is present. - [`prehook`](@ref) creates the Git repository for the package. - [`hook`](@ref) generates the `.gitignore` file, using the special [`gitignore`](@ref) function. - [`posthook`](@ref) adds and commits all the generated files. @@ -286,8 +310,8 @@ function hook(p::Tests, t::Template, pkg_dir::AbstractString) end ``` -There is also a default [`prehook`](@ref) implementation for [`BasicPlugin`](@ref)s, which checks that the plugin's [`source`](@ref) file exists, and throws an `ArgumentError` otherwise. -If you want to extend the prehook but keep the file existence check, use the `invoke` method as described above. +There is also a default [`validate`](@ref) implementation for [`BasicPlugin`](@ref)s, which checks that the plugin's [`source`](@ref) file exists, and throws an `ArgumentError` otherwise. +If you want to extend the validation but keep the file existence check, use the `invoke` method as described above. For more examples, see the plugins in the [Continuous Integration (CI)](@ref) and [Code Coverage](@ref) sections. diff --git a/src/plugin.jl b/src/plugin.jl index 88c76fb4..00fddc97 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -134,6 +134,15 @@ function badges(p::Plugin, t::Template, pkg::AbstractString) return map(b -> render_text(string(b), combined_view(p, t, pkg)), bs) end +""" + validate(::Plugin, ::Template) + +Perform any required validation for a [`Plugin`](@ref). + +It is preferred to do validation here instead of in [`prehook`](@ref), because this function is called at [`Template`](@ref) construction time, whereas the prehook is only run at package generation time. +""" +validate(::Plugin, ::Template) = nothing + """ prehook(::Plugin, ::Template, pkg_dir::AbstractString) @@ -168,7 +177,7 @@ At this point, both the [`prehook`](@ref)s and [`hook`](@ref)s have run. """ posthook(::Plugin, ::Template, ::AbstractString) = nothing -function prehook(p::T, ::Template, ::AbstractString) where T <: BasicPlugin +function validate(p::T, ::Template) where T <: BasicPlugin src = source(p) src === nothing && return isfile(src) || throw(ArgumentError("$(nameof(T)): The file $src does not exist")) diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index 6fb9f5c2..6931d3ac 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -89,6 +89,16 @@ function view(p::Documenter{TravisCI}, t::Template, pkg::AbstractString) return merge(base, Dict("HAS_DEPLOY" => true)) end +foreach((TravisCI, GitLabCI)) do T + @eval function validate(::Documenter{$T}, t::Template) + if !hasplugin(t, $T) + name = nameof($T) + s = "Documenter: The $name plugin must be included for docs deployment to be set up" + throw(ArgumentError(s)) + end + end +end + function hook(p::Documenter, t::Template, pkg_dir::AbstractString) pkg = basename(pkg_dir) docs_dir = joinpath(pkg_dir, "docs") diff --git a/src/plugins/git.jl b/src/plugins/git.jl index 5b413ab8..352a7b55 100644 --- a/src/plugins/git.jl +++ b/src/plugins/git.jl @@ -30,11 +30,20 @@ function gitignore(p::Git) return ignore end -# Set up the Git repository. -function prehook(p::Git, t::Template, pkg_dir::AbstractString) +function validate(p::Git, t::Template) if p.gpgsign && try run(pipeline(`git --version`; stdout=devnull)); false catch; true end throw(ArgumentError("Git: gpgsign is set but the Git CLI is not installed")) end + + foreach(("user.name", "user.email")) do k + if isempty(LibGit2.getconfig(k, "")) + throw(ArgumentError("Git: Global Git config is missing required value '$k'")) + end + end +end + +# Set up the Git repository. +function prehook(p::Git, t::Template, pkg_dir::AbstractString) LibGit2.with(LibGit2.init(pkg_dir)) do repo commit(p, repo, pkg_dir, "Initial commit") pkg = basename(pkg_dir) diff --git a/src/plugins/src_dir.jl b/src/plugins/src_dir.jl index fbbdad37..aa1e177f 100644 --- a/src/plugins/src_dir.jl +++ b/src/plugins/src_dir.jl @@ -24,6 +24,5 @@ view(::SrcDir, ::Template, pkg::AbstractString) = Dict("PKG" => pkg) # Update the destination now that we know the package name. # Kind of hacky, but oh well. function prehook(p::SrcDir, t::Template, pkg_dir::AbstractString) - invoke(prehook, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) p.destination = joinpath("src", basename(pkg_dir) * ".jl") end diff --git a/src/plugins/tests.jl b/src/plugins/tests.jl index 796c6b58..a7e36206 100644 --- a/src/plugins/tests.jl +++ b/src/plugins/tests.jl @@ -23,8 +23,8 @@ source(p::Tests) = p.file destination(::Tests) = joinpath("test", "runtests.jl") view(::Tests, ::Template, pkg::AbstractString) = Dict("PKG" => pkg) -function prehook(p::Tests, t::Template, pkg_dir::AbstractString) - invoke(prehook, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) +function validate(p::Tests, t::Template) + invoke(validate, Tuple{BasicPlugin, Template}, p, t) p.project && t.julia < v"1.2" && @warn string( "Tests: The project option is set to create a project (supported in Julia 1.2 and later) ", "but a Julia version older than 1.2 is supported by the Template.", diff --git a/src/template.jl b/src/template.jl index d15873d3..9a08ae07 100644 --- a/src/template.jl +++ b/src/template.jl @@ -85,7 +85,9 @@ function Template(::Val{false}; kwargs...) end end - return Template(authors, dir, host, julia, plugins, user) + t = Template(authors, dir, host, julia, plugins, user) + foreach(p -> validate(p, t), t.plugins) + return t end """ diff --git a/test/template.jl b/test/template.jl index b4b583cf..260f34ee 100644 --- a/test/template.jl +++ b/test/template.jl @@ -46,13 +46,19 @@ end @testset "hasplugin" begin - t = tpl(; plugins=[Documenter{TravisCI}()]) + t = tpl(; plugins=[TravisCI(), Documenter{TravisCI}()]) @test PT.hasplugin(t, typeof(first(PT.default_plugins()))) @test PT.hasplugin(t, Documenter) + @test PT.hasplugin(t, PT.is_ci) @test PT.hasplugin(t, _ -> true) @test !PT.hasplugin(t, _ -> false) @test !PT.hasplugin(t, Citation) - @test !PT.hasplugin(t, PT.is_ci) + end + + @testset "validate" begin + mock(LibGit2.getconfig => (_k, _d) -> "") do _gc + @test_throws ArgumentError tpl(; plugins=[Git()]) + end end end From 49a1dae4689883d0a3b968cb00dc334126e369f2 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Wed, 25 Sep 2019 23:26:59 +0700 Subject: [PATCH 49/81] Tweak some docs --- docs/src/developer.md | 3 ++- docs/src/migrating.md | 1 - src/plugins/git.jl | 2 +- src/plugins/src_dir.jl | 3 +++ src/plugins/tests.jl | 4 ++-- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/src/developer.md b/docs/src/developer.md index 7a92c15e..f08f4ba0 100644 --- a/docs/src/developer.md +++ b/docs/src/developer.md @@ -25,7 +25,8 @@ The [`Template`](@ref) constructor basically does this: ``` - extract values from keyword arguments - create a Template from the values -- validate each plugin against the constructed Template +- for each plugin: + - validate plugin against the template ``` The plugin validation step uses the [`validate`](@ref) function. diff --git a/docs/src/migrating.md b/docs/src/migrating.md index a003078b..fd9f1f0b 100644 --- a/docs/src/migrating.md +++ b/docs/src/migrating.md @@ -59,7 +59,6 @@ Although it's unlikely that anyone used these. | :------------------: | :--------------------------------------------------------------------------------------------------: | | `available_licenses` | [View licenses on GitHub](https://github.com/invenia/PkgTemplates.jl/tree/master/templates/licenses) | | `show_license` | [View licenses on GitHub](https://github.com/invenia/PkgTemplates.jl/tree/master/templates/licenses) | -| | | ## Custom Plugins diff --git a/src/plugins/git.jl b/src/plugins/git.jl index 352a7b55..94a01bd9 100644 --- a/src/plugins/git.jl +++ b/src/plugins/git.jl @@ -10,7 +10,7 @@ Creates a Git repository and a `.gitignore` file. If left unset, HTTPS is used. - `manifest::Bool`: Whether or not to commit `Manifest.toml`. - `gpgsign::Bool`: Whether or not to sign commits with your GPG key. - This option requires that the Git CLI is installed. + This option requires that the Git CLI is installed, and for you to have a GPG key associated with your committer identity. """ @with_kw_noshow struct Git <: Plugin ignore::Vector{String} = [] diff --git a/src/plugins/src_dir.jl b/src/plugins/src_dir.jl index aa1e177f..1f07a29a 100644 --- a/src/plugins/src_dir.jl +++ b/src/plugins/src_dir.jl @@ -2,6 +2,9 @@ SrcDir(; file="$(contractuser(default_file("src", "module.jl")))") Creates a module entrypoint. + +## Keyword Arguments +- `file::AbstractString`: Template file for `src/.jl`. """ @with_kw_noshow mutable struct SrcDir <: BasicPlugin file::String = default_file("src", "module.jl") diff --git a/src/plugins/tests.jl b/src/plugins/tests.jl index a7e36206..8281be6e 100644 --- a/src/plugins/tests.jl +++ b/src/plugins/tests.jl @@ -7,7 +7,7 @@ const TEST_DEP = PackageSpec(; name="Test", uuid=TEST_UUID) Sets up testing for packages. ## Keyword Arguments -- `file::AbstractString`: Template file for the `runtests.jl`. +- `file::AbstractString`: Template file for `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. @@ -27,7 +27,7 @@ function validate(p::Tests, t::Template) invoke(validate, Tuple{BasicPlugin, Template}, p, t) p.project && t.julia < v"1.2" && @warn string( "Tests: The project option is set to create a project (supported in Julia 1.2 and later) ", - "but a Julia version older than 1.2 is supported by the Template.", + "but a Julia version older than 1.2 is supported by the Template", ) end From 004d84ecfa92fb4824720b7369f8531f8ed90862 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Thu, 26 Sep 2019 00:30:16 +0700 Subject: [PATCH 50/81] Fix rebase mistakes --- src/generate.jl | 89 ----------- test/tests.jl | 407 ------------------------------------------------ 2 files changed, 496 deletions(-) delete mode 100644 src/generate.jl delete mode 100644 test/tests.jl diff --git a/src/generate.jl b/src/generate.jl deleted file mode 100644 index 0c240e81..00000000 --- a/src/generate.jl +++ /dev/null @@ -1,89 +0,0 @@ -""" - (::Template)(pkg::AbstractString) - -Generate a package named `pkg` from a [`Template`](@ref). -""" -function (t::Template)(pkg::AbstractString) - endswith(pkg, ".jl") && (pkg = pkg[1:end-3]) - pkg_dir = joinpath(t.dir, pkg) - ispath(pkg_dir) && throw(ArgumentError("$pkg_dir already exists")) - repo = nothing - - try - # Create the directory with some boilerplate inside. - Pkg.generate(pkg_dir) - - # Replace the authors field with the template's authors, and add a compat entry. - if !isempty(t.authors) - path = joinpath(pkg_dir, "Project.toml") - toml = TOML.parsefile(path) - toml["authors"] = t.authors - get!(toml, "compat", Dict())["julia"] = compat_version(t.julia_version) - open(io -> TOML.print(io, toml), path, "w") - end - - if t.git - # Initialize the repo, make a commit, and set the remote. - repo = LibGit2.init(pkg_dir) - LibGit2.commit(repo, "Initial commit") - url = if t.ssh - "git@$(t.host):$(t.user)/$pkg.jl.git" - else - "https://$(t.host)/$(t.user)/$pkg.jl" - end - LibGit2.with(GitRemote(repo, "origin", url)) do remote - # TODO: `git pull` still requires some Git branch config. - LibGit2.add_push!(repo, remote, "refs/heads/master") - end - end - - # Generate the files. - foreach(p -> gen_plugin(p, t, pkg_dir), values(t.plugins)) - - if t.git - # Commit the files. - LibGit2.add!(repo, ".") - msg = "Files generated by PkgTemplates" - installed = Pkg.installed() - if haskey(installed, "PkgTemplates") - ver = string(installed["PkgTemplates"]) - msg *= "\n\nPkgTemplates version: $ver" - end - LibGit2.commit(repo, msg) - end - - if t.dev - # Add the new package to the current environment. - Pkg.develop(PackageSpec(; path=pkg_dir)) - 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" - catch - rm(pkg_dir; recursive=true, force=true) - rethrow() - finally - repo === nothing || close(repo) - end -end - -""" - compat_version(v::VersionNumber) -> String - -Format a `VersionNumber` to exclude trailing zero components. -""" -function compat_version(v::VersionNumber) - return if v.patch == 0 && v.minor == 0 - "$(v.major)" - elseif v.patch == 0 - "$(v.major).$(v.minor)" - else - "$(v.major).$(v.minor).$(v.patch)" - end -end diff --git a/test/tests.jl b/test/tests.jl deleted file mode 100644 index 1b3e5ae9..00000000 --- a/test/tests.jl +++ /dev/null @@ -1,407 +0,0 @@ -# A dummy GenericPlugin subtype. -struct Foo <: GenericPlugin - gitignore::Vector{AbstractString} - src::Union{AbstractString, Nothing} - dest::AbstractString - badges::Vector{Badge} - view::Dict{String, Any} - function Foo(; config_file=test_file) - new([], @__FILE__, config_file, [Badge("foo", "bar", "baz")], Dict{String, Any}()) - end -end -# A dummy CustomPlugin subtype. -struct Bar <: CustomPlugin end -# A dummy Plugin subtype. -struct Baz <: Plugin end -# A Documenter with extra kwargs -struct Qux <: Documenter - assets::Vector{AbstractString} - additional_kwargs::Union{AbstractDict, NamedTuple} -end - -# Various options to be passed into templates. -const me = "christopher-dG" -const test_pkg = "TestPkg" -const fake_path = "/dev/null/this/file/does/not/exist" -const test_file = tempname() -const default_dir = Pkg.devdir() -const gitconfig = GitConfig(joinpath(@__DIR__, "gitconfig")) -const template_text = """ - PKGNAME: {{PKGNAME}} - VERSION: {{VERSION}}} - {{#DOCUMENTER}}Documenter{{/DOCUMENTER}} - {{#CODECOV}}Codecov{{/CODECOV}} - {{#COVERALLS}}Coveralls{{/COVERALLS}} - {{#AFTER}}After{{/AFTER}} - {{#OTHER}}Other{{/OTHER}} - """ -write(test_file, template_text) - -@testset "Template creation" begin - # Checking default field assignments. - t = Template(; authors="foo", user=me) - @test t.user == me - @test t.license == "MIT" - @test t.authors == "foo" - @test t.dir == default_dir - @test t.julia_version == PkgTemplates.default_version - @test !t.ssh - @test !t.manifest - @test isempty(t.plugins) - - # Checking non-default field assignments. - - t = Template(; user=me, license="") - @test t.license == "" - - t = Template(; user=me, license="MPL") - @test t.license == "MPL" - - t = Template(; user=me, authors="Some Guy") - @test t.authors == "Some Guy" - # Vectors of authors should be comma-joined. - t = Template(; user=me, authors=["Guy", "Gal"]) - @test t.authors == "Guy, Gal" - - t = Template(; user=me, dir=test_file) - @test t.dir == abspath(test_file) - if Sys.isunix() # ~ means temporary file on Windows, not $HOME. - # '~' should be replaced by home dir. - t = Template(; user=me, dir="~/$(basename(test_file))") - @test t.dir == joinpath(homedir(), basename(test_file)) - end - - t = Template(; user=me, julia_version=v"0.1.2") - @test t.julia_version == v"0.1.2" - - t = Template(; user=me, ssh=true) - @test t.ssh - - t = Template(; user=me, manifest=true) - @test t.manifest - - # The template should contain whatever plugins you give it. - t = Template(; - user=me, - plugins = [GitHubPages(), TravisCI(), AppVeyor(), Codecov(), Coveralls()], - ) - @test Set(keys(t.plugins)) == Set(map(typeof, values(t.plugins))) == Set( - [GitHubPages, TravisCI, AppVeyor, Codecov, Coveralls] - ) - - # Duplicate plugins should warn. - @test_logs (:warn, r"duplicates") match_mode=:any t = Template(; - user=me, - plugins=[TravisCI(), TravisCI()], - ) - - # If github.user is configured, use that as a default. - if isempty(LibGit2.getconfig("github.user", "")) - @test_throws ArgumentError Template() - else - t = Template() - @test t.user == LibGit2.getconfig("github.user", "") - end - @test_throws ArgumentError Template(; user=me, license="FakeLicense") -end - -@testset "Show methods" begin - pkg_dir = replace(default_dir, homedir() => "~") - ver = PkgTemplates.version_floor(PkgTemplates.default_version) - buf = IOBuffer() - t = Template(; user=me, authors="foo") - show(buf, t) - text = String(take!(buf)) - expected = """ - Template: - → User: $me - → Host: github.com - → License: MIT (foo $(year(today()))) - → Package directory: $pkg_dir - → Minimum Julia version: v$ver - → SSH remote: No - → Add packages to main environment: Yes - → Commit Manifest.toml: No - → Plugins: None - """ - @test text == rstrip(expected) - t = Template( - user=me, - license="", - ssh=true, - manifest=true, - plugins=[ - TravisCI(), - Codecov(), - GitHubPages(), - ], - ) - show(buf, t) - text = String(take!(buf)) - expected = """ - Template: - → User: $me - → Host: github.com - → License: None - → Package directory: $pkg_dir - → Minimum Julia version: v$ver - → SSH remote: Yes - → Add packages to main environment: Yes - → Commit Manifest.toml: Yes - → Plugins: - • Codecov: - → Config file: None - → 3 gitignore entries: "*.jl.cov", "*.jl.*.cov", "*.jl.mem" - • GitHubPages: - → 0 asset files - → 2 gitignore entries: "/docs/build/", "/docs/site/" - • TravisCI: - → Config file: Default - → 0 gitignore entries - """ - @test text == rstrip(expected) -end - -@testset "File generation" begin - t = Template(; - user=me, - license="MPL", - plugins=[Coveralls(), TravisCI(), Codecov(), GitHubPages(), AppVeyor()], - ) - temp_dir = mktempdir() - pkg_dir = joinpath(temp_dir, test_pkg) - - temp_file = tempname() - gen_file(temp_file, "Hello, world") - @test isfile(temp_file) - @test read(temp_file, String) == "Hello, world\n" - rm(temp_file) - - # Test the README generation. - @test gen_readme(pkg_dir, t) == ["README.md"] - @test isfile(joinpath(pkg_dir, "README.md")) - readme = readchomp(joinpath(pkg_dir, "README.md")) - rm(joinpath(pkg_dir, "README.md")) - @test occursin("# $test_pkg", readme) - for p in values(t.plugins) - @test occursin(join(badges(p, t.user, test_pkg), "\n"), readme) - end - # Check the order of the badges. - @test something(findfirst("github.io", readme)).start < - something(findfirst("travis", readme)).start < - something(findfirst("appveyor", readme)).start < - something(findfirst("codecov", readme)).start < - something(findfirst("coveralls", readme)).start - # Plugins with badges but not in BADGE_ORDER should appear at the far right side. - t.plugins[Foo] = Foo() - gen_readme(pkg_dir, t) - readme = readchomp(joinpath(pkg_dir, "README.md")) - rm(joinpath(pkg_dir, "README.md")) - @test findfirst("coveralls", readme).start < findfirst("baz", readme).start - - # Test the gitignore generation. - @test gen_gitignore(pkg_dir, t) == [".gitignore"] - @test isfile(joinpath(pkg_dir, ".gitignore")) - gitignore = read(joinpath(pkg_dir, ".gitignore"), String) - rm(joinpath(pkg_dir, ".gitignore")) - @test occursin(".DS_Store", gitignore) - @test occursin("Manifest.toml", gitignore) - for p in values(t.plugins) - for entry in p.gitignore - @test occursin(entry, gitignore) - end - end - t = Template(; user=me, manifest=true) - @test gen_gitignore(pkg_dir, t) == [".gitignore", "Manifest.toml"] - gitignore = read(joinpath(pkg_dir, ".gitignore"), String) - @test !occursin("Manifest.toml", gitignore) - rm(joinpath(pkg_dir, ".gitignore")) - - # Test the license generation. - @test gen_license(pkg_dir, t) == ["LICENSE"] - @test isfile(joinpath(pkg_dir, "LICENSE")) - license = readchomp(joinpath(pkg_dir, "LICENSE")) - rm(joinpath(pkg_dir, "LICENSE")) - @test occursin(t.authors, license) - @test occursin(read_license(t.license), license) - - # Test the test generation. - @test gen_tests(pkg_dir, t) == ["test/"] - @test isfile(joinpath(pkg_dir, "Project.toml")) - project = read(joinpath(pkg_dir, "Project.toml"), String) - @test occursin("[extras]\nTest = ", project) - @test isdir(joinpath(pkg_dir, "test")) - @test isfile(joinpath(pkg_dir, "test", "runtests.jl")) - @test isfile(joinpath(pkg_dir, "Manifest.toml")) - runtests = read(joinpath(pkg_dir, "test", "runtests.jl"), String) - rm(joinpath(pkg_dir, "test"); recursive=true) - @test occursin("using $test_pkg", runtests) - @test occursin("using Test", runtests) - manifest = read(joinpath(pkg_dir, "Manifest.toml"), String) - @test !occursin("[[Test]]", manifest) - - rm(temp_dir; recursive=true) -end - -@testset "Package generation" begin - t = Template(; user=me) - generate(test_pkg, t; gitconfig=gitconfig) - pkg_dir = joinpath(default_dir, test_pkg) - - # 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, ".gitignore")) - @test isdir(joinpath(pkg_dir, "src")) - @test isfile(joinpath(pkg_dir, "src", "$test_pkg.jl")) - @test isfile(joinpath(pkg_dir, "Project.toml")) - @test isdir(joinpath(pkg_dir, "test")) - @test isfile(joinpath(pkg_dir, "test", "runtests.jl")) - @test isfile(joinpath(pkg_dir, "Manifest.toml")) - # Check the configured remote and branches. - # Note: This test will fail on your system if you've configured Git - # to replace all HTTPS URLs with SSH. - repo = LibGit2.GitRepo(pkg_dir) - remote = LibGit2.get(LibGit2.GitRemote, repo, "origin") - branches = map(b -> LibGit2.shortname(first(b)), LibGit2.GitBranchIter(repo)) - @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. - t = Template(; user=me, ssh=true) - generate(t, test_pkg; gitconfig=gitconfig) # Test the reversed-arguments method here. - repo = LibGit2.GitRepo(pkg_dir) - remote = LibGit2.get(LibGit2.GitRemote, repo, "origin") - @test LibGit2.url(remote) == "git@github.com:$me/$test_pkg.jl.git" - rm(pkg_dir; recursive=true) - - # Check that the remote is set correctly for non-default hosts. - t = Template(; user=me, host="gitlab.com") - generate(test_pkg, t; gitconfig=gitconfig) - repo = LibGit2.GitRepo(pkg_dir) - remote = LibGit2.get(LibGit2.GitRemote, repo, "origin") - @test LibGit2.url(remote) == "https://gitlab.com/$me/$test_pkg.jl" - rm(pkg_dir; recursive=true) - - # Check that the package ends up in the right directory. - temp_dir = mktempdir() - t = Template(; user=me, dir=temp_dir) - generate(test_pkg, t; gitconfig=gitconfig) - @test isdir(joinpath(temp_dir, test_pkg)) - rm(temp_dir; recursive=true) - - # Check that the Manifest.toml is not commited by default. - t = Template(; user=me) - generate(test_pkg, t; gitconfig=gitconfig) - @test occursin("Manifest.toml", read(joinpath(pkg_dir, ".gitignore"), String)) - # I'm not sure this is the "right" way to do this. - repo = GitRepo(pkg_dir) - idx = LibGit2.GitIndex(repo) - @test findall("Manifest.toml", idx) === nothing - rm(pkg_dir; recursive=true) - - # And that it is when you tell it to be. - t = Template(; user=me, manifest=true) - generate(test_pkg, t; gitconfig=gitconfig) - @test !occursin("Manifest.toml", read(joinpath(pkg_dir, ".gitignore"), String)) - # I'm not sure this is the "right" way to do this. - repo = GitRepo(pkg_dir) - idx = LibGit2.GitIndex(repo) - @test findall("Manifest.toml", idx) !== nothing - rm(pkg_dir; recursive=true) - - # Check that the created package ends up developed in the current environment. - temp_dir = mktempdir() - Pkg.activate(temp_dir) - t = Template(; user=me) - generate(test_pkg, t; gitconfig=gitconfig) - @test haskey(Pkg.installed(), test_pkg) - rm(pkg_dir; recursive=true) - Pkg.activate() - rm(temp_dir; recursive=true) -end - -@testset "Git-less package generation" begin - t = Template(; user=me) - generate(test_pkg, t; git=false) - @test !ispath(joinpath(t.dir, ".git")) - @test !isfile(joinpath(t.dir, ".gitignore")) -end - -@testset "Plugins" begin - t = Template(; user=me) - pkg_dir = joinpath(t.dir, test_pkg) - - # Check badge constructor and formatting. - badge = Badge("A", "B", "C") - @test badge.hover == "A" - @test badge.image == "B" - @test badge.link == "C" - @test format(badge) == "[![A](B)](C)" - - p = Bar() - @test isempty(badges(p, me, test_pkg)) - @test isempty(gen_plugin(p, t, test_pkg)) - - p = Baz() - @test isempty(badges(p, me, test_pkg)) - @test isempty(gen_plugin(p, t, test_pkg)) - - include(joinpath("plugins", "travisci.jl")) - include(joinpath("plugins", "appveyor.jl")) - include(joinpath("plugins", "gitlabci.jl")) - include(joinpath("plugins", "cirrusci.jl")) - include(joinpath("plugins", "codecov.jl")) - include(joinpath("plugins", "coveralls.jl")) - include(joinpath("plugins", "githubpages.jl")) - include(joinpath("plugins", "gitlabpages.jl")) - include(joinpath("plugins", "citation.jl")) -end - -@testset "Documenter add kwargs" begin - t = Template(; user=me) - pkg_dir = joinpath(t.dir, test_pkg) - - function check_kwargs(kwargs, warn_str) - p = Qux([], kwargs) - @test_logs (:warn, warn_str) gen_plugin(p, t, test_pkg) - - make = readchomp(joinpath(pkg_dir, "docs", "make.jl")) - @test occursin("\n stringarg=\"string\",\n", make) - @test occursin("\n strict=true,\n", make) - @test occursin("\n checkdocs=:none,\n", make) - - @test !occursin("format=:markdown", make) - @test occursin("format=Documenter.HTML()", make) - rm(pkg_dir; recursive=true) - end - # Test with string kwargs - kwargs = Dict("checkdocs" => :none, - "strict" => true, - "format" => :markdown, - "stringarg" => "string", - ) - warn_str = "Ignoring predefined Documenter kwargs \"format\" from additional kwargs" - check_kwargs(kwargs, warn_str) - - kwargs = Dict( - :checkdocs => :none, - :strict => true, - :format => :markdown, - :stringarg => "string", - ) - warn_str = "Ignoring predefined Documenter kwargs :format from additional kwargs" - check_kwargs(kwargs, warn_str) - - kwargs = (checkdocs = :none, strict = true, format = :markdown, stringarg = "string") - warn_str = "Ignoring predefined Documenter kwargs :format from additional kwargs" - check_kwargs(kwargs, warn_str) -end - -include(joinpath("interactive", "interactive.jl")) From 05b8d2245a7d1f9ef560e2460c5ac18c1a9ee409 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Thu, 26 Sep 2019 10:28:05 +0700 Subject: [PATCH 51/81] Add interactive Template constructor, but not interactive Plugins --- src/interactive.jl | 123 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 118 insertions(+), 5 deletions(-) diff --git a/src/interactive.jl b/src/interactive.jl index 2da39cfb..991ead4f 100644 --- a/src/interactive.jl +++ b/src/interactive.jl @@ -1,8 +1,3 @@ -# const PLUGIN_TYPES = let -# leaves(T::Type) = isconcretetype(T) ? [T] : vcat(map(leaves, subtypes(T))...) -# leaves(Plugin) -# end - function Base.show(io::IO, ::MIME"text/plain", p::T) where T <: Plugin indent = get(io, :indent, 0) print(io, repeat(' ', indent), T) @@ -21,6 +16,15 @@ else show_field(x::AbstractString) = repr(contractuser(x)) end +""" + interactive(::Type{T<:Plugin}) -> T + +Create a [`Plugin`](@ref) of type `T` interactively from user input. +""" +function interactive(::Type{T}) where T <: Plugin + return T() # TODO +end + function Base.show(io::IO, m::MIME"text/plain", t::Template) println(io, "Template:") foreach(fieldnames(Template)) do n @@ -36,3 +40,112 @@ function Base.show(io::IO, m::MIME"text/plain", t::Template) end end end + +leaves(T::Type) = isconcretetype(T) ? [T] : vcat(map(leaves, subtypes(T))...) + +function plugin_types() + Ts = leaves(Plugin) + # Hack both Documenter types into the list. + # Unfortunately there's no way to do this automatically, + # but it's unlikely for more parametric plugin types to exist. + push!(Ts, Documenter{TravisCI}, Documenter{GitLabCI}) + return Ts +end + +function Template(::Val{true}; kwargs...) + opts = Dict{Symbol, Any}(kwargs) + + if !haskey(opts, :user) + opts[:user] = prompt(String, "Git hosting service username", defaultkw(:user)) + end + + if !haskey(opts, :host) + opts[:host] = prompt(String, "Git hosting service URL", defaultkw(:host)) + end + + if !haskey(opts, :authors) + opts[:authors] = prompt(String, "Package author(s)", defaultkw(:authors)) + end + + if !haskey(opts, :dir) + opts[:dir] = prompt(String, "Path to package parent directory", defaultkw(:dir)) + end + + if !haskey(opts, :julia) + opts[:julia] = prompt(VersionNumber, "Supported Julia version", defaultkw(:julia)) + end + + if !haskey(opts, :disable_defaults) + available = map(typeof, default_plugins()) + opts[:disable_defaults] = select("Select defaults to disable:", available, []) + end + + if !haskey(opts, :plugins) + # Don't offer any disabled plugins as options. + available = setdiff(sort(plugin_types(); by=string), opts[:disable_defaults]) + initial = setdiff(map(typeof, default_plugins()), opts[:disable_defaults]) + chosen = select("Select plugins", available, initial) + opts[:plugins] = map(interactive, chosen) + end + + return Template(Val(false); opts...) +end + +function prompt(::Type{String}, s::AbstractString, default; required::Bool=false) + default isa AbstractString && (default = contractuser(default)) + default_display = required ? "REQUIRED" : repr(default) + print("$s [$default_display]: ") + input = strip(readline()) + return if isempty(input) && required + println("This option is required") + prompt(String, s, default; required=required) + elseif isempty(input) + default + else + input + end + +end + +function prompt( + ::Type{VersionNumber}, s::AbstractString, default::VersionNumber; + required::Bool=false, +) + v = prompt(String, s, default; required=required) + return if v isa VersionNumber + v + else + startswith(v, "v") && (v = v[2:end]) + v = replace(v, "\"" => "") + VersionNumber(v) + end +end + +function prompt(::Type{Bool}, s::AbstractString, default::Bool; required::Bool=false) + b = prompt(String, s, default; required=required) + return uppercase(b) in ("Y", "YES", "T", "TRUE") +end + +function prompt(::Type{Vector{String}}, s::AbstractString, default::Vector{<:AbstractString}) + # TODO +end + +# TODO: These can be made simpler when this is merged: +# https://github.com/JuliaLang/julia/pull/30043 + +select(s::AbstractString, xs::Vector, initial) = select(string, s, xs, initial) + +# Select any number of elements from a collection. +function select(f::Function, s::AbstractString, xs::Vector, initial::Vector) + m = MultiSelectMenu(map(f, xs); pagesize=length(xs)) + foreach(x -> push!(m.selected, findfirst(==(x), xs)), initial) + selection = request(s, m) + return map(i -> xs[i], collect(selection)) +end + +# Select one item frm oa collection. +function select(f::Function, s::AbstractString, xs::Vector, _initial) + # Can't use the initial value yet. + selection = request(s, RadioMenu(map(f, xs))) + return xs[selection] +end From 3aa4316ae63a54e9b53a0469852c32d5c1bfcc86 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Thu, 26 Sep 2019 10:41:05 +0700 Subject: [PATCH 52/81] Remove .DS_Store from gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index de2e6edb..0529c7fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ /docs/build/ /docs/site/ -.DS_Store *.jl.*.cov *.jl.cov *.jl.mem From 5aa0a87c358475c09c0b69694485b6502ed4c037 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Thu, 26 Sep 2019 10:42:03 +0700 Subject: [PATCH 53/81] Remove /docs/site from Documenter's gitignore --- .gitignore | 1 - src/plugins/documenter.jl | 2 +- test/fixtures/AllPlugins/.gitignore | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 0529c7fa..96092701 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ /docs/build/ -/docs/site/ *.jl.*.cov *.jl.cov *.jl.mem diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index 6931d3ac..b450013b 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -52,7 +52,7 @@ end Documenter(; kwargs...) = Documenter{Nothing}(; kwargs...) -gitignore(::Documenter) = ["/docs/build/", "/docs/site/"] +gitignore(::Documenter) = ["/docs/build/"] badges(::Documenter) = Badge[] badges(::Documenter{TravisCI}) = [ diff --git a/test/fixtures/AllPlugins/.gitignore b/test/fixtures/AllPlugins/.gitignore index 0cdd26b9..3804c222 100644 --- a/test/fixtures/AllPlugins/.gitignore +++ b/test/fixtures/AllPlugins/.gitignore @@ -2,5 +2,4 @@ *.jl.cov *.jl.mem /docs/build/ -/docs/site/ Manifest.toml From 0fcbaa83bf0514377cc65f37a66ad9b2272ee4d9 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Thu, 26 Sep 2019 13:22:20 +0700 Subject: [PATCH 54/81] Add compat with Julia 1.4 --- src/plugins/git.jl | 19 +++++++++++++------ test/git.jl | 2 +- test/runtests.jl | 6 ++++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/plugins/git.jl b/src/plugins/git.jl index 94a01bd9..06e93f6d 100644 --- a/src/plugins/git.jl +++ b/src/plugins/git.jl @@ -80,12 +80,8 @@ function posthook(p::Git, ::Template, pkg_dir::AbstractString) LibGit2.with(GitRepo(pkg_dir)) do repo LibGit2.add!(repo, ".") msg = "Files generated by PkgTemplates" - # TODO: Newer versions of Julia will not have Pkg.installed. - installed = Pkg.installed() - if haskey(installed, "PkgTemplates") - ver = string(installed["PkgTemplates"]) - msg *= "\n\nPkgTemplates version: $ver" - end + v = version_of("PkgTemplates") + v === nothing || (msg *= "\n\nPkgTemplates version: $v") commit(p, repo, pkg_dir, msg) end end @@ -99,3 +95,14 @@ function commit(p::Git, repo::GitRepo, pkg_dir::AbstractString, msg::AbstractStr end needs_username(::Git) = true + +if isdefined(Pkg, :dependencies) + function version_of(pkg::AbstractString) + for p in values(Pkg.dependencies()) + p.name == pkg && return p.version + end + return nothing + end +else + version_of(pkg::AbstractString) = get(Pkg.installed(), pkg, nothing) +end diff --git a/test/git.jl b/test/git.jl index d87870d9..25ac3192 100644 --- a/test/git.jl +++ b/test/git.jl @@ -38,7 +38,7 @@ @testset "Adds version to commit message" begin # We're careful to avoid a Pkg.update as it triggers Cassette#130. t = tpl(; disable_defaults=[Tests], plugins=[Git()]) - mock(Pkg.installed => () -> Dict("PkgTemplates" => v"1.2.3")) do _pi + mock(PT.version_of => _p -> v"1.2.3") do _i with_pkg(t) do pkg pkg_dir = joinpath(t.dir, pkg) LibGit2.with(GitRepo(pkg_dir)) do repo diff --git a/test/runtests.jl b/test/runtests.jl index 6c93fb18..dc369b81 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,7 +6,7 @@ using Random: Random using Test: @test, @testset, @test_throws using ReferenceTests: @test_reference -using SimpleMock: Mock, mock +using SimpleMock: mock using Suppressor: @suppress using PkgTemplates @@ -30,7 +30,9 @@ function with_pkg(f::Function, t::Template, pkg::AbstractString=pkgname()) try f(pkg) finally - haskey(Pkg.installed(), pkg) && @suppress Pkg.rm(pkg) + # On 1.4, this sometimes won't work, but the error is that the package isn't installed. + # We're going to delete the package directory anyways, so just ignore any errors. + PT.version_of(pkg) === nothing || try @suppress Pkg.rm(pkg) catch; end rm(joinpath(t.dir, pkg); recursive=true, force=true) end end From 17e3927eb11cc8cc183f644520da161b21a73c4d Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Thu, 26 Sep 2019 14:49:18 +0700 Subject: [PATCH 55/81] Use active_project instead of current_project for expected behaviour --- src/PkgTemplates.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index e86d1aa7..ec8f53a0 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -1,6 +1,6 @@ module PkgTemplates -using Base: current_project +using Base: active_project using Base.Filesystem: contractuser using Dates: month, today, year @@ -45,7 +45,7 @@ include("interactive.jl") # Run some function with a project activated at the given path. function with_project(f::Function, path::AbstractString) - proj = current_project() + proj = active_project() try Pkg.activate(path) f() From 3f886525a7ba44824dd66c5f9f96d910c4e8947c Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Thu, 26 Sep 2019 17:56:16 +0700 Subject: [PATCH 56/81] Start implementing the interactive plugin constructors --- src/PkgTemplates.jl | 2 +- src/plugin.jl | 30 ++++++++++++++++++++++++++++++ src/plugins/ci.jl | 8 ++++---- src/plugins/citation.jl | 2 +- src/plugins/coverage.jl | 4 ++-- src/plugins/documenter.jl | 2 +- src/plugins/git.jl | 2 +- src/plugins/readme.jl | 2 +- src/plugins/src_dir.jl | 2 +- src/plugins/tests.jl | 2 +- 10 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index ec8f53a0..a1886c20 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -11,7 +11,7 @@ using REPL.TerminalMenus: MultiSelectMenu, RadioMenu, request using UUIDs: uuid4 using Mustache: render -using Parameters: @with_kw_noshow +using Parameters: with_kw export Template, diff --git a/src/plugin.jl b/src/plugin.jl index 00fddc97..52fd04cf 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -235,6 +235,36 @@ If you are implementing a plugin that uses the `user` field of a [`Template`](@r """ needs_username(::Plugin) = false +""" + @with_defaults struct T #= ... =# end + +Wraps Parameters.jl's [`@with_kw_noshow`](https://mauro3.github.io/Parameters.jl/stable/api/#Parameters.@with_kw_noshow-Tuple{Any}) to generate keyword constructors, + +TODO explain prompt syntax. + +## Example + +```julia +struct Foo <: Plugin + file::String = "/dev/null" <- "Path to the file to use" + n::Int <- "This one has no default, but this is the interactive prompt" + xyz::String = "Without a prompt, defaultkw is not implemented for this field" +end +``` +""" +macro with_defaults(ex::Expr) + T = esc(ex.args[2].args[1]) + + # TODO: Parse out `<- "prompt"` stuff. + funcs = map(filter(arg -> arg isa Expr && arg.head === :(=), ex.args[3].args)) do arg + name = QuoteNode(arg.args[1].args[1]) + val = arg.args[2] + :(PkgTemplates.defaultkw(::Type{$T}, ::Val{$name}) = $(esc(arg.args[2]))) + end + + return Expr(:block, esc(with_kw(ex, __module__, false)), funcs...) +end + include(joinpath("plugins", "project_file.jl")) include(joinpath("plugins", "src_dir.jl")) include(joinpath("plugins", "tests.jl")) diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index 825448ad..0b2b41b7 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -44,7 +44,7 @@ Integrates your packages with [Travis CI](https://travis-ci.com). - `coverage::Bool`: Whether or not to publish code coverage (another code coverage plugin such as [`Codecov`](@ref) must also be included). $EXTRA_VERSIONS_DOC """ -@with_kw_noshow struct TravisCI <: BasicPlugin +@with_defaults struct TravisCI <: BasicPlugin file::String = default_file("travis.yml") linux::Bool = true osx::Bool = true @@ -113,7 +113,7 @@ Integrates your packages with [AppVeyor](https://appveyor.com) via [AppVeyor.jl] - `coverage::Bool`: Whether or not to publish code coverage ([`Codecov`](@ref) must also be included). $EXTRA_VERSIONS_DOC """ -@with_kw_noshow struct AppVeyor <: BasicPlugin +@with_defaults struct AppVeyor <: BasicPlugin file::String = default_file("appveyor.yml") x86::Bool = false coverage::Bool = true @@ -166,7 +166,7 @@ $EXTRA_VERSIONS_DOC !!! note Code coverage submission from Cirrus CI is not yet supported by [Coverage.jl](https://github.com/JuliaCI/Coverage.jl). """ -@with_kw_noshow struct CirrusCI <: BasicPlugin +@with_defaults struct CirrusCI <: BasicPlugin file::String = default_file("cirrus.yml") image::String = "freebsd-12-0-release-amd64" coverage::Bool = true @@ -215,7 +215,7 @@ See [`Documenter`](@ref) for more information. !!! note Nightly Julia is not supported. """ -@with_kw_noshow struct GitLabCI <: BasicPlugin +@with_defaults struct GitLabCI <: BasicPlugin file::String = default_file("gitlab-ci.yml") coverage::Bool = true # Nightly has no Docker image. diff --git a/src/plugins/citation.jl b/src/plugins/citation.jl index 805d446b..fcb8e6fc 100644 --- a/src/plugins/citation.jl +++ b/src/plugins/citation.jl @@ -7,7 +7,7 @@ Creates a `CITATION.bib` file for citing package repositories. - `file::AbstractString`: Template file for `CITATION.bib`. - `readme::Bool`: Whether or not to include a section about citing in the README. """ -@with_kw_noshow struct Citation <: BasicPlugin +@with_defaults struct Citation <: BasicPlugin file::String = default_file("CITATION.bib") readme::Bool = false end diff --git a/src/plugins/coverage.jl b/src/plugins/coverage.jl index 448cc36d..58b4cae5 100644 --- a/src/plugins/coverage.jl +++ b/src/plugins/coverage.jl @@ -8,7 +8,7 @@ Sets up code coverage submission from CI to [Codecov](https://codecov.io). ## Keyword Arguments - `file::Union{AbstractString, Nothing}`: Template file for `.codecov.yml`, or `nothing` to create no file. """ -@with_kw_noshow struct Codecov <: BasicPlugin +@with_defaults struct Codecov <: BasicPlugin file::Union{String, Nothing} = nothing end @@ -29,7 +29,7 @@ Sets up code coverage submission from CI to [Coveralls](https://coveralls.io). ## Keyword Arguments - `file::Union{AbstractString, Nothing}`: Template file for `.coveralls.yml`, or `nothing` to create no file. """ -@with_kw_noshow struct Coveralls <: BasicPlugin +@with_defaults struct Coveralls <: BasicPlugin file::Union{String, Nothing} = nothing end diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index b450013b..fcfe5b5a 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -38,7 +38,7 @@ struct Documenter{T<:Union{TravisCI, GitLabCI, Nothing}} <: Plugin make_jl::String index_md::String - # Can't use @with_kw_noshow due to some weird precompilation issues. + # Can't use @with_defaults due to some weird precompilation issues. function Documenter{T}(; assets::Vector{<:AbstractString}=String[], makedocs_kwargs::Dict{Symbol}=Dict{Symbol, Any}(), diff --git a/src/plugins/git.jl b/src/plugins/git.jl index 06e93f6d..c1ec679a 100644 --- a/src/plugins/git.jl +++ b/src/plugins/git.jl @@ -12,7 +12,7 @@ Creates a Git repository and a `.gitignore` file. - `gpgsign::Bool`: Whether or not to sign commits with your GPG key. This option requires that the Git CLI is installed, and for you to have a GPG key associated with your committer identity. """ -@with_kw_noshow struct Git <: Plugin +@with_defaults struct Git <: Plugin ignore::Vector{String} = [] ssh::Bool = false manifest::Bool = false diff --git a/src/plugins/readme.jl b/src/plugins/readme.jl index d4aca5b9..c277f623 100644 --- a/src/plugins/readme.jl +++ b/src/plugins/readme.jl @@ -14,7 +14,7 @@ By default, it includes badges for other included plugins For example, values of `"README"` or `"README.rst"` might be desired. - `inline_badges::Bool`: Whether or not to put the badges on the same line as the package name. """ -@with_kw_noshow struct Readme <: BasicPlugin +@with_defaults struct Readme <: BasicPlugin file::String = default_file("README.md") destination::String = "README.md" inline_badges::Bool = false diff --git a/src/plugins/src_dir.jl b/src/plugins/src_dir.jl index 1f07a29a..38b9acc3 100644 --- a/src/plugins/src_dir.jl +++ b/src/plugins/src_dir.jl @@ -6,7 +6,7 @@ Creates a module entrypoint. ## Keyword Arguments - `file::AbstractString`: Template file for `src/.jl`. """ -@with_kw_noshow mutable struct SrcDir <: BasicPlugin +@with_defaults mutable struct SrcDir <: BasicPlugin file::String = default_file("src", "module.jl") destination::String = joinpath("src", ".jl") end diff --git a/src/plugins/tests.jl b/src/plugins/tests.jl index 8281be6e..1dc4684a 100644 --- a/src/plugins/tests.jl +++ b/src/plugins/tests.jl @@ -14,7 +14,7 @@ Sets up testing for packages. !!! note Managing test dependencies with `test/Project.toml` is only supported in Julia 1.2 and later. """ -@with_kw_noshow struct Tests <: BasicPlugin +@with_defaults struct Tests <: BasicPlugin file::String = default_file("test", "runtests.jl") project::Bool = false end From 3a9c9634e69ec2164e1c727d2ae12ef810b55e22 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Thu, 26 Sep 2019 23:02:02 +0700 Subject: [PATCH 57/81] A bunch of experimental interactive code This needs some good tests, but it seems to be mostly working in the REPL! Some general cleanup is needed, too. --- src/interactive.jl | 93 ++++++++++++++++++++++++++++++----------- src/plugin.jl | 34 +++++++++++---- src/plugins/ci.jl | 36 ++++++++-------- src/plugins/citation.jl | 4 +- src/plugins/coverage.jl | 4 +- src/plugins/git.jl | 8 ++-- src/plugins/license.jl | 15 ++++++- src/plugins/readme.jl | 6 +-- src/plugins/src_dir.jl | 2 +- src/plugins/tests.jl | 4 +- src/template.jl | 18 ++++---- 11 files changed, 149 insertions(+), 75 deletions(-) diff --git a/src/interactive.jl b/src/interactive.jl index 991ead4f..dfe22733 100644 --- a/src/interactive.jl +++ b/src/interactive.jl @@ -16,15 +16,6 @@ else show_field(x::AbstractString) = repr(contractuser(x)) end -""" - interactive(::Type{T<:Plugin}) -> T - -Create a [`Plugin`](@ref) of type `T` interactively from user input. -""" -function interactive(::Type{T}) where T <: Plugin - return T() # TODO -end - function Base.show(io::IO, m::MIME"text/plain", t::Template) println(io, "Template:") foreach(fieldnames(Template)) do n @@ -41,6 +32,29 @@ function Base.show(io::IO, m::MIME"text/plain", t::Template) end end +""" + interactive(::Type{T<:Plugin}) -> T + +Create a [`Plugin`](@ref) of type `T` interactively from user input. +""" +function interactive(::Type{T}) where T <: Plugin + kwargs = Dict{Symbol, Any}() + + foreach(fieldnames(T)) do name + F = fieldtype(T, name) + v = Val(name) + required = !applicable(defaultkw, T, v) + default = required ? defaultkw(F) : defaultkw(T, v) + kwargs[name] = if applicable(prompt, T, v) + prompt(F, "$T: $(prompt(T, v))", default, required=required) + else + prompt(F, "$T: Value for field '$name' ($F)", default; required=required) + end + end + + return T(; kwargs...) +end + leaves(T::Type) = isconcretetype(T) ? [T] : vcat(map(leaves, subtypes(T))...) function plugin_types() @@ -56,28 +70,34 @@ function Template(::Val{true}; kwargs...) opts = Dict{Symbol, Any}(kwargs) if !haskey(opts, :user) - opts[:user] = prompt(String, "Git hosting service username", defaultkw(:user)) + default = defaultkw(Template, :user) + opts[:user] = prompt(String, "Git hosting service username", default) end if !haskey(opts, :host) - opts[:host] = prompt(String, "Git hosting service URL", defaultkw(:host)) + default = defaultkw(Template, :host) + opts[:host] = prompt(String, "Git hosting service URL", default) end if !haskey(opts, :authors) - opts[:authors] = prompt(String, "Package author(s)", defaultkw(:authors)) + default = defaultkw(Template, :authors) + opts[:authors] = prompt(String, "Package author(s)", default) end if !haskey(opts, :dir) - opts[:dir] = prompt(String, "Path to package parent directory", defaultkw(:dir)) + default = defaultkw(Template, :dir) + opts[:dir] = prompt(String, "Path to package parent directory", default) end if !haskey(opts, :julia) - opts[:julia] = prompt(VersionNumber, "Supported Julia version", defaultkw(:julia)) + default = defaultkw(Template, :julia) + opts[:julia] = prompt(VersionNumber, "Supported Julia version", default) end if !haskey(opts, :disable_defaults) available = map(typeof, default_plugins()) - opts[:disable_defaults] = select("Select defaults to disable:", available, []) + initial = defaultkw(Template, :disable_defaults) + opts[:disable_defaults] = select("Select defaults to disable:", available, initial) end if !haskey(opts, :plugins) @@ -91,20 +111,35 @@ function Template(::Val{true}; kwargs...) return Template(Val(false); opts...) end -function prompt(::Type{String}, s::AbstractString, default; required::Bool=false) +defaultkw(::Type{String}) = "" +defaultkw(::Type{Union{T, Nothing}}) where T = nothing +defaultkw(::Type{T}) where T <: Number = zero(T) +defaultkw(::Type{Vector{T}}) where T = T[] + +function prompt( + ::Type{<:Union{String, Nothing}}, s::AbstractString, default; + required::Bool=false, +) default isa AbstractString && (default = contractuser(default)) - default_display = required ? "REQUIRED" : repr(default) + default_display = if required + "REQUIRED" + elseif default === nothing + "None" + else + repr(default) + end + print("$s [$default_display]: ") input = strip(readline()) + return if isempty(input) && required - println("This option is required") + println("This option is required") prompt(String, s, default; required=required) elseif isempty(input) default else input end - end function prompt( @@ -123,11 +158,19 @@ end function prompt(::Type{Bool}, s::AbstractString, default::Bool; required::Bool=false) b = prompt(String, s, default; required=required) - return uppercase(b) in ("Y", "YES", "T", "TRUE") + return b === default ? default : uppercase(b) in ("Y", "YES", "T", "TRUE") +end + +function prompt(::Type{Vector}, s::AbstractString, default::Vector; required::Bool=false) + return prompt(Vector{String}, s, default; required=required) end -function prompt(::Type{Vector{String}}, s::AbstractString, default::Vector{<:AbstractString}) - # TODO +function prompt( + ::Type{Vector{String}}, s::AbstractString, default::Vector{<:AbstractString}; + required::Bool=false, +) + s = prompt(String, "$s (comma-delimited)", join(default, ", "); required=required) + return convert(Vector{String}, map(strip, split(s, ","; keepempty=false))) end # TODO: These can be made simpler when this is merged: @@ -144,8 +187,8 @@ function select(f::Function, s::AbstractString, xs::Vector, initial::Vector) end # Select one item frm oa collection. -function select(f::Function, s::AbstractString, xs::Vector, _initial) - # Can't use the initial value yet. - selection = request(s, RadioMenu(map(f, xs))) +function select(f::Function, s::AbstractString, xs::Vector, initial) + print(stdin.buffer, repeat("\e[B", findfirst(==(initial), xs) - 1)) + selection = request("$s:", RadioMenu(map(f, xs); pagesize=length(xs))) return xs[selection] end diff --git a/src/plugin.jl b/src/plugin.jl index 52fd04cf..23cf3060 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -235,6 +235,11 @@ If you are implementing a plugin that uses the `user` field of a [`Template`](@r """ needs_username(::Plugin) = false +function prompt end + +iscall(x, ::Symbol) = false +iscall(ex::Expr, s::Symbol) = ex.head === :call && ex.args[1] === s + """ @with_defaults struct T #= ... =# end @@ -253,13 +258,28 @@ end ``` """ macro with_defaults(ex::Expr) - T = esc(ex.args[2].args[1]) - - # TODO: Parse out `<- "prompt"` stuff. - funcs = map(filter(arg -> arg isa Expr && arg.head === :(=), ex.args[3].args)) do arg - name = QuoteNode(arg.args[1].args[1]) - val = arg.args[2] - :(PkgTemplates.defaultkw(::Type{$T}, ::Val{$name}) = $(esc(arg.args[2]))) + T = esc(ex.args[2].args[1]) # This assumes T <: U. + + # This is a bit nasty. + funcs = Expr[] + foreach(filter(arg -> arg isa Expr, ex.args[3].args)) do arg + if iscall(arg, :<) && iscall(arg.args[3], :-) # x::T <- "prompt" + name = QuoteNode(arg.args[2].args[1]) + prompt = arg.args[2] + push!(funcs, :(PkgTemplates.prompt(::Type{$T}, ::Val{$name}) = $(esc(prompt)))) + elseif arg.head === :(=) + rhs = arg.args[2] + if iscall(rhs, :<) && iscall(rhs.args[3], :-) # x::T = "foo" <- "prompt" + name = QuoteNode(arg.args[1].args[1]) + prompt = rhs.args[3].args[2] + default = arg.args[2] = rhs.args[2] + push!( + funcs, + :(PkgTemplates.prompt(::Type{$T}, ::Val{$name}) = $(esc(prompt))), + :(PkgTemplates.defaultkw(::Type{$T}, ::Val{$name}) = $(esc(default))), + ) + end + end end return Expr(:block, esc(with_kw(ex, __module__, false)), funcs...) diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index 0b2b41b7..a9ce0fc2 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -45,13 +45,13 @@ Integrates your packages with [Travis CI](https://travis-ci.com). $EXTRA_VERSIONS_DOC """ @with_defaults struct TravisCI <: BasicPlugin - file::String = default_file("travis.yml") - linux::Bool = true - osx::Bool = true - windows::Bool = true - x86::Bool = false - coverage::Bool = true - extra_versions::Vector = DEFAULT_CI_VERSIONS + file::String = default_file("travis.yml") <- "Path to .travis.yml template" + linux::Bool = true <- "Enable Linux bulds" + osx::Bool = true <- "Enable OSX builds" + windows::Bool = true <- "Enable Windows builds" + x86::Bool = false <- "Enable 32-bit builds" + coverage::Bool = true <- "Enable code coverage submission" + extra_versions::Vector = DEFAULT_CI_VERSIONS <- "Extra Julia versions to test" end source(p::TravisCI) = p.file @@ -114,10 +114,10 @@ Integrates your packages with [AppVeyor](https://appveyor.com) via [AppVeyor.jl] $EXTRA_VERSIONS_DOC """ @with_defaults struct AppVeyor <: BasicPlugin - file::String = default_file("appveyor.yml") - x86::Bool = false - coverage::Bool = true - extra_versions::Vector = DEFAULT_CI_VERSIONS + file::String = default_file("appveyor.yml") <- "Path to .appveyor.yml template" + x86::Bool = false <- "Enable 32-bit builds" + coverage::Bool = true <- "Enable code coverage submission" + extra_versions::Vector = DEFAULT_CI_VERSIONS <- "Extra Julia versions to test" end source(p::AppVeyor) = p.file @@ -167,10 +167,10 @@ $EXTRA_VERSIONS_DOC Code coverage submission from Cirrus CI is not yet supported by [Coverage.jl](https://github.com/JuliaCI/Coverage.jl). """ @with_defaults struct CirrusCI <: BasicPlugin - file::String = default_file("cirrus.yml") - image::String = "freebsd-12-0-release-amd64" - coverage::Bool = true - extra_versions::Vector = DEFAULT_CI_VERSIONS + file::String = default_file("cirrus.yml") <- "Path to .cirrus.yml template" + image::String = "freebsd-12-0-release-amd64" <- "FreeBSD image" + coverage::Bool = true <- "Enable code coverage submission" + extra_versions::Vector = DEFAULT_CI_VERSIONS <- "Extra Julia versions to test" end source(p::CirrusCI) = p.file @@ -216,10 +216,10 @@ See [`Documenter`](@ref) for more information. Nightly Julia is not supported. """ @with_defaults struct GitLabCI <: BasicPlugin - file::String = default_file("gitlab-ci.yml") - coverage::Bool = true + file::String = default_file("gitlab-ci.yml") <- "Path to .gitlab-ci.yml template" + coverage::Bool = true <- "Enable code coverage submission" # Nightly has no Docker image. - extra_versions::Vector = map(format_version, [default_version(), VERSION]) + extra_versions::Vector = map(format_version, [default_version(), VERSION]) <- "Extra Julia versions to test" end gitignore(p::GitLabCI) = p.coverage ? COVERAGE_GITIGNORE : String[] diff --git a/src/plugins/citation.jl b/src/plugins/citation.jl index fcb8e6fc..68b6f25d 100644 --- a/src/plugins/citation.jl +++ b/src/plugins/citation.jl @@ -8,8 +8,8 @@ Creates a `CITATION.bib` file for citing package repositories. - `readme::Bool`: Whether or not to include a section about citing in the README. """ @with_defaults struct Citation <: BasicPlugin - file::String = default_file("CITATION.bib") - readme::Bool = false + file::String = default_file("CITATION.bib") <- "Path to CITATION.bib template" + readme::Bool = false <- """Enable "Citing" README section""" end tags(::Citation) = "<<", ">>" diff --git a/src/plugins/coverage.jl b/src/plugins/coverage.jl index 58b4cae5..26d11df6 100644 --- a/src/plugins/coverage.jl +++ b/src/plugins/coverage.jl @@ -9,7 +9,7 @@ Sets up code coverage submission from CI to [Codecov](https://codecov.io). - `file::Union{AbstractString, Nothing}`: Template file for `.codecov.yml`, or `nothing` to create no file. """ @with_defaults struct Codecov <: BasicPlugin - file::Union{String, Nothing} = nothing + file::Union{String, Nothing} = nothing <- "Path to .codecov.yml template" end source(p::Codecov) = p.file @@ -30,7 +30,7 @@ Sets up code coverage submission from CI to [Coveralls](https://coveralls.io). - `file::Union{AbstractString, Nothing}`: Template file for `.coveralls.yml`, or `nothing` to create no file. """ @with_defaults struct Coveralls <: BasicPlugin - file::Union{String, Nothing} = nothing + file::Union{String, Nothing} = nothing <- "Path to .coveralls.yml template" end source(p::Coveralls) = p.file diff --git a/src/plugins/git.jl b/src/plugins/git.jl index c1ec679a..8ba57180 100644 --- a/src/plugins/git.jl +++ b/src/plugins/git.jl @@ -13,10 +13,10 @@ Creates a Git repository and a `.gitignore` file. This option requires that the Git CLI is installed, and for you to have a GPG key associated with your committer identity. """ @with_defaults struct Git <: Plugin - ignore::Vector{String} = [] - ssh::Bool = false - manifest::Bool = false - gpgsign::Bool = false + ignore::Vector{String} = String[] <- "Gitignore entries" + ssh::Bool = false <- "Enable SSH Git remote" + manifest::Bool = false <- "Commit Manifest.toml" + gpgsign::Bool = false <- "GPG-sign commits" end # Try to make sure that no files are created after we commit. diff --git a/src/plugins/license.jl b/src/plugins/license.jl index f6bf72ca..5a2fc207 100644 --- a/src/plugins/license.jl +++ b/src/plugins/license.jl @@ -16,7 +16,7 @@ struct License <: BasicPlugin destination::String end -function License( +function License(; name::AbstractString="MIT", path::Union{AbstractString, Nothing}=nothing, destination::AbstractString="LICENSE", @@ -28,10 +28,21 @@ function License( return License(path, destination) end - source(p::License) = p.path destination(p::License) = p.destination view(::License, t::Template, ::AbstractString) = Dict( "AUTHORS" => join(t.authors, ", "), "YEAR" => year(today()), ) + +function interactive(::Type{License}) + destination = prompt(String, "License: License file destination", "LICENSE") + return if prompt(Bool, "License: Use custom license file", false) + path = prompt(String, "License: Path to custom license file", ""; required=true) + License(; path=path, destination=destination) + else + available = sort(readdir(joinpath(TEMPLATES_DIR, "licenses"))) + name = select("License: Select a license", available, "MIT") + License(; name=name, destination=destination) + end +end diff --git a/src/plugins/readme.jl b/src/plugins/readme.jl index c277f623..f982fab2 100644 --- a/src/plugins/readme.jl +++ b/src/plugins/readme.jl @@ -15,9 +15,9 @@ By default, it includes badges for other included plugins - `inline_badges::Bool`: Whether or not to put the badges on the same line as the package name. """ @with_defaults struct Readme <: BasicPlugin - file::String = default_file("README.md") - destination::String = "README.md" - inline_badges::Bool = false + file::String = default_file("README.md") <- "Path to README.md template" + destination::String = "README.md" <- "README file destination" + inline_badges::Bool = false <- "Enable inline badges" end source(p::Readme) = p.file diff --git a/src/plugins/src_dir.jl b/src/plugins/src_dir.jl index 38b9acc3..9f0c58a3 100644 --- a/src/plugins/src_dir.jl +++ b/src/plugins/src_dir.jl @@ -7,7 +7,7 @@ Creates a module entrypoint. - `file::AbstractString`: Template file for `src/.jl`. """ @with_defaults mutable struct SrcDir <: BasicPlugin - file::String = default_file("src", "module.jl") + file::String = default_file("src", "module.jl") <- "Path to src/.jl template" destination::String = joinpath("src", ".jl") end diff --git a/src/plugins/tests.jl b/src/plugins/tests.jl index 1dc4684a..e125ee17 100644 --- a/src/plugins/tests.jl +++ b/src/plugins/tests.jl @@ -15,8 +15,8 @@ Sets up testing for packages. Managing test dependencies with `test/Project.toml` is only supported in Julia 1.2 and later. """ @with_defaults struct Tests <: BasicPlugin - file::String = default_file("test", "runtests.jl") - project::Bool = false + file::String = default_file("test", "runtests.jl") <- "Path to runtests.jl template" + project::Bool = false <- "Enable test/Project.toml" end source(p::Tests) = p.file diff --git a/src/template.jl b/src/template.jl index 9a08ae07..fa190188 100644 --- a/src/template.jl +++ b/src/template.jl @@ -127,14 +127,14 @@ function getplugin(t::Template, ::Type{T}) where T <: Plugin end # Get a keyword, or compute some default value. -getkw(kwargs, k) = get(() -> defaultkw(k), kwargs, k) +getkw(kwargs, k) = get(() -> defaultkw(Template, k), kwargs, k) # Default Template keyword values. -defaultkw(s::Symbol) = defaultkw(Val(s)) -defaultkw(::Val{:authors}) = default_authors() -defaultkw(::Val{:dir}) = Pkg.devdir() -defaultkw(::Val{:disable_defaults}) = DataType[] -defaultkw(::Val{:host}) = "github.com" -defaultkw(::Val{:julia}) = default_version() -defaultkw(::Val{:plugins}) = Plugin[] -defaultkw(::Val{:user}) = default_user() +defaultkw(::Type{T}, s::Symbol) where T = defaultkw(T, Val(s)) +defaultkw(::Type{Template}, ::Val{:authors}) = default_authors() +defaultkw(::Type{Template}, ::Val{:dir}) = Pkg.devdir() +defaultkw(::Type{Template}, ::Val{:disable_defaults}) = DataType[] +defaultkw(::Type{Template}, ::Val{:host}) = "github.com" +defaultkw(::Type{Template}, ::Val{:julia}) = default_version() +defaultkw(::Type{Template}, ::Val{:plugins}) = Plugin[] +defaultkw(::Type{Template}, ::Val{:user}) = default_user() From a373a25c05d2cc3c4743798458c10a7a127dc658 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Fri, 27 Sep 2019 00:08:02 +0700 Subject: [PATCH 58/81] Add interactive constructor for Documenter --- src/interactive.jl | 12 +++++++++++- src/plugins/documenter.jl | 26 ++++++++++++++++++++++++-- src/plugins/src_dir.jl | 2 +- templates/docs/{ => src}/index.md | 0 4 files changed, 36 insertions(+), 4 deletions(-) rename templates/docs/{ => src}/index.md (100%) diff --git a/src/interactive.jl b/src/interactive.jl index dfe22733..a60c86ae 100644 --- a/src/interactive.jl +++ b/src/interactive.jl @@ -173,6 +173,16 @@ function prompt( return convert(Vector{String}, map(strip, split(s, ","; keepempty=false))) end +function prompt(::Type{<:Dict}, s::AbstractString, default::Dict, required::Bool=false) + default_display = join(map(p -> "$(p.first)=$(p.second)", collect(default)), ", ") + s = prompt(String, "$s (k=v, comma-delimited)", default_display; required=required) + return if isempty(s) + Dict{String, String}() + else + Dict{String, String}(Pair(split(strip(kv), "=")...) for kv in split(s, ",")) + end +end + # TODO: These can be made simpler when this is merged: # https://github.com/JuliaLang/julia/pull/30043 @@ -182,7 +192,7 @@ select(s::AbstractString, xs::Vector, initial) = select(string, s, xs, initial) function select(f::Function, s::AbstractString, xs::Vector, initial::Vector) m = MultiSelectMenu(map(f, xs); pagesize=length(xs)) foreach(x -> push!(m.selected, findfirst(==(x), xs)), initial) - selection = request(s, m) + selection = request("$s:", m) return map(i -> xs[i], collect(selection)) end diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index fcfe5b5a..bf158ad7 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -6,7 +6,7 @@ const DOCUMENTER_DEP = PackageSpec(; """ Documenter{T<:Union{TravisCI, GitLabCI, Nothing}}(; make_jl="$(contractuser(default_file("docs", "make.jl")))", - index_md="$(contractuser(default_file("docs", "index.md")))", + index_md="$(contractuser(default_file("docs", "src", "index.md")))", assets=String[], canonical_url=make_canonical(T), makedocs_kwargs=Dict{Symbol, Any}(), @@ -44,7 +44,7 @@ struct Documenter{T<:Union{TravisCI, GitLabCI, Nothing}} <: Plugin makedocs_kwargs::Dict{Symbol}=Dict{Symbol, Any}(), canonical_url::Union{Function, Nothing}=make_canonical(T), make_jl::AbstractString=default_file("docs", "make.jl"), - index_md::AbstractString=default_file("docs", "index.md"), + index_md::AbstractString=default_file("docs", "src", "index.md"), ) where T <: Union{TravisCI, GitLabCI, Nothing} return new(assets, makedocs_kwargs, canonical_url, make_jl, index_md) end @@ -52,6 +52,28 @@ end Documenter(; kwargs...) = Documenter{Nothing}(; kwargs...) +function interactive(::Type{Documenter}) + kwargs = Dict{Symbol, Any}() + + default = default_file("docs", "make.jl") + kwargs[:make_jl] = prompt(String, "Documenter: Path to make.jl template", default) + + default = default_file("docs", "src", "index.md") + kwargs[:index_md] = prompt(String, "Documenter: Path to make.jl template", default) + + kwargs[:assets] = prompt(Vector{String}, "Documenter: Extra asset files", String[]) + + md_kw = prompt(Dict{String, String}, "Documenter: makedocs keyword arguments", Dict()) + parsed = Dict{Symbol, Any}(Symbol(p.first) => eval(Meta.parse(p.second)) for p in md_kw) + kwargs[:makedocs_kwargs] = parsed + + available = [Nothing, TravisCI, GitLabCI] + f = T -> string(nameof(T)) + T = select(f, "Documenter: Documentation deployment strategy", available, Nothing) + + return Documenter{T}(; kwargs...) +end + gitignore(::Documenter) = ["/docs/build/"] badges(::Documenter) = Badge[] diff --git a/src/plugins/src_dir.jl b/src/plugins/src_dir.jl index 9f0c58a3..d23fda21 100644 --- a/src/plugins/src_dir.jl +++ b/src/plugins/src_dir.jl @@ -7,7 +7,7 @@ Creates a module entrypoint. - `file::AbstractString`: Template file for `src/.jl`. """ @with_defaults mutable struct SrcDir <: BasicPlugin - file::String = default_file("src", "module.jl") <- "Path to src/.jl template" + file::String = default_file("src", "module.jl") <- "Path to .jl template" destination::String = joinpath("src", ".jl") end diff --git a/templates/docs/index.md b/templates/docs/src/index.md similarity index 100% rename from templates/docs/index.md rename to templates/docs/src/index.md From 719538e9e885a2f1358e3bc21ec596fbb4934760 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Fri, 27 Sep 2019 11:54:00 +0700 Subject: [PATCH 59/81] Move some code around --- src/PkgTemplates.jl | 1 + src/interactive.jl | 34 ------------------ src/plugin.jl | 88 ++++++++++++++++++++++----------------------- src/show.jl | 33 +++++++++++++++++ 4 files changed, 77 insertions(+), 79 deletions(-) create mode 100644 src/show.jl diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index a1886c20..9afc6672 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -41,6 +41,7 @@ abstract type Plugin end include("template.jl") include("plugin.jl") +include("show.jl") include("interactive.jl") # Run some function with a project activated at the given path. diff --git a/src/interactive.jl b/src/interactive.jl index a60c86ae..782dec1b 100644 --- a/src/interactive.jl +++ b/src/interactive.jl @@ -1,37 +1,3 @@ -function Base.show(io::IO, ::MIME"text/plain", p::T) where T <: Plugin - indent = get(io, :indent, 0) - print(io, repeat(' ', indent), T) - ns = fieldnames(T) - isempty(ns) || print(io, ":") - foreach(ns) do n - println(io) - print(io, repeat(' ', indent + 2), n, ": ", show_field(getfield(p, n))) - end -end - -show_field(x) = repr(x) -if Sys.iswindows() - show_field(x::AbstractString) = replace(repr(contractuser(x)), "\\\\" => "\\") -else - show_field(x::AbstractString) = repr(contractuser(x)) -end - -function Base.show(io::IO, m::MIME"text/plain", t::Template) - println(io, "Template:") - foreach(fieldnames(Template)) do n - n === :plugins || println(io, repeat(' ', 2), n, ": ", show_field(getfield(t, n))) - end - if isempty(t.plugins) - print(io, " plugins: None") - else - print(io, repeat(' ', 2), "plugins:") - foreach(sort(t.plugins; by=string)) do p - println(io) - show(IOContext(io, :indent => 4), m, p) - end - end -end - """ interactive(::Type{T<:Plugin}) -> T diff --git a/src/plugin.jl b/src/plugin.jl index 23cf3060..c6623eef 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -1,6 +1,49 @@ const TEMPLATES_DIR = normpath(joinpath(@__DIR__, "..", "templates")) const DEFAULT_PRIORITY = 1000 +""" + @with_defaults struct T #= ... =# end + +Wraps Parameters.jl's [`@with_kw_noshow`](https://mauro3.github.io/Parameters.jl/stable/api/#Parameters.@with_kw_noshow-Tuple{Any}) to generate keyword constructors, + +## Example + +```julia +struct Foo <: Plugin + file::String = "/dev/null" <- "Path to the file to use" + n::Int <- "This one has no default, but this is the interactive prompt" + xyz::String = "Without a prompt, defaultkw is not implemented for this field" +end +``` +""" +macro with_defaults(ex::Expr) + T = esc(ex.args[2].args[1]) # This assumes T <: U. + + # This is a bit nasty. + funcs = Expr[] + foreach(filter(arg -> arg isa Expr, ex.args[3].args)) do arg + if iscall(arg, :<) && iscall(arg.args[3], :-) # x::T <- "prompt" + name = QuoteNode(arg.args[2].args[1]) + prompt = arg.args[2] + push!(funcs, :(PkgTemplates.prompt(::Type{$T}, ::Val{$name}) = $(esc(prompt)))) + elseif arg.head === :(=) + rhs = arg.args[2] + if iscall(rhs, :<) && iscall(rhs.args[3], :-) # x::T = "foo" <- "prompt" + name = QuoteNode(arg.args[1].args[1]) + prompt = rhs.args[3].args[2] + default = arg.args[2] = rhs.args[2] + push!( + funcs, + :(PkgTemplates.prompt(::Type{$T}, ::Val{$name}) = $(esc(prompt))), + :(PkgTemplates.defaultkw(::Type{$T}, ::Val{$name}) = $(esc(default))), + ) + end + end + end + + return Expr(:block, esc(with_kw(ex, __module__, false)), funcs...) +end + """ A simple plugin that, in general, creates a single file. """ @@ -240,51 +283,6 @@ function prompt end iscall(x, ::Symbol) = false iscall(ex::Expr, s::Symbol) = ex.head === :call && ex.args[1] === s -""" - @with_defaults struct T #= ... =# end - -Wraps Parameters.jl's [`@with_kw_noshow`](https://mauro3.github.io/Parameters.jl/stable/api/#Parameters.@with_kw_noshow-Tuple{Any}) to generate keyword constructors, - -TODO explain prompt syntax. - -## Example - -```julia -struct Foo <: Plugin - file::String = "/dev/null" <- "Path to the file to use" - n::Int <- "This one has no default, but this is the interactive prompt" - xyz::String = "Without a prompt, defaultkw is not implemented for this field" -end -``` -""" -macro with_defaults(ex::Expr) - T = esc(ex.args[2].args[1]) # This assumes T <: U. - - # This is a bit nasty. - funcs = Expr[] - foreach(filter(arg -> arg isa Expr, ex.args[3].args)) do arg - if iscall(arg, :<) && iscall(arg.args[3], :-) # x::T <- "prompt" - name = QuoteNode(arg.args[2].args[1]) - prompt = arg.args[2] - push!(funcs, :(PkgTemplates.prompt(::Type{$T}, ::Val{$name}) = $(esc(prompt)))) - elseif arg.head === :(=) - rhs = arg.args[2] - if iscall(rhs, :<) && iscall(rhs.args[3], :-) # x::T = "foo" <- "prompt" - name = QuoteNode(arg.args[1].args[1]) - prompt = rhs.args[3].args[2] - default = arg.args[2] = rhs.args[2] - push!( - funcs, - :(PkgTemplates.prompt(::Type{$T}, ::Val{$name}) = $(esc(prompt))), - :(PkgTemplates.defaultkw(::Type{$T}, ::Val{$name}) = $(esc(default))), - ) - end - end - end - - return Expr(:block, esc(with_kw(ex, __module__, false)), funcs...) -end - include(joinpath("plugins", "project_file.jl")) include(joinpath("plugins", "src_dir.jl")) include(joinpath("plugins", "tests.jl")) diff --git a/src/show.jl b/src/show.jl new file mode 100644 index 00000000..fddad047 --- /dev/null +++ b/src/show.jl @@ -0,0 +1,33 @@ +function Base.show(io::IO, m::MIME"text/plain", t::Template) + println(io, "Template:") + foreach(fieldnames(Template)) do n + n === :plugins || println(io, repeat(' ', 2), n, ": ", show_field(getfield(t, n))) + end + if isempty(t.plugins) + print(io, " plugins: None") + else + print(io, repeat(' ', 2), "plugins:") + foreach(sort(t.plugins; by=string)) do p + println(io) + show(IOContext(io, :indent => 4), m, p) + end + end +end + +function Base.show(io::IO, ::MIME"text/plain", p::T) where T <: Plugin + indent = get(io, :indent, 0) + print(io, repeat(' ', indent), T) + ns = fieldnames(T) + isempty(ns) || print(io, ":") + foreach(ns) do n + println(io) + print(io, repeat(' ', indent + 2), n, ": ", show_field(getfield(p, n))) + end +end + +show_field(x) = repr(x) +if Sys.iswindows() + show_field(x::AbstractString) = replace(repr(contractuser(x)), "\\\\" => "\\") +else + show_field(x::AbstractString) = repr(contractuser(x)) +end From f7743df133fc0a19c6e463788b0fa8a12226e9a6 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Fri, 27 Sep 2019 23:50:23 +0700 Subject: [PATCH 60/81] Add more template saving recommendations --- docs/src/user.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/docs/src/user.md b/docs/src/user.md index 6d344209..b9624299 100644 --- a/docs/src/user.md +++ b/docs/src/user.md @@ -201,3 +201,38 @@ end ``` Add this to your `startup.jl`, and you can create your template from anywhere, without incurring any startup cost. + +Another strategy is to write the string representation of the template to a Julia file: + +```julia +const t = Template(; #= ... =#) +open("template.jl", "w") do io + println(io, "using PkgTemplates") + sprint(show, io, t) +end +``` + +Then the template is just an `include` away: + +```julia +const t = include("template.jl") +``` + +The only disadvantage to this approach is that the saved template is much less human-readable than code you wrote yourself. + +One more method of saving templates is to simply use the Serialization package in the standard library: + +```julia +const t = Template(; #= ... =#) +using Serialization +open(io -> serialize(io, t), "template.bin", "w") +``` + +Then simply `deserialize` to load: + +```julia +using Serialization +const t = open(deserialize, "template.bin") +``` + +This approach has the same disadvantage as the previous one, and the serialization format is not guaranteed to be stable across Julia versions. From f630f9c3f4e74339d5afb76dd7e256a61b43ad1d Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sat, 28 Sep 2019 00:07:55 +0700 Subject: [PATCH 61/81] Properly allow not prompting for fields with defaults --- src/interactive.jl | 4 +++- src/plugin.jl | 11 ++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/interactive.jl b/src/interactive.jl index 782dec1b..a26414ac 100644 --- a/src/interactive.jl +++ b/src/interactive.jl @@ -13,8 +13,10 @@ function interactive(::Type{T}) where T <: Plugin default = required ? defaultkw(F) : defaultkw(T, v) kwargs[name] = if applicable(prompt, T, v) prompt(F, "$T: $(prompt(T, v))", default, required=required) - else + elseif required prompt(F, "$T: Value for field '$name' ($F)", default; required=required) + else + default end end diff --git a/src/plugin.jl b/src/plugin.jl index c6623eef..bc5bba1f 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -28,16 +28,13 @@ macro with_defaults(ex::Expr) push!(funcs, :(PkgTemplates.prompt(::Type{$T}, ::Val{$name}) = $(esc(prompt)))) elseif arg.head === :(=) rhs = arg.args[2] + name = QuoteNode(arg.args[1].args[1]) if iscall(rhs, :<) && iscall(rhs.args[3], :-) # x::T = "foo" <- "prompt" - name = QuoteNode(arg.args[1].args[1]) prompt = rhs.args[3].args[2] - default = arg.args[2] = rhs.args[2] - push!( - funcs, - :(PkgTemplates.prompt(::Type{$T}, ::Val{$name}) = $(esc(prompt))), - :(PkgTemplates.defaultkw(::Type{$T}, ::Val{$name}) = $(esc(default))), - ) + push!(funcs, :(PkgTemplates.prompt(::Type{$T}, ::Val{$name}) = $(esc(prompt)))) end + default = arg.args[2] = rhs.args[2] + push!(funcs, :(PkgTemplates.defaultkw(::Type{$T}, ::Val{$name}) = $(esc(default)))) end end From 19afffbbb8a550f5f9760367211fd7b1be965696 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sat, 28 Sep 2019 00:12:25 +0700 Subject: [PATCH 62/81] Add a compat entry for Mustache Since we're using custom tags. --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index 58aa3f7c..ac0ddbf2 100644 --- a/Project.toml +++ b/Project.toml @@ -15,6 +15,7 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [compat] julia = "1" +Mustache = ">= 0.5.13" [extras] Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" From aa3e7769edc0081dbcef5616767f047ce92b13e2 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sat, 28 Sep 2019 09:45:24 +0700 Subject: [PATCH 63/81] Add another set of reference tests, fix a bug they found --- src/plugins/documenter.jl | 2 +- templates/docs/make.jl | 2 +- test/fixtures/WackyOptions/.appveyor.yml | 31 +++++++ test/fixtures/WackyOptions/.cirrus.yml | 13 +++ test/fixtures/WackyOptions/.codecov.yml | 1 + test/fixtures/WackyOptions/.coveralls.yml | 1 + test/fixtures/WackyOptions/.gitignore | 7 ++ test/fixtures/WackyOptions/.gitlab-ci.yml | 29 ++++++ test/fixtures/WackyOptions/.travis.yml | 19 ++++ test/fixtures/WackyOptions/CITATION.bib | 8 ++ test/fixtures/WackyOptions/LICENSE | 15 ++++ test/fixtures/WackyOptions/Manifest.toml | 2 + test/fixtures/WackyOptions/Project.toml | 7 ++ test/fixtures/WackyOptions/README.md | 5 ++ test/fixtures/WackyOptions/docs/Manifest.toml | 89 +++++++++++++++++++ test/fixtures/WackyOptions/docs/Project.toml | 2 + test/fixtures/WackyOptions/docs/make.jl | 20 +++++ .../WackyOptions/docs/src/assets/static.txt | 1 + test/fixtures/WackyOptions/docs/src/index.md | 12 +++ .../fixtures/WackyOptions/src/WackyOptions.jl | 5 ++ test/fixtures/WackyOptions/test/Manifest.toml | 33 +++++++ test/fixtures/WackyOptions/test/Project.toml | 2 + test/fixtures/WackyOptions/test/runtests.jl | 6 ++ test/fixtures/static.txt | 1 + test/reference.jl | 25 +++++- 25 files changed, 333 insertions(+), 5 deletions(-) create mode 100644 test/fixtures/WackyOptions/.appveyor.yml create mode 100644 test/fixtures/WackyOptions/.cirrus.yml create mode 100644 test/fixtures/WackyOptions/.codecov.yml create mode 100644 test/fixtures/WackyOptions/.coveralls.yml create mode 100644 test/fixtures/WackyOptions/.gitignore create mode 100644 test/fixtures/WackyOptions/.gitlab-ci.yml create mode 100644 test/fixtures/WackyOptions/.travis.yml create mode 100644 test/fixtures/WackyOptions/CITATION.bib create mode 100644 test/fixtures/WackyOptions/LICENSE create mode 100644 test/fixtures/WackyOptions/Manifest.toml create mode 100644 test/fixtures/WackyOptions/Project.toml create mode 100644 test/fixtures/WackyOptions/README.md create mode 100644 test/fixtures/WackyOptions/docs/Manifest.toml create mode 100644 test/fixtures/WackyOptions/docs/Project.toml create mode 100644 test/fixtures/WackyOptions/docs/make.jl create mode 100644 test/fixtures/WackyOptions/docs/src/assets/static.txt create mode 100644 test/fixtures/WackyOptions/docs/src/index.md create mode 100644 test/fixtures/WackyOptions/src/WackyOptions.jl create mode 100644 test/fixtures/WackyOptions/test/Manifest.toml create mode 100644 test/fixtures/WackyOptions/test/Project.toml create mode 100644 test/fixtures/WackyOptions/test/runtests.jl create mode 100644 test/fixtures/static.txt diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index bf158ad7..5c232236 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -96,7 +96,7 @@ badges(::Documenter{GitLabCI}) = Badge( ) view(p::Documenter, t::Template, pkg::AbstractString) = Dict( - "ASSETS" => p.assets, + "ASSETS" => map(basename, p.assets), "AUTHORS" => join(t.authors, ", "), "CANONICAL" => p.canonical_url === nothing ? nothing : p.canonical_url(t, pkg), "HAS_ASSETS" => !isempty(p.assets), diff --git a/templates/docs/make.jl b/templates/docs/make.jl index 366e5a8f..a9a09c9d 100644 --- a/templates/docs/make.jl +++ b/templates/docs/make.jl @@ -12,7 +12,7 @@ makedocs(; {{/CANONICAL}} assets={{^HAS_ASSETS}}String{{/HAS_ASSETS}}[{{^HAS_ASSETS}}],{{/HAS_ASSETS}} {{#ASSETS}} - "{{{.}}}", + "assets/{{{.}}}", {{/ASSETS}} {{#HAS_ASSETS}} ], diff --git a/test/fixtures/WackyOptions/.appveyor.yml b/test/fixtures/WackyOptions/.appveyor.yml new file mode 100644 index 00000000..5f56bb54 --- /dev/null +++ b/test/fixtures/WackyOptions/.appveyor.yml @@ -0,0 +1,31 @@ +# Documentation: https://github.com/JuliaCI/Appveyor.jl +environment: + matrix: + - julia_version: 1.2 + - julia_version: 1.3 +platform: + - x64 + - x86 +matrix: + allow_failures: + - julia_version: 1.3 +branches: + only: + - master + - /release-.*/ +notifications: + - provider: Email + on_build_success: false + on_build_failure: false + on_build_status_changed: false +install: + - ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1")) +build_script: + - echo "%JL_BUILD_SCRIPT%" + - C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%" +test_script: + - echo "%JL_TEST_SCRIPT%" + - C:\julia\bin\julia -e "%JL_TEST_SCRIPT%" +on_success: + - echo "%JL_CODECOV_SCRIPT%" + - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%" diff --git a/test/fixtures/WackyOptions/.cirrus.yml b/test/fixtures/WackyOptions/.cirrus.yml new file mode 100644 index 00000000..3c3ac8df --- /dev/null +++ b/test/fixtures/WackyOptions/.cirrus.yml @@ -0,0 +1,13 @@ +freebsd_instance: + image: freebsd-123 +task: + name: FreeBSD + env: + JULIA_VERSION: 1.1 + JULIA_VERSION: 1.2 + install_script: + - sh -c "$(fetch https://raw.githubusercontent.com/ararslan/CirrusCI.jl/master/bin/install.sh -o -)" + build_script: + - cirrusjl build + test_script: + - cirrusjl test diff --git a/test/fixtures/WackyOptions/.codecov.yml b/test/fixtures/WackyOptions/.codecov.yml new file mode 100644 index 00000000..7846e37f --- /dev/null +++ b/test/fixtures/WackyOptions/.codecov.yml @@ -0,0 +1 @@ +DO NOT CHANGE THE CONTENTS OF THIS FILE! diff --git a/test/fixtures/WackyOptions/.coveralls.yml b/test/fixtures/WackyOptions/.coveralls.yml new file mode 100644 index 00000000..7846e37f --- /dev/null +++ b/test/fixtures/WackyOptions/.coveralls.yml @@ -0,0 +1 @@ +DO NOT CHANGE THE CONTENTS OF THIS FILE! diff --git a/test/fixtures/WackyOptions/.gitignore b/test/fixtures/WackyOptions/.gitignore new file mode 100644 index 00000000..739bc26e --- /dev/null +++ b/test/fixtures/WackyOptions/.gitignore @@ -0,0 +1,7 @@ +*.jl.*.cov +*.jl.cov +*.jl.mem +/docs/build/ +a +b +c diff --git a/test/fixtures/WackyOptions/.gitlab-ci.yml b/test/fixtures/WackyOptions/.gitlab-ci.yml new file mode 100644 index 00000000..88c61198 --- /dev/null +++ b/test/fixtures/WackyOptions/.gitlab-ci.yml @@ -0,0 +1,29 @@ +.definitions: + script: &script + script: + - julia --project=@. -e ' + using Pkg; + Pkg.build(); + Pkg.test();' +Julia 0.6: + image: julia:0.6 + <<: *script +Julia 1.2: + image: julia:1.2 + <<: *script +pages: + image: julia:1.2 + stage: deploy + script: + - julia --project=docs -e ' + using Pkg; + Pkg.develop(PackageSpec(; path=pwd())); + Pkg.instantiate(); + include("docs/make.jl");' + - mkdir -p public + - mv docs/build public/dev + artifacts: + paths: + - public + only: + - master diff --git a/test/fixtures/WackyOptions/.travis.yml b/test/fixtures/WackyOptions/.travis.yml new file mode 100644 index 00000000..5a97f173 --- /dev/null +++ b/test/fixtures/WackyOptions/.travis.yml @@ -0,0 +1,19 @@ +# Documentation: http://docs.travis-ci.com/user/languages/julia +language: julia +notifications: + email: false +julia: + - 1.1 + - 1.2 +os: + - linux + - osx +jobs: + fast_finish: true + include: + - julia: 1.1 + os: linux + arch: x86 + - julia: 1.2 + os: linux + arch: x86 diff --git a/test/fixtures/WackyOptions/CITATION.bib b/test/fixtures/WackyOptions/CITATION.bib new file mode 100644 index 00000000..2395a73d --- /dev/null +++ b/test/fixtures/WackyOptions/CITATION.bib @@ -0,0 +1,8 @@ +@misc{WackyOptions.jl, + author = {tester}, + title = {WackyOptions.jl}, + url = {https://github.com/tester/WackyOptions.jl}, + version = {v0.1.0}, + year = {2019}, + month = {8} +} diff --git a/test/fixtures/WackyOptions/LICENSE b/test/fixtures/WackyOptions/LICENSE new file mode 100644 index 00000000..a677137b --- /dev/null +++ b/test/fixtures/WackyOptions/LICENSE @@ -0,0 +1,15 @@ +ISC License + +Copyright (c) 2019, tester + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/test/fixtures/WackyOptions/Manifest.toml b/test/fixtures/WackyOptions/Manifest.toml new file mode 100644 index 00000000..f45eecff --- /dev/null +++ b/test/fixtures/WackyOptions/Manifest.toml @@ -0,0 +1,2 @@ +# This file is machine-generated - editing it directly is not advised + diff --git a/test/fixtures/WackyOptions/Project.toml b/test/fixtures/WackyOptions/Project.toml new file mode 100644 index 00000000..2c84430c --- /dev/null +++ b/test/fixtures/WackyOptions/Project.toml @@ -0,0 +1,7 @@ +name = "WackyOptions" +uuid = "5b7e9947-ddc0-4b3f-9b55-0d8042f74170" +authors = ["tester"] +version = "0.1.0" + +[compat] +julia = "1.2" diff --git a/test/fixtures/WackyOptions/README.md b/test/fixtures/WackyOptions/README.md new file mode 100644 index 00000000..1a5721f4 --- /dev/null +++ b/test/fixtures/WackyOptions/README.md @@ -0,0 +1,5 @@ +# WackyOptions [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://tester.gitlab.io/WackyOptions.jl/dev) [![Build Status](https://gitlab.com/tester/WackyOptions.jl/badges/master/build.svg)](https://gitlab.com/tester/WackyOptions.jl/pipelines) [![Build Status](https://travis-ci.com/tester/WackyOptions.jl.svg?branch=master)](https://travis-ci.com/tester/WackyOptions.jl) [![Build Status](https://ci.appveyor.com/api/projects/status/github/tester/WackyOptions.jl?svg=true)](https://ci.appveyor.com/project/tester/WackyOptions-jl) [![Build Status](https://api.cirrus-ci.com/github/tester/WackyOptions.jl.svg)](https://cirrus-ci.com/github/tester/WackyOptions.jl) [![Coverage](https://codecov.io/gh//.jl/branch/master/graph/badge.svg)](https://codecov.io/gh//.jl) [![Coverage](https://coveralls.io/repos/github//.jl/badge.svg?branch=master)](https://coveralls.io/github//.jl?branch=master) + +## Citing + +See [`CITATION.bib`](CITATION.bib) for the relevant reference(s). diff --git a/test/fixtures/WackyOptions/docs/Manifest.toml b/test/fixtures/WackyOptions/docs/Manifest.toml new file mode 100644 index 00000000..fe717470 --- /dev/null +++ b/test/fixtures/WackyOptions/docs/Manifest.toml @@ -0,0 +1,89 @@ +# This file is machine-generated - editing it directly is not advised + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[Distributed]] +deps = ["Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[DocStringExtensions]] +deps = ["LibGit2", "Markdown", "Pkg", "Test"] +git-tree-sha1 = "0513f1a8991e9d83255e0140aace0d0fc4486600" +uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" +version = "0.8.0" + +[[Documenter]] +deps = ["Base64", "DocStringExtensions", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"] +git-tree-sha1 = "1b6ae3796f60311e39cd1770566140d2c056e87f" +uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +version = "0.23.3" + +[[InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[JSON]] +deps = ["Dates", "Mmap", "Parsers", "Unicode"] +git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.21.0" + +[[LibGit2]] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[Parsers]] +deps = ["Dates", "Test"] +git-tree-sha1 = "ef0af6c8601db18c282d092ccbd2f01f3f0cd70b" +uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" +version = "0.3.7" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" diff --git a/test/fixtures/WackyOptions/docs/Project.toml b/test/fixtures/WackyOptions/docs/Project.toml new file mode 100644 index 00000000..dfa65cd1 --- /dev/null +++ b/test/fixtures/WackyOptions/docs/Project.toml @@ -0,0 +1,2 @@ +[deps] +Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" diff --git a/test/fixtures/WackyOptions/docs/make.jl b/test/fixtures/WackyOptions/docs/make.jl new file mode 100644 index 00000000..a8131e6e --- /dev/null +++ b/test/fixtures/WackyOptions/docs/make.jl @@ -0,0 +1,20 @@ +using WackyOptions +using Documenter + +makedocs(; + modules=[WackyOptions], + authors="tester", + repo="https://github.com/tester/WackyOptions.jl/blob/{commit}{path}#L{line}", + sitename="WackyOptions.jl", + format=Documenter.HTML(; + canonical="http://example.com", + assets=[ + "assets/static.txt", + ], + ), + pages=[ + "Home" => "index.md", + ], + bar="baz", + foo="bar", +) diff --git a/test/fixtures/WackyOptions/docs/src/assets/static.txt b/test/fixtures/WackyOptions/docs/src/assets/static.txt new file mode 100644 index 00000000..7846e37f --- /dev/null +++ b/test/fixtures/WackyOptions/docs/src/assets/static.txt @@ -0,0 +1 @@ +DO NOT CHANGE THE CONTENTS OF THIS FILE! diff --git a/test/fixtures/WackyOptions/docs/src/index.md b/test/fixtures/WackyOptions/docs/src/index.md new file mode 100644 index 00000000..bd295dfd --- /dev/null +++ b/test/fixtures/WackyOptions/docs/src/index.md @@ -0,0 +1,12 @@ +```@meta +CurrentModule = WackyOptions +``` + +# WackyOptions + +```@index +``` + +```@autodocs +Modules = [WackyOptions] +``` diff --git a/test/fixtures/WackyOptions/src/WackyOptions.jl b/test/fixtures/WackyOptions/src/WackyOptions.jl new file mode 100644 index 00000000..08841a1f --- /dev/null +++ b/test/fixtures/WackyOptions/src/WackyOptions.jl @@ -0,0 +1,5 @@ +module WackyOptions + +# Write your package code here. + +end diff --git a/test/fixtures/WackyOptions/test/Manifest.toml b/test/fixtures/WackyOptions/test/Manifest.toml new file mode 100644 index 00000000..ac58105f --- /dev/null +++ b/test/fixtures/WackyOptions/test/Manifest.toml @@ -0,0 +1,33 @@ +# This file is machine-generated - editing it directly is not advised + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[Distributed]] +deps = ["Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/fixtures/WackyOptions/test/Project.toml b/test/fixtures/WackyOptions/test/Project.toml new file mode 100644 index 00000000..0c363327 --- /dev/null +++ b/test/fixtures/WackyOptions/test/Project.toml @@ -0,0 +1,2 @@ +[deps] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/fixtures/WackyOptions/test/runtests.jl b/test/fixtures/WackyOptions/test/runtests.jl new file mode 100644 index 00000000..730cd5aa --- /dev/null +++ b/test/fixtures/WackyOptions/test/runtests.jl @@ -0,0 +1,6 @@ +using WackyOptions +using Test + +@testset "WackyOptions.jl" begin + # Write your tests here. +end diff --git a/test/fixtures/static.txt b/test/fixtures/static.txt new file mode 100644 index 00000000..7846e37f --- /dev/null +++ b/test/fixtures/static.txt @@ -0,0 +1 @@ +DO NOT CHANGE THE CONTENTS OF THIS FILE! diff --git a/test/reference.jl b/test/reference.jl index 942248ff..e86d9f6a 100644 --- a/test/reference.jl +++ b/test/reference.jl @@ -1,3 +1,5 @@ +const STATIC_FILE = joinpath(@__DIR__, "fixtures", "static.txt") + function PT.user_view(::Citation, ::Template, ::AbstractString) return Dict("MONTH" => 8, "YEAR" => 2019) end @@ -16,17 +18,34 @@ end @testset "Reference tests" begin @testset "Default package" begin - test_all("Basic"; authors=USER, manifest=true) + test_all("Basic"; authors=USER) end @testset "All plugins" begin - test_all("AllPlugins"; authors=USER, manifest=true, plugins=[ + test_all("AllPlugins"; authors=USER, plugins=[ AppVeyor(), CirrusCI(), Citation(), Codecov(), Coveralls(), Develop(), Documenter(), GitLabCI(), TravisCI(), ]) end @testset "Wacky options" begin - # TODO + test_all("WackyOptions"; authors=USER, julia=v"1.2", plugins=[ + AppVeyor(; x86=true, coverage=true, extra_versions=[v"1.3"]), + CirrusCI(; image="freebsd-123", coverage=false, extra_versions=["1.1"]), + Citation(; readme=true), + Codecov(; file=STATIC_FILE), + Coveralls(; file=STATIC_FILE), + Documenter{GitLabCI}( + assets=[STATIC_FILE], + makedocs_kwargs=Dict(:foo => "bar", :bar => "baz"), + canonical_url=(_t, _pkg) -> "http://example.com", + ), + Git(; ignore=["a", "b", "c"], manifest=true), + GitLabCI(; coverage=false, extra_versions=[v"0.6"]), + License(; name="ISC"), + Readme(; inline_badges=true), + Tests(; project=true), + TravisCI(; coverage=false, windows=false, x86=true, extra_versions=["1.1"]), + ]) end end From 441eee321902e5f33765c399f184db42c1763807 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sat, 28 Sep 2019 11:21:45 +0700 Subject: [PATCH 64/81] Update docs with interactive stuff --- docs/src/developer.md | 22 ++++++++++++++-------- src/plugin.jl | 9 +++++---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/docs/src/developer.md b/docs/src/developer.md index f08f4ba0..e1f71474 100644 --- a/docs/src/developer.md +++ b/docs/src/developer.md @@ -76,23 +76,23 @@ To understand how they're implemented, let's look at simplified versions of two ### Example: `Documenter` ```julia -@with_kw_noshow struct Documenter <: Plugin - make_jl::String = default_file("make.jl") - index_md::String = default_file("index.md") +@with_defaults struct Documenter <: Plugin + make_jl::String = default_file("docs", "make.jl") <- "Path to make.jl template" + index_md::String = default_file("docs", "src", "index.md") <- "Path to index.md template" end -gitignore(::Documenter) = ["/docs/build/", "/docs/site/"] +gitignore(::Documenter) = ["/docs/build/"] badges(::Documenter) = [ Badge( "Stable", "https://img.shields.io/badge/docs-stable-blue.svg", - "https://{{USER}}.github.io/{{PKG}}.jl/stable", + "https://{{{USER}}}.github.io/{{{PKG}}}.jl/stable", ), Badge( "Dev", "https://img.shields.io/badge/docs-dev-blue.svg", - "https://{{USER}}.github.io/{{PKG}}.jl/dev", + "https://{{{}USER}}.github.io/{{{PKG}}}.jl/dev", ), ] @@ -118,8 +118,14 @@ function hook(p::Documenter, t::Template, pkg_dir::AbstractString) end ``` -First of all, `@with_kw_noshow` comes from [Parameters.jl](https://github.com/mauro3/Parameters.jl), and it just defines a nice keyword constructor for us. -The default values for our type are using [`default_file`](@ref) to point to files in this repository. +The first thing you'll notice is the strange struct definition with [`@with_defaults`](@ref). + +```@docs +@with_defaults +interactive +``` + +Inside of our struct definition we're using [`default_file`](@ref) to refer to files in this repository. ```@docs default_file diff --git a/src/plugin.jl b/src/plugin.jl index bc5bba1f..2eefa861 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -4,15 +4,16 @@ const DEFAULT_PRIORITY = 1000 """ @with_defaults struct T #= ... =# end -Wraps Parameters.jl's [`@with_kw_noshow`](https://mauro3.github.io/Parameters.jl/stable/api/#Parameters.@with_kw_noshow-Tuple{Any}) to generate keyword constructors, +Creates keyword constructors and generates methods needed to interactively create instances with [`interactive`](@ref). ## Example ```julia struct Foo <: Plugin - file::String = "/dev/null" <- "Path to the file to use" - n::Int <- "This one has no default, but this is the interactive prompt" - xyz::String = "Without a prompt, defaultkw is not implemented for this field" + file::String = "/the/default/value" <- "This is the interactive prompt" + n::Int <- "This one has no default, so it's a required keyword" + abc::String = "No prompt, so the default is always taken in interactive mode" + xyz::String # Required keyword, with a generic interactive prompt. end ``` """ From de22378975f49637f088bca26a3ebf6da730772f Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Fri, 4 Oct 2019 14:42:32 +0700 Subject: [PATCH 65/81] Make the license tests pass next year, too --- test/reference.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/reference.jl b/test/reference.jl index e86d9f6a..722c83e3 100644 --- a/test/reference.jl +++ b/test/reference.jl @@ -1,8 +1,7 @@ const STATIC_FILE = joinpath(@__DIR__, "fixtures", "static.txt") -function PT.user_view(::Citation, ::Template, ::AbstractString) - return Dict("MONTH" => 8, "YEAR" => 2019) -end +PT.user_view(::Citation, ::Template, ::AbstractString) = Dict("MONTH" => 8, "YEAR" => 2019) +PT.user_view(::License, ::Template, ::AbstractString) = Dict("YEAR" => 2019) function test_all(pkg::AbstractString; kwargs...) t = tpl(; kwargs...) From 5e9ff16cbec116c10f225972178186158b9c2ce4 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sun, 6 Oct 2019 14:43:17 +0700 Subject: [PATCH 66/81] Remove interactive stuff (for now) --- Project.toml | 4 +- README.md | 8 +- docs/src/developer.md | 13 +-- docs/src/migrating.md | 9 +- src/PkgTemplates.jl | 5 +- src/interactive.jl | 172 ----------------------------- src/plugin.jl | 46 -------- src/plugins/ci.jl | 48 ++++---- src/plugins/citation.jl | 6 +- src/plugins/coverage.jl | 8 +- src/plugins/documenter.jl | 24 +--- src/plugins/droneci.jl | 45 -------- src/plugins/git.jl | 10 +- src/plugins/license.jl | 12 -- src/plugins/readme.jl | 11 +- src/plugins/src_dir.jl | 6 +- src/plugins/tests.jl | 6 +- src/template.jl | 5 +- test/fixtures/AllPlugins/drone.yml | 29 ----- test/plugins/droneci.jl | 41 ------- test/template.jl | 2 +- 21 files changed, 58 insertions(+), 452 deletions(-) delete mode 100644 src/interactive.jl delete mode 100644 src/plugins/droneci.jl delete mode 100644 test/fixtures/AllPlugins/drone.yml delete mode 100644 test/plugins/droneci.jl diff --git a/Project.toml b/Project.toml index ac0ddbf2..5f61b62e 100644 --- a/Project.toml +++ b/Project.toml @@ -5,17 +5,15 @@ version = "0.7.0" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" -InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433" Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" -REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [compat] -julia = "1" Mustache = ">= 0.5.13" +julia = "1" [extras] Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" diff --git a/README.md b/README.md index 5232e88e..8ede9010 100644 --- a/README.md +++ b/README.md @@ -47,16 +47,10 @@ t = Template(; Codecov(), TravisCI(; x86=true), Documenter{TravisCI}(), -o ], + ], ) ``` -You can also create a `Template` interactively by following a set of prompts: - -```jl -julia> t = Template(; interactive=true) -``` - --- For a much more detailled overview, please see the documentation. diff --git a/docs/src/developer.md b/docs/src/developer.md index e1f71474..a049b15b 100644 --- a/docs/src/developer.md +++ b/docs/src/developer.md @@ -19,7 +19,6 @@ BasicPlugin ## Template + Package Creation Pipeline - The [`Template`](@ref) constructor basically does this: ``` @@ -76,7 +75,7 @@ To understand how they're implemented, let's look at simplified versions of two ### Example: `Documenter` ```julia -@with_defaults struct Documenter <: Plugin +@with_kw_noshow struct Documenter <: Plugin make_jl::String = default_file("docs", "make.jl") <- "Path to make.jl template" index_md::String = default_file("docs", "src", "index.md") <- "Path to index.md template" end @@ -118,14 +117,8 @@ function hook(p::Documenter, t::Template, pkg_dir::AbstractString) end ``` -The first thing you'll notice is the strange struct definition with [`@with_defaults`](@ref). - -```@docs -@with_defaults -interactive -``` - -Inside of our struct definition we're using [`default_file`](@ref) to refer to files in this repository. +The `@with_kw_noshow` macro defines keyword constructors for us. +Inside of our struct definition, we're using [`default_file`](@ref) to refer to files in this repository. ```@docs default_file diff --git a/docs/src/migrating.md b/docs/src/migrating.md index fd9f1f0b..f2d0e5b0 100644 --- a/docs/src/migrating.md +++ b/docs/src/migrating.md @@ -43,16 +43,11 @@ One less name to remember! ## Interactive Templates -Two less names to remember! - -| Old | New | -| :--------------------: | :---------------------------------: | -| `interactive_template` | `Template(; interactive=true)` | -| `generate_interactive` | `Template(; interactive=true)(pkg)` | +Currently not implemented, but will be in the future. ## Other Functions -Another two less names to remember! +Two less names to remember! Although it's unlikely that anyone used these. | Old | New | diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index 2f222473..52212452 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -4,14 +4,12 @@ using Base: active_project using Base.Filesystem: contractuser using Dates: month, today, year -using InteractiveUtils: subtypes using LibGit2: LibGit2, GitRemote, GitRepo using Pkg: Pkg, TOML, PackageSpec -using REPL.TerminalMenus: MultiSelectMenu, RadioMenu, request using UUIDs: uuid4 using Mustache: render -using Parameters: with_kw +using Parameters: @with_kw_noshow export Template, @@ -43,7 +41,6 @@ abstract type Plugin end include("template.jl") include("plugin.jl") include("show.jl") -include("interactive.jl") # Run some function with a project activated at the given path. function with_project(f::Function, path::AbstractString) diff --git a/src/interactive.jl b/src/interactive.jl deleted file mode 100644 index a26414ac..00000000 --- a/src/interactive.jl +++ /dev/null @@ -1,172 +0,0 @@ -""" - interactive(::Type{T<:Plugin}) -> T - -Create a [`Plugin`](@ref) of type `T` interactively from user input. -""" -function interactive(::Type{T}) where T <: Plugin - kwargs = Dict{Symbol, Any}() - - foreach(fieldnames(T)) do name - F = fieldtype(T, name) - v = Val(name) - required = !applicable(defaultkw, T, v) - default = required ? defaultkw(F) : defaultkw(T, v) - kwargs[name] = if applicable(prompt, T, v) - prompt(F, "$T: $(prompt(T, v))", default, required=required) - elseif required - prompt(F, "$T: Value for field '$name' ($F)", default; required=required) - else - default - end - end - - return T(; kwargs...) -end - -leaves(T::Type) = isconcretetype(T) ? [T] : vcat(map(leaves, subtypes(T))...) - -function plugin_types() - Ts = leaves(Plugin) - # Hack both Documenter types into the list. - # Unfortunately there's no way to do this automatically, - # but it's unlikely for more parametric plugin types to exist. - push!(Ts, Documenter{TravisCI}, Documenter{GitLabCI}) - return Ts -end - -function Template(::Val{true}; kwargs...) - opts = Dict{Symbol, Any}(kwargs) - - if !haskey(opts, :user) - default = defaultkw(Template, :user) - opts[:user] = prompt(String, "Git hosting service username", default) - end - - if !haskey(opts, :host) - default = defaultkw(Template, :host) - opts[:host] = prompt(String, "Git hosting service URL", default) - end - - if !haskey(opts, :authors) - default = defaultkw(Template, :authors) - opts[:authors] = prompt(String, "Package author(s)", default) - end - - if !haskey(opts, :dir) - default = defaultkw(Template, :dir) - opts[:dir] = prompt(String, "Path to package parent directory", default) - end - - if !haskey(opts, :julia) - default = defaultkw(Template, :julia) - opts[:julia] = prompt(VersionNumber, "Supported Julia version", default) - end - - if !haskey(opts, :disable_defaults) - available = map(typeof, default_plugins()) - initial = defaultkw(Template, :disable_defaults) - opts[:disable_defaults] = select("Select defaults to disable:", available, initial) - end - - if !haskey(opts, :plugins) - # Don't offer any disabled plugins as options. - available = setdiff(sort(plugin_types(); by=string), opts[:disable_defaults]) - initial = setdiff(map(typeof, default_plugins()), opts[:disable_defaults]) - chosen = select("Select plugins", available, initial) - opts[:plugins] = map(interactive, chosen) - end - - return Template(Val(false); opts...) -end - -defaultkw(::Type{String}) = "" -defaultkw(::Type{Union{T, Nothing}}) where T = nothing -defaultkw(::Type{T}) where T <: Number = zero(T) -defaultkw(::Type{Vector{T}}) where T = T[] - -function prompt( - ::Type{<:Union{String, Nothing}}, s::AbstractString, default; - required::Bool=false, -) - default isa AbstractString && (default = contractuser(default)) - default_display = if required - "REQUIRED" - elseif default === nothing - "None" - else - repr(default) - end - - print("$s [$default_display]: ") - input = strip(readline()) - - return if isempty(input) && required - println("This option is required") - prompt(String, s, default; required=required) - elseif isempty(input) - default - else - input - end -end - -function prompt( - ::Type{VersionNumber}, s::AbstractString, default::VersionNumber; - required::Bool=false, -) - v = prompt(String, s, default; required=required) - return if v isa VersionNumber - v - else - startswith(v, "v") && (v = v[2:end]) - v = replace(v, "\"" => "") - VersionNumber(v) - end -end - -function prompt(::Type{Bool}, s::AbstractString, default::Bool; required::Bool=false) - b = prompt(String, s, default; required=required) - return b === default ? default : uppercase(b) in ("Y", "YES", "T", "TRUE") -end - -function prompt(::Type{Vector}, s::AbstractString, default::Vector; required::Bool=false) - return prompt(Vector{String}, s, default; required=required) -end - -function prompt( - ::Type{Vector{String}}, s::AbstractString, default::Vector{<:AbstractString}; - required::Bool=false, -) - s = prompt(String, "$s (comma-delimited)", join(default, ", "); required=required) - return convert(Vector{String}, map(strip, split(s, ","; keepempty=false))) -end - -function prompt(::Type{<:Dict}, s::AbstractString, default::Dict, required::Bool=false) - default_display = join(map(p -> "$(p.first)=$(p.second)", collect(default)), ", ") - s = prompt(String, "$s (k=v, comma-delimited)", default_display; required=required) - return if isempty(s) - Dict{String, String}() - else - Dict{String, String}(Pair(split(strip(kv), "=")...) for kv in split(s, ",")) - end -end - -# TODO: These can be made simpler when this is merged: -# https://github.com/JuliaLang/julia/pull/30043 - -select(s::AbstractString, xs::Vector, initial) = select(string, s, xs, initial) - -# Select any number of elements from a collection. -function select(f::Function, s::AbstractString, xs::Vector, initial::Vector) - m = MultiSelectMenu(map(f, xs); pagesize=length(xs)) - foreach(x -> push!(m.selected, findfirst(==(x), xs)), initial) - selection = request("$s:", m) - return map(i -> xs[i], collect(selection)) -end - -# Select one item frm oa collection. -function select(f::Function, s::AbstractString, xs::Vector, initial) - print(stdin.buffer, repeat("\e[B", findfirst(==(initial), xs) - 1)) - selection = request("$s:", RadioMenu(map(f, xs); pagesize=length(xs))) - return xs[selection] -end diff --git a/src/plugin.jl b/src/plugin.jl index 2eefa861..00fddc97 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -1,47 +1,6 @@ const TEMPLATES_DIR = normpath(joinpath(@__DIR__, "..", "templates")) const DEFAULT_PRIORITY = 1000 -""" - @with_defaults struct T #= ... =# end - -Creates keyword constructors and generates methods needed to interactively create instances with [`interactive`](@ref). - -## Example - -```julia -struct Foo <: Plugin - file::String = "/the/default/value" <- "This is the interactive prompt" - n::Int <- "This one has no default, so it's a required keyword" - abc::String = "No prompt, so the default is always taken in interactive mode" - xyz::String # Required keyword, with a generic interactive prompt. -end -``` -""" -macro with_defaults(ex::Expr) - T = esc(ex.args[2].args[1]) # This assumes T <: U. - - # This is a bit nasty. - funcs = Expr[] - foreach(filter(arg -> arg isa Expr, ex.args[3].args)) do arg - if iscall(arg, :<) && iscall(arg.args[3], :-) # x::T <- "prompt" - name = QuoteNode(arg.args[2].args[1]) - prompt = arg.args[2] - push!(funcs, :(PkgTemplates.prompt(::Type{$T}, ::Val{$name}) = $(esc(prompt)))) - elseif arg.head === :(=) - rhs = arg.args[2] - name = QuoteNode(arg.args[1].args[1]) - if iscall(rhs, :<) && iscall(rhs.args[3], :-) # x::T = "foo" <- "prompt" - prompt = rhs.args[3].args[2] - push!(funcs, :(PkgTemplates.prompt(::Type{$T}, ::Val{$name}) = $(esc(prompt)))) - end - default = arg.args[2] = rhs.args[2] - push!(funcs, :(PkgTemplates.defaultkw(::Type{$T}, ::Val{$name}) = $(esc(default)))) - end - end - - return Expr(:block, esc(with_kw(ex, __module__, false)), funcs...) -end - """ A simple plugin that, in general, creates a single file. """ @@ -276,11 +235,6 @@ If you are implementing a plugin that uses the `user` field of a [`Template`](@r """ needs_username(::Plugin) = false -function prompt end - -iscall(x, ::Symbol) = false -iscall(ex::Expr, s::Symbol) = ex.head === :call && ex.args[1] === s - include(joinpath("plugins", "project_file.jl")) include(joinpath("plugins", "src_dir.jl")) include(joinpath("plugins", "tests.jl")) diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index a9ce0fc2..23d3e21e 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -9,6 +9,7 @@ format_version(v::AbstractString) = string(v) const ALLOWED_FAILURES = ["1.3", "nightly"] # TODO: Update this list with new RCs. const DEFAULT_CI_VERSIONS = map(format_version, [default_version(), VERSION, "nightly"]) +const DEFAULT_CI_VERSIONS_NO_NIGHTLY = map(format_version, [default_version(), VERSION]) const EXTRA_VERSIONS_DOC = "- `extra_versions::Vector`: Extra Julia versions to test, as strings or `VersionNumber`s." """ @@ -44,14 +45,14 @@ Integrates your packages with [Travis CI](https://travis-ci.com). - `coverage::Bool`: Whether or not to publish code coverage (another code coverage plugin such as [`Codecov`](@ref) must also be included). $EXTRA_VERSIONS_DOC """ -@with_defaults struct TravisCI <: BasicPlugin - file::String = default_file("travis.yml") <- "Path to .travis.yml template" - linux::Bool = true <- "Enable Linux bulds" - osx::Bool = true <- "Enable OSX builds" - windows::Bool = true <- "Enable Windows builds" - x86::Bool = false <- "Enable 32-bit builds" - coverage::Bool = true <- "Enable code coverage submission" - extra_versions::Vector = DEFAULT_CI_VERSIONS <- "Extra Julia versions to test" +@with_kw_noshow struct TravisCI <: BasicPlugin + file::String = default_file("travis.yml") + linux::Bool = true + osx::Bool = true + windows::Bool = true + x86::Bool = false + coverage::Bool = true + extra_versions::Vector = DEFAULT_CI_VERSIONS end source(p::TravisCI) = p.file @@ -113,11 +114,11 @@ Integrates your packages with [AppVeyor](https://appveyor.com) via [AppVeyor.jl] - `coverage::Bool`: Whether or not to publish code coverage ([`Codecov`](@ref) must also be included). $EXTRA_VERSIONS_DOC """ -@with_defaults struct AppVeyor <: BasicPlugin - file::String = default_file("appveyor.yml") <- "Path to .appveyor.yml template" - x86::Bool = false <- "Enable 32-bit builds" - coverage::Bool = true <- "Enable code coverage submission" - extra_versions::Vector = DEFAULT_CI_VERSIONS <- "Extra Julia versions to test" +@with_kw_noshow struct AppVeyor <: BasicPlugin + file::String = default_file("appveyor.yml") + x86::Bool = false + coverage::Bool = true + extra_versions::Vector = DEFAULT_CI_VERSIONS end source(p::AppVeyor) = p.file @@ -166,11 +167,11 @@ $EXTRA_VERSIONS_DOC !!! note Code coverage submission from Cirrus CI is not yet supported by [Coverage.jl](https://github.com/JuliaCI/Coverage.jl). """ -@with_defaults struct CirrusCI <: BasicPlugin - file::String = default_file("cirrus.yml") <- "Path to .cirrus.yml template" - image::String = "freebsd-12-0-release-amd64" <- "FreeBSD image" - coverage::Bool = true <- "Enable code coverage submission" - extra_versions::Vector = DEFAULT_CI_VERSIONS <- "Extra Julia versions to test" +@with_kw_noshow struct CirrusCI <: BasicPlugin + file::String = default_file("cirrus.yml") + image::String = "freebsd-12-0-release-amd64" + coverage::Bool = true + extra_versions::Vector = DEFAULT_CI_VERSIONS end source(p::CirrusCI) = p.file @@ -198,7 +199,7 @@ end GitLabCI(; file="$(contractuser(default_file("gitlab-ci.yml")))", coverage=true, - extra_versions=$(map(format_version, [default_version(), VERSION])), + extra_versions=$DEFAULT_CI_VERSIONS_NO_NIGHTLY, ) Integrates your packages with [GitLab CI](https://docs.gitlab.com/ce/ci/). @@ -215,11 +216,11 @@ See [`Documenter`](@ref) for more information. !!! note Nightly Julia is not supported. """ -@with_defaults struct GitLabCI <: BasicPlugin - file::String = default_file("gitlab-ci.yml") <- "Path to .gitlab-ci.yml template" - coverage::Bool = true <- "Enable code coverage submission" +@with_kw_noshow struct GitLabCI <: BasicPlugin + file::String = default_file("gitlab-ci.yml") + coverage::Bool = true # Nightly has no Docker image. - extra_versions::Vector = map(format_version, [default_version(), VERSION]) <- "Extra Julia versions to test" + extra_versions::Vector = DEFAULT_CI_VERSIONS_NO_NIGHTLY end gitignore(p::GitLabCI) = p.coverage ? COVERAGE_GITIGNORE : String[] @@ -252,7 +253,6 @@ function view(p::GitLabCI, t::Template, pkg::AbstractString) ) end - """ is_ci(::Plugin) -> Bool diff --git a/src/plugins/citation.jl b/src/plugins/citation.jl index 68b6f25d..805d446b 100644 --- a/src/plugins/citation.jl +++ b/src/plugins/citation.jl @@ -7,9 +7,9 @@ Creates a `CITATION.bib` file for citing package repositories. - `file::AbstractString`: Template file for `CITATION.bib`. - `readme::Bool`: Whether or not to include a section about citing in the README. """ -@with_defaults struct Citation <: BasicPlugin - file::String = default_file("CITATION.bib") <- "Path to CITATION.bib template" - readme::Bool = false <- """Enable "Citing" README section""" +@with_kw_noshow struct Citation <: BasicPlugin + file::String = default_file("CITATION.bib") + readme::Bool = false end tags(::Citation) = "<<", ">>" diff --git a/src/plugins/coverage.jl b/src/plugins/coverage.jl index 26d11df6..448cc36d 100644 --- a/src/plugins/coverage.jl +++ b/src/plugins/coverage.jl @@ -8,8 +8,8 @@ Sets up code coverage submission from CI to [Codecov](https://codecov.io). ## Keyword Arguments - `file::Union{AbstractString, Nothing}`: Template file for `.codecov.yml`, or `nothing` to create no file. """ -@with_defaults struct Codecov <: BasicPlugin - file::Union{String, Nothing} = nothing <- "Path to .codecov.yml template" +@with_kw_noshow struct Codecov <: BasicPlugin + file::Union{String, Nothing} = nothing end source(p::Codecov) = p.file @@ -29,8 +29,8 @@ Sets up code coverage submission from CI to [Coveralls](https://coveralls.io). ## Keyword Arguments - `file::Union{AbstractString, Nothing}`: Template file for `.coveralls.yml`, or `nothing` to create no file. """ -@with_defaults struct Coveralls <: BasicPlugin - file::Union{String, Nothing} = nothing <- "Path to .coveralls.yml template" +@with_kw_noshow struct Coveralls <: BasicPlugin + file::Union{String, Nothing} = nothing end source(p::Coveralls) = p.file diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index 5c232236..291639fe 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -38,7 +38,7 @@ struct Documenter{T<:Union{TravisCI, GitLabCI, Nothing}} <: Plugin make_jl::String index_md::String - # Can't use @with_defaults due to some weird precompilation issues. + # Can't use @with_kw_noshow due to some weird precompilation issues. function Documenter{T}(; assets::Vector{<:AbstractString}=String[], makedocs_kwargs::Dict{Symbol}=Dict{Symbol, Any}(), @@ -52,28 +52,6 @@ end Documenter(; kwargs...) = Documenter{Nothing}(; kwargs...) -function interactive(::Type{Documenter}) - kwargs = Dict{Symbol, Any}() - - default = default_file("docs", "make.jl") - kwargs[:make_jl] = prompt(String, "Documenter: Path to make.jl template", default) - - default = default_file("docs", "src", "index.md") - kwargs[:index_md] = prompt(String, "Documenter: Path to make.jl template", default) - - kwargs[:assets] = prompt(Vector{String}, "Documenter: Extra asset files", String[]) - - md_kw = prompt(Dict{String, String}, "Documenter: makedocs keyword arguments", Dict()) - parsed = Dict{Symbol, Any}(Symbol(p.first) => eval(Meta.parse(p.second)) for p in md_kw) - kwargs[:makedocs_kwargs] = parsed - - available = [Nothing, TravisCI, GitLabCI] - f = T -> string(nameof(T)) - T = select(f, "Documenter: Documentation deployment strategy", available, Nothing) - - return Documenter{T}(; kwargs...) -end - gitignore(::Documenter) = ["/docs/build/"] badges(::Documenter) = Badge[] diff --git a/src/plugins/droneci.jl b/src/plugins/droneci.jl deleted file mode 100644 index 5ce2027c..00000000 --- a/src/plugins/droneci.jl +++ /dev/null @@ -1,45 +0,0 @@ -""" - DroneCI(; config_file::Union{AbstractString, Nothing}="") -> DroneCI - -Add `DroneCI` to a template's plugins to add a `.drone.yml` configuration file to -generated repositories, and an appropriate badge to the README. The default configuration -file supports Linux on ARM32 and ARM64. - -# Keyword Arguments -* `config_file::Union{AbstractString, Nothing}=""`: Path to a custom `.drone.yml`. - If `nothing` is supplied, no file will be generated. -""" -struct DroneCI <: GenericPlugin - gitignore::Vector{String} - src::Union{String, Nothing} - dest::String - badges::Vector{Badge} - view::Dict{String, Any} - - function DroneCI(; config_file::Union{AbstractString, Nothing}="") - if config_file !== nothing - config_file = if isempty(config_file) - joinpath(DEFAULTS_DIR, "drone.yml") - elseif isfile(config_file) - abspath(config_file) - else - throw(ArgumentError("File $(abspath(config_file)) does not exist")) - end - end - return new( - [], - config_file, - ".drone.yml", - [ - Badge( - "Build Status", - "https://cloud.drone.io/api/badges/{{USER}}/{{PKGNAME}}.jl/status.svg", - "https://cloud.drone.io/{{USER}}/{{PKGNAME}}.jl", - ), - ], - Dict{String, Any}(), - ) - end -end - -interactive(::Type{DroneCI}) = interactive(DroneCI; file="drone.yml") diff --git a/src/plugins/git.jl b/src/plugins/git.jl index 8ba57180..aaea9174 100644 --- a/src/plugins/git.jl +++ b/src/plugins/git.jl @@ -12,11 +12,11 @@ Creates a Git repository and a `.gitignore` file. - `gpgsign::Bool`: Whether or not to sign commits with your GPG key. This option requires that the Git CLI is installed, and for you to have a GPG key associated with your committer identity. """ -@with_defaults struct Git <: Plugin - ignore::Vector{String} = String[] <- "Gitignore entries" - ssh::Bool = false <- "Enable SSH Git remote" - manifest::Bool = false <- "Commit Manifest.toml" - gpgsign::Bool = false <- "GPG-sign commits" +@with_kw_noshow struct Git <: Plugin + ignore::Vector{String} = String[] + ssh::Bool = false + manifest::Bool = false + gpgsign::Bool = false end # Try to make sure that no files are created after we commit. diff --git a/src/plugins/license.jl b/src/plugins/license.jl index 5a2fc207..be8314a7 100644 --- a/src/plugins/license.jl +++ b/src/plugins/license.jl @@ -34,15 +34,3 @@ view(::License, t::Template, ::AbstractString) = Dict( "AUTHORS" => join(t.authors, ", "), "YEAR" => year(today()), ) - -function interactive(::Type{License}) - destination = prompt(String, "License: License file destination", "LICENSE") - return if prompt(Bool, "License: Use custom license file", false) - path = prompt(String, "License: Path to custom license file", ""; required=true) - License(; path=path, destination=destination) - else - available = sort(readdir(joinpath(TEMPLATES_DIR, "licenses"))) - name = select("License: Select a license", available, "MIT") - License(; name=name, destination=destination) - end -end diff --git a/src/plugins/readme.jl b/src/plugins/readme.jl index f982fab2..97ec2282 100644 --- a/src/plugins/readme.jl +++ b/src/plugins/readme.jl @@ -5,8 +5,7 @@ inline_badges=false, ) -Creates a `README` file. -By default, it includes badges for other included plugins +Creates a `README` file that contains badges for other included plugins. ## Keyword Arguments - `file::AbstractString`: Template file for the `README`. @@ -14,10 +13,10 @@ By default, it includes badges for other included plugins For example, values of `"README"` or `"README.rst"` might be desired. - `inline_badges::Bool`: Whether or not to put the badges on the same line as the package name. """ -@with_defaults struct Readme <: BasicPlugin - file::String = default_file("README.md") <- "Path to README.md template" - destination::String = "README.md" <- "README file destination" - inline_badges::Bool = false <- "Enable inline badges" +@with_kw_noshow struct Readme <: BasicPlugin + file::String = default_file("README.md") + destination::String = "README.md" + inline_badges::Bool = false end source(p::Readme) = p.file diff --git a/src/plugins/src_dir.jl b/src/plugins/src_dir.jl index d23fda21..be90d198 100644 --- a/src/plugins/src_dir.jl +++ b/src/plugins/src_dir.jl @@ -6,9 +6,9 @@ Creates a module entrypoint. ## Keyword Arguments - `file::AbstractString`: Template file for `src/.jl`. """ -@with_defaults mutable struct SrcDir <: BasicPlugin - file::String = default_file("src", "module.jl") <- "Path to .jl template" - destination::String = joinpath("src", ".jl") +@with_kw_noshow mutable struct SrcDir <: BasicPlugin + file::String = default_file("src", "module.jl") + destination::String = "" end Base.:(==)(a::SrcDir, b::SrcDir) = a.file == b.file diff --git a/src/plugins/tests.jl b/src/plugins/tests.jl index e125ee17..8281be6e 100644 --- a/src/plugins/tests.jl +++ b/src/plugins/tests.jl @@ -14,9 +14,9 @@ Sets up testing for packages. !!! note Managing test dependencies with `test/Project.toml` is only supported in Julia 1.2 and later. """ -@with_defaults struct Tests <: BasicPlugin - file::String = default_file("test", "runtests.jl") <- "Path to runtests.jl template" - project::Bool = false <- "Enable test/Project.toml" +@with_kw_noshow struct Tests <: BasicPlugin + file::String = default_file("test", "runtests.jl") + project::Bool = false end source(p::Tests) = p.file diff --git a/src/template.jl b/src/template.jl index fa190188..9b7dc3ef 100644 --- a/src/template.jl +++ b/src/template.jl @@ -34,9 +34,6 @@ A configuration used to generate packages. The default plugins are [`ProjectFile`](@ref), [`SrcDir`](@ref), [`Tests`](@ref), [`Readme`](@ref), [`License`](@ref), and [`Git`](@ref). To override a default plugin instead of disabling it altogether, supply it via `plugins`. -### Interactive Usage -- `interactive::Bool=false`: When set, the template is created interactively, filling unset keywords with user input. - --- To create a package from a `Template`, use the following syntax: @@ -56,7 +53,7 @@ struct Template user::String end -Template(; interactive::Bool=false, kwargs...) = Template(Val(interactive); kwargs...) +Template(; kwargs...) = Template(Val(false); kwargs...) # Non-interactive constructor. function Template(::Val{false}; kwargs...) diff --git a/test/fixtures/AllPlugins/drone.yml b/test/fixtures/AllPlugins/drone.yml deleted file mode 100644 index 90f3f82b..00000000 --- a/test/fixtures/AllPlugins/drone.yml +++ /dev/null @@ -1,29 +0,0 @@ ---- -kind: pipeline -name: linux - arm - Julia {{VERSION}} - -platform: - os: linux - arch: arm - -steps: -- name: build - image: julia:{{VERSION}} - commands: - - "julia --project=. --check-bounds=yes --color=yes -e 'using InteractiveUtils; versioninfo(verbose=true); using Pkg; Pkg.build(); Pkg.test(coverage=true)'" - ---- -kind: pipeline -name: linux - arm64 - Julia {{VERSION}} - -platform: - os: linux - arch: arm64 - -steps: -- name: build - image: julia:{{VERSION}} - commands: - - "julia --project=. --check-bounds=yes --color=yes -e 'using InteractiveUtils; versioninfo(verbose=true); using Pkg; Pkg.build(); Pkg.test(coverage=true)'" - -... diff --git a/test/plugins/droneci.jl b/test/plugins/droneci.jl deleted file mode 100644 index 5b7fc6f1..00000000 --- a/test/plugins/droneci.jl +++ /dev/null @@ -1,41 +0,0 @@ -t = Template(; user=me) -pkg_dir = joinpath(t.dir, test_pkg) - -@testset "DroneCI" begin - @testset "Plugin creation" begin - p = DroneCI() - @test isempty(p.gitignore) - @test p.src == joinpath(DEFAULTS_DIR, "drone.yml") - @test p.dest == ".drone.yml" - @test p.badges == [ - Badge( - "Build Status", - "https://cloud.drone.io/api/badges/{{USER}}/{{PKGNAME}}.jl/status.svg", - "https://cloud.drone.io/{{USER}}/{{PKGNAME}}.jl", - ), - ] - @test isempty(p.view) - p = DroneCI(; config_file=nothing) - @test p.src === nothing - p = DroneCI(; config_file=test_file) - @test p.src == test_file - @test_throws ArgumentError DroneCI(; config_file=fake_path) - end - - @testset "Badge generation" begin - p = DroneCI() - @test badges(p, me, test_pkg) == ["[![Build Status](https://cloud.drone.io/api/badges/$me/$test_pkg.jl/status.svg)](https://cloud.drone.io/$me/$test_pkg.jl)"] - end - - @testset "File generation" begin - # Without a coverage plugin in the template, there should be no coverage step. - p = DroneCI() - @test gen_plugin(p, t, test_pkg) == [".drone.yml"] - @test isfile(joinpath(pkg_dir, ".drone.yml")) - drone = read(joinpath(pkg_dir, ".drone.yml"), String) - @test !occursin("coverage_script", drone) - rm(joinpath(pkg_dir, ".drone.yml")) - end -end - -rm(pkg_dir; recursive=true) diff --git a/test/template.jl b/test/template.jl index 260f34ee..11a2e21d 100644 --- a/test/template.jl +++ b/test/template.jl @@ -6,7 +6,7 @@ @test isempty(Template(; disable_defaults=[Git]).user) end mock(PT.default_user => () -> "username") do _du - @test Template().user == PT.default_user() + @test Template().user == "username" end end From ad8e78d87e60317d5c012f9969828a341cbfcea1 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sun, 6 Oct 2019 15:13:37 +0700 Subject: [PATCH 67/81] Add DroneCI plugin for new PkgTemplates --- docs/src/user.md | 1 + src/plugins/ci.jl | 59 +++++++++++++++++++++++++- src/plugins/readme.jl | 1 + templates/drone.star | 27 ++++++++++++ test/fixtures/AllPlugins/.drone.star | 27 ++++++++++++ test/fixtures/AllPlugins/README.md | 1 + test/fixtures/WackyOptions/.drone.star | 27 ++++++++++++ test/fixtures/WackyOptions/README.md | 2 +- test/reference.jl | 3 +- 9 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 templates/drone.star create mode 100644 test/fixtures/AllPlugins/.drone.star create mode 100644 test/fixtures/WackyOptions/.drone.star diff --git a/docs/src/user.md b/docs/src/user.md index b9624299..4446ca1f 100644 --- a/docs/src/user.md +++ b/docs/src/user.md @@ -49,6 +49,7 @@ These plugins will create the configuration files of common CI services for you. ```@docs AppVeyor CirrusCI +DroneCI GitLabCI TravisCI ``` diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index 23d3e21e..1ede6210 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -253,6 +253,61 @@ function view(p::GitLabCI, t::Template, pkg::AbstractString) ) end +""" + DroneCI(; + file="$(contractuser(default_file("drone.star")))", + amd64=true, + arm=false, + arm64=false, + extra_versions=$DEFAULT_CI_VERSIONS_NO_NIGHTLY, + ) + +Integrates your packages with [Drone CI](https://drone.io). + +## Keyword Arguments +- `file::AbstractString`: Template file for `.drone.star`. +- `destination::AbstractString`: File destination, relative to the repository root. + For example, you might want to generate a `.drone.yml` instead of the default Starlark file. +- `amd64::Bool`: Whether or not to run builds on AMD64. +- `arm::Bool`: Whether or not to run builds on ARM (32-bit). +- `arm::Bool`: Whether or not to run builds on ARM64. +$EXTRA_VERSIONS_DOC + +!!! note + Nightly Julia is not supported. +""" +@with_kw_noshow struct DroneCI <: BasicPlugin + file::String = default_file("drone.star") + destination::String = ".drone.star" + amd64::Bool = true + arm::Bool = false + arm64::Bool = false + extra_versions::Vector = DEFAULT_CI_VERSIONS_NO_NIGHTLY +end + +source(p::DroneCI) = p.file +destination(p::DroneCI) = p.destination + +badges(::DroneCI) = Badge( + "Build Status", + "https://cloud.drone.io/api/badges/{{{USER}}}/{{{PKG}}}.jl/status.svg", + "https://cloud.drone.io/{{{USER}}}/{{{PKG}}}.jl", +) + +function view(p::DroneCI, t::Template, pkg::AbstractString) + arches = String[] + p.amd64 && push!(arches, "amd64") + p.arm && push!(arches, "arm") + p.arm64 && push!(arches, "arm64") + + return Dict( + "ARCHES" => join(map(repr, arches), ", "), + "PKG" => pkg, + "USER" => t.user, + "VERSIONS" => join(map(repr, collect_versions(t, p.extra_versions)), ", "), + ) +end + """ is_ci(::Plugin) -> Bool @@ -260,6 +315,6 @@ Determine whether or not a plugin is a CI plugin. If you are adding a CI plugin, you should implement this function and return `true`. """ is_ci(::Plugin) = false -is_ci(::Union{AppVeyor, TravisCI, CirrusCI, GitLabCI}) = true +is_ci(::Union{AppVeyor, TravisCI, CirrusCI, GitLabCI, DroneCI}) = true -needs_username(::Union{AppVeyor, TravisCI, CirrusCI, GitLabCI}) = true +needs_username(::Union{AppVeyor, TravisCI, CirrusCI, GitLabCI, DroneCI}) = true diff --git a/src/plugins/readme.jl b/src/plugins/readme.jl index 97ec2282..8f80dc0f 100644 --- a/src/plugins/readme.jl +++ b/src/plugins/readme.jl @@ -51,6 +51,7 @@ badge_order() = [ GitLabCI, TravisCI, AppVeyor, + DroneCI, CirrusCI, Codecov, Coveralls, diff --git a/templates/drone.star b/templates/drone.star new file mode 100644 index 00000000..b911765f --- /dev/null +++ b/templates/drone.star @@ -0,0 +1,27 @@ +def main(ctx): + pipelines = [] + for arch in [{{{ARCHES}}}]: + for julia in [{{{VERSIONS}}}]: + pipelines.append(pipeline(arch, julia)) + return pipelines + +def pipeline(arch, julia): + return { + "kind": "pipeline", + "type": "docker", + "name": "Julia %s - %s" % (julia, arch), + "platform": { + "os": "linux", + "arch": arch, + }, + "steps": [ + { + "name": "test", + "image": "julia:%s" % julia, + "commands": [ + "julia -e 'using InteractiveUtils; versioninfo()'", + "julia --project=@. -e 'using Pkg; Pkg.instantiate(); Pkg.build(); Pkg.test();'", + ], + }, + ], + } diff --git a/test/fixtures/AllPlugins/.drone.star b/test/fixtures/AllPlugins/.drone.star new file mode 100644 index 00000000..cdfb36eb --- /dev/null +++ b/test/fixtures/AllPlugins/.drone.star @@ -0,0 +1,27 @@ +def main(ctx): + pipelines = [] + for arch in ["amd64"]: + for julia in ["1.0", "1.2"]: + pipelines.append(pipeline(arch, julia)) + return pipelines + +def pipeline(arch, julia): + return { + "kind": "pipeline", + "type": "docker", + "name": "Julia %s - %s" % (julia, arch), + "platform": { + "os": "linux", + "arch": arch, + }, + "steps": [ + { + "name": "test", + "image": "julia:%s" % julia, + "commands": [ + "julia -e 'using InteractiveUtils; versioninfo()'", + "julia --project=@. -e 'using Pkg; Pkg.instantiate(); Pkg.build(); Pkg.test();'", + ], + }, + ], + } diff --git a/test/fixtures/AllPlugins/README.md b/test/fixtures/AllPlugins/README.md index adbba2f3..c6416961 100644 --- a/test/fixtures/AllPlugins/README.md +++ b/test/fixtures/AllPlugins/README.md @@ -4,6 +4,7 @@ [![Coverage](https://gitlab.com/tester/AllPlugins.jl/badges/master/coverage.svg)](https://gitlab.com/tester/AllPlugins.jl/commits/master) [![Build Status](https://travis-ci.com/tester/AllPlugins.jl.svg?branch=master)](https://travis-ci.com/tester/AllPlugins.jl) [![Build Status](https://ci.appveyor.com/api/projects/status/github/tester/AllPlugins.jl?svg=true)](https://ci.appveyor.com/project/tester/AllPlugins-jl) +[![Build Status](https://cloud.drone.io/api/badges/tester/AllPlugins.jl/status.svg)](https://cloud.drone.io/tester/AllPlugins.jl) [![Build Status](https://api.cirrus-ci.com/github/tester/AllPlugins.jl.svg)](https://cirrus-ci.com/github/tester/AllPlugins.jl) [![Coverage](https://codecov.io/gh//.jl/branch/master/graph/badge.svg)](https://codecov.io/gh//.jl) [![Coverage](https://coveralls.io/repos/github//.jl/badge.svg?branch=master)](https://coveralls.io/github//.jl?branch=master) diff --git a/test/fixtures/WackyOptions/.drone.star b/test/fixtures/WackyOptions/.drone.star new file mode 100644 index 00000000..25ce6311 --- /dev/null +++ b/test/fixtures/WackyOptions/.drone.star @@ -0,0 +1,27 @@ +def main(ctx): + pipelines = [] + for arch in ["arm", "arm64"]: + for julia in ["1.1", "1.2"]: + pipelines.append(pipeline(arch, julia)) + return pipelines + +def pipeline(arch, julia): + return { + "kind": "pipeline", + "type": "docker", + "name": "Julia %s - %s" % (julia, arch), + "platform": { + "os": "linux", + "arch": arch, + }, + "steps": [ + { + "name": "test", + "image": "julia:%s" % julia, + "commands": [ + "julia -e 'using InteractiveUtils; versioninfo()'", + "julia --project=@. -e 'using Pkg; Pkg.instantiate(); Pkg.build(); Pkg.test();'", + ], + }, + ], + } diff --git a/test/fixtures/WackyOptions/README.md b/test/fixtures/WackyOptions/README.md index 1a5721f4..d7c163bc 100644 --- a/test/fixtures/WackyOptions/README.md +++ b/test/fixtures/WackyOptions/README.md @@ -1,4 +1,4 @@ -# WackyOptions [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://tester.gitlab.io/WackyOptions.jl/dev) [![Build Status](https://gitlab.com/tester/WackyOptions.jl/badges/master/build.svg)](https://gitlab.com/tester/WackyOptions.jl/pipelines) [![Build Status](https://travis-ci.com/tester/WackyOptions.jl.svg?branch=master)](https://travis-ci.com/tester/WackyOptions.jl) [![Build Status](https://ci.appveyor.com/api/projects/status/github/tester/WackyOptions.jl?svg=true)](https://ci.appveyor.com/project/tester/WackyOptions-jl) [![Build Status](https://api.cirrus-ci.com/github/tester/WackyOptions.jl.svg)](https://cirrus-ci.com/github/tester/WackyOptions.jl) [![Coverage](https://codecov.io/gh//.jl/branch/master/graph/badge.svg)](https://codecov.io/gh//.jl) [![Coverage](https://coveralls.io/repos/github//.jl/badge.svg?branch=master)](https://coveralls.io/github//.jl?branch=master) +# WackyOptions [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://tester.gitlab.io/WackyOptions.jl/dev) [![Build Status](https://gitlab.com/tester/WackyOptions.jl/badges/master/build.svg)](https://gitlab.com/tester/WackyOptions.jl/pipelines) [![Build Status](https://travis-ci.com/tester/WackyOptions.jl.svg?branch=master)](https://travis-ci.com/tester/WackyOptions.jl) [![Build Status](https://ci.appveyor.com/api/projects/status/github/tester/WackyOptions.jl?svg=true)](https://ci.appveyor.com/project/tester/WackyOptions-jl) [![Build Status](https://cloud.drone.io/api/badges/tester/WackyOptions.jl/status.svg)](https://cloud.drone.io/tester/WackyOptions.jl) [![Build Status](https://api.cirrus-ci.com/github/tester/WackyOptions.jl.svg)](https://cirrus-ci.com/github/tester/WackyOptions.jl) [![Coverage](https://codecov.io/gh//.jl/branch/master/graph/badge.svg)](https://codecov.io/gh//.jl) [![Coverage](https://coveralls.io/repos/github//.jl/badge.svg?branch=master)](https://coveralls.io/github//.jl?branch=master) ## Citing diff --git a/test/reference.jl b/test/reference.jl index 722c83e3..9fd31984 100644 --- a/test/reference.jl +++ b/test/reference.jl @@ -23,7 +23,7 @@ end @testset "All plugins" begin test_all("AllPlugins"; authors=USER, plugins=[ AppVeyor(), CirrusCI(), Citation(), Codecov(), Coveralls(), - Develop(), Documenter(), GitLabCI(), TravisCI(), + Develop(), Documenter(), DroneCI(), GitLabCI(), TravisCI(), ]) end @@ -39,6 +39,7 @@ end makedocs_kwargs=Dict(:foo => "bar", :bar => "baz"), canonical_url=(_t, _pkg) -> "http://example.com", ), + DroneCI(; amd64=false, arm=true, arm64=true, extra_versions=["1.1"]), Git(; ignore=["a", "b", "c"], manifest=true), GitLabCI(; coverage=false, extra_versions=[v"0.6"]), License(; name="ISC"), From 266a22d5c286af04fe9db9fba75a521dae2d23ad Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sun, 6 Oct 2019 16:12:20 +0700 Subject: [PATCH 68/81] Check and warn for unused keywords, update some metadata --- LICENSE | 2 ++ Project.toml | 2 +- src/template.jl | 24 ++++++++++++++---------- test/runtests.jl | 2 +- test/template.jl | 5 +++++ 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/LICENSE b/LICENSE index a1486d40..2d40ab71 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,5 @@ +MIT License + Copyright (c) 2017-2019 Chris de Graaf, Invenia Technical Computing Corporation Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/Project.toml b/Project.toml index 5f61b62e..713da4f9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "PkgTemplates" uuid = "14b8a8f1-9102-5b29-a752-f990bacb7fe1" -authors = ["Chris de Graaf "] +authors = ["Chris de Graaf", "Invenia Technical Computing Corporation"] version = "0.7.0" [deps] diff --git a/src/template.jl b/src/template.jl index 9b7dc3ef..af768cf1 100644 --- a/src/template.jl +++ b/src/template.jl @@ -57,18 +57,20 @@ Template(; kwargs...) = Template(Val(false); kwargs...) # Non-interactive constructor. function Template(::Val{false}; kwargs...) - user = getkw(kwargs, :user) - dir = abspath(expanduser(getkw(kwargs, :dir))) - host = replace(getkw(kwargs, :host), r".*://" => "") - julia = getkw(kwargs, :julia) + kwargs = Dict(kwargs) - authors = getkw(kwargs, :authors) + user = getkw!(kwargs, :user) + dir = abspath(expanduser(getkw!(kwargs, :dir))) + host = replace(getkw!(kwargs, :host), r".*://" => "") + julia = getkw!(kwargs, :julia) + + authors = getkw!(kwargs, :authors) authors isa Vector || (authors = map(strip, split(authors, ","))) # User-supplied plugins come first, so that deduping the list will remove the defaults. plugins = Plugin[] - append!(plugins, getkw(kwargs, :plugins)) - disabled = getkw(kwargs, :disable_defaults) + append!(plugins, getkw!(kwargs, :plugins)) + disabled = getkw!(kwargs, :disable_defaults) append!(plugins, filter(p -> !(typeof(p) in disabled), default_plugins())) plugins = sort(unique(typeof, plugins); by=string) @@ -82,6 +84,8 @@ function Template(::Val{false}; kwargs...) end end + isempty(kwargs) || @warn "Unrecognized keywords were supplied" kwargs + t = Template(authors, dir, host, julia, plugins, user) foreach(p -> validate(p, t), t.plugins) return t @@ -120,11 +124,11 @@ hasplugin(t::Template, ::Type{T}) where T <: Plugin = hasplugin(t, p -> p isa T) # Get a plugin by type. function getplugin(t::Template, ::Type{T}) where T <: Plugin i = findfirst(p -> p isa T, t.plugins) - i === nothing ? nothing : t.plugins[i] + return i === nothing ? nothing : t.plugins[i] end -# Get a keyword, or compute some default value. -getkw(kwargs, k) = get(() -> defaultkw(Template, k), kwargs, k) +# Get a keyword or a default value. +getkw!(kwargs, k) = pop!(kwargs, k, defaultkw(Template, k)) # Default Template keyword values. defaultkw(::Type{T}, s::Symbol) where T = defaultkw(T, Val(s)) diff --git a/test/runtests.jl b/test/runtests.jl index dc369b81..9836b302 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,7 +3,7 @@ using Base.Filesystem: contractuser, path_separator using LibGit2: LibGit2, GitCommit, GitRemote, GitRepo using Pkg: Pkg using Random: Random -using Test: @test, @testset, @test_throws +using Test: @test, @testset, @test_logs, @test_throws using ReferenceTests: @test_reference using SimpleMock: mock diff --git a/test/template.jl b/test/template.jl index 11a2e21d..db47e136 100644 --- a/test/template.jl +++ b/test/template.jl @@ -43,6 +43,11 @@ # Disabling a default plugin. test_plugins([], setdiff(defaults, [default_g]), [Git]) end + + @testset "Unsupported keywords warning" begin + @test_logs tpl() + @test_logs (:warn, "Unrecognized keywords were supplied") tpl(; x=1, y=2) + end end @testset "hasplugin" begin From ca51806cf60ea73f5598893312d87cb2ca3682c0 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sun, 6 Oct 2019 16:55:32 +0700 Subject: [PATCH 69/81] Reduce line length of docstrings --- Manifest.toml | 4 ++-- docs/src/developer.md | 2 +- src/plugin.jl | 50 ++++++++++++++++++++++++++------------- src/plugins/ci.jl | 28 ++++++++++++++-------- src/plugins/coverage.jl | 6 +++-- src/plugins/develop.jl | 4 +++- src/plugins/documenter.jl | 18 +++++++++----- src/plugins/git.jl | 3 ++- src/plugins/license.jl | 3 ++- src/plugins/tests.jl | 6 +++-- src/template.jl | 6 +++-- 11 files changed, 85 insertions(+), 45 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index bffdf4c8..e9084606 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -4,9 +4,9 @@ uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" [[DataAPI]] -git-tree-sha1 = "8903f0219d3472543fc4b2f5ebaf675a07f817c0" +git-tree-sha1 = "674b67f344687a88310213ddfa8a2b3c76cc4252" uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" -version = "1.0.1" +version = "1.1.0" [[DataValueInterfaces]] git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" diff --git a/docs/src/developer.md b/docs/src/developer.md index a049b15b..16e7c6a4 100644 --- a/docs/src/developer.md +++ b/docs/src/developer.md @@ -91,7 +91,7 @@ badges(::Documenter) = [ Badge( "Dev", "https://img.shields.io/badge/docs-dev-blue.svg", - "https://{{{}USER}}.github.io/{{{PKG}}}.jl/dev", + "https://{{{USER}}}.github.io/{{{PKG}}}.jl/dev", ), ] diff --git a/src/plugin.jl b/src/plugin.jl index 00fddc97..a9f12f8a 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -9,7 +9,8 @@ abstract type BasicPlugin <: Plugin end """ default_file(paths::AbstractString...) -> String -Return a path relative to the default template file directory (`$(contractuser(TEMPLATES_DIR))`). +Return a path relative to the default template file directory +(`$(contractuser(TEMPLATES_DIR))`). """ default_file(paths::AbstractString...) = joinpath(TEMPLATES_DIR, paths...) @@ -19,8 +20,10 @@ default_file(paths::AbstractString...) = joinpath(TEMPLATES_DIR, paths...) Return the view to be passed to the text templating engine for this plugin. `pkg` is the name of the package being generated. -For [`BasicPlugin`](@ref)s, this is used for both the plugin badges (see [`badges`](@ref)) and the template file (see [`source`](@ref)). -For other [`Plugin`](@ref)s, it is used only for badges, but you can always call it yourself as part of your [`hook`](@ref) implementation. +For [`BasicPlugin`](@ref)s, this is used for both the plugin badges +(see [`badges`](@ref)) and the template file (see [`source`](@ref)). +For other [`Plugin`](@ref)s, it is used only for badges, +but you can always call it yourself as part of your [`hook`](@ref) implementation. By default, an empty `Dict` is returned. """ @@ -31,7 +34,8 @@ view(::Plugin, ::Template, ::AbstractString) = Dict{String, Any}() The same as [`view`](@ref), but for use by package *users* for extension. -Values returned by this function will override those from [`view`](@ref) when the keys are the same. +Values returned by this function will override those from [`view`](@ref) +when the keys are the same. """ user_view(::Plugin, ::Template, ::AbstractString) = Dict{String, Any}() @@ -39,7 +43,9 @@ user_view(::Plugin, ::Template, ::AbstractString) = Dict{String, Any}() combined_view(::Plugin, ::Template, pkg::AbstractString) -> Dict{String, Any} This function combines [`view`](@ref) and [`user_view`](@ref) for use in text templating. -If you're doing manual file creation or text templating (i.e. writing [`Plugin`](@ref)s that are not [`BasicPlugin`](@ref)s), then you should use this function rather than either of the former two. +If you're doing manual file creation or text templating (i.e. writing [`Plugin`](@ref)s +that are not [`BasicPlugin`](@ref)s), then you should use this function +rather than either of the former two. !!! note Do not implement this function yourself! @@ -66,7 +72,8 @@ tags(::Plugin) = "{{", "}}" Determines the order in which plugins are processed (higher goes first). The default priority (`DEFAULT_PRIORITY`), is `$DEFAULT_PRIORITY`. -You can implement this function per-stage (by using `::typeof(hook)`, for example), or for all stages by simply using `::Function`. +You can implement this function per-stage (by using `::typeof(hook)`, for example), +or for all stages by simply using `::Function`. """ priority(::Plugin, ::Function) = DEFAULT_PRIORITY @@ -112,12 +119,13 @@ function destination end Badge(hover::AbstractString, image::AbstractString, link::AbstractString) Container for Markdown badge data. -Each argument can contain placeholders (which will be filled in with values from [`combined_view`](@ref)). +Each argument can contain placeholders, +which will be filled in with values from [`combined_view`](@ref). ## Arguments -* `hover::AbstractString`: Text to appear when the mouse is hovered over the badge. -* `image::AbstractString`: URL to the image to display. -* `link::AbstractString`: URL to go to upon clicking the badge. +- `hover::AbstractString`: Text to appear when the mouse is hovered over the badge. +- `image::AbstractString`: URL to the image to display. +- `link::AbstractString`: URL to go to upon clicking the badge. """ struct Badge hover::String @@ -139,7 +147,9 @@ end Perform any required validation for a [`Plugin`](@ref). -It is preferred to do validation here instead of in [`prehook`](@ref), because this function is called at [`Template`](@ref) construction time, whereas the prehook is only run at package generation time. +It is preferred to do validation here instead of in [`prehook`](@ref), +because this function is called at [`Template`](@ref) construction time, +whereas the prehook is only run at package generation time. """ validate(::Plugin, ::Template) = nothing @@ -147,7 +157,8 @@ validate(::Plugin, ::Template) = nothing prehook(::Plugin, ::Template, pkg_dir::AbstractString) Stage 1 of the package generation process (the "before" stage, in general). -At this point, `pkg_dir` is an empty directory that will eventually contain the package, and neither the [`hook`](@ref)s nor the [`posthook`](@ref)s have run. +At this point, `pkg_dir` is an empty directory that will eventually contain the package, +and neither the [`hook`](@ref)s nor the [`posthook`](@ref)s have run. !!! note `pkg_dir` only stays empty until the first plugin chooses to create a file. @@ -161,11 +172,13 @@ prehook(::Plugin, ::Template, ::AbstractString) = nothing Stage 2 of the package generation pipeline (the "main" stage, in general). At this point, the [`prehook`](@ref)s have run, but not the [`posthook`](@ref)s. -`pkg_dir` is the directory in which the package is being generated (so `basename(pkg_dir)` is the package name). +`pkg_dir` is the directory in which the package is being generated +(so `basename(pkg_dir)` is the package name). !!! note You usually shouldn't implement this function for [`BasicPlugin`](@ref)s. - If you do, it should probably `invoke` the generic method (otherwise, there's not much reason to subtype `BasicPlugin`). + If you do, it should probably `invoke` the generic method + (otherwise, there's not much reason to subtype `BasicPlugin`). """ hook(::Plugin, ::Template, ::AbstractString) = nothing @@ -211,7 +224,8 @@ end render_file(file::AbstractString view::Dict{<:AbstractString}, tags) -> String Render a template file with the data in `view`. -`tags` should be a tuple of two strings, which are the opening and closing delimiters, or `nothing` to use the default delimiters. +`tags` should be a tuple of two strings, which are the opening and closing delimiters, +or `nothing` to use the default delimiters. """ function render_file(file::AbstractString, view::Dict{<:AbstractString}, tags) return render_text(read(file, String), view, tags) @@ -221,7 +235,8 @@ end render_text(text::AbstractString, view::Dict{<:AbstractString}, tags=nothing) -> String Render some text with the data in `view`. -`tags` should be a tuple of two strings, which are the opening and closing delimiters, or `nothing` to use the default delimiters. +`tags` should be a tuple of two strings, which are the opening and closing delimiters, +or `nothing` to use the default delimiters. """ function render_text(text::AbstractString, view::Dict{<:AbstractString}, tags=nothing) return tags === nothing ? render(text, view) : render(text, view; tags=tags) @@ -231,7 +246,8 @@ end needs_username(::Plugin) -> Bool Determine whether or not a plugin needs a Git hosting service username to function correctly. -If you are implementing a plugin that uses the `user` field of a [`Template`](@ref), you should implement this function and return `true`. +If you are implementing a plugin that uses the `user` field of a [`Template`](@ref), +you should implement this function and return `true`. """ needs_username(::Plugin) = false diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index 1ede6210..531e3062 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -41,8 +41,10 @@ Integrates your packages with [Travis CI](https://travis-ci.com). - `linux::Bool`: Whether or not to run builds on Linux. - `osx::Bool`: Whether or not to run builds on OSX (MacOS). - `windows::Bool`: Whether or not to run builds on Windows. -- `x86::Bool`: Whether or not to run builds on 32-bit systems, in addition to the default 64-bit builds. -- `coverage::Bool`: Whether or not to publish code coverage (another code coverage plugin such as [`Codecov`](@ref) must also be included). +- `x86::Bool`: Whether or not to run builds on 32-bit systems, + in addition to the default 64-bit builds. +- `coverage::Bool`: Whether or not to publish code coverage. + Another code coverage plugin such as [`Codecov`](@ref) must also be included. $EXTRA_VERSIONS_DOC """ @with_kw_noshow struct TravisCI <: BasicPlugin @@ -106,12 +108,15 @@ end extra_versions=$DEFAULT_CI_VERSIONS, ) -Integrates your packages with [AppVeyor](https://appveyor.com) via [AppVeyor.jl](https://github.com/JuliaCI/Appveyor.jl). +Integrates your packages with [AppVeyor](https://appveyor.com) +via [AppVeyor.jl](https://github.com/JuliaCI/Appveyor.jl). ## Keyword Arguments - `file::AbstractString`: Template file for `.appveyor.yml`. -- `x86::Bool`: Whether or not to run builds on 32-bit systems, in addition to the default 64-bit builds. -- `coverage::Bool`: Whether or not to publish code coverage ([`Codecov`](@ref) must also be included). +- `x86::Bool`: Whether or not to run builds on 32-bit systems, + in addition to the default 64-bit builds. +- `coverage::Bool`: Whether or not to publish code coverage. + [`Codecov`](@ref) must also be included. $EXTRA_VERSIONS_DOC """ @with_kw_noshow struct AppVeyor <: BasicPlugin @@ -156,16 +161,19 @@ end extra_versions=$DEFAULT_CI_VERSIONS, ) -Integrates your packages with [Cirrus CI](https://cirrus-ci.org) via [CirrusCI.jl](https://github.com/ararslan/CirrusCI.jl). +Integrates your packages with [Cirrus CI](https://cirrus-ci.org) +via [CirrusCI.jl](https://github.com/ararslan/CirrusCI.jl). ## Keyword Arguments - `file::AbstractString`: Template file for `.cirrus.yml`. - `image::AbstractString`: The FreeBSD image to be used. -- `coverage::Bool`: Whether or not to publish code coverage ([`Codecov`](@ref) must also be included). +- `coverage::Bool`: Whether or not to publish code coverage. + [`Codecov`](@ref) must also be included. $EXTRA_VERSIONS_DOC !!! note - Code coverage submission from Cirrus CI is not yet supported by [Coverage.jl](https://github.com/JuliaCI/Coverage.jl). + Code coverage submission from Cirrus CI is not yet supported by + [Coverage.jl](https://github.com/JuliaCI/Coverage.jl). """ @with_kw_noshow struct CirrusCI <: BasicPlugin file::String = default_file("cirrus.yml") @@ -202,7 +210,7 @@ end extra_versions=$DEFAULT_CI_VERSIONS_NO_NIGHTLY, ) -Integrates your packages with [GitLab CI](https://docs.gitlab.com/ce/ci/). +Integrates your packages with [GitLab CI](https://docs.gitlab.com/ce/ci). ## Keyword Arguments - `file::AbstractString`: Template file for `.gitlab-ci.yml`. @@ -270,7 +278,7 @@ Integrates your packages with [Drone CI](https://drone.io). For example, you might want to generate a `.drone.yml` instead of the default Starlark file. - `amd64::Bool`: Whether or not to run builds on AMD64. - `arm::Bool`: Whether or not to run builds on ARM (32-bit). -- `arm::Bool`: Whether or not to run builds on ARM64. +- `arm64::Bool`: Whether or not to run builds on ARM64. $EXTRA_VERSIONS_DOC !!! note diff --git a/src/plugins/coverage.jl b/src/plugins/coverage.jl index 448cc36d..50674bbd 100644 --- a/src/plugins/coverage.jl +++ b/src/plugins/coverage.jl @@ -6,7 +6,8 @@ const COVERAGE_GITIGNORE = ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] Sets up code coverage submission from CI to [Codecov](https://codecov.io). ## Keyword Arguments -- `file::Union{AbstractString, Nothing}`: Template file for `.codecov.yml`, or `nothing` to create no file. +- `file::Union{AbstractString, Nothing}`: Template file for `.codecov.yml`, + or `nothing` to create no file. """ @with_kw_noshow struct Codecov <: BasicPlugin file::Union{String, Nothing} = nothing @@ -27,7 +28,8 @@ badges(::Codecov) = Badge( Sets up code coverage submission from CI to [Coveralls](https://coveralls.io). ## Keyword Arguments -- `file::Union{AbstractString, Nothing}`: Template file for `.coveralls.yml`, or `nothing` to create no file. +- `file::Union{AbstractString, Nothing}`: Template file for `.coveralls.yml`, + or `nothing` to create no file. """ @with_kw_noshow struct Coveralls <: BasicPlugin file::Union{String, Nothing} = nothing diff --git a/src/plugins/develop.jl b/src/plugins/develop.jl index a06fef74..835f2717 100644 --- a/src/plugins/develop.jl +++ b/src/plugins/develop.jl @@ -2,7 +2,9 @@ Develop() Adds generated packages to the current environment by `dev`ing them. -See the Pkg documentation [here](https://julialang.github.io/Pkg.jl/v1/managing-packages/#Developing-packages-1) for more details. +See the Pkg documentation +[here](https://julialang.github.io/Pkg.jl/v1/managing-packages/#Developing-packages-1) +for more details. """ struct Develop <: Plugin end diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index 291639fe..87541b3c 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -13,23 +13,29 @@ const DOCUMENTER_DEP = PackageSpec(; ) Sets up documentation generation via [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl). -Documentation deployment depends on `T`, where `T` is some supported CI plugin, or `Nothing` to only support local documentation builds. +Documentation deployment depends on `T`, where `T` is some supported CI plugin, +or `Nothing` to only support local documentation builds. ## Supported Type Parameters -- `TravisCI`: Deploys documentation to [GitHub Pages](https://pages.github.com) with the help of [`TravisCI`](@ref). -- `GitLabCI`: Deploys documentation to [GitLab Pages](https://pages.gitlab.com) with the help of [`GitLabCI`](@ref). +- `TravisCI`: Deploys documentation to [GitHub Pages](https://pages.github.com) + with the help of [`TravisCI`](@ref). +- `GitLabCI`: Deploys documentation to [GitLab Pages](https://pages.gitlab.com) + with the help of [`GitLabCI`](@ref). - `Nothing` (default): Does not set up documentation deployment. ## Keyword Arguments - `make_jl::AbstractString`: Template file for `make.jl`. - `index_md::AbstractString`: Template file for `index.md`. - `assets::Vector{<:AbstractString}`: Extra assets for the generated site. -- `canonical_url::Union{Function, Nothing}`: A function to generate the documentation site's canonical URL. - The default value will compute GitHub Pages and GitLab Pages URLs for [`TravisCI`](@ref) and [`GitLabCI`](@ref), respectively. +- `canonical_url::Union{Function, Nothing}`: A function to generate the site's canonical URL. + The default value will compute GitHub Pages and GitLab Pages URLs + for [`TravisCI`](@ref) and [`GitLabCI`](@ref), respectively. + If set to `nothing`, no canonical URL is set. - `makedocs_kwargs::Dict{Symbol}`: Extra keyword arguments to be inserted into `makedocs`. !!! note - If deploying documentation with Travis CI, don't forget to complete [the required configuration](https://juliadocs.github.io/Documenter.jl/stable/man/hosting/#SSH-Deploy-Keys-1). + If deploying documentation with Travis CI, don't forget to complete + [the required configuration](https://juliadocs.github.io/Documenter.jl/stable/man/hosting/#SSH-Deploy-Keys-1). """ struct Documenter{T<:Union{TravisCI, GitLabCI, Nothing}} <: Plugin assets::Vector{String} diff --git a/src/plugins/git.jl b/src/plugins/git.jl index aaea9174..d105f226 100644 --- a/src/plugins/git.jl +++ b/src/plugins/git.jl @@ -10,7 +10,8 @@ Creates a Git repository and a `.gitignore` file. If left unset, HTTPS is used. - `manifest::Bool`: Whether or not to commit `Manifest.toml`. - `gpgsign::Bool`: Whether or not to sign commits with your GPG key. - This option requires that the Git CLI is installed, and for you to have a GPG key associated with your committer identity. + This option requires that the Git CLI is installed, + and for you to have a GPG key associated with your committer identity. """ @with_kw_noshow struct Git <: Plugin ignore::Vector{String} = String[] diff --git a/src/plugins/license.jl b/src/plugins/license.jl index be8314a7..e88bcbef 100644 --- a/src/plugins/license.jl +++ b/src/plugins/license.jl @@ -5,7 +5,8 @@ Creates a license file. ## Keyword Arguments - `name::AbstractString`: Name of a license supported by PkgTemplates. - Available licenses can be seen [here](https://github.com/invenia/PkgTemplates.jl/tree/master/templates/licenses). + Available licenses can be seen + [here](https://github.com/invenia/PkgTemplates.jl/tree/master/templates/licenses). - `path::Union{AbstractString, Nothing}`: Path to a custom license file. This keyword takes priority over `name`. - `destination::AbstractString`: File destination, relative to the repository root. diff --git a/src/plugins/tests.jl b/src/plugins/tests.jl index 8281be6e..955c0f5a 100644 --- a/src/plugins/tests.jl +++ b/src/plugins/tests.jl @@ -9,10 +9,12 @@ Sets up testing for packages. ## Keyword Arguments - `file::AbstractString`: Template file for `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. + 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. + Managing test dependencies with `test/Project.toml` is only supported + in Julia 1.2 and later. """ @with_kw_noshow struct Tests <: BasicPlugin file::String = default_file("test", "runtests.jl") diff --git a/src/template.jl b/src/template.jl index af768cf1..c079f758 100644 --- a/src/template.jl +++ b/src/template.jl @@ -21,7 +21,8 @@ A configuration used to generate packages. The default value comes from the global Git config (`github.user`). If no value is obtained, many plugins that use this value will not work. - `authors::Union{AbstractString, Vector{<:AbstractString}}="$(default_authors())"`: Package authors. - Like `user`, it takes its default value from the global Git config (`user.name` and `user.email`). + Like `user`, it takes its default value from the global Git config + (`user.name` and `user.email`). ### Package Options - `dir::AbstractString="$(contractuser(Pkg.devdir()))"`: Directory to place packages in. @@ -31,7 +32,8 @@ A configuration used to generate packages. ### Template Plugins - `plugins::Vector{<:Plugin}=Plugin[]`: A list of [`Plugin`](@ref)s used by the template. - `disable_defaults::Vector{DataType}=DataType[]`: Default plugins to disable. - The default plugins are [`ProjectFile`](@ref), [`SrcDir`](@ref), [`Tests`](@ref), [`Readme`](@ref), [`License`](@ref), and [`Git`](@ref). + The default plugins are [`ProjectFile`](@ref), [`SrcDir`](@ref), [`Tests`](@ref), + [`Readme`](@ref), [`License`](@ref), and [`Git`](@ref). To override a default plugin instead of disabling it altogether, supply it via `plugins`. --- From 69a7c5c68b1b47ba17750de6602a6713525394e3 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sun, 6 Oct 2019 16:55:54 +0700 Subject: [PATCH 70/81] Add a test for the test/Project.toml warning --- src/plugins/tests.jl | 2 +- test/plugin.jl | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/plugins/tests.jl b/src/plugins/tests.jl index 955c0f5a..50a0ecad 100644 --- a/src/plugins/tests.jl +++ b/src/plugins/tests.jl @@ -29,7 +29,7 @@ function validate(p::Tests, t::Template) invoke(validate, Tuple{BasicPlugin, Template}, p, t) p.project && t.julia < v"1.2" && @warn string( "Tests: The project option is set to create a project (supported in Julia 1.2 and later) ", - "but a Julia version older than 1.2 is supported by the Template", + "but a Julia version older than 1.2 ($(t.julia)) is supported by the template", ) end diff --git a/test/plugin.jl b/test/plugin.jl index c76efa07..975dea3a 100644 --- a/test/plugin.jl +++ b/test/plugin.jl @@ -26,4 +26,12 @@ PT.user_view(::BasicTest, ::Template, ::AbstractString) = Dict("X" => 1, "Z" => @test read(joinpath(pkg_dir, "foo.txt"), String) == s end end + + @testset "Tests Project.toml warning on Julia < 1.2" begin + p = Tests(; project=true) + @test_logs (:warn, r"The project option is set") tpl(; julia=v"1", plugins=[p]) + @test_logs (:warn, r"The project option is set") tpl(; julia=v"1.1", plugins=[p]) + @test_logs tpl(; julia=v"1.2", plugins=[p]) + @test_logs tpl(; julia=v"1.3", plugins=[p]) + end end From eac2a1278d2eedda2f13f91297c7af04e091fc24 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Wed, 16 Oct 2019 22:39:46 +0700 Subject: [PATCH 71/81] Update deps/fixtures, skip more tests when Git is not installed TODO: We need to figure something out to stop dependency versions from constantly changing in the fixture manifests, because that's going to get annoying to update all the time. I still want it to be included in the tests, though. --- docs/Manifest.toml | 8 ++++---- src/plugins/git.jl | 11 ++++++++++- test/fixtures/WackyOptions/docs/Manifest.toml | 8 ++++---- test/runtests.jl | 19 ++++++++++++------- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/docs/Manifest.toml b/docs/Manifest.toml index fe717470..2fbd4f44 100644 --- a/docs/Manifest.toml +++ b/docs/Manifest.toml @@ -13,15 +13,15 @@ uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" [[DocStringExtensions]] deps = ["LibGit2", "Markdown", "Pkg", "Test"] -git-tree-sha1 = "0513f1a8991e9d83255e0140aace0d0fc4486600" +git-tree-sha1 = "88bb0edb352b16608036faadcc071adda068582a" uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" -version = "0.8.0" +version = "0.8.1" [[Documenter]] deps = ["Base64", "DocStringExtensions", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"] -git-tree-sha1 = "1b6ae3796f60311e39cd1770566140d2c056e87f" +git-tree-sha1 = "d45c163c7a3ae293c15361acc52882c0f853f97c" uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4" -version = "0.23.3" +version = "0.23.4" [[InteractiveUtils]] deps = ["Markdown"] diff --git a/src/plugins/git.jl b/src/plugins/git.jl index d105f226..36c79b3d 100644 --- a/src/plugins/git.jl +++ b/src/plugins/git.jl @@ -32,7 +32,7 @@ function gitignore(p::Git) end function validate(p::Git, t::Template) - if p.gpgsign && try run(pipeline(`git --version`; stdout=devnull)); false catch; true end + if p.gpgsign && !git_is_installed() throw(ArgumentError("Git: gpgsign is set but the Git CLI is not installed")) end @@ -97,6 +97,15 @@ end needs_username(::Git) = true +function git_is_installed() + return try + run(pipeline(`git --version`; stdout=devnull)) + true + catch + false + end +end + if isdefined(Pkg, :dependencies) function version_of(pkg::AbstractString) for p in values(Pkg.dependencies()) diff --git a/test/fixtures/WackyOptions/docs/Manifest.toml b/test/fixtures/WackyOptions/docs/Manifest.toml index fe717470..2fbd4f44 100644 --- a/test/fixtures/WackyOptions/docs/Manifest.toml +++ b/test/fixtures/WackyOptions/docs/Manifest.toml @@ -13,15 +13,15 @@ uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" [[DocStringExtensions]] deps = ["LibGit2", "Markdown", "Pkg", "Test"] -git-tree-sha1 = "0513f1a8991e9d83255e0140aace0d0fc4486600" +git-tree-sha1 = "88bb0edb352b16608036faadcc071adda068582a" uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" -version = "0.8.0" +version = "0.8.1" [[Documenter]] deps = ["Base64", "DocStringExtensions", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"] -git-tree-sha1 = "1b6ae3796f60311e39cd1770566140d2c056e87f" +git-tree-sha1 = "d45c163c7a3ae293c15361acc52882c0f853f97c" uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4" -version = "0.23.3" +version = "0.23.4" [[InteractiveUtils]] deps = ["Markdown"] diff --git a/test/runtests.jl b/test/runtests.jl index 9836b302..eebc326a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -44,16 +44,21 @@ mktempdir() do dir @testset "PkgTemplates.jl" begin include("template.jl") include("plugin.jl") - include("git.jl") include("show.jl") - # Quite a bit of output depends on the Julia version, - # and the test fixtures are made with Julia 1.2. - # TODO: Keep this on the latest stable Julia version. - if VERSION.major == 1 && VERSION.minor == 2 - include("reference.jl") + if PT.git_is_installed() + include("git.jl") + + # Quite a bit of output depends on the Julia version, + # and the test fixtures are made with Julia 1.2. + # TODO: Keep this on the latest stable Julia version. + if VERSION.major == 1 && VERSION.minor == 2 + include("reference.jl") + else + @info "Skipping reference tests" julia=VERSION + end else - @info "Skipping reference tests" julia=VERSION + @info "Git is not installed, skipping Git and reference tests" end end finally From 1d2810e40c396132d40e44fbe1a1c5d847955614 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Tue, 22 Oct 2019 16:11:00 +0700 Subject: [PATCH 72/81] Add some custom template examples --- docs/src/user.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/docs/src/user.md b/docs/src/user.md index 4446ca1f..c213422f 100644 --- a/docs/src/user.md +++ b/docs/src/user.md @@ -76,6 +76,42 @@ Develop Citation ``` +## A More Complicated Example + +Here are a few example templates that use the options and plugins explained above. + +This one includes plugins suitable for a project hosted on GitHub, and some other customizations: + +```julia +Template(; + user="my-username", + dir="~/code", + authors="Acme Corp", + julia=v"1.1", + plugins=[ + License(; name="MPL"), + Git(; manifest=true, ssh=true), + TravisCI(; x86=true), + Codecov(), + Documenter{TravisCI}(), + Develop(), + ], +) +``` + +Here's one that works well for projects hosted on GitLab: + +```julia +Template(; + user="my-username", + host="gitlab.com", + plugins=[ + GitLabCI(), + Documenter{GitLabCI}(), + ], +) +``` + ## Custom Template Files !!! note "Templates vs Templating" From b3449ee272e4c712ba55c3c00d8d3fbc9e8ae7d8 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Tue, 22 Oct 2019 19:24:19 +0700 Subject: [PATCH 73/81] Add a fetch ref to the remote, too We can't add upstream remotes until the remote actually exists, it seems. So that has to wait until we also create the upstream repo. --- src/plugins/git.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/git.jl b/src/plugins/git.jl index 36c79b3d..19243a66 100644 --- a/src/plugins/git.jl +++ b/src/plugins/git.jl @@ -54,7 +54,7 @@ function prehook(p::Git, t::Template, pkg_dir::AbstractString) "https://$(t.host)/$(t.user)/$pkg.jl" end LibGit2.with(GitRemote(repo, "origin", url)) do remote - # TODO: `git pull` still requires some Git branch config. + LibGit2.add_fetch!(repo, remote, "refs/heads/master") LibGit2.add_push!(repo, remote, "refs/heads/master") end end From ab55313ee9a1bde42bdffaf54ac17667ca698131 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Fri, 1 Nov 2019 08:15:17 +0700 Subject: [PATCH 74/81] Add a bit more detail to the extra kwargs warning --- src/template.jl | 4 +++- test/template.jl | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/template.jl b/src/template.jl index c079f758..e3eac7ba 100644 --- a/src/template.jl +++ b/src/template.jl @@ -86,7 +86,9 @@ function Template(::Val{false}; kwargs...) end end - isempty(kwargs) || @warn "Unrecognized keywords were supplied" kwargs + if !isempty(kwargs) + @warn "Unrecognized keywords were supplied, see the documentation for help" kwargs + end t = Template(authors, dir, host, julia, plugins, user) foreach(p -> validate(p, t), t.plugins) diff --git a/test/template.jl b/test/template.jl index db47e136..bea47055 100644 --- a/test/template.jl +++ b/test/template.jl @@ -46,7 +46,7 @@ @testset "Unsupported keywords warning" begin @test_logs tpl() - @test_logs (:warn, "Unrecognized keywords were supplied") tpl(; x=1, y=2) + @test_logs (:warn, r"Unrecognized keywords were supplied") tpl(; x=1, y=2) end end From 206b7e9ade6b328de6f38aba119e1fbdf4d27364 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Fri, 1 Nov 2019 09:27:12 +0700 Subject: [PATCH 75/81] Support ARM builds on Travis CI --- src/plugins/ci.jl | 18 +++++++++++++----- templates/travis.yml | 6 +++--- test/fixtures/WackyOptions/.travis.yml | 6 ++++++ test/reference.jl | 8 +++++++- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index 531e3062..2b8dd634 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -30,6 +30,7 @@ end osx=true, windows=true, x86=false, + arm=false, coverage=true, extra_versions=$DEFAULT_CI_VERSIONS, ) @@ -43,6 +44,7 @@ Integrates your packages with [Travis CI](https://travis-ci.com). - `windows::Bool`: Whether or not to run builds on Windows. - `x86::Bool`: Whether or not to run builds on 32-bit systems, in addition to the default 64-bit builds. +- `arm::Bool`: Whether or not to run builds on the ARM architecture, in addition to AMD64. - `coverage::Bool`: Whether or not to publish code coverage. Another code coverage plugin such as [`Codecov`](@ref) must also be included. $EXTRA_VERSIONS_DOC @@ -53,6 +55,7 @@ $EXTRA_VERSIONS_DOC osx::Bool = true windows::Bool = true x86::Bool = false + arm::Bool = false coverage::Bool = true extra_versions::Vector = DEFAULT_CI_VERSIONS end @@ -75,11 +78,16 @@ function view(p::TravisCI, t::Template, pkg::AbstractString) versions = collect_versions(t, p.extra_versions) allow_failures = filter(in(versions), ALLOWED_FAILURES) - x86 = Dict{String, String}[] + jobs = Dict{String, String}[] if p.x86 foreach(versions) do v - p.linux && push!(x86, Dict("JULIA" => v, "OS" => "linux")) - p.windows && push!(x86, Dict("JULIA" => v, "OS" => "windows")) + p.linux && push!(jobs, Dict("JULIA" => v, "OS" => "linux", "ARCH" => "x86")) + p.windows && push!(jobs, Dict("JULIA" => v, "OS" => "windows", "ARCH" => "x86")) + end + end + if p.arm + foreach(versions) do v + p.linux && push!(jobs, Dict("JULIA" => v, "OS" => "linux", "ARCH" => "arm64")) end end @@ -90,13 +98,13 @@ function view(p::TravisCI, t::Template, pkg::AbstractString) "HAS_COVERAGE" => p.coverage && hasplugin(t, is_coverage), "HAS_COVERALLS" => hasplugin(t, Coveralls), "HAS_DOCUMENTER" => hasplugin(t, Documenter{TravisCI}), - "HAS_JOBS" => p.x86 || hasplugin(t, Documenter{TravisCI}), + "HAS_JOBS" => !isempty(jobs) || hasplugin(t, Documenter{TravisCI}), "OS" => os, "PKG" => pkg, "USER" => t.user, "VERSION" => format_version(t.julia), "VERSIONS" => versions, - "X86" => x86, + "JOBS" => jobs, ) end diff --git a/templates/travis.yml b/templates/travis.yml index accf0d2a..64837ede 100644 --- a/templates/travis.yml +++ b/templates/travis.yml @@ -21,11 +21,11 @@ jobs: {{#HAS_JOBS}} include: {{/HAS_JOBS}} -{{#X86}} +{{#JOBS}} - julia: {{{JULIA}}} os: {{{OS}}} - arch: x86 -{{/X86}} + arch: {{{ARCH}}} +{{/JOBS}} {{#HAS_DOCUMENTER}} - stage: Documentation julia: {{{VERSION}}} diff --git a/test/fixtures/WackyOptions/.travis.yml b/test/fixtures/WackyOptions/.travis.yml index 5a97f173..23e5a574 100644 --- a/test/fixtures/WackyOptions/.travis.yml +++ b/test/fixtures/WackyOptions/.travis.yml @@ -17,3 +17,9 @@ jobs: - julia: 1.2 os: linux arch: x86 + - julia: 1.1 + os: linux + arch: arm64 + - julia: 1.2 + os: linux + arch: arm64 diff --git a/test/reference.jl b/test/reference.jl index 9fd31984..ac929d9f 100644 --- a/test/reference.jl +++ b/test/reference.jl @@ -45,7 +45,13 @@ end License(; name="ISC"), Readme(; inline_badges=true), Tests(; project=true), - TravisCI(; coverage=false, windows=false, x86=true, extra_versions=["1.1"]), + TravisCI(; + coverage=false, + windows=false, + x86=true, + arm=true, + extra_versions=["1.1"], + ), ]) end end From 5a8934350c12ff53a2fdb218a384f441fe6f2d73 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Fri, 1 Nov 2019 09:41:22 +0700 Subject: [PATCH 76/81] Disable pretty urls except in CI --- docs/make.jl | 1 + templates/docs/make.jl | 1 + test/fixtures/AllPlugins/docs/make.jl | 1 + test/fixtures/WackyOptions/docs/make.jl | 1 + 4 files changed, 4 insertions(+) diff --git a/docs/make.jl b/docs/make.jl index 622e8953..d8c0af6f 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -7,6 +7,7 @@ makedocs(; repo="https://github.com/invenia/PkgTemplates.jl/blob/{commit}{path}#L{line}", sitename="PkgTemplates.jl", format=Documenter.HTML(; + prettyurls=get(ENV, "CI", "false") == "true", canonical="https://invenia.github.io/PkgTemplates.jl", assets=String[], ), diff --git a/templates/docs/make.jl b/templates/docs/make.jl index a9a09c9d..dd0aa69a 100644 --- a/templates/docs/make.jl +++ b/templates/docs/make.jl @@ -7,6 +7,7 @@ makedocs(; repo="https://{{{REPO}}}/blob/{commit}{path}#L{line}", sitename="{{{PKG}}}.jl", format=Documenter.HTML(; + prettyurls=get(ENV, "CI", "false") == "true", {{#CANONICAL}} canonical="{{{CANONICAL}}}", {{/CANONICAL}} diff --git a/test/fixtures/AllPlugins/docs/make.jl b/test/fixtures/AllPlugins/docs/make.jl index 4141053f..35c4a8d3 100644 --- a/test/fixtures/AllPlugins/docs/make.jl +++ b/test/fixtures/AllPlugins/docs/make.jl @@ -7,6 +7,7 @@ makedocs(; repo="https://github.com/tester/AllPlugins.jl/blob/{commit}{path}#L{line}", sitename="AllPlugins.jl", format=Documenter.HTML(; + prettyurls=get(ENV, "CI", "false") == "true", assets=String[], ), pages=[ diff --git a/test/fixtures/WackyOptions/docs/make.jl b/test/fixtures/WackyOptions/docs/make.jl index a8131e6e..888f0a07 100644 --- a/test/fixtures/WackyOptions/docs/make.jl +++ b/test/fixtures/WackyOptions/docs/make.jl @@ -7,6 +7,7 @@ makedocs(; repo="https://github.com/tester/WackyOptions.jl/blob/{commit}{path}#L{line}", sitename="WackyOptions.jl", format=Documenter.HTML(; + prettyurls=get(ENV, "CI", "false") == "true", canonical="http://example.com", assets=[ "assets/static.txt", From aaa1f5280cd9cf9c3f0b5c03eb14220165e0b3a3 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Fri, 1 Nov 2019 11:45:55 +0700 Subject: [PATCH 77/81] Clean up Travis configs and temp name generation --- .travis.yml | 6 +--- src/plugins/ci.jl | 41 +++++++++++--------------- templates/travis.yml | 25 +++++++++++----- test/fixtures/AllPlugins/.travis.yml | 2 ++ test/fixtures/WackyOptions/.travis.yml | 22 ++++++-------- test/reference.jl | 2 +- test/runtests.jl | 8 ++--- 7 files changed, 51 insertions(+), 55 deletions(-) diff --git a/.travis.yml b/.travis.yml index a9fdc1ce..a979400e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,11 +19,7 @@ matrix: - julia: 1.3 - julia: nightly include: - - os: linux - arch: x86 - julia: 1.0 - - os: windows - arch: x86 + - arch: x86 julia: 1.0 - stage: Documentation julia: 1.0 diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index 2b8dd634..7db08da8 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -29,8 +29,9 @@ end linux=true, osx=true, windows=true, + x64=true, x86=false, - arm=false, + arm64=false, coverage=true, extra_versions=$DEFAULT_CI_VERSIONS, ) @@ -42,9 +43,9 @@ Integrates your packages with [Travis CI](https://travis-ci.com). - `linux::Bool`: Whether or not to run builds on Linux. - `osx::Bool`: Whether or not to run builds on OSX (MacOS). - `windows::Bool`: Whether or not to run builds on Windows. -- `x86::Bool`: Whether or not to run builds on 32-bit systems, - in addition to the default 64-bit builds. -- `arm::Bool`: Whether or not to run builds on the ARM architecture, in addition to AMD64. +- `x64::Bool`: Whether or not to run builds on 64-bit architecture. +- `x86::Bool`: Whether or not to run builds on 32-bit architecture. +- `arm64::Bool`: Whether or not to run builds on the ARM64 architecture. - `coverage::Bool`: Whether or not to publish code coverage. Another code coverage plugin such as [`Codecov`](@ref) must also be included. $EXTRA_VERSIONS_DOC @@ -54,8 +55,9 @@ $EXTRA_VERSIONS_DOC linux::Bool = true osx::Bool = true windows::Bool = true + x64::Bool = true x86::Bool = false - arm::Bool = false + arm64::Bool = false coverage::Bool = true extra_versions::Vector = DEFAULT_CI_VERSIONS end @@ -70,41 +72,34 @@ badges(::TravisCI) = Badge( ) function view(p::TravisCI, t::Template, pkg::AbstractString) - os = String[] - p.linux && push!(os, "linux") - p.osx && push!(os, "osx") - p.windows && push!(os, "windows") - + os = filter(o -> getfield(p, Symbol(o)), ["linux", "osx", "windows"]) + arch = filter(a -> getfield(p, Symbol(a)), ["x64", "x86", "arm64"]) versions = collect_versions(t, p.extra_versions) allow_failures = filter(in(versions), ALLOWED_FAILURES) - jobs = Dict{String, String}[] - if p.x86 - foreach(versions) do v - p.linux && push!(jobs, Dict("JULIA" => v, "OS" => "linux", "ARCH" => "x86")) - p.windows && push!(jobs, Dict("JULIA" => v, "OS" => "windows", "ARCH" => "x86")) - end - end - if p.arm - foreach(versions) do v - p.linux && push!(jobs, Dict("JULIA" => v, "OS" => "linux", "ARCH" => "arm64")) - end + excludes = Dict{String, String}[] + p.x86 && p.osx && push!(excludes, Dict("E_OS" => "osx", "E_ARCH" => "x86")) + if p.arm64 + p.osx && push!(excludes, Dict("E_OS" => "osx", "E_ARCH" => "arm64")) + p.windows && push!(excludes, Dict("E_OS" => "windows", "E_ARCH" => "arm64")) + "nightly" in versions && push!(excludes, Dict("E_JULIA" => "nightly", "E_ARCH" => "arm64")) end return Dict( "ALLOW_FAILURES" => allow_failures, + "ARCH" => arch, + "EXCLUDES" => excludes, "HAS_ALLOW_FAILURES" => !isempty(allow_failures), "HAS_CODECOV" => hasplugin(t, Codecov), "HAS_COVERAGE" => p.coverage && hasplugin(t, is_coverage), "HAS_COVERALLS" => hasplugin(t, Coveralls), "HAS_DOCUMENTER" => hasplugin(t, Documenter{TravisCI}), - "HAS_JOBS" => !isempty(jobs) || hasplugin(t, Documenter{TravisCI}), + "HAS_EXCLUDES" => !isempty(excludes), "OS" => os, "PKG" => pkg, "USER" => t.user, "VERSION" => format_version(t.julia), "VERSIONS" => versions, - "JOBS" => jobs, ) end diff --git a/templates/travis.yml b/templates/travis.yml index 64837ede..b6a0172c 100644 --- a/templates/travis.yml +++ b/templates/travis.yml @@ -10,6 +10,10 @@ os: {{#OS}} - {{{.}}} {{/OS}} +arch: +{{#ARCH}} + - {{{.}}} +{{/ARCH}} jobs: fast_finish: true {{#HAS_ALLOW_FAILURES}} @@ -18,15 +22,20 @@ jobs: {{#ALLOW_FAILURES}} - julia: {{{.}}} {{/ALLOW_FAILURES}} -{{#HAS_JOBS}} - include: -{{/HAS_JOBS}} -{{#JOBS}} - - julia: {{{JULIA}}} - os: {{{OS}}} - arch: {{{ARCH}}} -{{/JOBS}} +{{#HAS_EXCLUDES}} + exclude: +{{/HAS_EXCLUDES}} +{{#EXCLUDES}} + - arch: {{{E_ARCH}}} + {{#E_OS}} + os: {{{E_OS}}} + {{/E_OS}} + {{#E_JULIA}} + julia: {{{E_JULIA}}} + {{/E_JULIA}} +{{/EXCLUDES}} {{#HAS_DOCUMENTER}} + include: - stage: Documentation julia: {{{VERSION}}} script: julia --project=docs -e ' diff --git a/test/fixtures/AllPlugins/.travis.yml b/test/fixtures/AllPlugins/.travis.yml index 91a26e33..93151129 100644 --- a/test/fixtures/AllPlugins/.travis.yml +++ b/test/fixtures/AllPlugins/.travis.yml @@ -10,6 +10,8 @@ os: - linux - osx - windows +arch: + - x64 jobs: fast_finish: true allow_failures: diff --git a/test/fixtures/WackyOptions/.travis.yml b/test/fixtures/WackyOptions/.travis.yml index 23e5a574..1b2d1ee1 100644 --- a/test/fixtures/WackyOptions/.travis.yml +++ b/test/fixtures/WackyOptions/.travis.yml @@ -8,18 +8,14 @@ julia: os: - linux - osx +arch: + - x64 + - x86 + - arm64 jobs: fast_finish: true - include: - - julia: 1.1 - os: linux - arch: x86 - - julia: 1.2 - os: linux - arch: x86 - - julia: 1.1 - os: linux - arch: arm64 - - julia: 1.2 - os: linux - arch: arm64 + exclude: + - arch: x86 + os: osx + - arch: arm64 + os: osx diff --git a/test/reference.jl b/test/reference.jl index ac929d9f..1aa8ac3d 100644 --- a/test/reference.jl +++ b/test/reference.jl @@ -49,7 +49,7 @@ end coverage=false, windows=false, x86=true, - arm=true, + arm64=true, extra_versions=["1.1"], ), ]) diff --git a/test/runtests.jl b/test/runtests.jl index eebc326a..aab362f6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,7 +2,7 @@ using Base.Filesystem: contractuser, path_separator using LibGit2: LibGit2, GitCommit, GitRemote, GitRepo using Pkg: Pkg -using Random: Random +using Random: Random, randstring using Test: @test, @testset, @test_logs, @test_throws using ReferenceTests: @test_reference @@ -19,10 +19,8 @@ Random.seed!(1) # Creata a template that won't error because of a missing username. tpl(; kwargs...) = Template(; user=USER, kwargs...) -const PKG = Ref("A") - -# Generate an unused package name. -pkgname() = PKG[] *= "a" +# Generate a random package name. +pkgname() = titlecase(randstring('A':'Z', 16)) # Create a randomly named package with a template, and delete it afterwards. function with_pkg(f::Function, t::Template, pkg::AbstractString=pkgname()) From 6bb3c2c6696fc7db1fcb87b6344c553bd4390ef0 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Mon, 4 Nov 2019 15:58:32 +0700 Subject: [PATCH 78/81] Add version option to ProjectFile plugin to set initial version --- src/plugins/project_file.jl | 13 +++++++++---- test/fixtures/WackyOptions/Project.toml | 2 +- test/reference.jl | 1 + test/show.jl | 3 ++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/plugins/project_file.jl b/src/plugins/project_file.jl index 15ea375c..0afbd04f 100644 --- a/src/plugins/project_file.jl +++ b/src/plugins/project_file.jl @@ -1,19 +1,24 @@ """ - ProjectFile() + ProjectFile(; version=v"0.1.0") Creates a `Project.toml`. + +## Keyword Arguments +- `version::VersionNumber`: The initial version of created packages. """ -struct ProjectFile <: Plugin end +@with_kw_noshow struct ProjectFile <: Plugin + version::VersionNumber = v"0.1.0" +end # Other plugins like Tests will modify this file. priority(::ProjectFile, ::typeof(hook)) = typemax(Int) - 5 -function hook(::ProjectFile, t::Template, pkg_dir::AbstractString) +function hook(p::ProjectFile, t::Template, pkg_dir::AbstractString) toml = Dict( "name" => basename(pkg_dir), "uuid" => string(uuid4()), "authors" => t.authors, - "version" => "0.1.0", + "version" => string(p.version), "compat" => Dict("julia" => compat_version(t.julia)), ) open(io -> TOML.print(io, toml), joinpath(pkg_dir, "Project.toml"), "w") diff --git a/test/fixtures/WackyOptions/Project.toml b/test/fixtures/WackyOptions/Project.toml index 2c84430c..c1ac4eea 100644 --- a/test/fixtures/WackyOptions/Project.toml +++ b/test/fixtures/WackyOptions/Project.toml @@ -1,7 +1,7 @@ name = "WackyOptions" uuid = "5b7e9947-ddc0-4b3f-9b55-0d8042f74170" authors = ["tester"] -version = "0.1.0" +version = "1.0.0" [compat] julia = "1.2" diff --git a/test/reference.jl b/test/reference.jl index 1aa8ac3d..55c0b692 100644 --- a/test/reference.jl +++ b/test/reference.jl @@ -43,6 +43,7 @@ end Git(; ignore=["a", "b", "c"], manifest=true), GitLabCI(; coverage=false, extra_versions=[v"0.6"]), License(; name="ISC"), + ProjectFile(; version=v"1"), Readme(; inline_badges=true), Tests(; project=true), TravisCI(; diff --git a/test/show.jl b/test/show.jl index 8683f436..688e7bb1 100644 --- a/test/show.jl +++ b/test/show.jl @@ -38,7 +38,8 @@ const LICENSES_DIR = joinpath(TEMPLATES_DIR, "licenses") License: path: "$(joinpath(LICENSES_DIR, "MIT"))" destination: "LICENSE" - ProjectFile + ProjectFile: + version: v"0.1.0" Readme: file: "$(joinpath(TEMPLATES_DIR, "README.md"))" destination: "README.md" From 4d70635d3a81c1a3e24bf140a6a901c162af3b92 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sat, 9 Nov 2019 00:26:05 +0700 Subject: [PATCH 79/81] Add GitHubActions plugin for CI and docs The docs deployment requires Documenter 0.24 but I'm assuming that PkgTemplates 0.7 won't be released until after Documenter 0.24. --- docs/src/user.md | 5 +- src/PkgTemplates.jl | 1 + src/plugins/ci.jl | 97 +++++++++++++++++-- src/plugins/documenter.jl | 28 +++--- src/plugins/readme.jl | 1 + templates/github/workflows/ci.yml | 67 +++++++++++++ .../AllPlugins/.github/workflows/ci.yml | 33 +++++++ test/fixtures/AllPlugins/README.md | 1 + .../WackyOptions/.github/workflows/ci.yml | 30 ++++++ test/fixtures/WackyOptions/README.md | 2 +- test/fixtures/WackyOptions/docs/Manifest.toml | 4 +- test/reference.jl | 5 +- test/template.jl | 3 + 13 files changed, 250 insertions(+), 27 deletions(-) create mode 100644 templates/github/workflows/ci.yml create mode 100644 test/fixtures/AllPlugins/.github/workflows/ci.yml create mode 100644 test/fixtures/WackyOptions/.github/workflows/ci.yml diff --git a/docs/src/user.md b/docs/src/user.md index c213422f..d2771ac3 100644 --- a/docs/src/user.md +++ b/docs/src/user.md @@ -50,6 +50,7 @@ These plugins will create the configuration files of common CI services for you. AppVeyor CirrusCI DroneCI +GitHubActions GitLabCI TravisCI ``` @@ -91,9 +92,9 @@ Template(; plugins=[ License(; name="MPL"), Git(; manifest=true, ssh=true), - TravisCI(; x86=true), + GitHubActions(; x86=true), Codecov(), - Documenter{TravisCI}(), + Documenter{GitHubActions}(), Develop(), ], ) diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index 52212452..2e080db4 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -22,6 +22,7 @@ export Develop, Documenter, Git, + GitHubActions, GitLabCI, License, ProjectFile, diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl index 7db08da8..de18b96d 100644 --- a/src/plugins/ci.jl +++ b/src/plugins/ci.jl @@ -13,14 +13,84 @@ const DEFAULT_CI_VERSIONS_NO_NIGHTLY = map(format_version, [default_version(), V const EXTRA_VERSIONS_DOC = "- `extra_versions::Vector`: Extra Julia versions to test, as strings or `VersionNumber`s." """ - collect_versions(t::Template, versions::Vector) -> Vector{String} + GitHubActions(; + file="$(contractuser(default_file("github", "workflows", "ci.yml")))", + destination="ci.yml", + linux=true, + osx=true, + windows=true, + x64=true, + x86=false, + coverage=true, + extra_versions=$DEFAULT_CI_VERSIONS_NO_NIGHTLY, + ) -Combine `t`'s Julia version with `versions`, and format them as `major.minor`. -This is useful for creating lists of versions to be included in CI configurations. +Integrates your packages with [GitHub Actions](https://github.com/features/actions). + +## Keyword Arguments +- `file::AbstractString`: Template file for the workflow file. +- `destination::AbstractString`: Destination of the worflow file, + relative to `.github/workflows`. +- `linux::Bool`: Whether or not to run builds on Linux. +- `osx::Bool`: Whether or not to run builds on OSX (MacOS). +- `windows::Bool`: Whether or not to run builds on Windows. +- `x64::Bool`: Whether or not to run builds on 64-bit architecture. +- `x86::Bool`: Whether or not to run builds on 32-bit architecture. +- `coverage::Bool`: Whether or not to publish code coverage. + Another code coverage plugin such as [`Codecov`](@ref) must also be included. +$EXTRA_VERSIONS_DOC + +!!! note + If using coverage plugins, don't forget to manually add your API tokens as secrets, + as described [here](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets#creating-encrypted-secrets). + +!!! note + Nightly Julia is not supported. """ -function collect_versions(t::Template, versions::Vector) - vs = map(format_version, [t.julia, versions...]) - return sort(unique(vs)) +@with_kw_noshow struct GitHubActions <: BasicPlugin + file::String = default_file("github", "workflows", "ci.yml") + destination::String = "ci.yml" + linux::Bool = true + osx::Bool = true + windows::Bool = true + x64::Bool = true + x86::Bool = false + coverage::Bool = true + extra_versions::Vector = DEFAULT_CI_VERSIONS_NO_NIGHTLY +end + +source(p::GitHubActions) = p.file +destination(p::GitHubActions) = joinpath(".github", "workflows", p.destination) + +tags(::GitHubActions) = "<<", ">>" + +badges(p::GitHubActions) = Badge( + "Build Status", + "https://github.com/{{{USER}}}/{{{PKG}}}.jl/actions", + "https://github.com/{{{USER}}}/{{{PKG}}}.jl/workflows/CI/badge.svg", +) + +function view(p::GitHubActions, t::Template, pkg::AbstractString) + os = String[] + p.linux && push!(os, "ubuntu-latest") + p.osx && push!(os, "macOS-latest") + p.windows && push!(os, "windows-latest") + arch = filter(a -> getfield(p, Symbol(a)), ["x64", "x86"]) + excludes = Dict{String, String}[] + p.osx && p.x86 && push!(excludes, Dict("E_OS" => "macOS-latest", "E_ARCH" => "x86")) + + return Dict( + "ARCH" => arch, + "EXCLUDES" => excludes, + "HAS_CODECOV" => p.coverage && hasplugin(t, Codecov), + "HAS_COVERALLS" => p.coverage && hasplugin(t, Coveralls), + "HAS_DOCUMENTER" => hasplugin(t, Documenter{GitHubActions}), + "HAS_EXCLUDES" => !isempty(excludes), + "OS" => os, + "PKG" => pkg, + "USER" => t.user, + "VERSIONS" => collect_versions(t, p.extra_versions), + ) end """ @@ -319,6 +389,17 @@ function view(p::DroneCI, t::Template, pkg::AbstractString) ) end +""" + collect_versions(t::Template, versions::Vector) -> Vector{String} + +Combine `t`'s Julia version with `versions`, and format them as `major.minor`. +This is useful for creating lists of versions to be included in CI configurations. +""" +function collect_versions(t::Template, versions::Vector) + vs = map(format_version, [t.julia, versions...]) + return sort(unique(vs)) +end + """ is_ci(::Plugin) -> Bool @@ -326,6 +407,6 @@ Determine whether or not a plugin is a CI plugin. If you are adding a CI plugin, you should implement this function and return `true`. """ is_ci(::Plugin) = false -is_ci(::Union{AppVeyor, TravisCI, CirrusCI, GitLabCI, DroneCI}) = true +is_ci(::Union{AppVeyor, GitHubActions, TravisCI, CirrusCI, GitLabCI, DroneCI}) = true -needs_username(::Union{AppVeyor, TravisCI, CirrusCI, GitLabCI, DroneCI}) = true +needs_username(::Union{AppVeyor, GitHubActions, TravisCI, CirrusCI, GitLabCI, DroneCI}) = true diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index 87541b3c..227e39df 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -3,6 +3,9 @@ const DOCUMENTER_DEP = PackageSpec(; uuid="e30172f5-a6a5-5a46-863b-614d45cd2de4", ) +const DeployStyle = Union{TravisCI, GitHubActions, GitLabCI, Nothing} +const GitHubPagesStyle = Union{TravisCI, GitHubActions} + """ Documenter{T<:Union{TravisCI, GitLabCI, Nothing}}(; make_jl="$(contractuser(default_file("docs", "make.jl")))", @@ -17,6 +20,8 @@ Documentation deployment depends on `T`, where `T` is some supported CI plugin, or `Nothing` to only support local documentation builds. ## Supported Type Parameters +- `GitHubActions`: Deploys documentation to [GitHub Pages](https://pages.github.com) + with the help of [`GitHubActions`](@ref). - `TravisCI`: Deploys documentation to [GitHub Pages](https://pages.github.com) with the help of [`TravisCI`](@ref). - `GitLabCI`: Deploys documentation to [GitLab Pages](https://pages.gitlab.com) @@ -37,7 +42,7 @@ or `Nothing` to only support local documentation builds. If deploying documentation with Travis CI, don't forget to complete [the required configuration](https://juliadocs.github.io/Documenter.jl/stable/man/hosting/#SSH-Deploy-Keys-1). """ -struct Documenter{T<:Union{TravisCI, GitLabCI, Nothing}} <: Plugin +struct Documenter{T<:DeployStyle} <: Plugin assets::Vector{String} makedocs_kwargs::Dict{Symbol} canonical_url::Union{Function, Nothing} @@ -51,7 +56,7 @@ struct Documenter{T<:Union{TravisCI, GitLabCI, Nothing}} <: Plugin canonical_url::Union{Function, Nothing}=make_canonical(T), make_jl::AbstractString=default_file("docs", "make.jl"), index_md::AbstractString=default_file("docs", "src", "index.md"), - ) where T <: Union{TravisCI, GitLabCI, Nothing} + ) where T <: DeployStyle return new(assets, makedocs_kwargs, canonical_url, make_jl, index_md) end end @@ -61,7 +66,7 @@ Documenter(; kwargs...) = Documenter{Nothing}(; kwargs...) gitignore(::Documenter) = ["/docs/build/"] badges(::Documenter) = Badge[] -badges(::Documenter{TravisCI}) = [ +badges(::Documenter{<:GitHubPagesStyle}) = [ Badge( "Stable", "https://img.shields.io/badge/docs-stable-blue.svg", @@ -90,18 +95,17 @@ view(p::Documenter, t::Template, pkg::AbstractString) = Dict( "USER" => t.user, ) -function view(p::Documenter{TravisCI}, t::Template, pkg::AbstractString) +function view(p::Documenter{<:GitHubPagesStyle}, t::Template, pkg::AbstractString) base = invoke(view, Tuple{Documenter, Template, AbstractString}, p, t, pkg) return merge(base, Dict("HAS_DEPLOY" => true)) end -foreach((TravisCI, GitLabCI)) do T - @eval function validate(::Documenter{$T}, t::Template) - if !hasplugin(t, $T) - name = nameof($T) - s = "Documenter: The $name plugin must be included for docs deployment to be set up" - throw(ArgumentError(s)) - end +validate(::Documenter{Nothing}, ::Template) = nothing +function validate(::Documenter{T}, t::Template) where T <: DeployStyle + if !hasplugin(t, T) + name = nameof(T) + s = "Documenter: The $name plugin must be included for docs deployment to be set up" + throw(ArgumentError(s)) end end @@ -127,7 +131,7 @@ end github_pages_url(t::Template, pkg::AbstractString) = "https://$(t.user).github.io/$pkg.jl" gitlab_pages_url(t::Template, pkg::AbstractString) = "https://$(t.user).gitlab.io/$pkg.jl" -make_canonical(::Type{TravisCI}) = github_pages_url +make_canonical(::Type{<:GitHubPagesStyle}) = github_pages_url make_canonical(::Type{GitLabCI}) = gitlab_pages_url make_canonical(::Type{Nothing}) = nothing diff --git a/src/plugins/readme.jl b/src/plugins/readme.jl index 8f80dc0f..f5196615 100644 --- a/src/plugins/readme.jl +++ b/src/plugins/readme.jl @@ -48,6 +48,7 @@ end badge_order() = [ Documenter{GitLabCI}, Documenter{TravisCI}, + GitHubActions, GitLabCI, TravisCI, AppVeyor, diff --git a/templates/github/workflows/ci.yml b/templates/github/workflows/ci.yml new file mode 100644 index 00000000..d02a57ad --- /dev/null +++ b/templates/github/workflows/ci.yml @@ -0,0 +1,67 @@ +name: CI +on: + - push + - pull_request +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + version: + <<#VERSIONS>> + - '<<&.>>' + <> + os: + <<#OS>> + - <<&.>> + <> + arch: + <<#ARCH>> + - <<&.>> + <> + <<#HAS_EXCLUDES>> + exclude: + <> + <<#EXCLUDES>> + - os: <<&E_OS>> + arch: <<&E_ARCH>> + <<#E_VERSION>> + version: '<<&E_VERSION>>' + <> + <> + steps: + - uses: actions/checkout@v1 + - uses: julia-actions/setup-julia@latest + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: julia-actions/julia-buildpkg@latest + - uses: julia-actions/julia-runtest@latest + <<#HAS_CODECOV>> + - uses: julia-actions/julia-uploadcodecov@latest + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + <> + <<#HAS_COVERALLS>> + - uses: julia-actions/julia-uploadcoveralls@latest + env: + COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }} + <> + <<#HAS_DOCUMENTER>> + docs: + name: Documentation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: julia-actions/setup-julia@latest + with: + version: '1.0' + - run: julia --project=docs -e ' + using Pkg; + Pkg.develop(PackageSpec(; path=pwd())); + Pkg.instantiate();' + - run: julia --project=docs docs/make.jl + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + <> diff --git a/test/fixtures/AllPlugins/.github/workflows/ci.yml b/test/fixtures/AllPlugins/.github/workflows/ci.yml new file mode 100644 index 00000000..2710c614 --- /dev/null +++ b/test/fixtures/AllPlugins/.github/workflows/ci.yml @@ -0,0 +1,33 @@ +name: CI +on: + - push + - pull_request +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + version: + - '1.0' + - '1.2' + os: + - ubuntu-latest + - macOS-latest + - windows-latest + arch: + - x64 + steps: + - uses: actions/checkout@v1 + - uses: julia-actions/setup-julia@latest + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: julia-actions/julia-buildpkg@latest + - uses: julia-actions/julia-runtest@latest + - uses: julia-actions/julia-uploadcodecov@latest + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + - uses: julia-actions/julia-uploadcoveralls@latest + env: + COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }} diff --git a/test/fixtures/AllPlugins/README.md b/test/fixtures/AllPlugins/README.md index c6416961..b2b41aaf 100644 --- a/test/fixtures/AllPlugins/README.md +++ b/test/fixtures/AllPlugins/README.md @@ -1,5 +1,6 @@ # AllPlugins +[![Build Status](https://github.com/tester/AllPlugins.jl/actions)](https://github.com/tester/AllPlugins.jl/workflows/CI/badge.svg) [![Build Status](https://gitlab.com/tester/AllPlugins.jl/badges/master/build.svg)](https://gitlab.com/tester/AllPlugins.jl/pipelines) [![Coverage](https://gitlab.com/tester/AllPlugins.jl/badges/master/coverage.svg)](https://gitlab.com/tester/AllPlugins.jl/commits/master) [![Build Status](https://travis-ci.com/tester/AllPlugins.jl.svg?branch=master)](https://travis-ci.com/tester/AllPlugins.jl) diff --git a/test/fixtures/WackyOptions/.github/workflows/ci.yml b/test/fixtures/WackyOptions/.github/workflows/ci.yml new file mode 100644 index 00000000..ff776ce9 --- /dev/null +++ b/test/fixtures/WackyOptions/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: CI +on: + - push + - pull_request +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + version: + - '1.0' + - '1.2' + os: + - macOS-latest + - windows-latest + arch: + - x64 + - x86 + exclude: + - os: macOS-latest + arch: x86 + steps: + - uses: actions/checkout@v1 + - uses: julia-actions/setup-julia@latest + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: julia-actions/julia-buildpkg@latest + - uses: julia-actions/julia-runtest@latest diff --git a/test/fixtures/WackyOptions/README.md b/test/fixtures/WackyOptions/README.md index d7c163bc..9a9d4aae 100644 --- a/test/fixtures/WackyOptions/README.md +++ b/test/fixtures/WackyOptions/README.md @@ -1,4 +1,4 @@ -# WackyOptions [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://tester.gitlab.io/WackyOptions.jl/dev) [![Build Status](https://gitlab.com/tester/WackyOptions.jl/badges/master/build.svg)](https://gitlab.com/tester/WackyOptions.jl/pipelines) [![Build Status](https://travis-ci.com/tester/WackyOptions.jl.svg?branch=master)](https://travis-ci.com/tester/WackyOptions.jl) [![Build Status](https://ci.appveyor.com/api/projects/status/github/tester/WackyOptions.jl?svg=true)](https://ci.appveyor.com/project/tester/WackyOptions-jl) [![Build Status](https://cloud.drone.io/api/badges/tester/WackyOptions.jl/status.svg)](https://cloud.drone.io/tester/WackyOptions.jl) [![Build Status](https://api.cirrus-ci.com/github/tester/WackyOptions.jl.svg)](https://cirrus-ci.com/github/tester/WackyOptions.jl) [![Coverage](https://codecov.io/gh//.jl/branch/master/graph/badge.svg)](https://codecov.io/gh//.jl) [![Coverage](https://coveralls.io/repos/github//.jl/badge.svg?branch=master)](https://coveralls.io/github//.jl?branch=master) +# WackyOptions [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://tester.gitlab.io/WackyOptions.jl/dev) [![Build Status](https://github.com/tester/WackyOptions.jl/actions)](https://github.com/tester/WackyOptions.jl/workflows/CI/badge.svg) [![Build Status](https://gitlab.com/tester/WackyOptions.jl/badges/master/build.svg)](https://gitlab.com/tester/WackyOptions.jl/pipelines) [![Build Status](https://travis-ci.com/tester/WackyOptions.jl.svg?branch=master)](https://travis-ci.com/tester/WackyOptions.jl) [![Build Status](https://ci.appveyor.com/api/projects/status/github/tester/WackyOptions.jl?svg=true)](https://ci.appveyor.com/project/tester/WackyOptions-jl) [![Build Status](https://cloud.drone.io/api/badges/tester/WackyOptions.jl/status.svg)](https://cloud.drone.io/tester/WackyOptions.jl) [![Build Status](https://api.cirrus-ci.com/github/tester/WackyOptions.jl.svg)](https://cirrus-ci.com/github/tester/WackyOptions.jl) [![Coverage](https://codecov.io/gh//.jl/branch/master/graph/badge.svg)](https://codecov.io/gh//.jl) [![Coverage](https://coveralls.io/repos/github//.jl/badge.svg?branch=master)](https://coveralls.io/github//.jl?branch=master) ## Citing diff --git a/test/fixtures/WackyOptions/docs/Manifest.toml b/test/fixtures/WackyOptions/docs/Manifest.toml index 2fbd4f44..286113bb 100644 --- a/test/fixtures/WackyOptions/docs/Manifest.toml +++ b/test/fixtures/WackyOptions/docs/Manifest.toml @@ -48,9 +48,9 @@ uuid = "a63ad114-7e13-5084-954f-fe012c677804" [[Parsers]] deps = ["Dates", "Test"] -git-tree-sha1 = "ef0af6c8601db18c282d092ccbd2f01f3f0cd70b" +git-tree-sha1 = "c56ecb484f286639f161e712b8311f5ab77e8d32" uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" -version = "0.3.7" +version = "0.3.8" [[Pkg]] deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] diff --git a/test/reference.jl b/test/reference.jl index 55c0b692..b0adb93d 100644 --- a/test/reference.jl +++ b/test/reference.jl @@ -22,8 +22,8 @@ end @testset "All plugins" begin test_all("AllPlugins"; authors=USER, plugins=[ - AppVeyor(), CirrusCI(), Citation(), Codecov(), Coveralls(), - Develop(), Documenter(), DroneCI(), GitLabCI(), TravisCI(), + AppVeyor(), CirrusCI(), Citation(), Codecov(), Coveralls(), Develop(), + Documenter(), DroneCI(), GitHubActions(), GitLabCI(), TravisCI(), ]) end @@ -41,6 +41,7 @@ end ), DroneCI(; amd64=false, arm=true, arm64=true, extra_versions=["1.1"]), Git(; ignore=["a", "b", "c"], manifest=true), + GitHubActions(; x86=true, linux=false, coverage=false), GitLabCI(; coverage=false, extra_versions=[v"0.6"]), License(; name="ISC"), ProjectFile(; version=v"1"), diff --git a/test/template.jl b/test/template.jl index bea47055..aaa1f445 100644 --- a/test/template.jl +++ b/test/template.jl @@ -61,6 +61,9 @@ end @testset "validate" begin + foreach((GitHubActions, TravisCI, GitLabCI)) do T + @test_throws ArgumentError tpl(; plugins=[Documenter{T}()]) + end mock(LibGit2.getconfig => (_k, _d) -> "") do _gc @test_throws ArgumentError tpl(; plugins=[Git()]) end From 8edafa6fe5dcce374af921a4dc1ab54ff9281025 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sat, 9 Nov 2019 00:26:59 +0700 Subject: [PATCH 80/81] Fix a gitignore bug This only came up when you generate more than one package in the same Julia session. The mutating `append!` function was adding stuff to the global variable that the coverage plugins were using for their gitignores. The new `vcat` is non-mutating. --- src/plugins/git.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/git.jl b/src/plugins/git.jl index 19243a66..250b0741 100644 --- a/src/plugins/git.jl +++ b/src/plugins/git.jl @@ -62,7 +62,7 @@ end # Create the .gitignore. function hook(p::Git, t::Template, pkg_dir::AbstractString) - ignore = mapreduce(gitignore, append!, t.plugins) + ignore = mapreduce(gitignore, vcat, t.plugins) # Only ignore manifests at the repo root. p.manifest || "Manifest.toml" in ignore || push!(ignore, "/Manifest.toml") unique!(sort!(ignore)) From 90253e580d18f201b9f0dcdb02a9d55ce68e64ec Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sat, 9 Nov 2019 00:28:02 +0700 Subject: [PATCH 81/81] Add some more Documenter reference tests --- .../.github/workflows/ci.yml | 42 +++++++++++++++++++ .../DocumenterGitHubActions/.gitignore | 2 + test/fixtures/DocumenterGitHubActions/LICENSE | 21 ++++++++++ .../DocumenterGitHubActions/Project.toml | 13 ++++++ .../DocumenterGitHubActions/README.md | 5 +++ .../DocumenterGitHubActions/docs/Project.toml | 2 + .../DocumenterGitHubActions/docs/make.jl | 21 ++++++++++ .../DocumenterGitHubActions/docs/src/index.md | 12 ++++++ .../src/DocumenterGitHubActions.jl | 5 +++ .../DocumenterGitHubActions/test/runtests.jl | 6 +++ test/fixtures/DocumenterTravis/.gitignore | 2 + test/fixtures/DocumenterTravis/.travis.yml | 27 ++++++++++++ test/fixtures/DocumenterTravis/LICENSE | 21 ++++++++++ test/fixtures/DocumenterTravis/Project.toml | 13 ++++++ test/fixtures/DocumenterTravis/README.md | 5 +++ .../DocumenterTravis/docs/Project.toml | 2 + test/fixtures/DocumenterTravis/docs/make.jl | 21 ++++++++++ .../DocumenterTravis/docs/src/index.md | 12 ++++++ .../DocumenterTravis/src/DocumenterTravis.jl | 5 +++ .../DocumenterTravis/test/runtests.jl | 6 +++ test/reference.jl | 13 ++++++ 21 files changed, 256 insertions(+) create mode 100644 test/fixtures/DocumenterGitHubActions/.github/workflows/ci.yml create mode 100644 test/fixtures/DocumenterGitHubActions/.gitignore create mode 100644 test/fixtures/DocumenterGitHubActions/LICENSE create mode 100644 test/fixtures/DocumenterGitHubActions/Project.toml create mode 100644 test/fixtures/DocumenterGitHubActions/README.md create mode 100644 test/fixtures/DocumenterGitHubActions/docs/Project.toml create mode 100644 test/fixtures/DocumenterGitHubActions/docs/make.jl create mode 100644 test/fixtures/DocumenterGitHubActions/docs/src/index.md create mode 100644 test/fixtures/DocumenterGitHubActions/src/DocumenterGitHubActions.jl create mode 100644 test/fixtures/DocumenterGitHubActions/test/runtests.jl create mode 100644 test/fixtures/DocumenterTravis/.gitignore create mode 100644 test/fixtures/DocumenterTravis/.travis.yml create mode 100644 test/fixtures/DocumenterTravis/LICENSE create mode 100644 test/fixtures/DocumenterTravis/Project.toml create mode 100644 test/fixtures/DocumenterTravis/README.md create mode 100644 test/fixtures/DocumenterTravis/docs/Project.toml create mode 100644 test/fixtures/DocumenterTravis/docs/make.jl create mode 100644 test/fixtures/DocumenterTravis/docs/src/index.md create mode 100644 test/fixtures/DocumenterTravis/src/DocumenterTravis.jl create mode 100644 test/fixtures/DocumenterTravis/test/runtests.jl diff --git a/test/fixtures/DocumenterGitHubActions/.github/workflows/ci.yml b/test/fixtures/DocumenterGitHubActions/.github/workflows/ci.yml new file mode 100644 index 00000000..74a25a26 --- /dev/null +++ b/test/fixtures/DocumenterGitHubActions/.github/workflows/ci.yml @@ -0,0 +1,42 @@ +name: CI +on: + - push + - pull_request +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + version: + - '1.0' + - '1.2' + os: + - ubuntu-latest + - macOS-latest + - windows-latest + arch: + - x64 + steps: + - uses: actions/checkout@v1 + - uses: julia-actions/setup-julia@latest + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: julia-actions/julia-buildpkg@latest + - uses: julia-actions/julia-runtest@latest + docs: + name: Documentation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: julia-actions/setup-julia@latest + with: + version: '1.0' + - run: julia --project=docs -e ' + using Pkg; + Pkg.develop(PackageSpec(; path=pwd())); + Pkg.instantiate();' + - run: julia --project=docs docs/make.jl + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/test/fixtures/DocumenterGitHubActions/.gitignore b/test/fixtures/DocumenterGitHubActions/.gitignore new file mode 100644 index 00000000..11b69edd --- /dev/null +++ b/test/fixtures/DocumenterGitHubActions/.gitignore @@ -0,0 +1,2 @@ +/docs/build/ +Manifest.toml diff --git a/test/fixtures/DocumenterGitHubActions/LICENSE b/test/fixtures/DocumenterGitHubActions/LICENSE new file mode 100644 index 00000000..b7731085 --- /dev/null +++ b/test/fixtures/DocumenterGitHubActions/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 tester + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/test/fixtures/DocumenterGitHubActions/Project.toml b/test/fixtures/DocumenterGitHubActions/Project.toml new file mode 100644 index 00000000..ac61e7d4 --- /dev/null +++ b/test/fixtures/DocumenterGitHubActions/Project.toml @@ -0,0 +1,13 @@ +name = "DocumenterGitHubActions" +uuid = "5b7e9947-ddc0-4b3f-9b55-0d8042f74170" +authors = ["tester"] +version = "0.1.0" + +[compat] +julia = "1" + +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test"] diff --git a/test/fixtures/DocumenterGitHubActions/README.md b/test/fixtures/DocumenterGitHubActions/README.md new file mode 100644 index 00000000..8736688c --- /dev/null +++ b/test/fixtures/DocumenterGitHubActions/README.md @@ -0,0 +1,5 @@ +# DocumenterGitHubActions + +[![Build Status](https://github.com/tester/DocumenterGitHubActions.jl/actions)](https://github.com/tester/DocumenterGitHubActions.jl/workflows/CI/badge.svg) +[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://tester.github.io/DocumenterGitHubActions.jl/stable) +[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://tester.github.io/DocumenterGitHubActions.jl/dev) diff --git a/test/fixtures/DocumenterGitHubActions/docs/Project.toml b/test/fixtures/DocumenterGitHubActions/docs/Project.toml new file mode 100644 index 00000000..dfa65cd1 --- /dev/null +++ b/test/fixtures/DocumenterGitHubActions/docs/Project.toml @@ -0,0 +1,2 @@ +[deps] +Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" diff --git a/test/fixtures/DocumenterGitHubActions/docs/make.jl b/test/fixtures/DocumenterGitHubActions/docs/make.jl new file mode 100644 index 00000000..ca4caf37 --- /dev/null +++ b/test/fixtures/DocumenterGitHubActions/docs/make.jl @@ -0,0 +1,21 @@ +using DocumenterGitHubActions +using Documenter + +makedocs(; + modules=[DocumenterGitHubActions], + authors="tester", + repo="https://github.com/tester/DocumenterGitHubActions.jl/blob/{commit}{path}#L{line}", + sitename="DocumenterGitHubActions.jl", + format=Documenter.HTML(; + prettyurls=get(ENV, "CI", "false") == "true", + canonical="https://tester.github.io/DocumenterGitHubActions.jl", + assets=String[], + ), + pages=[ + "Home" => "index.md", + ], +) + +deploydocs(; + repo="github.com/tester/DocumenterGitHubActions.jl", +) diff --git a/test/fixtures/DocumenterGitHubActions/docs/src/index.md b/test/fixtures/DocumenterGitHubActions/docs/src/index.md new file mode 100644 index 00000000..f5f18e99 --- /dev/null +++ b/test/fixtures/DocumenterGitHubActions/docs/src/index.md @@ -0,0 +1,12 @@ +```@meta +CurrentModule = DocumenterGitHubActions +``` + +# DocumenterGitHubActions + +```@index +``` + +```@autodocs +Modules = [DocumenterGitHubActions] +``` diff --git a/test/fixtures/DocumenterGitHubActions/src/DocumenterGitHubActions.jl b/test/fixtures/DocumenterGitHubActions/src/DocumenterGitHubActions.jl new file mode 100644 index 00000000..c97d15b9 --- /dev/null +++ b/test/fixtures/DocumenterGitHubActions/src/DocumenterGitHubActions.jl @@ -0,0 +1,5 @@ +module DocumenterGitHubActions + +# Write your package code here. + +end diff --git a/test/fixtures/DocumenterGitHubActions/test/runtests.jl b/test/fixtures/DocumenterGitHubActions/test/runtests.jl new file mode 100644 index 00000000..16755e08 --- /dev/null +++ b/test/fixtures/DocumenterGitHubActions/test/runtests.jl @@ -0,0 +1,6 @@ +using DocumenterGitHubActions +using Test + +@testset "DocumenterGitHubActions.jl" begin + # Write your tests here. +end diff --git a/test/fixtures/DocumenterTravis/.gitignore b/test/fixtures/DocumenterTravis/.gitignore new file mode 100644 index 00000000..11b69edd --- /dev/null +++ b/test/fixtures/DocumenterTravis/.gitignore @@ -0,0 +1,2 @@ +/docs/build/ +Manifest.toml diff --git a/test/fixtures/DocumenterTravis/.travis.yml b/test/fixtures/DocumenterTravis/.travis.yml new file mode 100644 index 00000000..91da1450 --- /dev/null +++ b/test/fixtures/DocumenterTravis/.travis.yml @@ -0,0 +1,27 @@ +# Documentation: http://docs.travis-ci.com/user/languages/julia +language: julia +notifications: + email: false +julia: + - 1.0 + - 1.2 + - nightly +os: + - linux + - osx + - windows +arch: + - x64 +jobs: + fast_finish: true + allow_failures: + - julia: nightly + include: + - stage: Documentation + julia: 1.0 + script: julia --project=docs -e ' + using Pkg; + Pkg.develop(PackageSpec(; path=pwd())); + Pkg.instantiate(); + include("docs/make.jl");' + after_success: skip diff --git a/test/fixtures/DocumenterTravis/LICENSE b/test/fixtures/DocumenterTravis/LICENSE new file mode 100644 index 00000000..b7731085 --- /dev/null +++ b/test/fixtures/DocumenterTravis/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 tester + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/test/fixtures/DocumenterTravis/Project.toml b/test/fixtures/DocumenterTravis/Project.toml new file mode 100644 index 00000000..c1c62704 --- /dev/null +++ b/test/fixtures/DocumenterTravis/Project.toml @@ -0,0 +1,13 @@ +name = "DocumenterTravis" +uuid = "5b7e9947-ddc0-4b3f-9b55-0d8042f74170" +authors = ["tester"] +version = "0.1.0" + +[compat] +julia = "1" + +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test"] diff --git a/test/fixtures/DocumenterTravis/README.md b/test/fixtures/DocumenterTravis/README.md new file mode 100644 index 00000000..72633eef --- /dev/null +++ b/test/fixtures/DocumenterTravis/README.md @@ -0,0 +1,5 @@ +# DocumenterTravis + +[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://tester.github.io/DocumenterTravis.jl/stable) +[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://tester.github.io/DocumenterTravis.jl/dev) +[![Build Status](https://travis-ci.com/tester/DocumenterTravis.jl.svg?branch=master)](https://travis-ci.com/tester/DocumenterTravis.jl) diff --git a/test/fixtures/DocumenterTravis/docs/Project.toml b/test/fixtures/DocumenterTravis/docs/Project.toml new file mode 100644 index 00000000..dfa65cd1 --- /dev/null +++ b/test/fixtures/DocumenterTravis/docs/Project.toml @@ -0,0 +1,2 @@ +[deps] +Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" diff --git a/test/fixtures/DocumenterTravis/docs/make.jl b/test/fixtures/DocumenterTravis/docs/make.jl new file mode 100644 index 00000000..b2036fb5 --- /dev/null +++ b/test/fixtures/DocumenterTravis/docs/make.jl @@ -0,0 +1,21 @@ +using DocumenterTravis +using Documenter + +makedocs(; + modules=[DocumenterTravis], + authors="tester", + repo="https://github.com/tester/DocumenterTravis.jl/blob/{commit}{path}#L{line}", + sitename="DocumenterTravis.jl", + format=Documenter.HTML(; + prettyurls=get(ENV, "CI", "false") == "true", + canonical="https://tester.github.io/DocumenterTravis.jl", + assets=String[], + ), + pages=[ + "Home" => "index.md", + ], +) + +deploydocs(; + repo="github.com/tester/DocumenterTravis.jl", +) diff --git a/test/fixtures/DocumenterTravis/docs/src/index.md b/test/fixtures/DocumenterTravis/docs/src/index.md new file mode 100644 index 00000000..78a8bd7b --- /dev/null +++ b/test/fixtures/DocumenterTravis/docs/src/index.md @@ -0,0 +1,12 @@ +```@meta +CurrentModule = DocumenterTravis +``` + +# DocumenterTravis + +```@index +``` + +```@autodocs +Modules = [DocumenterTravis] +``` diff --git a/test/fixtures/DocumenterTravis/src/DocumenterTravis.jl b/test/fixtures/DocumenterTravis/src/DocumenterTravis.jl new file mode 100644 index 00000000..4bf20935 --- /dev/null +++ b/test/fixtures/DocumenterTravis/src/DocumenterTravis.jl @@ -0,0 +1,5 @@ +module DocumenterTravis + +# Write your package code here. + +end diff --git a/test/fixtures/DocumenterTravis/test/runtests.jl b/test/fixtures/DocumenterTravis/test/runtests.jl new file mode 100644 index 00000000..99fd8ed0 --- /dev/null +++ b/test/fixtures/DocumenterTravis/test/runtests.jl @@ -0,0 +1,6 @@ +using DocumenterTravis +using Test + +@testset "DocumenterTravis.jl" begin + # Write your tests here. +end diff --git a/test/reference.jl b/test/reference.jl index b0adb93d..6618693d 100644 --- a/test/reference.jl +++ b/test/reference.jl @@ -27,6 +27,19 @@ end ]) end + @testset "Documenter (TravisCI)" begin + test_all("DocumenterTravis"; authors=USER, plugins=[ + Documenter{TravisCI}(), TravisCI(), + ]) + end + + @testset "Documenter (GitHubActions)" begin + test_all("DocumenterGitHubActions"; authors=USER, plugins=[ + Documenter{GitHubActions}(), GitHubActions(), + ]) + end + + @testset "Wacky options" begin test_all("WackyOptions"; authors=USER, julia=v"1.2", plugins=[ AppVeyor(; x86=true, coverage=true, extra_versions=[v"1.3"]),