Skip to content

Commit

Permalink
Move direct wrapper functions to internal module Copier
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsiqueira committed Jun 4, 2024
1 parent 127d058 commit f7afcf3
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/src/90-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ Pages = ["90-reference.md"]
```

```@autodocs
Modules = [COPIERTemplate]
Modules = [COPIERTemplate, COPIERTemplate.Copier]
```
46 changes: 3 additions & 43 deletions src/COPIERTemplate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand All @@ -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...)
Expand Down
60 changes: 60 additions & 0 deletions src/Copier.jl
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ 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

@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
Expand All @@ -134,7 +134,7 @@ end
run(`git config user.email "[email protected]"`)
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
Expand Down

0 comments on commit f7afcf3

Please sign in to comment.