diff --git a/.JuliaFormatter.toml b/.JuliaFormatter.toml deleted file mode 100644 index 4c49a86..0000000 --- a/.JuliaFormatter.toml +++ /dev/null @@ -1,3 +0,0 @@ -# See https://domluna.github.io/JuliaFormatter.jl/stable/ for a list of options -style = "blue" -indent = 2 diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml index 456fa05..0614de9 100644 --- a/.github/workflows/CompatHelper.yml +++ b/.github/workflows/CompatHelper.yml @@ -2,7 +2,7 @@ name: "CompatHelper" on: schedule: - - cron: 0 0 * * * + - cron: '0 0 * * *' workflow_dispatch: permissions: contents: write diff --git a/.github/workflows/FormatCheck.yml b/.github/workflows/FormatCheck.yml index 3f78afc..1525861 100644 --- a/.github/workflows/FormatCheck.yml +++ b/.github/workflows/FormatCheck.yml @@ -1,11 +1,14 @@ name: "Format Check" on: - push: - branches: - - 'main' - tags: '*' - pull_request: + pull_request_target: + paths: ['**/*.jl'] + types: [opened, synchronize, reopened, ready_for_review] + +permissions: + contents: read + actions: write + pull-requests: write jobs: format-check: diff --git a/.gitignore b/.gitignore index 10593a9..7085ca8 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,10 @@ .vscode/ Manifest.toml benchmark/*.json +dev/ +docs/LocalPreferences.toml docs/Manifest.toml docs/build/ docs/src/index.md +examples/LocalPreferences.toml +test/LocalPreferences.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 88bc8b4..3fc4743 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ ci: - skip: [julia-formatter] + skip: [runic] repos: - repo: https://github.com/pre-commit/pre-commit-hooks @@ -11,7 +11,7 @@ repos: - id: end-of-file-fixer exclude_types: [markdown] # incompatible with Literate.jl -- repo: "https://github.com/domluna/JuliaFormatter.jl" - rev: v2.1.6 +- repo: https://github.com/fredrikekre/runic-pre-commit + rev: v2.0.1 hooks: - - id: "julia-formatter" + - id: runic diff --git a/Project.toml b/Project.toml index 1aa94e6..8818940 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "UnspecifiedTypes" uuid = "42b3faec-625b-4613-8ddc-352bf9672b8d" authors = ["ITensor developers and contributors"] -version = "0.1.6" +version = "0.1.7" [compat] julia = "1.10" diff --git a/docs/make.jl b/docs/make.jl index 44ec616..2a0c72a 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -2,23 +2,23 @@ using UnspecifiedTypes: UnspecifiedTypes using Documenter: Documenter, DocMeta, deploydocs, makedocs DocMeta.setdocmeta!( - UnspecifiedTypes, :DocTestSetup, :(using UnspecifiedTypes); recursive=true + UnspecifiedTypes, :DocTestSetup, :(using UnspecifiedTypes); recursive = true ) include("make_index.jl") makedocs(; - modules=[UnspecifiedTypes], - authors="ITensor developers and contributors", - sitename="UnspecifiedTypes.jl", - format=Documenter.HTML(; - canonical="https://itensor.github.io/UnspecifiedTypes.jl", - edit_link="main", - assets=["assets/favicon.ico", "assets/extras.css"], - ), - pages=["Home" => "index.md", "Reference" => "reference.md"], + modules = [UnspecifiedTypes], + authors = "ITensor developers and contributors", + sitename = "UnspecifiedTypes.jl", + format = Documenter.HTML(; + canonical = "https://itensor.github.io/UnspecifiedTypes.jl", + edit_link = "main", + assets = ["assets/favicon.ico", "assets/extras.css"], + ), + pages = ["Home" => "index.md", "Reference" => "reference.md"], ) deploydocs(; - repo="github.com/ITensor/UnspecifiedTypes.jl", devbranch="main", push_preview=true + repo = "github.com/ITensor/UnspecifiedTypes.jl", devbranch = "main", push_preview = true ) diff --git a/docs/make_index.jl b/docs/make_index.jl index dc07df2..ae2b8aa 100644 --- a/docs/make_index.jl +++ b/docs/make_index.jl @@ -2,20 +2,20 @@ using Literate: Literate using UnspecifiedTypes: UnspecifiedTypes function ccq_logo(content) - include_ccq_logo = """ + include_ccq_logo = """ ```@raw html Flatiron Center for Computational Quantum Physics logo. Flatiron Center for Computational Quantum Physics logo. ``` """ - content = replace(content, "{CCQ_LOGO}" => include_ccq_logo) - return content + content = replace(content, "{CCQ_LOGO}" => include_ccq_logo) + return content end Literate.markdown( - joinpath(pkgdir(UnspecifiedTypes), "examples", "README.jl"), - joinpath(pkgdir(UnspecifiedTypes), "docs", "src"); - flavor=Literate.DocumenterFlavor(), - name="index", - postprocess=ccq_logo, + joinpath(pkgdir(UnspecifiedTypes), "examples", "README.jl"), + joinpath(pkgdir(UnspecifiedTypes), "docs", "src"); + flavor = Literate.DocumenterFlavor(), + name = "index", + postprocess = ccq_logo, ) diff --git a/docs/make_readme.jl b/docs/make_readme.jl index 7630ada..5065491 100644 --- a/docs/make_readme.jl +++ b/docs/make_readme.jl @@ -2,20 +2,20 @@ using Literate: Literate using UnspecifiedTypes: UnspecifiedTypes function ccq_logo(content) - include_ccq_logo = """ + include_ccq_logo = """ Flatiron Center for Computational Quantum Physics logo. """ - content = replace(content, "{CCQ_LOGO}" => include_ccq_logo) - return content + content = replace(content, "{CCQ_LOGO}" => include_ccq_logo) + return content end Literate.markdown( - joinpath(pkgdir(UnspecifiedTypes), "examples", "README.jl"), - joinpath(pkgdir(UnspecifiedTypes)); - flavor=Literate.CommonMarkFlavor(), - name="README", - postprocess=ccq_logo, + joinpath(pkgdir(UnspecifiedTypes), "examples", "README.jl"), + joinpath(pkgdir(UnspecifiedTypes)); + flavor = Literate.CommonMarkFlavor(), + name = "README", + postprocess = ccq_logo, ) diff --git a/examples/README.jl b/examples/README.jl index fb881e4..1a9fbf3 100644 --- a/examples/README.jl +++ b/examples/README.jl @@ -1,5 +1,5 @@ # # UnspecifiedTypes.jl -# +# # [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://itensor.github.io/UnspecifiedTypes.jl/stable/) # [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://itensor.github.io/UnspecifiedTypes.jl/dev/) # [![Build Status](https://github.com/ITensor/UnspecifiedTypes.jl/actions/workflows/Tests.yml/badge.svg?branch=main)](https://github.com/ITensor/UnspecifiedTypes.jl/actions/workflows/Tests.yml?query=branch%3Amain) diff --git a/src/unspecifiedarray.jl b/src/unspecifiedarray.jl index e47e983..427bd9a 100644 --- a/src/unspecifiedarray.jl +++ b/src/unspecifiedarray.jl @@ -1 +1 @@ -struct UnspecifiedArray{ElT,N} <: AbstractArray{ElT,N} end +struct UnspecifiedArray{ElT, N} <: AbstractArray{ElT, N} end diff --git a/src/unspecifiednumber.jl b/src/unspecifiednumber.jl index 62851c7..afa8f46 100644 --- a/src/unspecifiednumber.jl +++ b/src/unspecifiednumber.jl @@ -1,18 +1,18 @@ abstract type AbstractUnspecifiedNumber <: Number end -struct UnspecifiedNumber{T<:Number} <: AbstractUnspecifiedNumber - value::T - global @inline function _UnspecifiedNumber(value::Number) - return new{typeof(value)}(value) - end +struct UnspecifiedNumber{T <: Number} <: AbstractUnspecifiedNumber + value::T + global @inline function _UnspecifiedNumber(value::Number) + return new{typeof(value)}(value) + end end UnspecifiedNumber(n::Number) = _UnspecifiedNumber(n) -UnspecifiedNumber{T}(n::Number) where {T<:Number} = UnspecifiedNumber(convert(T, n)) +UnspecifiedNumber{T}(n::Number) where {T <: Number} = UnspecifiedNumber(convert(T, n)) -UnspecifiedNumber{T}(n::UnspecifiedNumber{T}) where {T<:Number} = n +UnspecifiedNumber{T}(n::UnspecifiedNumber{T}) where {T <: Number} = n # Fix ambiguity error. -function UnspecifiedNumber{T}(n::Base.TwicePrecision) where {T<:Number} - return UnspecifiedNumber(convert(T, n)) +function UnspecifiedNumber{T}(n::Base.TwicePrecision) where {T <: Number} + return UnspecifiedNumber(convert(T, n)) end diff --git a/src/unspecifiedzero.jl b/src/unspecifiedzero.jl index adf81fd..8a986c3 100644 --- a/src/unspecifiedzero.jl +++ b/src/unspecifiedzero.jl @@ -10,7 +10,7 @@ Base.zero(n::UnspecifiedZero) = zero(typeof(n)) # This helps handle a lot of basic algebra, like: # UnspecifiedZero() + 2.3 == 2.3 -Base.convert(::Type{T}, x::UnspecifiedZero) where {T<:Number} = T(zero(T)) +Base.convert(::Type{T}, x::UnspecifiedZero) where {T <: Number} = T(zero(T)) #Base.convert(::Type{Complex{UnspecifiedZero}}, x::UnspecifiedZero) = complex(x) diff --git a/test/runtests.jl b/test/runtests.jl index e2c9599..39c332d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,58 +6,60 @@ using Suppressor: Suppressor const pat = r"(?:--group=)(\w+)" arg_id = findfirst(contains(pat), ARGS) const GROUP = uppercase( - if isnothing(arg_id) - get(ENV, "GROUP", "ALL") - else - only(match(pat, ARGS[arg_id]).captures) - end, + if isnothing(arg_id) + get(ENV, "GROUP", "ALL") + else + only(match(pat, ARGS[arg_id]).captures) + end, ) "match files of the form `test_*.jl`, but exclude `*setup*.jl`" function istestfile(fn) - return endswith(fn, ".jl") && startswith(basename(fn), "test_") && !contains(fn, "setup") + return endswith(fn, ".jl") && startswith(basename(fn), "test_") && !contains(fn, "setup") end "match files of the form `*.jl`, but exclude `*_notest.jl` and `*setup*.jl`" function isexamplefile(fn) - return endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup") + return endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup") end @time begin - # tests in groups based on folder structure - for testgroup in filter(isdir, readdir(@__DIR__)) - if GROUP == "ALL" || GROUP == uppercase(testgroup) - for file in filter(istestfile, readdir(joinpath(@__DIR__, testgroup); join=true)) - @eval @safetestset $file begin - include($file) + # tests in groups based on folder structure + for testgroup in filter(isdir, readdir(@__DIR__)) + if GROUP == "ALL" || GROUP == uppercase(testgroup) + for file in filter(istestfile, readdir(joinpath(@__DIR__, testgroup); join = true)) + @eval @safetestset $file begin + include($file) + end + end end - end end - end - # single files in top folder - for file in filter(istestfile, readdir(@__DIR__)) - (file == basename(@__FILE__)) && continue # exclude this file to avoid infinite recursion - @eval @safetestset $file begin - include($file) + # single files in top folder + for file in filter(istestfile, readdir(@__DIR__)) + (file == basename(@__FILE__)) && continue # exclude this file to avoid infinite recursion + @eval @safetestset $file begin + include($file) + end end - end - # test examples - examplepath = joinpath(@__DIR__, "..", "examples") - for (root, _, files) in walkdir(examplepath) - contains(chopprefix(root, @__DIR__), "setup") && continue - for file in filter(isexamplefile, files) - filename = joinpath(root, file) - @eval begin - @safetestset $file begin - $(Expr( - :macrocall, - GlobalRef(Suppressor, Symbol("@suppress")), - LineNumberNode(@__LINE__, @__FILE__), - :(include($filename)), - )) + # test examples + examplepath = joinpath(@__DIR__, "..", "examples") + for (root, _, files) in walkdir(examplepath) + contains(chopprefix(root, @__DIR__), "setup") && continue + for file in filter(isexamplefile, files) + filename = joinpath(root, file) + @eval begin + @safetestset $file begin + $( + Expr( + :macrocall, + GlobalRef(Suppressor, Symbol("@suppress")), + LineNumberNode(@__LINE__, @__FILE__), + :(include($filename)), + ) + ) + end + end end - end end - end end diff --git a/test/test_aqua.jl b/test/test_aqua.jl index 8803cd3..5d7a146 100644 --- a/test/test_aqua.jl +++ b/test/test_aqua.jl @@ -3,5 +3,5 @@ using Aqua: Aqua using Test: @testset @testset "Code quality (Aqua.jl)" begin - Aqua.test_all(UnspecifiedTypes) + Aqua.test_all(UnspecifiedTypes) end diff --git a/test/test_basics.jl b/test/test_basics.jl index 25c0bd0..ea85dc6 100644 --- a/test/test_basics.jl +++ b/test/test_basics.jl @@ -2,20 +2,20 @@ using UnspecifiedTypes: UnspecifiedZero using Test: @testset, @test @testset "UnspecifiedTypes (eltype=$elt)" for elt in ( - Float32, Float64, Complex{Float32}, Complex{Float64} -) - for x in (elt(2) + UnspecifiedZero(), UnspecifiedZero() + elt(2)) - @test x isa elt - @test x === elt(2) - end + Float32, Float64, Complex{Float32}, Complex{Float64}, + ) + for x in (elt(2) + UnspecifiedZero(), UnspecifiedZero() + elt(2)) + @test x isa elt + @test x === elt(2) + end - for x in (elt(2) * UnspecifiedZero(), UnspecifiedZero() * elt(2)) - @test x isa UnspecifiedZero - @test x === UnspecifiedZero() - end + for x in (elt(2) * UnspecifiedZero(), UnspecifiedZero() * elt(2)) + @test x isa UnspecifiedZero + @test x === UnspecifiedZero() + end - # Normally, any number type takes precedence over - # `Bool`, check this isn't the case with `UnspecifiedZero`. - @test promote_type(UnspecifiedZero, Bool) === Bool - @test promote_type(Bool, UnspecifiedZero) === Bool + # Normally, any number type takes precedence over + # `Bool`, check this isn't the case with `UnspecifiedZero`. + @test promote_type(UnspecifiedZero, Bool) === Bool + @test promote_type(Bool, UnspecifiedZero) === Bool end