Skip to content

Commit 971358a

Browse files
szabo137Uwe Hernandez Acosta
and
Uwe Hernandez Acosta
authored
added formatting and respective workflow (#18)
* added formatting and respective workflow * added info in readme * updated .JuliaFormatter.toml --------- Co-authored-by: Uwe Hernandez Acosta <[email protected]>
1 parent 4fa96cf commit 971358a

File tree

12 files changed

+320
-278
lines changed

12 files changed

+320
-278
lines changed

.JuliaFormatter.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# See https://domluna.github.io/JuliaFormatter.jl/stable/ for a list of options
22
style = "blue"
3-
indent = 4
3+
indent = 2
44
margin = 92
55
normalize_line_endings = "unix"

.formatting/Project.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[deps]
2+
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"

.formatting/format_all.jl

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using JuliaFormatter
2+
3+
# we asume the format_all.jl script is located in QEDbase.jl/.formatting
4+
project_path = Base.Filesystem.joinpath(Base.Filesystem.dirname(Base.source_path()), "..")
5+
6+
not_formatted = format(project_path; verbose=true)
7+
if not_formatted
8+
@info "Formatting verified."
9+
else
10+
@warn "Formatting verification failed: Some files are not properly formatted!"
11+
end
12+
exit(not_formatted ? 0 : 1)

.github/workflows/Formatting.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: formatter
2+
on: [pull_request]
3+
jobs:
4+
formatter:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: checkout repo
8+
uses: actions/checkout@v4
9+
- name: install Julia
10+
uses: julia-actions/setup-julia@v1
11+
with:
12+
version: "1.10"
13+
- name: Install Julia requirements
14+
run: julia --project=${GITHUB_WORKSPACE}/.formatting -e 'import Pkg; Pkg.instantiate()'
15+
- name: Check code style
16+
run: julia --project=${GITHUB_WORKSPACE}/.formatting ${GITHUB_WORKSPACE}/.formatting/format_all.jl

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,18 @@ Base interfaces for four-momenta in high-energy physics.
77
[![Test workflow status](https://github.com/JuliaHEP/LorentzVectorBase.jl/actions/workflows/Test.yml/badge.svg?branch=main)](https://github.com/JuliaHEP/LorentzVectorBase.jl/actions/workflows/Test.yml?query=branch%3Amain)
88
[![Docs workflow Status](https://github.com/JuliaHEP/LorentzVectorBase.jl/actions/workflows/Docs.yml/badge.svg?branch=main)](https://github.com/JuliaHEP/LorentzVectorBase.jl/actions/workflows/Docs.yml?query=branch%3Amain)
99
[![Coverage](https://codecov.io/gh/JuliaHEP/LorentzVectorBase.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/JuliaHEP/LorentzVectorBase.jl)
10+
11+
# Code Formatting
12+
13+
This package follows a standardized formatting configuration to ensure consistency across
14+
the codebase. We enforce these formatting guidelines by running checks on all pull requests
15+
through continuous integration (CI).
16+
17+
To format your code locally and ensure it meets the required standards, you can run the
18+
following command in your terminal:
19+
20+
```bash
21+
julia --project=.formatting -e 'using Pkg; Pkg.instantiate(); include(".formatting/format_all.jl")'
22+
```
23+
24+
This will apply the necessary formatting rules to your code before submission.

docs/make.jl

+14-14
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@ using LorentzVectorBase
22
using Documenter
33

44
DocMeta.setdocmeta!(
5-
LorentzVectorBase, :DocTestSetup, :(using LorentzVectorBase); recursive=true
5+
LorentzVectorBase, :DocTestSetup, :(using LorentzVectorBase); recursive=true
66
)
77

88
const numbered_pages = [
9-
file for file in readdir(joinpath(@__DIR__, "src")) if
10-
file != "index.md" && splitext(file)[2] == ".md"
9+
file for file in readdir(joinpath(@__DIR__, "src")) if
10+
file != "index.md" && splitext(file)[2] == ".md"
1111
]
1212

1313
makedocs(;
14-
modules=[LorentzVectorBase],
15-
authors="Uwe Hernandez Acosta <[email protected]>",
16-
repo="https://github.com/JuliaHEP/LorentzVectorBase.jl/blob/{commit}{path}#{line}",
17-
sitename="LorentzVectorBase.jl",
18-
format=Documenter.HTML(;
19-
canonical="https://JuliaHEP.github.io/LorentzVectorBase.jl",
20-
repolink="https://github.com/JuliaHEP/LorentzVectorBase.jl",
21-
edit_link="main",
22-
assets=String[],
23-
),
24-
pages=["index.md"; numbered_pages],
14+
modules=[LorentzVectorBase],
15+
authors="Uwe Hernandez Acosta <[email protected]>",
16+
repo="https://github.com/JuliaHEP/LorentzVectorBase.jl/blob/{commit}{path}#{line}",
17+
sitename="LorentzVectorBase.jl",
18+
format=Documenter.HTML(;
19+
canonical="https://JuliaHEP.github.io/LorentzVectorBase.jl",
20+
repolink="https://github.com/JuliaHEP/LorentzVectorBase.jl",
21+
edit_link="main",
22+
assets=String[],
23+
),
24+
pages=["index.md"; numbered_pages],
2525
)
2626

2727
deploydocs(; repo="github.com/JuliaHEP/LorentzVectorBase.jl")

src/coordinate_systems/PtEtaPhiM.jl

+46-46
Original file line numberDiff line numberDiff line change
@@ -24,107 +24,107 @@ py(::PtEtaPhiM, v) = pt(v) * sin(phi(v))
2424
pz(::PtEtaPhiM, v) = pt(v) * sinh(eta(v))
2525

2626
function energy(::PtEtaPhiM, mom)
27-
return sqrt(px(mom)^2 + py(mom)^2 + pz(mom)^2 + invariant_mass2(mom))
27+
return sqrt(px(mom)^2 + py(mom)^2 + pz(mom)^2 + invariant_mass2(mom))
2828
end
2929

3030
@inline function spatial_magnitude2(::PtEtaPhiM, mom)
31-
return pt(mom)^2 * (1 + sinh(eta(mom))^2)
31+
return pt(mom)^2 * (1 + sinh(eta(mom))^2)
3232
end
3333

3434
@inline function spatial_magnitude(::PtEtaPhiM, mom)
35-
return sqrt(spatial_magnitude2(mom))
35+
return sqrt(spatial_magnitude2(mom))
3636
end
3737

3838
@inline function mass2(::PtEtaPhiM, mom)
39-
return mass(mom)^2
39+
return mass(mom)^2
4040
end
4141

4242
@inline function boost_beta(::PtEtaPhiM, mom)
43-
en = energy(mom)
44-
rho = spatial_magnitude(mom)
45-
if !iszero(en)
46-
rho / en
47-
elseif iszero(rho)
48-
return zero(rho)
49-
else
50-
throw(
51-
ArgumentError(
52-
"There is no beta for a four-momentum with vanishing time/energy component"
53-
),
54-
)
55-
end
43+
en = energy(mom)
44+
rho = spatial_magnitude(mom)
45+
if !iszero(en)
46+
rho / en
47+
elseif iszero(rho)
48+
return zero(rho)
49+
else
50+
throw(
51+
ArgumentError(
52+
"There is no beta for a four-momentum with vanishing time/energy component"
53+
),
54+
)
55+
end
5656
end
5757

5858
@inline function boost_gamma(::PtEtaPhiM, mom)
59-
return inv(sqrt(one(energy(mom)) - boost_beta(mom)^2))
59+
return inv(sqrt(one(energy(mom)) - boost_beta(mom)^2))
6060
end
6161

6262
########################
6363
# transverse coordinates
6464
########################
6565

6666
@inline function pt2(::PtEtaPhiM, mom)
67-
return pt(mom)^2
67+
return pt(mom)^2
6868
end
6969

7070
@inline function mt2(::PtEtaPhiM, mom)
71-
return energy(mom)^2 - pz(mom)^2
71+
return energy(mom)^2 - pz(mom)^2
7272
end
7373

7474
function mt(::PtEtaPhiM, mom)
75-
mT2 = mt2(mom)
76-
if mT2 < zero(mT2)
77-
# add optional waring: negative transverse mass -> -sqrt(-mT2) is returned.
78-
-sqrt(-mT2)
79-
else
80-
sqrt(mT2)
81-
end
75+
mT2 = mt2(mom)
76+
if mT2 < zero(mT2)
77+
# add optional waring: negative transverse mass -> -sqrt(-mT2) is returned.
78+
-sqrt(-mT2)
79+
else
80+
sqrt(mT2)
81+
end
8282
end
8383

8484
@inline function rapidity(::PtEtaPhiM, mom)
85-
E = energy(mom)
86-
pz1 = pz(mom)
87-
return 0.5 * log((E + pz1) / (E - pz1))
85+
E = energy(mom)
86+
pz1 = pz(mom)
87+
return 0.5 * log((E + pz1) / (E - pz1))
8888
end
8989

9090
#######################
9191
# spherical coordinates
9292
#######################
9393

9494
@inline function polar_angle(::PtEtaPhiM, mom)
95-
xcomp = px(mom)
96-
ycomp = py(mom)
97-
zcomp = pz(mom)
95+
xcomp = px(mom)
96+
ycomp = py(mom)
97+
zcomp = pz(mom)
9898

99-
return if iszero(xcomp) && iszero(ycomp) && iszero(zcomp)
100-
zero(xcomp)
101-
else
102-
atan(transverse_momentum(mom), zcomp)
103-
end
99+
return if iszero(xcomp) && iszero(ycomp) && iszero(zcomp)
100+
zero(xcomp)
101+
else
102+
atan(transverse_momentum(mom), zcomp)
103+
end
104104
end
105105

106106
@inline function cos_theta(::PtEtaPhiM, mom)
107-
r = spatial_magnitude(mom)
108-
return iszero(r) ? one(px(mom)) : pz(mom) / r
107+
r = spatial_magnitude(mom)
108+
return iszero(r) ? one(px(mom)) : pz(mom) / r
109109
end
110110

111111
function cos_phi(::PtEtaPhiM, mom)
112-
pT = pt(mom)
113-
return iszero(pT) ? one(pT) : px(mom) / pT
112+
pT = pt(mom)
113+
return iszero(pT) ? one(pT) : px(mom) / pT
114114
end
115115

116116
function sin_phi(::PtEtaPhiM, mom)
117-
pT = pt(mom)
118-
return iszero(pT) ? zero(pT) : py(mom) / pT
117+
pT = pt(mom)
118+
return iszero(pT) ? zero(pT) : py(mom) / pT
119119
end
120120

121121
########################
122122
# light cone coordinates
123123
########################
124124
@inline function plus_component(::PtEtaPhiM, mom)
125-
return 0.5 * (energy(mom) + pz(mom))
125+
return 0.5 * (energy(mom) + pz(mom))
126126
end
127127

128128
@inline function minus_component(::PtEtaPhiM, mom)
129-
return 0.5 * (energy(mom) - pz(mom))
129+
return 0.5 * (energy(mom) - pz(mom))
130130
end

0 commit comments

Comments
 (0)