Skip to content

Commit

Permalink
Formatting: format and add CI action (#2511)
Browse files Browse the repository at this point in the history
* Formatting: format and add CI action

* Update to 0.13.2 and fix ret

* Refactor how CI action exits

* Rebase and reformat
  • Loading branch information
odow authored Mar 17, 2021
1 parent 8b13032 commit f6be919
Show file tree
Hide file tree
Showing 49 changed files with 3,428 additions and 1,640 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/format_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: format-check
on:
push:
branches:
- master
- release-*
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: julia-actions/setup-julia@latest
with:
version: '1'
- uses: actions/checkout@v1
- name: Format check
shell: julia --color=yes {0}
run: |
using Pkg
Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.2"))
using JuliaFormatter
format("src", verbose=true)
format("test", verbose=true)
out = String(read(Cmd(`git diff`)))
if isempty(out)
exit(0)
end
@error "Some files have not been formatted !!!"
write(stdout, out)
exit(1)
39 changes: 24 additions & 15 deletions src/Containers/SparseAxisArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@ end
# Error for sa[..., :, ...]
function _colon_error() end
function _colon_error(::Colon, args...)
return throw(ArgumentError(
"Indexing with `:` is not supported by" * " Containers.SparseAxisArray",
))
return throw(
ArgumentError(
"Indexing with `:` is not supported by" *
" Containers.SparseAxisArray",
),
)
end
_colon_error(arg, args...) = _colon_error(args...)

Expand Down Expand Up @@ -140,10 +143,12 @@ Base.Broadcast.newindex(d::SparseAxisArray, idx) = idx

struct BroadcastStyle{N,K} <: Broadcast.BroadcastStyle end
function Base.BroadcastStyle(::BroadcastStyle, ::Base.BroadcastStyle)
return throw(ArgumentError(
"Cannot broadcast Containers.SparseAxisArray with" *
" another array of different type",
))
return throw(
ArgumentError(
"Cannot broadcast Containers.SparseAxisArray with" *
" another array of different type",
),
)
end
# Scalars can be used with SparseAxisArray in broadcast
function Base.BroadcastStyle(
Expand Down Expand Up @@ -171,10 +176,12 @@ function check_same_eachindex(each_index, not_sa, args...)
end
function check_same_eachindex(each_index, sa::SparseAxisArray, args...)
if Set(each_index) != Set(eachindex(sa))
throw(ArgumentError(
"Cannot broadcast Containers.SparseAxisArray with" *
" different indices",
))
throw(
ArgumentError(
"Cannot broadcast Containers.SparseAxisArray with" *
" different indices",
),
)
end
return check_same_eachindex(eachindex, args...)
end
Expand Down Expand Up @@ -277,10 +284,12 @@ function Base.show(io::IOContext, x::SparseAxisArray)
half_screen_rows = limit ? div(displaysize(io)[1] - 8, 2) : typemax(Int)
key_string(key::Tuple) = join(key, ", ")
print_entry(i) = i < half_screen_rows || i > length(x) - half_screen_rows
pad = maximum(Int[
print_entry(i) ? length(key_string(key)) : 0
for (i, key) in enumerate(keys(x.data))
])
pad = maximum(
Int[
print_entry(i) ? length(key_string(key)) : 0 for
(i, key) in enumerate(keys(x.data))
],
)
if !haskey(io, :compact)
io = IOContext(io, :compact => true)
end
Expand Down
14 changes: 8 additions & 6 deletions src/Containers/generate_container.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ function generate_container(T, indexvars, indexsets, requestedtype)
arrayexpr = :(Array{$T}(undef, $sizes...))

if requestedtype == :Array
has_dependent &&
return :(error("Unable to create requested Array because index sets are dependent.")),
true
has_dependent && return :(error(
"Unable to create requested Array because index sets are dependent.",
)),
true
if all(onetosets)
return arrayexpr, true
else
Expand Down Expand Up @@ -137,9 +138,10 @@ function generate_container(T, indexvars, indexsets, requestedtype)
append!(axisexpr.args, indexsets)

if requestedtype == :DenseAxisArray
has_dependent &&
return :(error("Unable to create requested DenseAxisArray because index sets are dependent.")),
true
has_dependent && return :(error(
"Unable to create requested DenseAxisArray because index sets are dependent.",
)),
true
return axisexpr, true
end

Expand Down
10 changes: 6 additions & 4 deletions src/Containers/macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function _parse_ref_sets(_error::Function, expr::Expr)
if idxvar in idxvars
_error(
"The index $(idxvar) appears more than once. The index " *
"associated with each set must be unique."
"associated with each set must be unique.",
)
end
push!(idxvars, idxvar)
Expand All @@ -156,14 +156,16 @@ returns:
function _build_ref_sets(_error::Function, expr)
idxvars, idxsets, condition = _parse_ref_sets(_error, expr)
if any(_expr_is_splat.(idxsets))
_error("cannot use splatting operator `...` in the definition of an index set.")
_error(
"cannot use splatting operator `...` in the definition of an index set.",
)
end
has_dependent = has_dependent_sets(idxvars, idxsets)
if has_dependent || condition != :()
esc_idxvars = esc.(idxvars)
idxfuns = [
:(($(esc_idxvars[1:(i-1)]...),) -> $(idxsets[i]))
for i in 1:length(idxvars)
:(($(esc_idxvars[1:(i-1)]...),) -> $(idxsets[i])) for
i in 1:length(idxvars)
]
if condition == :()
indices = :(Containers.nested($(idxfuns...)))
Expand Down
Loading

0 comments on commit f6be919

Please sign in to comment.