API
Contents
BetterInputFiles Functions
Public Objects
BetterInputFiles.setup_input
— Methodsetup_input(input_path::AbstractString, verbose::Bool, ext::InputExt; paths::OrderedDict{String, Tuple{String, String}}=OrderedDict{String, Tuple{String, String}}(), log_path::String="output_path", custom_metadata::Vector{Tuple{String, String}}=Vector{Tuple{String, String}}())
Main BetterInputFiles
function, given a path to an input file, this will preprocess, load, and postprocess the input file, including setting up paths and logging.
Arguments
input_path::AbstractString
: Path to input fileverbose::Bool
: Whether to log@debug
messagesext::InputExt
: Extension specifierpaths::OrderedDict{String, Tuple{String, String}}=OrderedDict{String, Tuple{String, String}}
: Paths to expand.paths
will be merged withSetupModule.default_paths
, withpaths
taking preference. SeeSetupModule.default_paths
for the syntax ofpaths
log_path::String="output_path"
: The"path_name"
of the directory where logging should output.log_path
must exist inpaths
or, be defined bySetupModule.default_paths
custom_metadata::Vector{Tuple{String, String}}=Vector{Tuple{String, String}}()
: Additonal metadata to include in the input file, in addition to creation date andinput_path
BetterInputFiles.setup_input
— Methodsetup_input(input_path::AbstractString, verbose::Bool, ext::String; paths::OrderedDict{String, Tuple{String, String}}=OrderedDict{String, Tuple{String, String}}(), log_path::String="output_path", custom_metadata::Vector{Tuple{String, String}}=Vector{Tuple{String, String}}())
Manually specify input file extension, then run setup_input(::AbstractString, ::Bool, ::InputExt, ::OrderedDict{String, Tuple{String, String}}, ::String, ::Vector{Tuple{String, String}})
Arguments
input_path::AbstractString
: Path to input fileverbose::Bool
: Whether to log@debug
messagesext::String
: Manual extension specifierpaths::OrderedDict{String, Tuple{String, String}}=OrderedDict{String, Tuple{String, String}}
: Paths to expand.paths
will be merged withSetupModule.default_paths
, withpaths
taking preference. SeeSetupModule.default_paths
for the syntax ofpaths
log_path::String="output_path"
: The"path_name"
of the directory where logging should output.log_path
must exist inpaths
or, be defined bySetupModule.default_paths
custom_metadata::Vector{Tuple{String, String}}=Vector{Tuple{String, String}}()
: Additonal metadata to include in the input file, in addition to creation date andinput_path
BetterInputFiles.setup_input
— Methodsetup_input(input_path::AbstractString, verbose::Bool; paths::OrderedDict{String, Tuple{String, String}}=OrderedDict{String, Tuple{String, String}}(), log_path::String="output_path", custom_metadata::Vector{Tuple{String, String}}=Vector{Tuple{String, String}}())
Automatically choose input file extension, then run setup_input(::AbstractString, ::Bool, ::InputExt, ::OrderedDict{String, Tuple{String, String}}, ::String, ::Vector{Tuple{String, String}})
Arguments
input_path::AbstractString
: Path to input fileverbose::Bool
: Whether to log@debug
messagespaths::OrderedDict{String, Tuple{String, String}}=OrderedDict{String, Tuple{String, String}}
: Paths to expand.paths
will be merged withSetupModule.default_paths
, withpaths
taking preference. SeeSetupModule.default_paths
for the syntax ofpaths
log_path::String="output_path"
: The"path_name"
of the directory where logging should output.log_path
must exist inpaths
or, be defined bySetupModule.default_paths
custom_metadata::Vector{Tuple{String, String}}=Vector{Tuple{String, String}}()
: Additonal metadata to include in the input file, in addition to creation date andinput_path
Setup Functions
Public Objects
BetterInputFiles.SetupModule.setup_global!
— Functionsetup_global!(input::Dict, input_path::AbstractString, verbose::Bool, paths::OrderedDict{String, Tuple{String, String}}=OrderedDict{String, Tuple{String, String}}(), log_path::String="OUTPUT_PATH"; test::Bool=false)
Setup the "GLOBAL"
information of input, including paths and logging.
Arguments
input::Dict
: The input file loaded into aDict
input_path::AbstractString
: The path to the input.input
file (from whichinput
is loaded)verbose::Bool
: Whether or not to display@debug
callspaths::OrderedDict{String, Tuple{String, String}}
: Paths to expand.paths
will be merged with the followingdefault_paths
, withpaths
taking preference. Seedefault_paths
for the syntax ofpaths
log_path::String
: The"path_name"
of the directory where logging should outputtest::Bool
: Whether this run is a test or not. This will decide whether to actually create directories, or log anything
See also setup_paths!
, and setup_logging!
Private Objects
BetterInputFiles.SetupModule.default_paths
— Constantdefault_paths::OrderedDict{String, Tuple{String, String}}
The default paths which will be expanded into absolute paths and used throughout the project.
default_paths::OrderedDict{String, Tuple{String, String}} = OrderedDict{String, Tuple{String, String}}(
# Name => relative, default
"BASE_PATH" => ("INPUT_PATH", ""),
"OUTPUT_PATH" => ("BASE_PATH", "Output")
)
This dictionary maps ("path_name" => ("relative_name", "default_path"))
, where "path_name"
is a human readable name for the path, "relative_name"
is the name of the path which "path_name"
is relative to, and "default_path"
is the default value for the path (either absolute or relative). If "path_name"
already exists inside input["GLOBAL"]
, then that path will be used either as is (if an absolute path) or relative to "relative_name"
, otherwise the "default_path"
will be used
BetterInputFiles.SetupModule.setup_logger
— Methodsetup_logger(log_file::AbstractString, verbose::Bool)
Helper function which sets up Logger formating and log level
Arguments
log_file::AbstractString
: Path to log fileverbose::Bool
: Whether or not to display@debug
calls
See also setup_logging!
and setup_global!
BetterInputFiles.SetupModule.setup_logging!
— Functionsetup_logging!(input::Dict, output_path::String="OUTPUT_PATH"; log::Bool=true)
Helper function which sets up log level, log files, etc... Assumes that setup_paths!
has already been run on input
Arguments
input::Dict
: The input file we are modifying. This assumes that the input already has a"GLOBAL"
key with valueDict{String, Any}("INPUT_PATH"=>"/path/to/input"), where
"INPUT_PATH"` is the path to the input fileoutput_path::String
: The"path_name"
of the output directory where log files should be written. Seedefault_paths
for more details
See also setup_global!
BetterInputFiles.SetupModule.setup_paths!
— Methodsetup_paths!(input::Dict, paths::OrderedDict{String, Tuple{String, String}})
Helper function which sets up paths, expanding relative paths and ensuring all interim directories exist
Arguments
input::Dict
: The input file we are modifying. This assumes that the input already has a"GLOBAL"
key with valueDict{String, Any}("INPUT_PATH"=>"/path/to/input"), where
"INPUT_PATH"is the path to the
input` filepaths::OrderedDict{String, Tuple{String, String}}
: Paths to expand.paths
will be merged with the followingdefault_paths
, withpaths
taking preference. Seedefault_paths
for a the syntax ofpaths
See also setup_global!
IO Functions
Public Objects
BetterInputFiles.IOModule.InputExt
— TypeInputExt
Abstract type for input extensions. Extended by TOMLExt
, JSONExt
, and YAMLExt
. Extend to add functionality for other input types. Names are assumed to be of the form EXTENSIONExt for .extension, i.e the extension in uppercase followed by Ext.
BetterInputFiles.IOModule.get_InputExt
— Methodget_InputExt(ext::String)
Converts from '.extension' to InputExt
subtype.
Arguments
ext::String
: '.extension' to convert to InputExt subtype
BetterInputFiles.IOModule.load_input
— Methodload_input(raw_input::String, ext::JSONExt)
Read .json file in to Dict
Arguments
raw_input::String
: Raw input to loadext::JSONExt
: Extension specifier
BetterInputFiles.IOModule.load_input
— Methodload_input(raw_input::String, ext::TOMLExt)
Read raw .toml file in to Dict
Arguments
raw_input::AbstractString
: Raw input to loadext::TOMLExt
: Extension specifier
BetterInputFiles.IOModule.load_input
— Methodload_input(raw_input::String, ext::YAMLExt)
Read .yaml file in to Dict
Arguments
raw_input::String
: Raw input to loadext::YAMLExt
: Extension specifier
BetterInputFiles.IOModule.load_inputfile
— Methodload_input(input_path::AbstractString, ext::JSONExt)
Read .json file in to Dict
Arguments
input_path::AbstractString
: Input path to loadext::JSONExt
: Extension specifier
BetterInputFiles.IOModule.load_inputfile
— Methodload_input(input_path::AbstractString, ext::TOMLExt)
Read .toml file in to Dict
Arguments
input_path::AbstractString
: Input path to loadext::TOMLExt
: Extension specifier
BetterInputFiles.IOModule.load_inputfile
— Methodload_input(input_path::AbstractString, ext::YAMLExt)
Read .yaml file in to Dict
Arguments
input_path::AbstractString
: Input path to loadext::YAMLExt
: Extension specifier
BetterInputFiles.IOModule.load_inputfile
— Methodload_input(input_path::AbstractString, ext::String)
Convert ext to InputExt, then attempt to load input into a dictionary
Arguments
input_path::AbstractString
: Input path to loadext::String
: Extension string
BetterInputFiles.IOModule.load_inputfile
— Methodload_input(input_path::AbstractString)
Automatically detect extension and attempt to load input into a dictionary
Arguments
input_path::AbstractString
: Input path to load
BetterInputFiles.IOModule.load_raw_inputfile
— Methodload_raw_inputfile(input_path::AbstractString)
Loads in the raw text in input_path
Arguments
input_path::AbstractString
: Input path to load
BetterInputFiles.IOModule.postprocess_input
— Methodpostprocess_input(input::Dict)
Run postprocessing on input
Arguments
input::Dict
: Input to postprocess
BetterInputFiles.IOModule.preprocess_input
— Functionpreprocess_input(input_path::AbstractString, ext::InputExt)
Preprocess the input path before running setup.
Arguments
input_path::AbstractString
: Input file to preprocessext::InputExt
: Extension type of input file
Preprocessing includes adding metadata comments at the top-level, including other files, inserting environmental variables, propegating default values, interpolating values, and ensuring all variables are upper-case.
BetterInputFiles.IOModule.preprocess_input
— Functionpreprocess_input(input_path::AbstractString, ext::String)
Specify the extension type of input_path
manually, then preprocess the ipnut.
Arguments
input_path::AbstractString
: Input file to preprocessext::String
: Manually selected extension. Must be part ofexts
If the extension of input_path
is not defined by BetterInputFiles
, but acts like a defined extension, you can specify which extension to use via this function, which will then run preprocess_input(::AbstractString, ::String)
BetterInputFiles.IOModule.preprocess_input
— Functionpreprocess_input(input_path::AbstractString)
Automatically detect extension type of input_path
, then preprocess the input.
Arguments
input_path::AbstractString
: Input file to preprocess
Will error if the extension of input_path
is not part of exts
. If you wish to manually specify the extension, use [preprocess_input(::AbstractString, ::String)]
(@ref). After the extension is found, will run [preprocess_input(::AbstractString, ::String)]
(@ref)
BetterInputFiles.IOModule.save_input
— Methodsave_input(input::Dict, output_file::AbstractString, ext::JSONExt)
Save input
to output_file
, as a .json
file
Arguments
input::Dict
: Input to saveoutput_file::AbstractString
: Path to saveext::JSONExt
: Extension specifier
BetterInputFiles.IOModule.save_input
— Methodsave_input(input::Dict, output_file::AbstractString, ext::TOMLExt)
Save input
to output_file
, as a .toml
file
Arguments
input::Dict
: Input to saveoutput_file::AbstractString
: Path to saveext::TOMLExt
: Extension specifier
BetterInputFiles.IOModule.save_input
— Methodsave_input(input::Dict, output_file::AbstractString, ext::YAMLExt)
Save input
to output_file
, as a .yaml
file
Arguments
input::Dict
: Input to saveoutput_file::AbstractString
: Path to saveext::YAMLExt
: Extension specifier
BetterInputFiles.IOModule.save_input
— Methodsave_input(input::Dict, log_path::String, input_path::AbstractString, ext::InputExt)
Save input
to the same directory that logging is being saved.
Arguments
input::Dict
: Input to savelog_path::String
: Directory to save input toinput_path::AbstractString
: Original path of inputext::InputExt
: Extension specifier
Private Objects
BetterInputFiles.IOModule.exts
— Constantexts::Vector{String}
Convencience list of all '.extension' file extensions for each defined subtype of InputExt
.
BetterInputFiles.IOModule.input_exts
— Constantinput_exts::Vector{InputExt}
Convenience list of all InputExt
subtypes defined.
BetterInputFiles.IOModule.JSONExt
— TypeJSONExt <: InputExt
InputExt
subtype for .json files.
BetterInputFiles.IOModule.TOMLExt
— TypeTOMLExt <: InputExt
InputExt
subtype for .toml files.
BetterInputFiles.IOModule.YAMLExt
— TypeYAMLExt <: InputExt
[InputExt
] for .yaml files.
BetterInputFiles.IOModule.add_metadata
— Functionadd_metadata(raw::String, ext::JSONExt, input_path::AbstractString)
Add metadata comment to top-level of .json file
Arguments
raw::String
: Raw text of input fileext::JSONExt
: Extension of input fileinput_path::AbstractString
: Path to input file
Adds a new "METADATA" key, containing the date of creation and input_path
BetterInputFiles.IOModule.add_metadata
— Functionadd_metadata(raw::String, ext::YAMLExt, input_path::AbstractString)
Add metadata comment to top-level of .yaml file
Arguments
raw::String
: Raw text of input fileext::YAMLExt
: Extension of input fileinput_path::AbstractString
: Path to input file
Adds a new "METADATA" key, containing the date of creation and input_path
BetterInputFiles.IOModule.add_metadata
— Functionadd_metadata(raw::String, ext::TOMLExt, input_path::AbstractString)
Add metadata comment to top-level of .toml file
Arguments
raw::String
: Raw text of input fileext::TOMLExt
: Extension of input fileinput_path::AbstractString
: Path to input file
Adds a new "METADATA" key, containing the date of creation and input_path
BetterInputFiles.IOModule.fix_dict_type
— Methodfix_dict_type(input::Dict)
Ensure dictionary is of type Dict{String, Any}
Arguments
input::Dict
: Input to fix
BetterInputFiles.IOModule.get_ext
— Methodget_ext(ext::InputExt)
Convert from the InputExt
type to the '.extension' file extension.
Arguments
ext::InputExt
: The InputExt subtype to convert into a file extension
BetterInputFiles.IOModule.process_env_vars
— Methodprocess_env_vars(raw::String)
Interpolate environmental variables into raw
, specified via <$ENV>
Arguments
raw::String
: Raw file to process
BetterInputFiles.IOModule.process_includes
— Methodprocess_includes(raw::String, input_path::AbstractString)
Copy include
files specified via <include path/to/include.file>
into raw
Arguments
raw::String
: Raw file to provessinput_path::AbstractString
: Path to input file
BetterInputFiles.IOModule.process_interpolation
— Methodprocess_interpolation(input::Dict)
Process interpolations for input
Arguments
input::Dict
The input to process
BetterInputFiles.IOModule.process_interpolation
— Methodprocess_interpolation(raw::String, ext::InputExt)
Given the raw string for an input, load the input (load_input
), and process all interpolations (process_interpolation(::Dict)
), respecting defaults
Arguments
raw::String
: The raw input file to processext::InputExt
: Extension specifier
BetterInputFiles.IOModule.update_case
— Methodupdate_case(input::AbstractArray)
Updated the case of every element in input
.
Arguments
input::AbstractArray
: Input to process
BetterInputFiles.IOModule.update_case
— Methodupdate_case(input::Any)
Stopping condition of postprocess_input(::Dict)
, when a value is reached
Arguments
input::Any
: Return input
BetterInputFiles.IOModule.update_case
— Methodupdate_case(input::Dict)
Recursively ensure every key in input
is uppercase
Arguments
input::Dict
: The input to update