JSON Config

Develop once, deploy everywhere

This compnent enables external configuration via a JSON-File. 
The definition of the config is done via en extensive Callback. To create the definition you need to return a dictionary containing Definition values. The possible values are passed as arguments to the GetConfigSchema callback.

Methods

LoadConfig( configStr: str = "" )
Forces the configComp to reload the contents.
It traverses several possibilitites:
  1. Check the configStr. If the configStr is a valid JsonString, it will be used.
  2. Check the GetConfigData Callback. Return data as a jsonString.
  3. Saved file on Disk.

After the Config is loaded, the data will be sanitized, validated and saved to the configFile!

Collection Value

CollectionValue( 
    default: any = "",
    validator: callable[[any], any] = lambda value: True,
    parser: callable[[any], any] = lambda value: value,
    typecheck: type = object
)
Arguments
  • default : The default value this CollectionValue obtains if the member is not present in the current config or the validation fails.
  • validator : A function taking the value and returning a boolean if the value is valid.
  • parser: takes the inputdata and returns the object parsed. i.E. for capitalising strings or making ints to floats.
  • typecheck : a single type or tuple of types to validate the type of the inputs.

Note: You can call any CollectionItem (Value, Dict, List) to create a copy of the item. This is needed if you want to reuse a component.
positiveValue = CollectionValue( default = 2, validator =lambda value: lambda > 0 )
return {
    "PositiveA" : positiveValue(),
    "PositiveB" : positiveValue() 
}

CollectionDict

CollectionDict(
    items:dict = {}
)
Arguments
  • items : A dictionary with a string key and either CollectionDict/Value/List

CollectionList

CollectionList(
    items:list = [],
    default_member = CollectionItem
   )
Arguments
  • items: prefill the list with items.
  • default_member: CollectionItem (Value, Dict, List) that will be used as a validator/parser for all items.

To acces the members use the Data-Attribute. ColectionValues have Value and Dependency members. Use Value for explicit use of the value. 
op("json_config").Data.MyValue
op("json_config").Data.MyValue.Dependency #T bind to the value
op("json_config").Data.MyValue.Value #For explicit read-access to the value itself.

Use the "Save" method or Pulseparameter to writte bound values in to the config itself.

Under Windows use
setx [variable_name] "[variable_value]"
to permanently set the env-variable, or a simple 
set TD_ENV=variablevalue
before starting in a .bat file.



Downloads: 1331

Created at: 6.2.2022

Uploaded: 6.9.2024
Fixed bug with changes not propagating correctly downstream beyond one level.
Download