Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add format check action - initial repo format #2520

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
15 changes: 5 additions & 10 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
always_for_in = true
always_use_return = true
import_to_using = true
margin = 110
pipe_to_function_call = true
remove_extra_newlines = true
short_to_long_function_def = true
style = "yas"
whitespace_in_kwargs = false
style = "minimal"
whitespace_ops_in_indices = true
whitespace_typedefs = false
whitespace_in_kwargs = true
indent_submodule = true
always_for_in = true
ignore = ["docs", "metrics"]
35 changes: 35 additions & 0 deletions .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: JuliaFormatter

on:
pull_request:
push:
branches: [master]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: julia-actions/setup-julia@latest
with:
version: '1'
- uses: actions/checkout@v4
- name: Install JuliaFormatter and format
run: |
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
julia -e 'using JuliaFormatter; format(".", verbose=true)'
- name: Format check
run: |
julia -e '
out = Cmd(`git diff --name-only`) |> read |> String
if out == ""
exit(0)
else
@error "Some files have not been formatted !!!"
write(stdout, out)
exit(1)
end
'
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

- Add formatter [#2520](https://github.com/MakieOrg/Makie.jl/pull/2520).
- Add `axislegend(ax, "title")` method [#3808](https://github.com/MakieOrg/Makie.jl/pull/3808)
- Improved thread safety of rendering with CairoMakie (independent `Scene`s only) by locking FreeType handles [#3777](https://github.com/MakieOrg/Makie.jl/pull/3777).

Expand Down
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ Please add tests for any new functionality that you want to add.
Makie uses both reference tests that check for visual regressions, and unit tests that check correctness of functions etc.
It is also appreciated if you add docstrings or documentation, and add an entry to the NEWS file.

## Format

A formatter check is used in Makie in order to work with consistent formatting in source files.

Please run the following snippet (maybe multiple times) for the format check to pass in PRs:
```julia
pkg> add JuliaFormatter
julia> using JuliaFormatter
julia> format(".")
```

### Tests

Please ensure locally that your feature works by running the tests.
Expand Down
2 changes: 1 addition & 1 deletion CairoMakie/src/CairoMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using Makie: spaces, is_data_space, is_pixel_space, is_relative_space, is_clip_s
using Makie: numbers_to_colors

# re-export Makie, including deprecated names
for name in names(Makie, all=true)
for name in names(Makie, all = true)
if Base.isexported(Makie, name)
@eval using Makie: $(name)
@eval export $(name)
Expand Down
10 changes: 5 additions & 5 deletions CairoMakie/src/cairo-extension.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ end
function show_glyph(ctx, glyph, x, y)
cg = Ref(CairoGlyph(glyph, x, y))
ccall((:cairo_show_glyphs, Cairo.libcairo),
Nothing, (Ptr{Nothing}, Ptr{CairoGlyph}, Cint),
ctx.ptr, cg, 1)
Nothing, (Ptr{Nothing}, Ptr{CairoGlyph}, Cint),
ctx.ptr, cg, 1)
end

function glyph_path(ctx, glyph, x, y)
cg = Ref(CairoGlyph(glyph, x, y))
ccall((:cairo_glyph_path, Cairo.libcairo),
Nothing, (Ptr{Nothing}, Ptr{CairoGlyph}, Cint),
ctx.ptr, cg, 1)
Nothing, (Ptr{Nothing}, Ptr{CairoGlyph}, Cint),
ctx.ptr, cg, 1)
end

function surface_set_device_scale(surf, device_x_scale, device_y_scale=device_x_scale)
function surface_set_device_scale(surf, device_x_scale, device_y_scale = device_x_scale)
# this sets a scaling factor on the lowest level that is "hidden" so its even
# enabled when the drawing space is reset for strokes
# that means it can be used to increase or decrease the image resolution
Expand Down
16 changes: 8 additions & 8 deletions CairoMakie/src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ function openurl(url::String)
@warn("Can't find a way to open a browser, open $(url) manually!")
end

function Base.display(screen::Screen, scene::Scene; connect=false)
function Base.display(screen::Screen, scene::Scene; connect = false)
# Nothing to do, since drawing is done in the other functions
# TODO write to file and implement upenurl
return screen
end

function Base.display(screen::Screen{IMAGE}, scene::Scene; connect=false)
function Base.display(screen::Screen{IMAGE}, scene::Scene; connect = false)
path = joinpath(mktempdir(), "display.png")
Makie.push_screen!(scene, screen)
cairo_draw(screen, scene)
Expand Down Expand Up @@ -73,14 +73,14 @@ function Makie.backend_show(screen::Screen{SVG}, io::IO, ::MIME"image/svg+xml",
# across svgs when embedding them on websites.
# the hash and therefore the salt will always be the same for the same file
# so the output is deterministic
salt = repr(CRC32c.crc32c(svg))[end-7:end]
salt = repr(CRC32c.crc32c(svg))[(end - 7):end]

# matches:
# id="someid"
# xlink:href="someid" (but not xlink:href="data:someothercontent" which is how image data is attached)
# url(#someid)
svg = replace(svg, r"((?:(?:id|xlink:href)=\"(?!data:)[^\"]+)|url\(#[^)]+)" => SubstitutionString("\\1-$salt"))

print(io, svg)
return screen
end
Expand Down Expand Up @@ -110,7 +110,7 @@ end

const DISABLED_MIMES = Set{String}()
const SUPPORTED_MIMES = Set([
map(x->string(x()), Makie.WEB_MIMES)...,
map(x -> string(x()), Makie.WEB_MIMES)...,
"image/svg+xml",
"application/pdf",
"application/postscript",
Expand All @@ -127,7 +127,7 @@ end

Converts anything like `"png", :png, "image/png", MIME"image/png"()` to `"image/png"`.
"""
function to_mime_string(mime::Union{String, Symbol, MIME})
function to_mime_string(mime::Union{String,Symbol,MIME})
t-bltg marked this conversation as resolved.
Show resolved Hide resolved
if mime isa MIME
mime_str = string(mime)
if !(mime_str in SUPPORTED_MIMES)
Expand All @@ -150,7 +150,7 @@ The default is automatic, which lets the display system figure out the best mime
If set to any other valid mime, will result in `showable(any_other_mime, figurelike)` to return false and only return true for `showable(preferred_mime, figurelike)`.
Depending on the display system used, this may result in nothing getting displayed.
"""
function disable_mime!(mimes::Union{String, Symbol, MIME}...)
function disable_mime!(mimes::Union{String,Symbol,MIME}...)
empty!(DISABLED_MIMES) # always start from 0
if isempty(mimes)
# Reset disabled mimes when called with no arguments
Expand All @@ -164,7 +164,7 @@ function disable_mime!(mimes::Union{String, Symbol, MIME}...)
return
end

function enable_only_mime!(mimes::Union{String, Symbol, MIME}...)
function enable_only_mime!(mimes::Union{String,Symbol,MIME}...)
empty!(DISABLED_MIMES) # always start from 0
if isempty(mimes)
# Reset disabled mimes when called with no arguments
Expand Down
4 changes: 2 additions & 2 deletions CairoMakie/src/infrastructure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ function draw_background(screen::Screen, scene::Scene)
Cairo.save(cr)
if scene.clear[]
bg = scene.backgroundcolor[]
Cairo.set_source_rgba(cr, red(bg), green(bg), blue(bg), alpha(bg));
Cairo.set_source_rgba(cr, red(bg), green(bg), blue(bg), alpha(bg))
r = viewport(scene)[]
Cairo.rectangle(cr, origin(r)..., widths(r)...) # background
fill(cr)
end
Cairo.restore(cr)
foreach(child_scene-> draw_background(screen, child_scene), scene.children)
foreach(child_scene -> draw_background(screen, child_scene), scene.children)
end

function draw_plot(scene::Scene, screen::Screen, primitive::Plot)
Expand Down
22 changes: 11 additions & 11 deletions CairoMakie/src/overrides.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ function draw_plot(scene::Scene, screen::Screen, poly::Poly)
# so, we should also take a look at converted
# First, we check whether a `draw_poly` method exists for the input arguments
# before conversion:
return if Base.hasmethod(draw_poly, Tuple{Scene, Screen, typeof(poly), typeof.(to_value.(poly.args))...})
return if Base.hasmethod(draw_poly, Tuple{Scene,Screen,typeof(poly),typeof.(to_value.(poly.args))...})
draw_poly(scene, screen, poly, to_value.(poly.args)...)
# If not, we check whether a `draw_poly` method exists for the arguments after conversion
# (`plot.converted`). This allows anything which decomposes to be checked for.
elseif Base.hasmethod(draw_poly, Tuple{Scene, Screen, typeof(poly), typeof.(to_value.(poly.converted))...})
# If not, we check whether a `draw_poly` method exists for the arguments after conversion
# (`plot.converted`). This allows anything which decomposes to be checked for.
elseif Base.hasmethod(draw_poly, Tuple{Scene,Screen,typeof(poly),typeof.(to_value.(poly.converted))...})
draw_poly(scene, screen, poly, to_value.(poly.converted)...)
# In the worst case, we return to drawing the polygon as a mesh + lines.
# In the worst case, we return to drawing the polygon as a mesh + lines.
else
draw_poly_as_mesh(scene, screen, poly)
end
Expand Down Expand Up @@ -49,8 +49,8 @@ function draw_poly(scene::Scene, screen::Screen, poly, points::Vector{<:Point2})
end

# when color is a Makie.AbstractPattern, we don't need to go to Mesh
function draw_poly(scene::Scene, screen::Screen, poly, points::Vector{<:Point2}, color::Union{Colorant, Cairo.CairoPattern},
model, strokecolor, strokestyle, strokewidth)
function draw_poly(scene::Scene, screen::Screen, poly, points::Vector{<:Point2}, color::Union{Colorant,Cairo.CairoPattern},
model, strokecolor, strokestyle, strokewidth)
space = to_value(get(poly, :space, :data))
points = project_position.(Ref(poly), space, points, Ref(model))
Cairo.move_to(screen.context, points[1]...)
Expand All @@ -75,7 +75,7 @@ function draw_poly(scene::Scene, screen::Screen, poly, points_list::Vector{<:Vec

broadcast_foreach(points_list, color,
strokecolor, strokestyle, poly.strokewidth[], Ref(poly.model[])) do points, color, strokecolor, strokestyle, strokewidth, model
draw_poly(scene, screen, poly, points, color, model, strokecolor, strokestyle, strokewidth)
draw_poly(scene, screen, poly, points, color, model, strokecolor, strokestyle, strokewidth)
end
end

Expand Down Expand Up @@ -180,7 +180,7 @@ function draw_poly(scene::Scene, screen::Screen, poly, polygons::AbstractArray{<

end

function draw_poly(scene::Scene, screen::Screen, poly, polygons::AbstractArray{<: MultiPolygon})
function draw_poly(scene::Scene, screen::Screen, poly, polygons::AbstractArray{<:MultiPolygon})
model = poly.model[]
space = to_value(get(poly, :space, :data))
projected_polys = project_multipolygon.(Ref(poly), space, polygons, Ref(model))
Expand Down Expand Up @@ -210,7 +210,7 @@ end
################################################################################

function draw_plot(scene::Scene, screen::Screen,
band::Band{<:Tuple{<:AbstractVector{<:Point2},<:AbstractVector{<:Point2}}})
band::Band{<:Tuple{<:AbstractVector{<:Point2},<:AbstractVector{<:Point2}}})

if !(band.color[] isa AbstractArray)
color = to_cairo_color(band.color[], band)
Expand Down Expand Up @@ -262,7 +262,7 @@ function draw_plot(scene::Scene, screen::Screen, tric::Tricontourf)
function draw_tripolys(polys, colornumbers, colors)
for (i, (pol, colnum, col)) in enumerate(zip(polys, colornumbers, colors))
polypath(screen.context, pol)
if i == length(colornumbers) || colnum != colornumbers[i+1]
if i == length(colornumbers) || colnum != colornumbers[i + 1]
set_source(screen.context, col)
Cairo.fill(screen.context)
end
Expand Down
10 changes: 5 additions & 5 deletions CairoMakie/src/precompiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ let
end
end
precompile(draw_atomic_scatter, (Scene, Cairo.CairoContext, Tuple{typeof(identity),typeof(identity)},
Vector{ColorTypes.RGBA{Float32}}, Vec{2,Float32}, ColorTypes.RGBA{Float32},
Float32, BezierPath, Vec{2,Float32}, Quaternionf,
Mat4f, Vector{Point{2,Float32}},
Mat4f, Makie.FreeTypeAbstraction.FTFont, Symbol,
Symbol))
Vector{ColorTypes.RGBA{Float32}}, Vec{2,Float32}, ColorTypes.RGBA{Float32},
Float32, BezierPath, Vec{2,Float32}, Quaternionf,
Mat4f, Vector{Point{2,Float32}},
Mat4f, Makie.FreeTypeAbstraction.FTFont, Symbol,
Symbol))
Loading
Loading