-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using PythonCall to enable running copier from the package
- Loading branch information
1 parent
0d25e31
commit 871c4a1
Showing
9 changed files
with
114 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.CondaPkg | ||
*.jl.*.cov | ||
*.jl.cov | ||
*.jl.mem | ||
Manifest.toml | ||
docs/build/ | ||
*.rej | ||
docs/build/ | ||
Manifest.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[deps] | ||
copier = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,12 @@ uuid = "5022dd56-1d41-4538-9f4c-b20739ff8283" | |
authors = ["Abel Soares Siqueira <[email protected]> and contributors"] | ||
version = "0.1.7" | ||
|
||
[deps] | ||
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab" | ||
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d" | ||
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" | ||
|
||
[compat] | ||
julia = "1.6" | ||
CondaPkg = "0.2" | ||
PythonCall = "0.9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,27 @@ | ||
module COPIERTemplate | ||
|
||
# Write your package code here. | ||
using PythonCall, CondaPkg, UUIDs | ||
|
||
function __init__() | ||
CondaPkg.add("copier") | ||
end | ||
|
||
""" | ||
generate(path, generate_missing_uuid = true; kwargs...) | ||
Runs the `copy` command of [copier](https://github.com/copier-org/copier) with the COPIERTemplate template. | ||
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...) | ||
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) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,35 @@ | ||
using COPIERTemplate | ||
using Test | ||
|
||
@testset "COPIERTemplate.jl" begin | ||
# Write your tests here. | ||
template_options = Dict( | ||
"PackageName" => "Tmp", | ||
"PackageUUID" => "1234", | ||
"PackageOwner" => "test", | ||
"AuthorName" => "Test", | ||
"AuthorEmail" => "[email protected]", | ||
"JuliaMinVersion" => "1.6", | ||
"License" => "MIT", | ||
"AddMacToCI" => true, | ||
"AddWinToCI" => true, | ||
"RunJuliaNightlyOnCI" => true, | ||
"UseCirrusCI" => true, | ||
) | ||
|
||
@testset "Compare folder generated by this call vs direct copier" begin | ||
tmpdir1 = mktempdir() | ||
tmpdir2 = mktempdir() | ||
|
||
COPIERTemplate.generate(tmpdir1; data = template_options) | ||
bash_args = vcat([["-d"; "$k=$v"] for (k, v) in template_options]...) | ||
run(`copier copy $bash_args https://github.com/abelsiqueira/COPIERTemplate.jl $tmpdir2`) | ||
for (root, dirs, files) in walkdir(tmpdir1) | ||
for file in files | ||
file1 = joinpath(root, file) | ||
file2 = replace(file1, tmpdir1 => tmpdir2) | ||
lines1 = readlines(file1) | ||
lines2 = readlines(file2) | ||
diff = ["$line1 vs $line2" for (line1, line2) in zip(lines1, lines2) if line1 != line2] | ||
@test diff == [] | ||
end | ||
end | ||
end |