Skip to content

Commit 137f91b

Browse files
leburgellkdvos
andauthored
Switch to Runic formatter (#60)
* Switch to Runic formatter * manual formatting changes * remove .JuliaFormatter * add pre-commit hook --------- Co-authored-by: Lukas Devos <[email protected]>
1 parent 750770a commit 137f91b

34 files changed

+889
-789
lines changed

.JuliaFormatter.toml

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/FormatCheck.yml

Lines changed: 11 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,15 @@
1-
name: FormatCheck
1+
name: 'Format'
22

33
on:
4-
push:
5-
branches:
6-
- 'main'
7-
- 'master'
8-
- 'release-'
9-
tags: '*'
10-
pull_request:
4+
pull_request_target:
5+
paths: ['**/*.jl']
6+
types: [opened, synchronize, reopened, ready_for_review]
117

12-
jobs:
13-
build:
14-
runs-on: ${{ matrix.os }}
15-
strategy:
16-
matrix:
17-
version:
18-
- '1' # automatically expands to the latest stable 1.x release of Julia
19-
os:
20-
- ubuntu-latest
21-
arch:
22-
- x64
23-
steps:
24-
- uses: julia-actions/setup-julia@latest
25-
with:
26-
version: ${{ matrix.version }}
27-
arch: ${{ matrix.arch }}
28-
29-
- uses: actions/checkout@v5
30-
- name: Install JuliaFormatter and format
31-
run: |
32-
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="v1"))'
33-
julia -e 'using JuliaFormatter; format(".", verbose=true)'
34-
- name: Format check
35-
id: format
36-
run: |
37-
julia -e '
38-
out = Cmd(`git diff --name-only`) |> read |> String
39-
if out == ""
40-
exit(0)
41-
else
42-
@error "Some files have not been formatted !!!"
43-
write(stdout, out)
44-
exit(1)
45-
end'
46-
- name: Create pull request
47-
if: ${{ failure() && steps.format.conclusion == 'failure' }}
48-
id: cpr
49-
uses: peter-evans/create-pull-request@v7
50-
with:
51-
token: ${{ secrets.GITHUB_TOKEN }}
52-
commit-message: Format .jl files
53-
title: 'Automatic JuliaFormatter.jl run'
54-
base: ${{ github.head_ref }}
55-
branch: auto-juliaformatter-pr
56-
delete-branch: true
57-
labels: formatting, automated pr, no changelog
8+
permissions:
9+
contents: read
10+
actions: write
11+
pull-requests: write
5812

59-
- name: Check outputs
60-
if: ${{ success() && steps.cpr.conclusion == 'success' }}
61-
run: |
62-
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
63-
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
13+
jobs:
14+
formatcheck:
15+
uses: "QuantumKitHub/QuantumKitHubActions/.github/workflows/FormatCheck.yml@main"

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
repos:
2+
- repo: https://github.com/fredrikekre/runic-pre-commit
3+
rev: v2.0.1
4+
hooks:
5+
- id: runic

docs/make.jl

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
if Base.active_project() != joinpath(@__DIR__, "Project.toml")
33
using Pkg
44
Pkg.activate(@__DIR__)
5-
Pkg.develop(PackageSpec(; path=(@__DIR__) * "/../"))
5+
Pkg.develop(PackageSpec(; path = (@__DIR__) * "/../"))
66
Pkg.resolve()
77
Pkg.instantiate()
88
end
@@ -11,18 +11,24 @@ using Documenter
1111
using MPSKitModels
1212

1313
makedocs(;
14-
modules=[MPSKitModels],
15-
sitename="MPSKitModels.jl",
16-
authors="Maarten Vandamme",
17-
format=Documenter.HTML(;
18-
prettyurls=get(ENV, "CI", nothing) == "true",
19-
mathengine=MathJax()),
20-
pages=["Home" => "index.md",
21-
"Manual" => ["man/operators.md",
22-
"man/mpoham.md",
23-
"man/lattices.md",
24-
"man/models.md"],
25-
"Index" => "package_index.md"],
26-
checkdocs=:public)
14+
modules = [MPSKitModels],
15+
sitename = "MPSKitModels.jl",
16+
authors = "Maarten Vandamme",
17+
format = Documenter.HTML(;
18+
prettyurls = get(ENV, "CI", nothing) == "true",
19+
mathengine = MathJax()
20+
),
21+
pages = [
22+
"Home" => "index.md",
23+
"Manual" => [
24+
"man/operators.md",
25+
"man/mpoham.md",
26+
"man/lattices.md",
27+
"man/models.md",
28+
],
29+
"Index" => "package_index.md",
30+
],
31+
checkdocs = :public
32+
)
2733

28-
deploydocs(; repo="github.com/QuantumKitHub/MPSKitModels.jl.git")
34+
deploydocs(; repo = "github.com/QuantumKitHub/MPSKitModels.jl.git")

src/lattices/chains.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A one dimensional infinite lattice with a unit cell containing `L` sites.
55
"""
66
struct InfiniteChain <: AbstractLattice{1}
77
L::Int
8-
function InfiniteChain(L::Integer=1)
8+
function InfiniteChain(L::Integer = 1)
99
return L > 0 ? new(L) : error("period should be positive ($L)")
1010
end
1111
end
@@ -19,15 +19,15 @@ A one-dimensional lattice of length `L`
1919
"""
2020
struct FiniteChain <: AbstractLattice{1}
2121
L::Int
22-
function FiniteChain(L::Integer=1)
22+
function FiniteChain(L::Integer = 1)
2323
return L > 0 ? new(L) : error("length should be positive ($L)")
2424
end
2525
end
2626
Base.axes(chain::FiniteChain) = (1:(chain.L),)
2727
Base.isfinite(::Type{FiniteChain}) = true
2828
Base.isfinite(::FiniteChain) = true
2929

30-
const Chain = Union{InfiniteChain,FiniteChain}
30+
const Chain = Union{InfiniteChain, FiniteChain}
3131

3232
vertices(chain::Chain) = LatticePoint.(1:(chain.L), Ref(chain))
3333
nearest_neighbours(chain::InfiniteChain) = map(v -> v => v + 1, vertices(chain))
@@ -44,12 +44,12 @@ function bipartition(chain::Chain)
4444
end
4545

4646
linearize_index(chain::InfiniteChain, i::Int) = i
47-
linearize_index(chain::Chain, i::NTuple{1,Int}) = linearize_index(chain, i...)
47+
linearize_index(chain::Chain, i::NTuple{1, Int}) = linearize_index(chain, i...)
4848
function linearize_index(chain::FiniteChain, i::Int)
4949
0 < i <= chain.L || throw(BoundsError("lattice point out of bounds"))
5050
return i
5151
end
5252

53-
function LinearAlgebra.norm(p::LatticePoint{1,<:Union{FiniteChain,InfiniteChain}})
53+
function LinearAlgebra.norm(p::LatticePoint{1, <:Union{FiniteChain, InfiniteChain}})
5454
return abs(p.coordinates[1])
5555
end

src/lattices/latticepoints.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
44
represents an `N`-dimensional point on a `G` lattice.
55
"""
6-
struct LatticePoint{N,G<:AbstractLattice{N}}
7-
coordinates::NTuple{N,Int}
6+
struct LatticePoint{N, G <: AbstractLattice{N}}
7+
coordinates::NTuple{N, Int}
88
lattice::G
9-
function LatticePoint(coordinates::NTuple{N,Int}, lattice::AbstractLattice{N}) where {N}
9+
function LatticePoint(coordinates::NTuple{N, Int}, lattice::AbstractLattice{N}) where {N}
1010
checkbounds(lattice, coordinates...)
11-
return new{N,typeof(lattice)}(coordinates, lattice)
11+
return new{N, typeof(lattice)}(coordinates, lattice)
1212
end
1313
end
1414

15-
function LatticePoint(ind::Int, lattice::G) where {G<:AbstractLattice{1}}
15+
function LatticePoint(ind::Int, lattice::G) where {G <: AbstractLattice{1}}
1616
return LatticePoint((ind,), lattice)
1717
end
1818

@@ -21,47 +21,47 @@ function Base.show(io::IO, p::LatticePoint)
2121
end
2222

2323
function Base.show(io::IO, ::MIME"text/plain", p::LatticePoint)
24-
if get(io, :typeinfo, Any) === typeof(p)
24+
return if get(io, :typeinfo, Any) === typeof(p)
2525
print(io, [p.coordinates...])
2626
else
2727
print(io, p.lattice, [p.coordinates...])
2828
end
2929
end
3030

31-
function Base.getindex(lattice::AbstractLattice{N}, inds::Vararg{Int,N}) where {N}
31+
function Base.getindex(lattice::AbstractLattice{N}, inds::Vararg{Int, N}) where {N}
3232
return LatticePoint(inds, lattice)
3333
end
3434

3535
Base.to_index(p::LatticePoint) = linearize_index(p)
3636
linearize_index(p::LatticePoint) = linearize_index(p.lattice, p.coordinates...)
3737

38-
function Base.:+(i::LatticePoint{N,G}, j::LatticePoint{N,G}) where {N,G}
38+
function Base.:+(i::LatticePoint{N, G}, j::LatticePoint{N, G}) where {N, G}
3939
i.lattice == j.lattice || throw(ArgumentError("lattices should be equal"))
4040
return LatticePoint(i.coordinates .+ j.coordinates, i.lattice)
4141
end
42-
function Base.:-(i::LatticePoint{N,G}, j::LatticePoint{N,G}) where {N,G}
42+
function Base.:-(i::LatticePoint{N, G}, j::LatticePoint{N, G}) where {N, G}
4343
i.lattice == j.lattice || throw(ArgumentError("lattices should be equal"))
4444
return LatticePoint(i.coordinates .- j.coordinates, i.lattice)
4545
end
4646

47-
function Base.:+(i::LatticePoint{N}, j::NTuple{N,Int}) where {N}
47+
function Base.:+(i::LatticePoint{N}, j::NTuple{N, Int}) where {N}
4848
return LatticePoint(i.coordinates .+ j, i.lattice)
4949
end
5050
Base.:+(i::LatticePoint{1}, j::Int) = LatticePoint(i.coordinates .+ j, i.lattice)
51-
Base.:+(i::NTuple{N,Int}, j::LatticePoint{N}) where {N} = j + i
51+
Base.:+(i::NTuple{N, Int}, j::LatticePoint{N}) where {N} = j + i
5252
Base.:+(i::Int, j::LatticePoint{1}) = j + i
5353

54-
function Base.:-(i::LatticePoint{N}, j::NTuple{N,Int}) where {N}
54+
function Base.:-(i::LatticePoint{N}, j::NTuple{N, Int}) where {N}
5555
return LatticePoint(i.coordinates .- j, i.lattice)
5656
end
5757
Base.:-(i::LatticePoint{1}, j::Int) = LatticePoint(i.coordinates .- j, i.lattice)
58-
function Base.:-(i::NTuple{N,Int}, j::LatticePoint{N}) where {N}
58+
function Base.:-(i::NTuple{N, Int}, j::LatticePoint{N}) where {N}
5959
return LatticePoint(i .- j.coordinates, j.lattice)
6060
end
6161
Base.:-(i::Int, j::LatticePoint{1}) = LatticePoint(i .- j, j.lattice)
6262

63-
Base.isless(i::L, j::L) where {L<:LatticePoint} = linearize_index(i) < linearize_index(j)
64-
function Base.isfinite(::Union{LatticePoint{N,G},Type{<:LatticePoint{N,G}}}) where {N,G}
63+
Base.isless(i::L, j::L) where {L <: LatticePoint} = linearize_index(i) < linearize_index(j)
64+
function Base.isfinite(::Union{LatticePoint{N, G}, Type{<:LatticePoint{N, G}}}) where {N, G}
6565
return isfinite(G)
6666
end
67-
latticetype(::Union{LatticePoint{N,G},Type{<:LatticePoint{N,G}}}) where {N,G} = G
67+
latticetype(::Union{LatticePoint{N, G}, Type{<:LatticePoint{N, G}}}) where {N, G} = G

src/lattices/lattices.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ Base.length(L::AbstractLattice) = length(vertices(L))
4444
Base.isfinite(L::AbstractLattice) = isfinite(typeof(L))
4545
Base.iterate(L::AbstractLattice) = iterate(vertices(L))
4646

47-
function Base.checkbounds(L::AbstractLattice{N}, inds::Vararg{Int,N}) where {N}
47+
function Base.checkbounds(L::AbstractLattice{N}, inds::Vararg{Int, N}) where {N}
4848
return checkbounds(Bool, L, inds...) || throw(BoundsError(L, inds))
4949
end
5050

51-
function Base.checkbounds(::Type{Bool}, L::AbstractLattice{N},
52-
inds::Vararg{Int,N}) where {N}
51+
function Base.checkbounds(
52+
::Type{Bool}, L::AbstractLattice{N},
53+
inds::Vararg{Int, N}
54+
) where {N}
5355
return Base.checkbounds_indices(Bool, axes(L), inds)
5456
end

src/lattices/snakepattern.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
44
Represents a given lattice with a linear order that is provided by `pattern`.
55
"""
6-
struct SnakePattern{N,G<:AbstractLattice{N},F} <: AbstractLattice{N}
6+
struct SnakePattern{N, G <: AbstractLattice{N}, F} <: AbstractLattice{N}
77
lattice::G
88
pattern::F
99
end
1010

1111
SnakePattern(lattice) = SnakePattern(lattice, identity)
1212

1313
Base.axes(lattice::SnakePattern) = axes(lattice.lattice)
14-
Base.isfinite(::Type{SnakePattern{N,G}}) where {N,G} = isfinite(G)
14+
Base.isfinite(::Type{SnakePattern{N, G}}) where {N, G} = isfinite(G)
1515

1616
function linearize_index(snake::SnakePattern, i...)
1717
return snake.pattern(linearize_index(snake.lattice, i...))

0 commit comments

Comments
 (0)