Skip to content

Commit

Permalink
Allow optional src_path argument to generate that default to URL (#174)
Browse files Browse the repository at this point in the history
If the argument is passed, copy from that location, otherwise use 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.

Fixes #146 

Co-authored-by: Abel Soares Siqueira <[email protected]>
  • Loading branch information
sverhoeven and abelsiqueira authored May 31, 2024
1 parent df54c94 commit 7d051fe
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ and this project adheres to [Semantic Versioning].
- Add author names to licenses (#145)
- Consistent caching in GitHub workflows (#53)

### Changed

- Signature of generate now accepts source path, which defaults to the URL (#174)

## [0.3.1] - 2024-05-23

### Added
Expand Down
14 changes: 11 additions & 3 deletions src/COPIERTemplate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(joinpath(@__DIR__, ".."), 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
20 changes: 19 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 7d051fe

Please sign in to comment.