Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow optional src_path argument to generate that default to URL #174

Merged
merged 3 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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"
abelsiqueira marked this conversation as resolved.
Show resolved Hide resolved

@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
Loading