Skip to content

Commit fc5ccb6

Browse files
committed
fixes and formatting
1 parent 4f56398 commit fc5ccb6

14 files changed

Lines changed: 76 additions & 73 deletions

File tree

ext/BlobArrow.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module BlobArrow
22

33
using Arrow
44
using DistributedFactorGraphs
5-
using DistributedFactorGraphs: _MIMEOverrides, format_to_mime
5+
using DistributedFactorGraphs: _MIMEOverrides, getMimetype
66

77
function __init__()
88
@info "Including Arrow blobs support in DFG."
@@ -15,7 +15,7 @@ function DFG.packBlob(::Type{format"Arrow"}, data; kwargs...)
1515
io = IOBuffer()
1616
Arrow.write(io, data; kwargs...)
1717
blob = take!(io)
18-
mimetype = format_to_mime(format"Arrow")
18+
mimetype = getMimetype(format"Arrow")
1919
return blob, mimetype
2020
end
2121

src/Common.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ function Timestamp(epoch::Val{:unix}, t::Float64, zone = tz"UTC")
214214
end
215215
Timestamp(t::Float64, zone = tz"UTC") = Timestamp(Val(:unix), t, zone)
216216
function Timestamp(epoch::Val{:rata}, t::Float64, zone = tz"UTC")
217-
return TimeDateZone(convert(DateTime, Millisecond(t*10^3)), zone)
217+
return TimeDateZone(convert(DateTime, Millisecond(t * 10^3)), zone)
218218
end
219219

220220
function now_tdz(zone = tz"UTC")

src/DataBlobs/entities/BlobEntry.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ StructUtils.@kwarg struct Blobentry
2020
""" (Optional) crc32c hash value to ensure data consistency which must correspond to the stored hash upon retrieval."""
2121
crchash::Union{UInt32, Nothing} =
2222
nothing & (
23-
json=(
24-
lower = h->isnothing(h) ? nothing : string(h, base = 16),
25-
lift = s->isnothing(s) ? nothing : parse(UInt32, s; base = 16),
23+
json = (
24+
lower = h -> isnothing(h) ? nothing : string(h; base = 16),
25+
lift = s -> isnothing(s) ? nothing : parse(UInt32, s; base = 16),
2626
)
2727
)
2828
""" (Optional) sha256 hash value to ensure data consistency which must correspond to the stored hash upon retrieval."""
2929
shahash::Union{Vector{UInt8}, Nothing} =
3030
nothing & (
31-
json=(
32-
lower = h->isnothing(h) ? nothing : bytes2hex(h),
33-
lift = s->isnothing(s) ? nothing : hex2bytes(s),
31+
json = (
32+
lower = h -> isnothing(h) ? nothing : bytes2hex(h),
33+
lift = s -> isnothing(s) ? nothing : hex2bytes(s),
3434
)
3535
)
3636
""" Source system or application where the blob was created (e.g., webapp, sdk, robot)"""
3737
origin::String = ""
3838
"""Number of bytes in blob serialized as a string"""
39-
size::Int64 = -1 & (json=(lower = string, lift = x->parse(Int64, x)))
39+
size::Int64 = -1 & (json = (lower = string, lift = x -> parse(Int64, x)))
4040
""" Additional information that can help a different user of the Blob. """
4141
description::String = ""
4242
""" MIME description describing the format of binary data in the `Blob`, e.g. 'image/png' or 'application/json'. """

src/DataBlobs/services/BlobPacking.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ const _MIMEOverrides = OrderedDict{DataType, MIME}(
1212
)
1313

1414
"""
15-
format_to_mime(::Type{DataFormat{S}}) -> MIME
15+
getMimetype(::Type{DataFormat{S}}) -> MIME
1616
1717
Get the MIME type for a FileIO `DataFormat`. Uses FileIO's extension registry
1818
and MIMEs.jl for standard types, falls back to `_MIMEOverrides` for
1919
domain-specific formats.
2020
2121
# Examples
2222
```julia
23-
format_to_mime(format"PNG") # MIME("image/png")
24-
format_to_mime(format"JSON") # MIME("application/json")
23+
getMimetype(format"PNG") # MIME("image/png")
24+
getMimetype(format"JSON") # MIME("application/json")
2525
```
2626
"""
27-
function format_to_mime(::Type{DataFormat{S}}) where {S}
27+
function getMimetype(::Type{DataFormat{S}}) where {S}
2828
T = DataFormat{S}
2929
haskey(_MIMEOverrides, T) && return _MIMEOverrides[T]
3030
try
@@ -39,7 +39,7 @@ function format_to_mime(::Type{DataFormat{S}}) where {S}
3939
end
4040

4141
"""
42-
mime_to_format(::MIME) -> Union{Type{DataFormat{S}}, Nothing}
42+
getDataFormat(::MIME) -> Union{Type{DataFormat{S}}, Nothing}
4343
4444
Get the FileIO `DataFormat` for a MIME type. Uses MIMEs.jl and FileIO's extension
4545
registry, falls back to `_MIMEOverrides`.
@@ -48,11 +48,11 @@ Returns `nothing` if no matching format is found.
4848
4949
# Examples
5050
```julia
51-
mime_to_format(MIME("image/png")) # format"PNG"
52-
mime_to_format(MIME("application/json")) # format"JSON"
51+
getDataFormat(MIME("image/png")) # format"PNG"
52+
getDataFormat(MIME("application/json")) # format"JSON"
5353
```
5454
"""
55-
function mime_to_format(m::MIME)
55+
function getDataFormat(m::MIME)
5656
for (fmt, mime) in _MIMEOverrides
5757
mime == m && return fmt
5858
end
@@ -78,14 +78,14 @@ function unpackBlob end
7878
unpackBlob(mime::String, blob) = unpackBlob(MIME(mime), blob)
7979

8080
function unpackBlob(T::MIME, blob)
81-
dataformat = mime_to_format(T)
81+
dataformat = getDataFormat(T)
8282
isnothing(dataformat) && error("Format not found for MIME type $(T)")
8383
return unpackBlob(dataformat, blob)
8484
end
8585

8686
# 1. JSON strings are saved as is
8787
function packBlob(::Type{format"JSON"}, json_str::String)
88-
mimetype = format_to_mime(format"JSON")
88+
mimetype = getMimetype(format"JSON")
8989
blob = Vector{UInt8}(json_str)
9090
return blob, mimetype
9191
end
@@ -102,7 +102,7 @@ function packBlob(::Type{T}, data::Any; kwargs...) where {T <: DataFormat}
102102
io = IOBuffer()
103103
save(Stream{T}(io), data; kwargs...)
104104
blob = take!(io)
105-
mimetype = format_to_mime(T)
105+
mimetype = getMimetype(T)
106106
return blob, mimetype
107107
end
108108

@@ -119,5 +119,5 @@ Detect the MIME type of data in an IO stream using FileIO's format detection.
119119
function getMimetype(io::IO)
120120
_getFormat(s::FileIO.Stream{T}) where {T} = T
121121
stream = FileIO.query(io)
122-
return format_to_mime(_getFormat(stream))
122+
return getMimetype(_getFormat(stream))
123123
end

src/DataBlobs/services/BlobWrappers.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,19 +231,19 @@ function saveImage_Variable!(
231231
blobstore::Symbol = :default;
232232
entry_kwargs...,
233233
)
234-
mimeType = get(entry_kwargs, :mimeType, MIME("image/png"))
235-
format = mime_to_format(mimeType)
234+
mimetype = get(entry_kwargs, :mimeType, MIME("image/png"))
235+
format = getDataFormat(mimetype)
236+
isnothing(format) &&
237+
throw(ArgumentError("Unsupported MIME type for image: $(mimetype)"))
238+
blob, mimetype = packBlob(format, img)
236239

237-
blob, mimeType = packBlob(format, img)
238-
239-
size = string(length(blob))
240240
entry = Blobentry(
241241
entry_label,
242242
blobstore;
243243
blobid = uuid4(),
244244
entry_kwargs...,
245-
size,
246-
mimeType = string(mimeType),
245+
size = length(blob),
246+
mimetype,
247247
)
248248

249249
return saveBlob_Variable!(dfg, variable_label, blob, entry)

src/DistributedFactorGraphs.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ const unstable_functions::Vector{Symbol} = [
479479
:packBlob,
480480
:hasTags,
481481
:unpackBlob,
482-
:format_to_mime,
483-
:mime_to_format,
482+
:getMimetype,
483+
:getDataFormat,
484484
:getMimetype,
485485
:emptyTags!,
486486
:ls,

src/FileDFG/services/FileDFG.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function loadDFG!(
119119
variablefiles = readdir(joinpath(loaddir, "variables"); sort = false, join = true)
120120

121121
# type instability on `variables` as either `::Vector{Variable}` or `::Vector{VariableDFG{<:}}` (vector of abstract)
122-
variables = @showprogress dt=1 desc = "loading variables" asyncmap(
122+
variables = @showprogress dt = 1 desc = "loading variables" asyncmap(
123123
variablefiles,
124124
) do file
125125
v = JSON.parsefile(file, V; style = DFGJSONStyle())
@@ -130,7 +130,7 @@ function loadDFG!(
130130

131131
factorfiles = readdir(joinpath(loaddir, "factors"); sort = false, join = true)
132132

133-
factors = @showprogress dt=1 desc = "loading factors" asyncmap(factorfiles) do file
133+
factors = @showprogress dt = 1 desc = "loading factors" asyncmap(factorfiles) do file
134134
f = JSON.parsefile(file, F; style = DFGJSONStyle())
135135
return addFactor!(dfgLoadInto, f)
136136
end
@@ -139,7 +139,7 @@ function loadDFG!(
139139

140140
if isa(dfgLoadInto, GraphsDFG) && getTypeDFGFactors(dfgLoadInto) <: FactorDFG
141141
# Finally, rebuild the CCW's for the factors to completely reinflate them
142-
@showprogress dt=1 desc = "Rebuilding factor solver cache" for factor in factors
142+
@showprogress dt = 1 desc = "Rebuilding factor solver cache" for factor in factors
143143
rebuildFactorCache!(dfgLoadInto, factor)
144144
end
145145
end

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ function listNeighbors(
239239

240240
# Additional filtering
241241
# solvable != 0 && filter!(lbl -> _isSolvable(dfg, lbl, solvable), neighbors_ll)
242-
filterDFG!(neighbors_ll, solvableFilter, l->getSolvable(dfg, l))
243-
filterDFG!(neighbors_ll, tagsFilter, l->listTags(dfg, l))
242+
filterDFG!(neighbors_ll, solvableFilter, l -> getSolvable(dfg, l))
243+
filterDFG!(neighbors_ll, tagsFilter, l -> listTags(dfg, l))
244244

245245
# Variable sorting (order is important)
246246
if haskey(dfg.g.factors, label)
@@ -278,8 +278,8 @@ function listNeighborhood(
278278

279279
allvarfacs = [dfg.g.labels[id] for id in nbhood]
280280

281-
filterDFG!(allvarfacs, solvableFilter, l->getSolvable(dfg, l))
282-
filterDFG!(allvarfacs, tagsFilter, l->listTags(dfg, l))
281+
filterDFG!(allvarfacs, solvableFilter, l -> getSolvable(dfg, l))
282+
filterDFG!(allvarfacs, tagsFilter, l -> listTags(dfg, l))
283283

284284
variableLabels = intersect(listVariables(dfg), allvarfacs)
285285
factorLabels = intersect(listFactors(dfg), allvarfacs)

src/entities/DFGFactor.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ StructUtils.@kwarg struct FactorDFG{T <: AbstractObservation, N} <: AbstractGrap
6565
tags::Set{Symbol} = Set{Symbol}([:FACTOR])
6666
"""Ordered list of the neighbor variables.
6767
Accessors: [`getVariableOrder`](@ref)"""
68-
variableorder::NTuple{N, Symbol} & (choosetype = x->NTuple{length(x), Symbol},) # NOTE v0.29 renamed from _variableOrderSymbols
68+
variableorder::NTuple{N, Symbol} & (choosetype = x -> NTuple{length(x), Symbol},) # NOTE v0.29 renamed from _variableOrderSymbols
6969
"""Variable timestamp.
7070
Accessors: [`getTimestamp`](@ref)"""
7171
timestamp::TimeDateZone = now_tdz() # NOTE v0.29 changed from ZonedDateTime
@@ -307,7 +307,7 @@ $(TYPEDFIELDS)
307307
tags::Set{Symbol}
308308
"""Ordered list of the neighbor variables.
309309
Accessors: [`getVariableOrder`](@ref)"""
310-
variableorder::Tuple{Vararg{Symbol}} & (choosetype = x->NTuple{length(x), Symbol},) #TODO changed to NTuple
310+
variableorder::Tuple{Vararg{Symbol}} & (choosetype = x -> NTuple{length(x), Symbol},) #TODO changed to NTuple
311311
"""Variable timestamp.
312312
Accessors: [`getTimestamp`](@ref)"""
313313
timestamp::TimeDateZone
@@ -348,7 +348,7 @@ $(TYPEDFIELDS)
348348
tags::Set{Symbol}
349349
"""Ordered list of the neighbor variables.
350350
Accessors: [`getVariableOrder`](@ref)"""
351-
variableorder::Tuple{Vararg{Symbol}} & (choosetype = x->NTuple{length(x), Symbol},)
351+
variableorder::Tuple{Vararg{Symbol}} & (choosetype = x -> NTuple{length(x), Symbol},)
352352
end
353353

354354
##------------------------------------------------------------------------------

src/services/AbstractDFG.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ Implement `mergeVariable!(dfg::AbstractDFG, variable::AbstractGraphVariable)`
276276
function mergeVariable! end
277277

278278
function mergeVariables!(dfg::AbstractDFG, variables::Vector{<:AbstractGraphVariable})
279-
counts = asyncmap(v->mergeVariable!(dfg, v), variables)
279+
counts = asyncmap(v -> mergeVariable!(dfg, v), variables)
280280
return sum(counts; init = 0)
281281
end
282282

@@ -289,7 +289,7 @@ Implement `mergeFactor!(dfg::AbstractDFG, factor::AbstractGraphFactor)`
289289
function mergeFactor! end
290290

291291
function mergeFactors!(dfg::AbstractDFG, factors::Vector{<:AbstractGraphFactor})
292-
counts = asyncmap(f->mergeFactor!(dfg, f), factors)
292+
counts = asyncmap(f -> mergeFactor!(dfg, f), factors)
293293
return sum(counts; init = 0)
294294
end
295295

0 commit comments

Comments
 (0)