diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index 3235a9ee..ee61d612 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -42,7 +42,6 @@ jobs: arch: - x64 allow_failure: [false] - steps: - uses: actions/checkout@v3 - uses: julia-actions/setup-julia@v1 diff --git a/.gitignore b/.gitignore index b19d550c..9a8db360 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ +.CondaPkg *.jl.*.cov *.jl.cov *.jl.mem -Manifest.toml -docs/build/ *.rej +docs/build/ +Manifest.toml diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e43de71..3dfba0a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning]. ## [Unreleased] +### Added + +- Should be installable as a Julia package now +- Use PythonCall to run copier directly from the Julia package + ### Changed - Move template to subdirectory diff --git a/CondaPkg.toml b/CondaPkg.toml new file mode 100644 index 00000000..432fb20b --- /dev/null +++ b/CondaPkg.toml @@ -0,0 +1,2 @@ +[deps] +copier = "" diff --git a/Project.toml b/Project.toml index f7ad5307..c5bf998a 100644 --- a/Project.toml +++ b/Project.toml @@ -3,5 +3,12 @@ uuid = "5022dd56-1d41-4538-9f4c-b20739ff8283" authors = ["Abel Soares Siqueira 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" diff --git a/README.md b/README.md index 18645f5c..c48ce1ac 100644 --- a/README.md +++ b/README.md @@ -4,19 +4,32 @@ # COPIERTemplate.jl - Copier OPInionated Evolving Reusable Template + +[![Stable Documentation](https://img.shields.io/badge/docs-stable-blue.svg)](https://abelsiqueira.github.io/COPIERTemplate.jl/stable) +[![In development documentation](https://img.shields.io/badge/docs-dev-blue.svg)](https://abelsiqueira.github.io/COPIERTemplate.jl/dev) + [![Lint workflow Status](https://github.com/abelsiqueira/COPIERTemplate.jl/actions/workflows/Lint.yml/badge.svg?branch=main)](https://github.com/abelsiqueira/COPIERTemplate.jl/actions/workflows/Lint.yml?query=branch%3Amain) +[![Build Status](https://github.com/abelsiqueira/COPIERTemplate.jl/workflows/Test/badge.svg)](https://github.com/abelsiqueira/COPIERTemplate.jl/actions) +[![Test workflow status](https://github.com/abelsiqueira/COPIERTemplate.jl/actions/workflows/Test.yml/badge.svg?branch=main)](https://github.com/abelsiqueira/COPIERTemplate.jl/actions/workflows/Test.yml?query=branch%3Amain) +[![Lint workflow Status](https://github.com/abelsiqueira/COPIERTemplate.jl/actions/workflows/Lint.yml/badge.svg?branch=main)](https://github.com/abelsiqueira/COPIERTemplate.jl/actions/workflows/Lint.yml?query=branch%3Amain) +[![Docs workflow Status](https://github.com/abelsiqueira/COPIERTemplate.jl/actions/workflows/Docs.yml/badge.svg?branch=main)](https://github.com/abelsiqueira/COPIERTemplate.jl/actions/workflows/Docs.yml?query=branch%3Amain) +[![Coverage](https://codecov.io/gh/abelsiqueira/COPIERTemplate.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/abelsiqueira/COPIERTemplate.jl) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.8350577.svg)](https://doi.org/10.5281/zenodo.8350577) -This is a [copier](https://copier.readthedocs.io) template/skeleton for Julia packages (see folder [template](template)). +This is + +- a [copier](https://copier.readthedocs.io) template/skeleton for Julia packages (see folder [template](template)); and +- a package created with the template that wraps `copier` in Julia using `PythonCall`. -- It is opinionated but allows options -- Can be used in existing package (thanks for copier) -- Automatically keeps track of changes in the template through Pull Requests +The template + +- is opinionated but allows options; +- can be applied to existing packages (thanks to copier); +- is automatically reapplied through Pull Requests made by the Copier.yml workflow. Additional wishlist -- Use as template for other templates -- Allow using the template directly from Julia instead of installing copier (through PythonCall, possibly) +- Use as template for other templates (Maybe just use forks?) **But why?** @@ -25,23 +38,30 @@ Because I have around 50 packages that follow similar configuration (but not equ **What about mass updates using the GitHub API?** I have done that in the past, but now I want even less manual intervention. +This will still require manual installation for the first time, and will still allow verifying the pull requests. ## How to install -1. Install [copier](https://copier.readthedocs.io). +> **Warning** +> +> It is unknown if the package works on Windows due to an issue with unsupported paths. +> See [Issue #21](https://github.com/abelsiqueira/COPIERTemplate.jl/pull/21). +> If it doesn't work, let us know, and use the alternative installation. -1. Run copier with this template +1. Install this package, use the module and run `COPIERTemplate.generate(path)`. - ```bash - copier copy https://github.com/abelsiqueira/COPIERTemplate.jl YourPackage.jl - ``` + Alternatively, this can also be installed directly via [copier](https://copier.readthedocs.io), with the command -1. Follow the instructions. In particular you will need a UUID. Your Linux might have `uuidgen` installed, but you can also use Julia: + ```bash + copier copy https://github.com/abelsiqueira/COPIERTemplate.jl YourPackage.jl + ``` - ```bash - using UUIDs - uuid4() - ``` + Follow the instructions. In particular you will need a UUID. Your Linux might have `uuidgen` installed, but you can also use Julia: + + ```bash + using UUIDs + uuid4() + ``` 1. The resulting folder will not be a `git` package yet (to avoid trust issues), so you need to handle that yourself. First, install [`pre-commit`](https://pre-commit.com), and then issue: @@ -77,10 +97,10 @@ I have done that in the past, but now I want even less manual intervention. 1. Create a Personal Access Token to be used by the Copier workflow. 1. Go to . - 2. Create a token with "Content", "Pull-request", and "Workflows" permissions. - 3. Copy the Token. - 4. Go to your YOUR_PACKAGE_URL/settings/secrets/actions. - 5. Create a "New repository secret" named `COPIER_PAT`. + 1. Create a token with "Content", "Pull-request", and "Workflows" permissions. + 1. Copy the Token. + 1. Go to your YOUR_PACKAGE_URL/settings/secrets/actions. + 1. Create a "New repository secret" named `COPIER_PAT`. 1. Before releasing, enable Zenodo integration at . @@ -126,7 +146,7 @@ Installing pre-commit (`pre-commit install`) will make sure that it runs right t Additionally, if you run `pre-commit run -a`, it runs all hooks, which can be used for Linting. Some hooks in the `.pre-commit-config.yaml` file have configuration files of their own: -`.JuliaFormatter.toml`, `.markdownlint.json`, and `.yamllint.yml`. +`.JuliaFormatter.toml`, `.markdownlint.json`, `.markdown-link-config.json`, and `.yamllint.yml`. Also slightly related, is the `.editorconfig` file, which tells your editor, if you install the coorect plugin, how to format some things. diff --git a/copier.yml b/copier.yml index eb127050..7b0640e2 100644 --- a/copier.yml +++ b/copier.yml @@ -52,6 +52,8 @@ UseCirrusCI: _exclude: - .git + - .github/workflows/Docs.yml + - .github/workflows/Test.yml - CHANGELOG.md - copier.yml - LICENSE diff --git a/src/COPIERTemplate.jl b/src/COPIERTemplate.jl index 54c0bf1e..8f2ad29d 100644 --- a/src/COPIERTemplate.jl +++ b/src/COPIERTemplate.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 77df0a6a..19c83458 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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" => "test@me.now", + "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