-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
140 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# See https://domluna.github.io/JuliaFormatter.jl/stable/ for a list of options | ||
style = "blue" | ||
ignore = ["templates"] | ||
indent = 2 |
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,13 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.5.0 | ||
hooks: | ||
- id: check-merge-conflict | ||
- id: check-toml | ||
- id: check-yaml | ||
- id: end-of-file-fixer | ||
exclude_types: [markdown] # incompatible with Literate.jl | ||
- repo: https://github.com/qiaojunfeng/pre-commit-julia-format | ||
rev: v0.2.0 | ||
hooks: | ||
- id: julia-format |
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,8 +3,18 @@ uuid = "3d388ab1-018a-49f4-ae50-18094d5f71ea" | |
authors = ["ITensor developers <[email protected]> and contributors"] | ||
version = "0.1.0" | ||
|
||
[deps] | ||
Git = "d7ba0133-e1db-5d97-8f8c-041e4b3a1eb2" | ||
Git_jll = "f8c6e375-362e-5223-8a59-34ff63f689eb" | ||
PkgSkeleton = "d254efa0-af53-535e-b7f1-03c1c9fbcbe7" | ||
Preferences = "21216c6a-2e73-6563-6e65-726566657250" | ||
|
||
[compat] | ||
Aqua = "0.8.9" | ||
Git = "1.3.1" | ||
Git_jll = "2.46.2" | ||
PkgSkeleton = "1.3.1" | ||
Preferences = "1.4.3" | ||
Test = "1.10" | ||
julia = "1.10" | ||
|
||
|
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,8 +1,16 @@ | ||
# ITensorPkgSkeleton | ||
# ITensorPkgSkeleton.jl | ||
|
||
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://ITensor.github.io/ITensorPkgSkeleton.jl/stable/) | ||
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://ITensor.github.io/ITensorPkgSkeleton.jl/dev/) | ||
[![Build Status](https://github.com/ITensor/ITensorPkgSkeleton.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/ITensor/ITensorPkgSkeleton.jl/actions/workflows/CI.yml?query=branch%3Amain) | ||
[![Coverage](https://codecov.io/gh/ITensor/ITensorPkgSkeleton.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/ITensor/ITensorPkgSkeleton.jl) | ||
[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle) | ||
[![Aqua](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl) | ||
|
||
```julia | ||
using ITensorPkgSkeleton: ITensorPkgSkeleton | ||
# This step might be required to circumvent issues with | ||
# the version of git installed by `Git.jl`. | ||
ITensorPkgSkeleton.use_system_git!() | ||
ITensorPkgSkeleton.generate("NewPkg") | ||
``` |
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,75 @@ | ||
module ITensorPkgSkeleton | ||
|
||
# Write your package code here. | ||
using Git: git | ||
using Git_jll: Git_jll | ||
using PkgSkeleton: PkgSkeleton | ||
using Preferences: Preferences | ||
|
||
# Configure `Git.jl`/`Git_jll.jl` to | ||
# use the local installation of git. | ||
using Preferences: Preferences | ||
function use_system_git!() | ||
git_path = try | ||
readchomp(`which git`) | ||
catch | ||
nothing | ||
end | ||
if !isnothing(git_path) | ||
Preferences.set_preferences!("Git_jll", "git_path" => git_path) | ||
end | ||
end | ||
|
||
# Get the default branch name. | ||
# This might be an alternative but it doesn't work for some reason: | ||
# ```julia | ||
# using LibGit2: LibGit2 | ||
# LibGit2.get(AbstractString, LibGit2.GitConfig(), "init.defaultBranch") | ||
# ``` | ||
function default_branch_name() | ||
return try | ||
readchomp(`$(git()) config --get init.defaultBranch`) | ||
catch | ||
"main" | ||
end | ||
end | ||
|
||
function change_branch_name(path, branch_name) | ||
original_dir = pwd() | ||
cd(path) | ||
original_branch_name = readchomp(`$(git()) branch --show-current`) | ||
run(`$(git()) branch -m $original_branch_name $branch_name`) | ||
cd(original_dir) | ||
return nothing | ||
end | ||
|
||
function default_path() | ||
# TODO: Use something like `joinpath(first(DEPOT_PATH), "dev", pkg_name)` | ||
# to make it more general. | ||
return joinpath(homedir(), ".julia", "dev") | ||
end | ||
|
||
function generate(pkg_name; path=default_path()) | ||
pkg_path = joinpath(path, pkg_name) | ||
# TODO: Turn this into a keyword argument. | ||
template_dir = joinpath(pkgdir(ITensorPkgSkeleton), "templates", "default") | ||
|
||
branch_name = default_branch_name() | ||
## TODO: Allow customization of these, currently | ||
## they are hardcoded in the template. | ||
user_replacements = Dict([ | ||
"GHUSER" => "ITensor", | ||
"USERNAME" => "ITensor developers", | ||
"USEREMAIL" => "[email protected]", | ||
]) | ||
PkgSkeleton.generate( | ||
pkg_path; | ||
templates=[template_dir], | ||
user_replacements, | ||
) | ||
|
||
# Change the default branch. | ||
change_branch_name(pkg_path, branch_name) | ||
return nothing | ||
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.5.0 | ||
hooks: | ||
- id: check-merge-conflict | ||
- id: check-toml | ||
- id: check-yaml | ||
- id: end-of-file-fixer | ||
exclude_types: [markdown] # incompatible with Literate.jl | ||
- repo: https://github.com/qiaojunfeng/pre-commit-julia-format | ||
rev: v0.2.0 | ||
hooks: | ||
- id: julia-format |
File renamed without changes.
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,8 @@ | ||
@eval module $(gensym()) | ||
using {PKGNAME}: {PKGNAME} | ||
using Test: @test, @testset | ||
|
||
@testset "{PKGNAME}" begin | ||
# Tests go here. | ||
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@eval module $(gensym()) | ||
using ITensorPkgSkeleton: ITensorPkgSkeleton | ||
using Test: @test, @testset | ||
|
||
@testset "ITensorPkgSkeleton" begin | ||
path = tempdir() | ||
@test isnothing(ITensorPkgSkeleton.generate("NewPkg"; path)) | ||
@test isdir(joinpath(path, "NewPkg")) | ||
@test isdir(joinpath(path, "NewPkg", ".github")) | ||
@test isdir(joinpath(path, "NewPkg", "benchmark")) | ||
@test isdir(joinpath(path, "NewPkg", "docs")) | ||
@test isdir(joinpath(path, "NewPkg", "src")) | ||
@test isdir(joinpath(path, "NewPkg", "test")) | ||
end | ||
end |