From 4af7a7611eae5105c84b762c3256c1c0ba02c994 Mon Sep 17 00:00:00 2001 From: Stefan Verhoeven Date: Wed, 29 May 2024 16:22:03 +0200 Subject: [PATCH 1/3] Use url as source Instead of using the copier.yml from ~/.julia/** use GH url. Fixes #146 --- src/COPIERTemplate.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/COPIERTemplate.jl b/src/COPIERTemplate.jl index 05b244ad..87ce8843 100644 --- a/src/COPIERTemplate.jl +++ b/src/COPIERTemplate.jl @@ -21,7 +21,7 @@ function generate(path, generate_missing_uuid = true; kwargs...) if generate_missing_uuid && !("PackageUUID" in keys(data)) data["PackageUUID"] = string(uuid4()) end - copier.run_copy(joinpath(@__DIR__, ".."), path; kwargs..., data = data, vcs_ref = "HEAD") + copier.run_copy("https://github.com/abelsiqueira/COPIERTemplate.jl", path; kwargs..., data = data, vcs_ref = "HEAD") end end From f207dbd75d3ea937cb3acb4d1724a398b5a47df4 Mon Sep 17 00:00:00 2001 From: Abel Soares Siqueira Date: Thu, 30 May 2024 12:49:08 +0200 Subject: [PATCH 2/3] Allow optional src_path argument to generate If the argument is passed, copy from that location, otherwise url the URL. BREAKING CHANGE: The default API now clones from the URL, which means that even if you clone the repo and run the generate command, it will use the latest tagged version. --- src/COPIERTemplate.jl | 14 +++++++++++--- test/runtests.jl | 20 +++++++++++++++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/COPIERTemplate.jl b/src/COPIERTemplate.jl index 87ce8843..df65c2bc 100644 --- a/src/COPIERTemplate.jl +++ b/src/COPIERTemplate.jl @@ -7,21 +7,29 @@ function __init__() end """ - generate(path, generate_missing_uuid = true; kwargs...) + generate(dst_path, generate_missing_uuid = true; kwargs...) + generate(src_path, dst_path, generate_missing_uuid = true; kwargs...) Runs the `copy` command of [copier](https://github.com/copier-org/copier) with the COPIERTemplate template. + +If `src_path` is not informed, the GitHub URL of COPIERTemplate.jl is used. + Even though the template is available offline through this template, this uses the github URL to allow updating. The keyword arguments are passed directly to the `run_copy` function of `copier`. If `generate_missing_uuid` is `true` and there is no `kwargs[:data]["PackageUUID"]`, then a UUID is generated for the package. """ -function generate(path, generate_missing_uuid = true; kwargs...) +function generate(src_path, dst_path, generate_missing_uuid = true; kwargs...) copier = PythonCall.pyimport("copier") data = copy(get(kwargs, :data, Dict())) if generate_missing_uuid && !("PackageUUID" in keys(data)) data["PackageUUID"] = string(uuid4()) end - copier.run_copy("https://github.com/abelsiqueira/COPIERTemplate.jl", path; kwargs..., data = data, vcs_ref = "HEAD") + copier.run_copy(src_path, dst_path; kwargs..., data = data, vcs_ref = "HEAD") +end + +function generate(dst_path, args...; kwargs...) + generate("https://github.com/abelsiqueira/COPIERTemplate.jl", dst_path, args...; kwargs...) end end diff --git a/test/runtests.jl b/test/runtests.jl index 0ab0b6f0..b7e081b8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -51,6 +51,18 @@ end bash_args = vcat([["-d"; "$k=$v"] for (k, v) in template_options]...) template_path = joinpath(@__DIR__, "..") +template_url = "https://github.com/abelsiqueira/COPIERTemplate.jl" + +@testset "Compare COPIERTemplate.generate vs copier CLI on URL/main" begin + mktempdir(; prefix = "cli_") do dir_copier_cli + run(`copier copy --vcs-ref main --quiet $bash_args $template_url $dir_copier_cli`) + + mktempdir(; prefix = "copy_") do tmpdir + COPIERTemplate.generate(tmpdir; data = template_options, quiet = true, vcs_ref = "main") + test_diff_dir(tmpdir, dir_copier_cli) + end + end +end @testset "Compare COPIERTemplate.generate vs copier CLI on HEAD" begin # This is a hack because Windows managed to dirty the repo. @@ -62,7 +74,13 @@ template_path = joinpath(@__DIR__, "..") run(`copier copy --vcs-ref HEAD --quiet $bash_args $template_path $dir_copier_cli`) mktempdir(; prefix = "copy_") do tmpdir - COPIERTemplate.generate(tmpdir; data = template_options, quiet = true, vcs_ref = "HEAD") + COPIERTemplate.generate( + template_path, + tmpdir; + data = template_options, + quiet = true, + vcs_ref = "HEAD", + ) test_diff_dir(tmpdir, dir_copier_cli) end end From 411080b37f90fb30e13da631fe6b216a41ebc083 Mon Sep 17 00:00:00 2001 From: Abel Soares Siqueira Date: Thu, 30 May 2024 16:11:08 +0200 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c377a927..c98613ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning]. - More reader-friendly README (#144) - Add author names to licenses (#145) +### Changed + +- Signature of generate now accepts source path, which defaults to the URL (#174) + ## [0.3.1] - 2024-05-23 ### Added