From 969b2e7bb72fdba1ed6a93de0b6243aa3cd50afa Mon Sep 17 00:00:00 2001 From: mtfishman Date: Thu, 26 Feb 2026 15:51:35 -0500 Subject: [PATCH 1/4] Format --- Project.toml | 2 +- src/ITensorPkgSkeleton.jl | 99 ++++++++++++++---- .../ISSUE_TEMPLATE/BUG_REPORT.md.template | 0 .../FEATURE_REQUEST.md.template | 0 .../.github/PULL_REQUEST_TEMPLATE.md.template | 0 .../.github/dependabot.yml.template | 0 .../workflows/CompatHelper.yml.template | 0 .../workflows/Documentation.yml.template | 0 .../workflows/FormatCheck.yml.template | 0 .../workflows/FormatPullRequest.yml.template | 0 .../workflows/IntegrationTest.yml.template | 0 .../IntegrationTestRequest.yml.template | 0 .../workflows/Registrator.yml.template | 0 .../.github/workflows/TagBot.yml.template | 0 .../.github/workflows/Tests.yml.template | 0 .../workflows/VersionCheck.yml.template | 0 templates/{gitignore => }/.gitignore.template | 0 .../.pre-commit-config.yaml.template | 0 templates/{license => }/LICENSE.template | 0 templates/{project => }/Project.toml.template | 0 templates/{docs => }/README.md.template | 0 .../{benchmark => }/benchmarks.jl.template | 0 .../docs/{docs => }/Project.toml.template | 0 templates/docs/{docs => }/make.jl.template | 0 .../docs/{docs => }/make_index.jl.template | 0 .../docs/{docs => }/make_readme.jl.template | 0 .../src/assets/CCQ-dark.png.template | Bin .../{docs => }/src/assets/CCQ.png.template | Bin .../{docs => }/src/assets/extras.css.template | 0 .../src/assets/favicon.ico.template | Bin .../src/assets/logo-dark.png.template | Bin .../{docs => }/src/assets/logo.png.template | Bin .../docs/{docs => }/src/reference.md.template | 0 .../{examples => }/Project.toml.template | 0 .../{examples => }/README.jl.template | 0 templates/src/{src => }/{PKGNAME}.jl.template | 0 .../test/{test => }/Project.toml.template | 0 .../test/{test => }/runtests.jl.template | 0 .../test/{test => }/test_aqua.jl.template | 0 .../test/{test => }/test_basics.jl.template | 0 40 files changed, 80 insertions(+), 21 deletions(-) rename templates/{github => }/.github/ISSUE_TEMPLATE/BUG_REPORT.md.template (100%) rename templates/{github => }/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md.template (100%) rename templates/{github => }/.github/PULL_REQUEST_TEMPLATE.md.template (100%) rename templates/{github => }/.github/dependabot.yml.template (100%) rename templates/{github => }/.github/workflows/CompatHelper.yml.template (100%) rename templates/{github => }/.github/workflows/Documentation.yml.template (100%) rename templates/{github => }/.github/workflows/FormatCheck.yml.template (100%) rename templates/{github => }/.github/workflows/FormatPullRequest.yml.template (100%) rename templates/{github => }/.github/workflows/IntegrationTest.yml.template (100%) rename templates/{github => }/.github/workflows/IntegrationTestRequest.yml.template (100%) rename templates/{github => }/.github/workflows/Registrator.yml.template (100%) rename templates/{github => }/.github/workflows/TagBot.yml.template (100%) rename templates/{github => }/.github/workflows/Tests.yml.template (100%) rename templates/{github => }/.github/workflows/VersionCheck.yml.template (100%) rename templates/{gitignore => }/.gitignore.template (100%) rename templates/{precommit => }/.pre-commit-config.yaml.template (100%) rename templates/{license => }/LICENSE.template (100%) rename templates/{project => }/Project.toml.template (100%) rename templates/{docs => }/README.md.template (100%) rename templates/benchmark/{benchmark => }/benchmarks.jl.template (100%) rename templates/docs/{docs => }/Project.toml.template (100%) rename templates/docs/{docs => }/make.jl.template (100%) rename templates/docs/{docs => }/make_index.jl.template (100%) rename templates/docs/{docs => }/make_readme.jl.template (100%) rename templates/docs/{docs => }/src/assets/CCQ-dark.png.template (100%) rename templates/docs/{docs => }/src/assets/CCQ.png.template (100%) rename templates/docs/{docs => }/src/assets/extras.css.template (100%) rename templates/docs/{docs => }/src/assets/favicon.ico.template (100%) rename templates/docs/{docs => }/src/assets/logo-dark.png.template (100%) rename templates/docs/{docs => }/src/assets/logo.png.template (100%) rename templates/docs/{docs => }/src/reference.md.template (100%) rename templates/examples/{examples => }/Project.toml.template (100%) rename templates/examples/{examples => }/README.jl.template (100%) rename templates/src/{src => }/{PKGNAME}.jl.template (100%) rename templates/test/{test => }/Project.toml.template (100%) rename templates/test/{test => }/runtests.jl.template (100%) rename templates/test/{test => }/test_aqua.jl.template (100%) rename templates/test/{test => }/test_basics.jl.template (100%) diff --git a/Project.toml b/Project.toml index 3e74806..6ee809c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ITensorPkgSkeleton" uuid = "3d388ab1-018a-49f4-ae50-18094d5f71ea" -version = "0.3.29" +version = "0.3.30" authors = ["ITensor developers and contributors"] [workspace] diff --git a/src/ITensorPkgSkeleton.jl b/src/ITensorPkgSkeleton.jl index 409df3f..b9da8b5 100644 --- a/src/ITensorPkgSkeleton.jl +++ b/src/ITensorPkgSkeleton.jl @@ -101,26 +101,82 @@ function format_downstreampkgs(user_replacements) return merge(user_replacements, (; downstreampkgs)) end -function set_default_template_path(template) - isabspath(template) && return template - return joinpath(pkgdir(ITensorPkgSkeleton), "templates", template) -end - const TEMPLATE_EXT = ".template" +const TEMPLATE_ROOT = joinpath(pkgdir(ITensorPkgSkeleton), "templates") +const TEMPLATE_NAMES = [ + "benchmark", + "docs", + "examples", + "github", + "gitignore", + "license", + "precommit", + "project", + "src", + "test", +] +const TEMPLATE_PATHS = Dict( + "benchmark" => ["benchmark"], + "docs" => ["docs", "README.md"], + "examples" => ["examples"], + "github" => [".github"], + "gitignore" => [".gitignore"], + "license" => ["LICENSE"], + "precommit" => [".pre-commit-config.yaml"], + "project" => ["Project.toml"], + "src" => ["src"], + "test" => ["test"] +) + +function copy_template_path!(src, template_dir, dest_dir) + if isdir(src) + for (root, dirs, files) in walkdir(src) + for dir in dirs + mkpath(joinpath(dest_dir, relpath(joinpath(root, dir), template_dir))) + end + for file in files + src_file = joinpath(root, file) + rel = relpath(src_file, template_dir) + if endswith(rel, TEMPLATE_EXT) + rel = rel[1:(end - length(TEMPLATE_EXT))] + end + dest_file = joinpath(dest_dir, rel) + mkpath(dirname(dest_file)) + cp(src_file, dest_file) + end + end + elseif isfile(src) + rel = relpath(src, template_dir) + if endswith(rel, TEMPLATE_EXT) + rel = rel[1:(end - length(TEMPLATE_EXT))] + end + dest_file = joinpath(dest_dir, rel) + mkpath(dirname(dest_file)) + cp(src, dest_file) + end + return nothing +end function prepare_template(template_dir) tmp_dir = mktempdir() - for (root, dirs, files) in walkdir(template_dir) - for dir in dirs - mkpath(joinpath(tmp_dir, relpath(joinpath(root, dir), template_dir))) - end - for file in files - src = joinpath(root, file) - rel = relpath(src, template_dir) - if endswith(rel, TEMPLATE_EXT) - rel = rel[1:(end - length(TEMPLATE_EXT))] + copy_template_path!(template_dir, template_dir, tmp_dir) + return tmp_dir +end + +function prepare_default_templates(templates) + tmp_dir = mktempdir() + for template in templates + paths = get(TEMPLATE_PATHS, template, nothing) + isnothing(paths) && + throw( + ArgumentError("Unknown template \"$template\". Options: $(TEMPLATE_NAMES)") + ) + for path in paths + src = joinpath(TEMPLATE_ROOT, "$path$TEMPLATE_EXT") + if !isfile(src) + src = joinpath(TEMPLATE_ROOT, path) end - cp(src, joinpath(tmp_dir, rel)) + copy_template_path!(src, TEMPLATE_ROOT, tmp_dir) end end return tmp_dir @@ -140,7 +196,7 @@ $(SIGNATURES) All available templates when constructing a package. Includes the following templates: `$(all_templates())` """ -all_templates() = readdir(joinpath(pkgdir(ITensorPkgSkeleton), "templates")) +all_templates() = copy(TEMPLATE_NAMES) """ $(SIGNATURES) @@ -242,10 +298,13 @@ function generate( # Process downstream package information. user_replacements = format_downstreampkgs(user_replacements) templates = setdiff(templates, ignore_templates) - # Fill in default path if missing. - templates = set_default_template_path.(templates) - # Copy templates to temp directories, stripping `.template` extension from filenames. - templates = prepare_template.(templates) + templates_abs = filter(isabspath, templates) + templates_default = setdiff(templates, templates_abs) + if !isempty(templates_default) + templates_abs = + vcat([prepare_default_templates(String.(templates_default))], templates_abs) + end + templates = prepare_template.(templates_abs) is_new_repo = !is_git_repo(pkgpath) branch_name = default_branch_name() user_replacements_pkgskeleton = to_pkgskeleton(user_replacements) diff --git a/templates/github/.github/ISSUE_TEMPLATE/BUG_REPORT.md.template b/templates/.github/ISSUE_TEMPLATE/BUG_REPORT.md.template similarity index 100% rename from templates/github/.github/ISSUE_TEMPLATE/BUG_REPORT.md.template rename to templates/.github/ISSUE_TEMPLATE/BUG_REPORT.md.template diff --git a/templates/github/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md.template b/templates/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md.template similarity index 100% rename from templates/github/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md.template rename to templates/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md.template diff --git a/templates/github/.github/PULL_REQUEST_TEMPLATE.md.template b/templates/.github/PULL_REQUEST_TEMPLATE.md.template similarity index 100% rename from templates/github/.github/PULL_REQUEST_TEMPLATE.md.template rename to templates/.github/PULL_REQUEST_TEMPLATE.md.template diff --git a/templates/github/.github/dependabot.yml.template b/templates/.github/dependabot.yml.template similarity index 100% rename from templates/github/.github/dependabot.yml.template rename to templates/.github/dependabot.yml.template diff --git a/templates/github/.github/workflows/CompatHelper.yml.template b/templates/.github/workflows/CompatHelper.yml.template similarity index 100% rename from templates/github/.github/workflows/CompatHelper.yml.template rename to templates/.github/workflows/CompatHelper.yml.template diff --git a/templates/github/.github/workflows/Documentation.yml.template b/templates/.github/workflows/Documentation.yml.template similarity index 100% rename from templates/github/.github/workflows/Documentation.yml.template rename to templates/.github/workflows/Documentation.yml.template diff --git a/templates/github/.github/workflows/FormatCheck.yml.template b/templates/.github/workflows/FormatCheck.yml.template similarity index 100% rename from templates/github/.github/workflows/FormatCheck.yml.template rename to templates/.github/workflows/FormatCheck.yml.template diff --git a/templates/github/.github/workflows/FormatPullRequest.yml.template b/templates/.github/workflows/FormatPullRequest.yml.template similarity index 100% rename from templates/github/.github/workflows/FormatPullRequest.yml.template rename to templates/.github/workflows/FormatPullRequest.yml.template diff --git a/templates/github/.github/workflows/IntegrationTest.yml.template b/templates/.github/workflows/IntegrationTest.yml.template similarity index 100% rename from templates/github/.github/workflows/IntegrationTest.yml.template rename to templates/.github/workflows/IntegrationTest.yml.template diff --git a/templates/github/.github/workflows/IntegrationTestRequest.yml.template b/templates/.github/workflows/IntegrationTestRequest.yml.template similarity index 100% rename from templates/github/.github/workflows/IntegrationTestRequest.yml.template rename to templates/.github/workflows/IntegrationTestRequest.yml.template diff --git a/templates/github/.github/workflows/Registrator.yml.template b/templates/.github/workflows/Registrator.yml.template similarity index 100% rename from templates/github/.github/workflows/Registrator.yml.template rename to templates/.github/workflows/Registrator.yml.template diff --git a/templates/github/.github/workflows/TagBot.yml.template b/templates/.github/workflows/TagBot.yml.template similarity index 100% rename from templates/github/.github/workflows/TagBot.yml.template rename to templates/.github/workflows/TagBot.yml.template diff --git a/templates/github/.github/workflows/Tests.yml.template b/templates/.github/workflows/Tests.yml.template similarity index 100% rename from templates/github/.github/workflows/Tests.yml.template rename to templates/.github/workflows/Tests.yml.template diff --git a/templates/github/.github/workflows/VersionCheck.yml.template b/templates/.github/workflows/VersionCheck.yml.template similarity index 100% rename from templates/github/.github/workflows/VersionCheck.yml.template rename to templates/.github/workflows/VersionCheck.yml.template diff --git a/templates/gitignore/.gitignore.template b/templates/.gitignore.template similarity index 100% rename from templates/gitignore/.gitignore.template rename to templates/.gitignore.template diff --git a/templates/precommit/.pre-commit-config.yaml.template b/templates/.pre-commit-config.yaml.template similarity index 100% rename from templates/precommit/.pre-commit-config.yaml.template rename to templates/.pre-commit-config.yaml.template diff --git a/templates/license/LICENSE.template b/templates/LICENSE.template similarity index 100% rename from templates/license/LICENSE.template rename to templates/LICENSE.template diff --git a/templates/project/Project.toml.template b/templates/Project.toml.template similarity index 100% rename from templates/project/Project.toml.template rename to templates/Project.toml.template diff --git a/templates/docs/README.md.template b/templates/README.md.template similarity index 100% rename from templates/docs/README.md.template rename to templates/README.md.template diff --git a/templates/benchmark/benchmark/benchmarks.jl.template b/templates/benchmark/benchmarks.jl.template similarity index 100% rename from templates/benchmark/benchmark/benchmarks.jl.template rename to templates/benchmark/benchmarks.jl.template diff --git a/templates/docs/docs/Project.toml.template b/templates/docs/Project.toml.template similarity index 100% rename from templates/docs/docs/Project.toml.template rename to templates/docs/Project.toml.template diff --git a/templates/docs/docs/make.jl.template b/templates/docs/make.jl.template similarity index 100% rename from templates/docs/docs/make.jl.template rename to templates/docs/make.jl.template diff --git a/templates/docs/docs/make_index.jl.template b/templates/docs/make_index.jl.template similarity index 100% rename from templates/docs/docs/make_index.jl.template rename to templates/docs/make_index.jl.template diff --git a/templates/docs/docs/make_readme.jl.template b/templates/docs/make_readme.jl.template similarity index 100% rename from templates/docs/docs/make_readme.jl.template rename to templates/docs/make_readme.jl.template diff --git a/templates/docs/docs/src/assets/CCQ-dark.png.template b/templates/docs/src/assets/CCQ-dark.png.template similarity index 100% rename from templates/docs/docs/src/assets/CCQ-dark.png.template rename to templates/docs/src/assets/CCQ-dark.png.template diff --git a/templates/docs/docs/src/assets/CCQ.png.template b/templates/docs/src/assets/CCQ.png.template similarity index 100% rename from templates/docs/docs/src/assets/CCQ.png.template rename to templates/docs/src/assets/CCQ.png.template diff --git a/templates/docs/docs/src/assets/extras.css.template b/templates/docs/src/assets/extras.css.template similarity index 100% rename from templates/docs/docs/src/assets/extras.css.template rename to templates/docs/src/assets/extras.css.template diff --git a/templates/docs/docs/src/assets/favicon.ico.template b/templates/docs/src/assets/favicon.ico.template similarity index 100% rename from templates/docs/docs/src/assets/favicon.ico.template rename to templates/docs/src/assets/favicon.ico.template diff --git a/templates/docs/docs/src/assets/logo-dark.png.template b/templates/docs/src/assets/logo-dark.png.template similarity index 100% rename from templates/docs/docs/src/assets/logo-dark.png.template rename to templates/docs/src/assets/logo-dark.png.template diff --git a/templates/docs/docs/src/assets/logo.png.template b/templates/docs/src/assets/logo.png.template similarity index 100% rename from templates/docs/docs/src/assets/logo.png.template rename to templates/docs/src/assets/logo.png.template diff --git a/templates/docs/docs/src/reference.md.template b/templates/docs/src/reference.md.template similarity index 100% rename from templates/docs/docs/src/reference.md.template rename to templates/docs/src/reference.md.template diff --git a/templates/examples/examples/Project.toml.template b/templates/examples/Project.toml.template similarity index 100% rename from templates/examples/examples/Project.toml.template rename to templates/examples/Project.toml.template diff --git a/templates/examples/examples/README.jl.template b/templates/examples/README.jl.template similarity index 100% rename from templates/examples/examples/README.jl.template rename to templates/examples/README.jl.template diff --git a/templates/src/src/{PKGNAME}.jl.template b/templates/src/{PKGNAME}.jl.template similarity index 100% rename from templates/src/src/{PKGNAME}.jl.template rename to templates/src/{PKGNAME}.jl.template diff --git a/templates/test/test/Project.toml.template b/templates/test/Project.toml.template similarity index 100% rename from templates/test/test/Project.toml.template rename to templates/test/Project.toml.template diff --git a/templates/test/test/runtests.jl.template b/templates/test/runtests.jl.template similarity index 100% rename from templates/test/test/runtests.jl.template rename to templates/test/runtests.jl.template diff --git a/templates/test/test/test_aqua.jl.template b/templates/test/test_aqua.jl.template similarity index 100% rename from templates/test/test/test_aqua.jl.template rename to templates/test/test_aqua.jl.template diff --git a/templates/test/test/test_basics.jl.template b/templates/test/test_basics.jl.template similarity index 100% rename from templates/test/test/test_basics.jl.template rename to templates/test/test_basics.jl.template From d76bd6281a68b3d71cf09c5f99feed850917b222 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Thu, 26 Feb 2026 16:00:57 -0500 Subject: [PATCH 2/4] Bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 6ee809c..0d4b957 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ITensorPkgSkeleton" uuid = "3d388ab1-018a-49f4-ae50-18094d5f71ea" -version = "0.3.30" +version = "0.3.31" authors = ["ITensor developers and contributors"] [workspace] From 6f29c3c5eaa4f8cbe0e7075c767e316279485ca6 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Thu, 26 Feb 2026 16:04:59 -0500 Subject: [PATCH 3/4] Small simplification --- src/ITensorPkgSkeleton.jl | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/ITensorPkgSkeleton.jl b/src/ITensorPkgSkeleton.jl index b9da8b5..4a4d434 100644 --- a/src/ITensorPkgSkeleton.jl +++ b/src/ITensorPkgSkeleton.jl @@ -103,18 +103,6 @@ end const TEMPLATE_EXT = ".template" const TEMPLATE_ROOT = joinpath(pkgdir(ITensorPkgSkeleton), "templates") -const TEMPLATE_NAMES = [ - "benchmark", - "docs", - "examples", - "github", - "gitignore", - "license", - "precommit", - "project", - "src", - "test", -] const TEMPLATE_PATHS = Dict( "benchmark" => ["benchmark"], "docs" => ["docs", "README.md"], @@ -127,6 +115,7 @@ const TEMPLATE_PATHS = Dict( "src" => ["src"], "test" => ["test"] ) +const TEMPLATE_NAMES = collect(keys(TEMPLATE_PATHS)) function copy_template_path!(src, template_dir, dest_dir) if isdir(src) From 7f8c01d14b054831b0ad563982b61b179e8fef90 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Thu, 26 Feb 2026 16:07:44 -0500 Subject: [PATCH 4/4] Small simplifications --- src/ITensorPkgSkeleton.jl | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/ITensorPkgSkeleton.jl b/src/ITensorPkgSkeleton.jl index 4a4d434..bc644ee 100644 --- a/src/ITensorPkgSkeleton.jl +++ b/src/ITensorPkgSkeleton.jl @@ -115,7 +115,9 @@ const TEMPLATE_PATHS = Dict( "src" => ["src"], "test" => ["test"] ) -const TEMPLATE_NAMES = collect(keys(TEMPLATE_PATHS)) +function strip_template_ext(path) + return endswith(path, TEMPLATE_EXT) ? path[1:(end - length(TEMPLATE_EXT))] : path +end function copy_template_path!(src, template_dir, dest_dir) if isdir(src) @@ -125,20 +127,14 @@ function copy_template_path!(src, template_dir, dest_dir) end for file in files src_file = joinpath(root, file) - rel = relpath(src_file, template_dir) - if endswith(rel, TEMPLATE_EXT) - rel = rel[1:(end - length(TEMPLATE_EXT))] - end + rel = strip_template_ext(relpath(src_file, template_dir)) dest_file = joinpath(dest_dir, rel) mkpath(dirname(dest_file)) cp(src_file, dest_file) end end elseif isfile(src) - rel = relpath(src, template_dir) - if endswith(rel, TEMPLATE_EXT) - rel = rel[1:(end - length(TEMPLATE_EXT))] - end + rel = strip_template_ext(relpath(src, template_dir)) dest_file = joinpath(dest_dir, rel) mkpath(dirname(dest_file)) cp(src, dest_file) @@ -158,7 +154,9 @@ function prepare_default_templates(templates) paths = get(TEMPLATE_PATHS, template, nothing) isnothing(paths) && throw( - ArgumentError("Unknown template \"$template\". Options: $(TEMPLATE_NAMES)") + ArgumentError( + "Unknown template \"$template\". Options: $(collect(keys(TEMPLATE_PATHS)))" + ) ) for path in paths src = joinpath(TEMPLATE_ROOT, "$path$TEMPLATE_EXT") @@ -171,6 +169,17 @@ function prepare_default_templates(templates) return tmp_dir end +function prepare_templates(templates) + templates_abs = filter(isabspath, templates) + templates_default = setdiff(templates, templates_abs) + prepared = String[] + if !isempty(templates_default) + push!(prepared, prepare_default_templates(String.(templates_default))) + end + append!(prepared, prepare_template.(templates_abs)) + return prepared +end + function is_git_repo(path) return try LibGit2.GitRepo(path) @@ -185,7 +194,7 @@ $(SIGNATURES) All available templates when constructing a package. Includes the following templates: `$(all_templates())` """ -all_templates() = copy(TEMPLATE_NAMES) +all_templates() = collect(keys(TEMPLATE_PATHS)) """ $(SIGNATURES) @@ -287,13 +296,7 @@ function generate( # Process downstream package information. user_replacements = format_downstreampkgs(user_replacements) templates = setdiff(templates, ignore_templates) - templates_abs = filter(isabspath, templates) - templates_default = setdiff(templates, templates_abs) - if !isempty(templates_default) - templates_abs = - vcat([prepare_default_templates(String.(templates_default))], templates_abs) - end - templates = prepare_template.(templates_abs) + templates = prepare_templates(templates) is_new_repo = !is_git_repo(pkgpath) branch_name = default_branch_name() user_replacements_pkgskeleton = to_pkgskeleton(user_replacements)