Skip to content

override_file and default_file can be something that is not a file #193

@Sbozzolo

Description

@Sbozzolo

"""
create_toml_dict(FT;
override_file,
default_file,
)
Creates a `ParamDict{FT}` struct, by reading and merging upto
two TOML files or Julia Dicts with override information taking precedence over
default information.
"""
function create_toml_dict(
::Type{FT};
override_file::Union{Nothing, String, Dict} = nothing,
default_file::Union{String, Dict} = joinpath(@__DIR__, "parameters.toml"),
) where {FT <: AbstractFloat}
default_dict =
default_file isa String ? TOML.parsefile(default_file) : default_file
default_toml_dict = ParamDict{FT}(default_dict, nothing)
isnothing(override_file) && return default_toml_dict
override_dict =
override_file isa String ? TOML.parsefile(override_file) : override_file
override_toml_dict = ParamDict{FT}(override_dict, override_dict)
return merge_override_default_values(override_toml_dict, default_toml_dict)
end

This function has a really counter-intuitive behavior, where you can pass a dictionary to an override_file/default_file. If we want to support this feature, it should be in different method instead of having a function that does all sorts of stuff and that can only be understood by reading the source code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions