The Config

Tiramisu is made of almost three main classes/concepts :

  • the Option stands for the option types
  • the OptionDescription is the shema, the option’s structure
  • the Config which is the whole configuration entry point

The handling of options

The handling of options is split into two parts: the description of which options are available, what their possible values and defaults are and how they are organized into a tree. A specific choice of options is bundled into a configuration object which has a reference to its option description (and therefore makes sure that the configuration values adhere to the option description).

Let’s perform a Getting started code review :

see the full source for: getting_started

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
"getting started with the tiramisu library (it loads and prints properly)"

from tiramisu import Config
from tiramisu import OptionDescription, BoolOption

# let's create a group of options
descr = OptionDescription("optgroup", "", [
                          # ... with only one option inside
                          BoolOption("bool", "", default=False)
                          ])

cfg = Config(descr)

Let’s review the code. First, line 7, we create an OptionDescription named optgroup.

from tiramisu import OptionDescription, BoolOption
# let's create a group of options
descr = OptionDescription("optgroup", "", [

Option objects can be created in different ways, here we create a BoolOption

from tiramisu import OptionDescription, BoolOption
                          # ... with only one option inside
                          BoolOption("bool", "", default=False)

Then, line 12, we make a Config with the OptionDescription we built :

from tiramisu import Config
cfg = Config(descr)

Here is how to print our Config details:

print(cfg.help())
Root config object that enables us to handle the configuration options

Settings:
    forcepermissive      Access to option without verifying permissive properties
    unrestraint          Access to option without property restriction

Commands:
    cache                None
    config               Actions to Config
    information          Manage config informations
    option               Select an option
    owner                Global owner
    permissive           Manage config permissives
    property             Manage config properties
    value                Manage config value

Then let’s print our Option details.

print(cfg.option.help())
Select an option

Call: Select an option by path

Commands:
    dict         convert config and option to tiramisu format
    find         Find an or a list of options
    list         List options (by default list only option)
    updates      updates value with tiramisu format

Finaly, let’s print the Config.

print(cfg)
<tiramisu.api.Config object at 0x7f3ee6204278>

download the getting started code

Option description are nested Options

The Option (in this case the BoolOption), are organized into a tree into nested OptionDescription objects.

_images/config.png

Every option has a name, as does every option group.