From b489ea395ca7838c3f318a6035b2e32a0f0838aa Mon Sep 17 00:00:00 2001 From: mtfishman Date: Sun, 22 Feb 2026 20:19:35 -0500 Subject: [PATCH 01/14] Update pre-commit hook to use itpkgfmt --- .pre-commit-config.yaml | 10 +++------- .pre-commit-hooks.yaml | 10 +++------- Project.toml | 3 +-- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d4eb7df..b360be0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,14 +2,10 @@ repos: - repo: "local" hooks: - id: "itensor-formatter" - name: "ITensor Formatter" - entry: "itfmt" - pass_filenames: true - always_run: false - types: - - "file" - files: "\\.jl$" + name: "ITensor Pkg Formatter" + entry: "itpkgfmt ." language: "system" + pass_filenames: false - repo: "meta" hooks: - id: "check-hooks-apply" diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index ec73c6c..90727d6 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -1,10 +1,6 @@ - id: "itensor-formatter" - name: "ITensor Formatter" - entry: "itfmt" - pass_filenames: true - always_run: false - types: - - "file" - files: "\\.jl$" + name: "ITensor Pkg Formatter" + entry: "itpkgfmt ." language: "system" + pass_filenames: false description: "Code formatter for the ITensor ecosystem built on Runic and JuliaFormatter." diff --git a/Project.toml b/Project.toml index cff26a7..aadeea2 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ITensorFormatter" uuid = "b6bf39f1-c9d3-4bad-aad8-593d802f65fd" -version = "0.2.14" +version = "0.2.15" authors = ["ITensor developers and contributors"] [workspace] @@ -25,7 +25,6 @@ TOML = "1.0.3" YAML = "0.4.16" julia = "1.10" - [apps.itfmt] [apps.itpkgfmt] From 32ed6997f03362eb4bae1573ed4222721b1d7811 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Sun, 22 Feb 2026 20:41:31 -0500 Subject: [PATCH 02/14] Update version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index aadeea2..c50a66d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ITensorFormatter" uuid = "b6bf39f1-c9d3-4bad-aad8-593d802f65fd" -version = "0.2.15" +version = "0.2.16" authors = ["ITensor developers and contributors"] [workspace] From 7372a0efc85bb1a4d146647e1e5d92b3ee32bc2b Mon Sep 17 00:00:00 2001 From: mtfishman Date: Sun, 22 Feb 2026 21:13:47 -0500 Subject: [PATCH 03/14] Minimize compilation --- Project.toml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index c50a66d..9918d4e 100644 --- a/Project.toml +++ b/Project.toml @@ -25,7 +25,6 @@ TOML = "1.0.3" YAML = "0.4.16" julia = "1.10" -[apps.itfmt] - -[apps.itpkgfmt] -submodule = "ITensorPkgFormatter" +[apps] +itfmt = { julia_flags = ["--compile=min", "--optimize=0"] } +itpkgfmt = { submodule = "ITensorPkgFormatter", julia_flags = ["--compile=min", "--optimize=0"] } From 85a3f1c4844ea5a9fcb7a80b9b5c6579d540d6f2 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Sun, 22 Feb 2026 21:16:34 -0500 Subject: [PATCH 04/14] Format Project.toml --- Project.toml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 9918d4e..2eaa4a4 100644 --- a/Project.toml +++ b/Project.toml @@ -25,6 +25,9 @@ TOML = "1.0.3" YAML = "0.4.16" julia = "1.10" -[apps] -itfmt = { julia_flags = ["--compile=min", "--optimize=0"] } -itpkgfmt = { submodule = "ITensorPkgFormatter", julia_flags = ["--compile=min", "--optimize=0"] } +[apps.itfmt] +julia_flags = ["--compile=min", "--optimize=0"] + +[apps.itpkgfmt] +julia_flags = ["--compile=min", "--optimize=0"] +submodule = "ITensorPkgFormatter" From bb4b1ba912636af01d3f00d915539f413ab888b5 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Sun, 22 Feb 2026 22:07:50 -0500 Subject: [PATCH 05/14] Add precompilation --- Project.toml | 2 ++ src/ITensorFormatter.jl | 1 + src/generate_readme.jl | 1 - src/precompile_workload.jl | 41 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/precompile_workload.jl diff --git a/Project.toml b/Project.toml index 2eaa4a4..5719a88 100644 --- a/Project.toml +++ b/Project.toml @@ -11,6 +11,7 @@ JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899" JuliaSyntax = "70703baa-626e-46a2-a12c-08ffd08c73b4" Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306" OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" Runic = "62bfec6d-59d7-401d-8490-b29ee721c001" TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6" @@ -20,6 +21,7 @@ JuliaFormatter = "2.3" JuliaSyntax = "0.4.10" Literate = "2.21" OrderedCollections = "1.8.1" +PrecompileTools = "1.3.3" Runic = "1.5.1" TOML = "1.0.3" YAML = "0.4.16" diff --git a/src/ITensorFormatter.jl b/src/ITensorFormatter.jl index 2c138ee..d2a4467 100644 --- a/src/ITensorFormatter.jl +++ b/src/ITensorFormatter.jl @@ -13,5 +13,6 @@ include("format_project_toml.jl") include("main.jl") include("generate_readme.jl") include("ITensorPkgFormatter.jl") +include("precompile_workload.jl") end diff --git a/src/generate_readme.jl b/src/generate_readme.jl index 889be91..20a51f3 100644 --- a/src/generate_readme.jl +++ b/src/generate_readme.jl @@ -4,7 +4,6 @@ function isitensorpkg(path::AbstractString) return isdir(path) && isfile(joinpath(path, "Project.toml")) && isdir(joinpath(path, "src")) && - isdir(joinpath(path, "test")) && isdir(joinpath(path, "docs")) && isfile(joinpath(path, "docs", "make_readme.jl")) end diff --git a/src/precompile_workload.jl b/src/precompile_workload.jl new file mode 100644 index 0000000..3764183 --- /dev/null +++ b/src/precompile_workload.jl @@ -0,0 +1,41 @@ +using PrecompileTools: @compile_workload, @setup_workload + +@setup_workload begin + tmp = mktempdir() + try + # Make tmp look like an ITensor package dir (so generate_readme! runs) + for d in ("src", "docs", "examples") + mkpath(joinpath(tmp, d)) + end + + # Minimal files so the formatter has something to do + write(joinpath(tmp, "src", "Example.jl"), "module Example\nx=1\nend\n") + write(joinpath(tmp, "config.yaml"), "a: 1\nb: 2\n") + write( + joinpath(tmp, "Project.toml"), + "name = \"Example\"\nuuid = \"00000000-0000-0000-0000-000000000000\"\nversion = \"0.1.0\"\n" + ) + + # Copy the package's real docs/make_readme.jl into tmp/docs/ + pkgroot = pkgdir(@__MODULE__) # ITensorFormatter package root + cp( + joinpath(pkgroot, "docs", "make_readme.jl"), + joinpath(tmp, "docs", "make_readme.jl"); + force = true + ) + + # Provide tmp/examples/README.jl for Literate to convert -> tmp/README.md + cp( + joinpath(pkgroot, "examples", "README.jl"), + joinpath(tmp, "examples", "README.jl"); + force = true + ) + + @compile_workload begin + main([tmp]) + # ITensorPkgFormatter.main([tmp]) + end + finally + rm(tmp; recursive = true, force = true) + end +end From d45c0dbeb842befa767b65250af27198dbb387f2 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Sun, 22 Feb 2026 22:20:29 -0500 Subject: [PATCH 06/14] Suppress printing from make_readme --- Project.toml | 3 +++ src/ITensorPkgFormatter.jl | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 5719a88..50f14d3 100644 --- a/Project.toml +++ b/Project.toml @@ -10,6 +10,7 @@ projects = ["benchmark", "dev", "docs", "examples", "test"] JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899" JuliaSyntax = "70703baa-626e-46a2-a12c-08ffd08c73b4" Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306" +Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" Runic = "62bfec6d-59d7-401d-8490-b29ee721c001" @@ -20,6 +21,7 @@ YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6" JuliaFormatter = "2.3" JuliaSyntax = "0.4.10" Literate = "2.21" +Logging = "1.11" OrderedCollections = "1.8.1" PrecompileTools = "1.3.3" Runic = "1.5.1" @@ -27,6 +29,7 @@ TOML = "1.0.3" YAML = "0.4.16" julia = "1.10" + [apps.itfmt] julia_flags = ["--compile=min", "--optimize=0"] diff --git a/src/ITensorPkgFormatter.jl b/src/ITensorPkgFormatter.jl index 3e830cd..a6960b7 100644 --- a/src/ITensorPkgFormatter.jl +++ b/src/ITensorPkgFormatter.jl @@ -1,11 +1,14 @@ module ITensorPkgFormatter using ITensorFormatter: ITensorFormatter +using Logging: Logging function main(argv) ITensorFormatter.main(argv) paths = filter(!startswith("--"), argv) - ITensorFormatter.generate_readmes!(paths) + Logging.with_logger(Logging.NullLogger()) do + return ITensorFormatter.generate_readmes!(paths) + end return nothing end From 44605c564d91506b280f37a9b3a80162a37668db Mon Sep 17 00:00:00 2001 From: mtfishman Date: Sun, 22 Feb 2026 22:40:35 -0500 Subject: [PATCH 07/14] Tweaks --- Project.toml | 2 +- src/generate_readme.jl | 2 +- src/precompile_workload.jl | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 50f14d3..7b000d8 100644 --- a/Project.toml +++ b/Project.toml @@ -21,7 +21,7 @@ YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6" JuliaFormatter = "2.3" JuliaSyntax = "0.4.10" Literate = "2.21" -Logging = "1.11" +Logging = "1.10" OrderedCollections = "1.8.1" PrecompileTools = "1.3.3" Runic = "1.5.1" diff --git a/src/generate_readme.jl b/src/generate_readme.jl index 20a51f3..e910393 100644 --- a/src/generate_readme.jl +++ b/src/generate_readme.jl @@ -22,7 +22,7 @@ function generate_readme!(path::AbstractString) end try cd(joinpath(path, "docs")) do - include("make_readme.jl") + include(joinpath(pwd(), "make_readme.jl")) return nothing end catch e diff --git a/src/precompile_workload.jl b/src/precompile_workload.jl index 3764183..f9fd0af 100644 --- a/src/precompile_workload.jl +++ b/src/precompile_workload.jl @@ -32,8 +32,11 @@ using PrecompileTools: @compile_workload, @setup_workload ) @compile_workload begin + # Ideally we might use `ITensorPkgFormatter.main([tmp])` to include + # precompilation of README generation, but some of that code seems to be + # problematic for precompilation because of some usage of `eval`, maybe + # in `include`. main([tmp]) - # ITensorPkgFormatter.main([tmp]) end finally rm(tmp; recursive = true, force = true) From cfc76c003a13c32be4e86540ae1fa0fb40ee6ec2 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Sun, 22 Feb 2026 23:03:06 -0500 Subject: [PATCH 08/14] Compat --- Project.toml | 2 +- src/main.jl | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Project.toml b/Project.toml index 7b000d8..79f53bf 100644 --- a/Project.toml +++ b/Project.toml @@ -23,7 +23,7 @@ JuliaSyntax = "0.4.10" Literate = "2.21" Logging = "1.10" OrderedCollections = "1.8.1" -PrecompileTools = "1.3.3" +PrecompileTools = "1" Runic = "1.5.1" TOML = "1.0.3" YAML = "0.4.16" diff --git a/src/main.jl b/src/main.jl index fb13a2f..43ba8ce 100644 --- a/src/main.jl +++ b/src/main.jl @@ -14,7 +14,10 @@ const JULIAFORMATTER_OPTIONS = ( for_in_replacement = "in", # Semantic transformations consistent with Runic always_use_return = true, - import_to_using = true, + # Ideally we would use `import_to_using = true`, however that changes the import + # formatting, which requires reformatting imports again which is expensive without + # a better solution besides running JuliaFormatter twice. + import_to_using = false, pipe_to_function_call = true, short_to_long_function_def = true, long_to_short_function_def = false, @@ -145,17 +148,13 @@ function main(argv) format_imports!(jlfiles) # Pass 2: Format via JuliaFormatter format_juliaformatter!(jlfiles) - # Pass 3: Re-organize imports again (fix up any changes from JuliaFormatter, e.g. - # import_to_using) - format_imports!(jlfiles) - # Pass 4: Format via JuliaFormatter again to fix import line wrapping - format_juliaformatter!(jlfiles) - # Pass 5: Canonicalize via Runic + # Pass 3: Canonicalize via Runic format_runic!(jlfiles) - # Pass 6: Format YAML files - format_yamls!(yamlfiles) - # Pass 7: Format Project.toml files + # Pass 4: Format Project.toml files format_project_tomls!(projectomls) + # Pass 5: Format YAML files + ## This is disabled right now because it is too slow. + ## format_yamls!(yamlfiles) return 0 end From 110a63c606ffcc40a1edeabe6f7fc46158469957 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Sun, 22 Feb 2026 23:11:34 -0500 Subject: [PATCH 09/14] Simplify precompilation workflow --- src/precompile_workload.jl | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/precompile_workload.jl b/src/precompile_workload.jl index f9fd0af..e5312cd 100644 --- a/src/precompile_workload.jl +++ b/src/precompile_workload.jl @@ -16,26 +16,10 @@ using PrecompileTools: @compile_workload, @setup_workload "name = \"Example\"\nuuid = \"00000000-0000-0000-0000-000000000000\"\nversion = \"0.1.0\"\n" ) - # Copy the package's real docs/make_readme.jl into tmp/docs/ - pkgroot = pkgdir(@__MODULE__) # ITensorFormatter package root - cp( - joinpath(pkgroot, "docs", "make_readme.jl"), - joinpath(tmp, "docs", "make_readme.jl"); - force = true - ) - - # Provide tmp/examples/README.jl for Literate to convert -> tmp/README.md - cp( - joinpath(pkgroot, "examples", "README.jl"), - joinpath(tmp, "examples", "README.jl"); - force = true - ) - @compile_workload begin # Ideally we might use `ITensorPkgFormatter.main([tmp])` to include - # precompilation of README generation, but some of that code seems to be - # problematic for precompilation because of some usage of `eval`, maybe - # in `include`. + # precompilation of README generation, however it seems tricky to get that + # working because of the file generation involved in that workflow. main([tmp]) end finally From 0ec51d197b9f39d470d3cd62f8cc2a8cc81e9cdb Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 23 Feb 2026 15:49:46 -0500 Subject: [PATCH 10/14] Add optional YAML formatting --- src/main.jl | 39 ++++++++++++++++++++++----------------- test/test_basics.jl | 15 +++++++++++++++ 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/main.jl b/src/main.jl index 43ba8ce..2719935 100644 --- a/src/main.jl +++ b/src/main.jl @@ -87,6 +87,9 @@ function print_help() --version Print ITensorFormatter and julia version information. + + --yaml + Also format YAML files (*.yml, *.yaml). Disabled by default. """ ) return @@ -103,20 +106,23 @@ end function process_args(argv) format = true + format_yaml = false argv_options = filter(startswith("--"), argv) - if !isempty(argv_options) - if "--help" in argv_options - print_help() - return String[], !format - elseif "--version" in argv_options - print_version() - return String[], !format - else - return error("Options not supported: `$argv_options`.") - end + + if "--help" in argv_options + print_help() + return (; paths = String[], format = false, format_yaml = false) + elseif "--version" in argv_options + print_version() + return (; paths = String[], format = false, format_yaml = false) end - # `argv` doesn't have any options, so treat all arguments as file/directory paths. - return argv, format + + format_yaml = "--yaml" ∈ argv_options + unknown = setdiff(argv_options, ["--yaml"]) + !isempty(unknown) && error("Options not supported: `$unknown`.") + + paths = filter(x -> !startswith(x, "--"), argv) + return (; paths, format, format_yaml) end """ @@ -138,11 +144,11 @@ julia> ITensorFormatter.main(["file1.jl", "file2.jl"]); ``` """ function main(argv) - paths, format = process_args(argv) + (; paths, format, format_yaml) = process_args(argv) !format && return 0 isempty(paths) && return error("No input paths provided.") jlfiles = filterpaths(isjlfile, paths) - yamlfiles = filterpaths(isyamlfile, paths) + yamlfiles = format_yaml ? filterpaths(isyamlfile, paths) : String[] projectomls = filterpaths(isprojecttoml, paths) # Pass 1: Organize import/using blocks format_imports!(jlfiles) @@ -152,9 +158,8 @@ function main(argv) format_runic!(jlfiles) # Pass 4: Format Project.toml files format_project_tomls!(projectomls) - # Pass 5: Format YAML files - ## This is disabled right now because it is too slow. - ## format_yamls!(yamlfiles) + # Pass 5: Format YAML files (optional) + format_yaml && format_yamls!(yamlfiles) return 0 end diff --git a/test/test_basics.jl b/test/test_basics.jl index f4118c8..9e6eeb6 100644 --- a/test/test_basics.jl +++ b/test/test_basics.jl @@ -196,6 +196,21 @@ end @test_throws ErrorException ITensorFormatter.main(["--bad"]) end + @testset "--yaml gates YAML parsing/formatting" begin + mktempdir() do dir + # Intentionally invalid YAML so we can detect whether YAML formatting ran. + ypath = joinpath(dir, "bad.yaml") + write(ypath, "a: [\n") + + # Default: YAML formatting is off, so this should succeed. + ret = @suppress ITensorFormatter.main([dir]) + @test ret == 0 + + # Opt-in: should attempt YAML parsing and throw. + @test_throws Exception ITensorFormatter.main(["--yaml", dir]) + end + end + @testset "no arguments" begin @test_throws ErrorException ITensorFormatter.main(String[]) end From f8de6066b9564b589f4cb69731839ca40d476a02 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 23 Feb 2026 16:02:15 -0500 Subject: [PATCH 11/14] Add missing docs --- src/ITensorPkgFormatter.jl | 25 +++++++++++++++++++++++++ src/main.jl | 37 +++++++++++++++++++++---------------- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/ITensorPkgFormatter.jl b/src/ITensorPkgFormatter.jl index a6960b7..9ced3b1 100644 --- a/src/ITensorPkgFormatter.jl +++ b/src/ITensorPkgFormatter.jl @@ -3,6 +3,31 @@ module ITensorPkgFormatter using ITensorFormatter: ITensorFormatter using Logging: Logging +""" + ITensorPkgFormatter.main(argv) + +Format ITensor Julia packages. This function first calls `ITensorFormatter.main(argv)` to format Julia source files, Project.toml, and YAML files, then generates README documentation for each provided ITensor package directory (by running `generate_readme!` in each directory's `docs/`). + +This is typically invoked via the `itpkgfmt` CLI or `julia -m ITensorPkgFormatter`. + +# Arguments + + - `argv`: Array of command-line arguments (paths and options). + +# Behavior + + - All formatting options and help/version flags are forwarded to `ITensorFormatter.main`. + - After formatting, for each path that is an ITensor package directory, a README is generated. + +# Example + +```julia-repl +julia> using ITensorPkgFormatter + +julia> ITensorPkgFormatter.main(["MyPkg"]) + +``` +""" function main(argv) ITensorFormatter.main(argv) paths = filter(!startswith("--"), argv) diff --git a/src/main.jl b/src/main.jl index 2719935..d85a4ca 100644 --- a/src/main.jl +++ b/src/main.jl @@ -61,36 +61,41 @@ function print_help() printstyled(io, "NAME"; bold = true) println(io) println(io, " ITensorFormatter.main - format Julia source code") + println( + io, + " ITensorPkgFormatter.main - format ITensor Julia packages and generate READMEs" + ) println(io) printstyled(io, "SYNOPSIS"; bold = true) println(io) println(io, " julia -m ITensorFormatter [] ...") + println(io, " julia -m ITensorPkgFormatter [] ...") println(io) printstyled(io, "DESCRIPTION"; bold = true) println(io) println( - io, """ - `ITensorFormatter.main` (typically invoked as `julia -m ITensorFormatter`) - formats Julia source code using the ITensorFormatter.jl formatter. + io, """ + `ITensorFormatter.main` (typically invoked as `julia -m ITensorFormatter` or `itfmt`)\n\ + formats Julia source code, Project.toml, and YAML files using the ITensorFormatter.jl formatter.\n\ + \n\ + `ITensorPkgFormatter.main` (typically invoked as `julia -m ITensorPkgFormatter` or `itpkgfmt`)\n\ + performs all formatting as above, and additionally generates README documentation for each provided ITensor package directory.\n """ ) printstyled(io, "OPTIONS"; bold = true) println(io) println( - io, """ - ... - Input path(s) (files and/or directories) to process. For directories, - all files (recursively) with the '*.jl' suffix are used as input files. - - --help - Print this message. - - --version - Print ITensorFormatter and julia version information. - - --yaml - Also format YAML files (*.yml, *.yaml). Disabled by default. + io, """ + ...\n\ + Input path(s) (files and/or directories) to process. For directories,\n\ + all files (recursively) with the '*.jl' suffix are used as input files.\n\ + --help\n\ + Print this message.\n\ + --version\n\ + Print ITensorFormatter and julia version information.\n\ + --yaml\n\ + Also format YAML files (*.yml, *.yaml). Disabled by default.\n """ ) return end From 796131aecf086ef0776f609d31b239bd5d4051c4 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 23 Feb 2026 16:17:41 -0500 Subject: [PATCH 12/14] Share more docs --- src/ITensorPkgFormatter.jl | 24 +---------------------- src/main.jl | 39 +++++++++++++++----------------------- 2 files changed, 16 insertions(+), 47 deletions(-) diff --git a/src/ITensorPkgFormatter.jl b/src/ITensorPkgFormatter.jl index 9ced3b1..5f0cdaf 100644 --- a/src/ITensorPkgFormatter.jl +++ b/src/ITensorPkgFormatter.jl @@ -4,29 +4,7 @@ using ITensorFormatter: ITensorFormatter using Logging: Logging """ - ITensorPkgFormatter.main(argv) - -Format ITensor Julia packages. This function first calls `ITensorFormatter.main(argv)` to format Julia source files, Project.toml, and YAML files, then generates README documentation for each provided ITensor package directory (by running `generate_readme!` in each directory's `docs/`). - -This is typically invoked via the `itpkgfmt` CLI or `julia -m ITensorPkgFormatter`. - -# Arguments - - - `argv`: Array of command-line arguments (paths and options). - -# Behavior - - - All formatting options and help/version flags are forwarded to `ITensorFormatter.main`. - - After formatting, for each path that is an ITensor package directory, a README is generated. - -# Example - -```julia-repl -julia> using ITensorPkgFormatter - -julia> ITensorPkgFormatter.main(["MyPkg"]) - -``` +$(ITensorFormatter.help_string()) """ function main(argv) ITensorFormatter.main(argv) diff --git a/src/main.jl b/src/main.jl index d85a4ca..3f5b694 100644 --- a/src/main.jl +++ b/src/main.jl @@ -56,8 +56,7 @@ format_runic!(path::AbstractString) = format_runic!([path]) const ITENSORFORMATTER_VERSION = pkgversion(@__MODULE__) # Print a typical cli program help message -function print_help() - io = stdout +function print_help(io::IO = stdout) printstyled(io, "NAME"; bold = true) println(io) println(io, " ITensorFormatter.main - format Julia source code") @@ -76,11 +75,16 @@ function print_help() println( io, """ - `ITensorFormatter.main` (typically invoked as `julia -m ITensorFormatter` or `itfmt`)\n\ - formats Julia source code, Project.toml, and YAML files using the ITensorFormatter.jl formatter.\n\ - \n\ - `ITensorPkgFormatter.main` (typically invoked as `julia -m ITensorPkgFormatter` or `itpkgfmt`)\n\ - performs all formatting as above, and additionally generates README documentation for each provided ITensor package directory.\n """ + `ITensorFormatter.main` (typically invoked as `julia -m ITensorFormatter` or `itfmt`) + formats Julia source code, Project.toml, and optionally YAML files using the ITensorFormatter.jl formatter. + """ + ) + println( + io, + """ + `ITensorPkgFormatter.main` (typically invoked as `julia -m ITensorPkgFormatter` or `itpkgfmt`) + performs all formatting as above, and additionally generates README documentation for each provided ITensor package directory. + """ ) printstyled(io, "OPTIONS"; bold = true) println(io) @@ -97,9 +101,11 @@ function print_help() --yaml\n\ Also format YAML files (*.yml, *.yaml). Disabled by default.\n """ ) - return + return nothing end +help_string() = sprint(print_help) + function print_version() print(stdout, "itfmt version ") print(stdout, ITENSORFORMATTER_VERSION) @@ -131,22 +137,7 @@ function process_args(argv) end """ - ITensorFormatter.main(argv) - -Format Julia source files. Primarily formats using Runic formatting, but additionally -organizes using/import statements by merging adjacent blocks, sorting modules and symbols, -and line-wrapping. Accepts file paths and directories as arguments. - -# Examples - -```julia-repl -julia> using ITensorFormatter: ITensorFormatter - -julia> ITensorFormatter.main(["."]); - -julia> ITensorFormatter.main(["file1.jl", "file2.jl"]); - -``` +$(help_string()) """ function main(argv) (; paths, format, format_yaml) = process_args(argv) From 606cb252237c505330bb6b440b7f89b2b35879a8 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 23 Feb 2026 16:25:19 -0500 Subject: [PATCH 13/14] Export ITensorPkgFormatter --- src/ITensorFormatter.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ITensorFormatter.jl b/src/ITensorFormatter.jl index d2a4467..7162cf3 100644 --- a/src/ITensorFormatter.jl +++ b/src/ITensorFormatter.jl @@ -1,5 +1,6 @@ module ITensorFormatter +export ITensorPkgFormatter if VERSION >= v"1.11.0-DEV.469" let str = "public main" eval(Meta.parse(str)) From e3b2d249d4db0493f74600d9fa4ada40b85af724 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 23 Feb 2026 16:30:42 -0500 Subject: [PATCH 14/14] Improve docs --- docs/src/reference.md | 2 +- src/ITensorFormatter.jl | 3 +-- src/ITensorPkgFormatter.jl | 2 +- src/main.jl | 11 +++++++++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/src/reference.md b/docs/src/reference.md index 6105143..387feef 100644 --- a/docs/src/reference.md +++ b/docs/src/reference.md @@ -1,5 +1,5 @@ # Reference ```@autodocs -Modules = [ITensorFormatter] +Modules = [ITensorFormatter, ITensorFormatter.ITensorPkgFormatter] ``` diff --git a/src/ITensorFormatter.jl b/src/ITensorFormatter.jl index 7162cf3..776aae1 100644 --- a/src/ITensorFormatter.jl +++ b/src/ITensorFormatter.jl @@ -1,8 +1,7 @@ module ITensorFormatter -export ITensorPkgFormatter if VERSION >= v"1.11.0-DEV.469" - let str = "public main" + let str = "public ITensorPkgFormatter, main" eval(Meta.parse(str)) end end diff --git a/src/ITensorPkgFormatter.jl b/src/ITensorPkgFormatter.jl index 5f0cdaf..c58dc9f 100644 --- a/src/ITensorPkgFormatter.jl +++ b/src/ITensorPkgFormatter.jl @@ -4,7 +4,7 @@ using ITensorFormatter: ITensorFormatter using Logging: Logging """ -$(ITensorFormatter.help_string()) +$(ITensorFormatter.help_markdown()) """ function main(argv) ITensorFormatter.main(argv) diff --git a/src/main.jl b/src/main.jl index 3f5b694..a16919c 100644 --- a/src/main.jl +++ b/src/main.jl @@ -104,7 +104,14 @@ function print_help(io::IO = stdout) return nothing end -help_string() = sprint(print_help) +# One shared generator for the plain-text help +function help_text() + # ensure no ANSI styling sneaks into docstring text + return sprint(io -> print_help(IOContext(io, :color => false))) +end + +# Docstring-friendly wrapper +help_markdown() = "```text\n" * help_text() * "\n```" function print_version() print(stdout, "itfmt version ") @@ -137,7 +144,7 @@ function process_args(argv) end """ -$(help_string()) +$(help_markdown()) """ function main(argv) (; paths, format, format_yaml) = process_args(argv)