diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e417c4a..82a29b79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning]. ### Changed - Adds `data` positional argument to `generate` (#142) +- An internal module `Copier` was created with the wrapper functions ### Removed diff --git a/docs/src/90-reference.md b/docs/src/90-reference.md index 83ddcc97..a7a88be1 100644 --- a/docs/src/90-reference.md +++ b/docs/src/90-reference.md @@ -13,5 +13,5 @@ Pages = ["90-reference.md"] ``` ```@autodocs -Modules = [COPIERTemplate] +Modules = [COPIERTemplate, COPIERTemplate.Copier] ``` diff --git a/src/COPIERTemplate.jl b/src/COPIERTemplate.jl index 95add16d..4d4a552a 100644 --- a/src/COPIERTemplate.jl +++ b/src/COPIERTemplate.jl @@ -8,47 +8,7 @@ The main functions are: [`generate`](@ref) """ module COPIERTemplate -using PythonCall, CondaPkg, UUIDs - -function __init__() - CondaPkg.add("copier") -end - -""" - copy(dst_path[, data]; kwargs...) - copy(src_path, dst_path[, data]; kwargs...) - -Wrapper around Python's [copier.run_copy](https://copier.readthedocs.io/en/stable/reference/main/#copier.main.run_copy). -Use [`generate`](@ref) for a more user-friendly function. -""" -function Base.copy(src_path, dst_path, data::Dict = Dict(); kwargs...) - copier = PythonCall.pyimport("copier") - copier.run_copy(src_path, dst_path, data; kwargs...) -end - -function Base.copy(dst_path, data::Dict = Dict(); kwargs...) - copy(joinpath(@__DIR__, ".."), dst_path, data; kwargs...) -end - -""" - recopy(dst_path[, data]; kwargs...) - -Wrapper around Python's [copier.run_recopy](https://copier.readthedocs.io/en/stable/reference/main/#copier.main.run_recopy). -""" -function recopy(dst_path, data::Dict = Dict(); kwargs...) - copier = PythonCall.pyimport("copier") - copier.run_recopy(dst_path, data; kwargs...) -end - -""" - update(dst_path[, data]; kwargs...) - -Wrapper around Python's [copier.run_update](https://copier.readthedocs.io/en/stable/reference/main/#copier.main.run_update). -""" -function update(dst_path, data::Dict = Dict(); kwargs...) - copier = PythonCall.pyimport("copier") - copier.run_update(dst_path, data; kwargs...) -end +include("Copier.jl") """ generate(dst_path[, data]; kwargs...) @@ -61,10 +21,10 @@ The `data` argument is a dictionary of answers (values) to questions (keys) that ## Keyword arguments -The keyword arguments are passed directly to [`copy`](@ref). +The keyword arguments are passed directly to the internal [`Copier.copy`](@ref). """ function generate(src_path, dst_path, data::Dict = Dict(); kwargs...) - copy(src_path, dst_path, data; kwargs...) + Copier.copy(src_path, dst_path, data; kwargs...) end function generate(dst_path, data::Dict = Dict(); kwargs...) diff --git a/src/Copier.jl b/src/Copier.jl new file mode 100644 index 00000000..53cfbfca --- /dev/null +++ b/src/Copier.jl @@ -0,0 +1,60 @@ +""" +Wrapper around [copier](https://copier.readthedocs.io/). + +There are three functions in this module: + +- [`copy`](@ref) +- [`recopy`](@ref) +- [`update`](@ref) +""" +module Copier + +using CondaPkg: CondaPkg +using PythonCall: PythonCall + +function __init__() + CondaPkg.add("copier") +end + +""" + copy(dst_path[, data]; kwargs...) + copy(src_path, dst_path[, data]; kwargs...) + +Wrapper around [copier.run_copy](https://copier.readthedocs.io/en/stable/reference/main/#copier.main.run_copy). + +This is an internal function, if COPIERTemplate's main API is not sufficient, open an issue. +""" +function Base.copy(src_path, dst_path, data::Dict = Dict(); kwargs...) + copier = PythonCall.pyimport("copier") + copier.run_copy(src_path, dst_path, data; kwargs...) +end + +function Base.copy(dst_path, data::Dict = Dict(); kwargs...) + copy(joinpath(@__DIR__, ".."), dst_path, data; kwargs...) +end + +""" + recopy(dst_path[, data]; kwargs...) + +Wrapper around [copier.run_recopy](https://copier.readthedocs.io/en/stable/reference/main/#copier.main.run_recopy). + +This is an internal function, if COPIERTemplate's main API is not sufficient, open an issue. +""" +function recopy(dst_path, data::Dict = Dict(); kwargs...) + copier = PythonCall.pyimport("copier") + copier.run_recopy(dst_path, data; kwargs...) +end + +""" + update(dst_path[, data]; kwargs...) + +Wrapper around [copier.run_update](https://copier.readthedocs.io/en/stable/reference/main/#copier.main.run_update). + +This is an internal function, if COPIERTemplate's main API is not sufficient, open an issue. +""" +function update(dst_path, data::Dict = Dict(); kwargs...) + copier = PythonCall.pyimport("copier") + copier.run_update(dst_path, data; kwargs...) +end + +end diff --git a/test/runtests.jl b/test/runtests.jl index ecbc0ac2..a50c6d9d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -111,7 +111,7 @@ end @testset "Compare copied project vs copier CLI baseline" begin mktempdir(TMPDIR; prefix = "copy_") do tmpdir - COPIERTemplate.copy(tmpdir, template_options; quiet = true) + COPIERTemplate.Copier.copy(tmpdir, template_options; quiet = true) test_diff_dir(tmpdir, dir_copier_cli) end end @@ -119,7 +119,7 @@ end @testset "Compare recopied project vs copier CLI baseline" begin mktempdir(TMPDIR; prefix = "recopy_") do tmpdir run(`copier copy --defaults --quiet $min_bash_args $template_path $tmpdir`) - COPIERTemplate.recopy(tmpdir, template_options; quiet = true, overwrite = true) + COPIERTemplate.Copier.recopy(tmpdir, template_options; quiet = true, overwrite = true) test_diff_dir(tmpdir, dir_copier_cli) end end @@ -134,7 +134,7 @@ end run(`git config user.email "test@test.com"`) run(`git commit -q -m "First commit"`) end - COPIERTemplate.update(tmpdir, template_options; overwrite = true, quiet = true) + COPIERTemplate.Copier.update(tmpdir, template_options; overwrite = true, quiet = true) test_diff_dir(tmpdir, dir_copier_cli) end end