Skip to content

Latest commit

 

History

History
200 lines (142 loc) · 3.51 KB

features.rst

File metadata and controls

200 lines (142 loc) · 3.51 KB

Features

Read a multiple config contained YAML, and get profile which was selected by default.

  • Example YAML:
    USED_CONFIG>: Fruits
    
    Fruits:
      Small:
        RED: 1
        YELLOW: 2
    
    Vegetables:
      Big:
        RED: 3
        YELLOW: 4
  • Reader code:
    import octoconf
    
    config = octoconf.loads(yaml_string)
    print(config)
  • Results:
    {
        'Small': {
            'RED': 1,
            'YELLOW': 2
        }
    }

Read a YAML file which contains variables.

  • Example YAML:
    USED_CONFIG>: Fruits
    
    Fruits:
      Small:
        RED: 1
        YELLOW: XXX${VAR1}XXX
    
    Vegetables:
      GREEN: 2
  • Reader code:
    import octoconf
    
    config = octoconf.loads(yaml_string, variables={'VAR1': '/test1'})
    print(config)
  • Results:
    {
        'Small': {
            'RED': 1,
            'YELLOW': 'XXX/test1XXX'
        }
    }

Read a multiple config contained YAML, where the selected config is inherited from another config.

  • Example YAML:
    USED_CONFIG>: ExtraSmallFruits
    
    Fruits:
      Small:
        RED: 1
        YELLOW: 2
        GREEN: 3
    
    SmallFruits:
      <BASE: Fruits
      Small:
        RED: 4
        YELLOW: 5
    
    ExtraSmallFruits:
      <BASE: SmallFruits
      Small:
        RED: 6

    Order of overrides: Fruits >> SmallFruits >> ExtraSmallFruits

  • Reader code:
    import octoconf
    
    config = octoconf.loads(yaml_string)
    print(config)
  • Results:
    {
        'Small': {
            'RED': 6,
            'YELLOW': 5
            'GREEN': 3,
        }
    }

Read config from multiple YAML files. The ``<INCLUDE`` directive allows one YAML string or multiple YAMLs as list

  • Example YAML files:
    • main.yml
      USED_CONFIG>: Fruits
      <INCLUDE:
        - vendor/default.yml
        - extra.yml
      
      Fruits:
        Small:
          PURPLE: 4
    • vendor/default.yml
      USED_CONFIG>: ExtraSmallFruits
      <INCLUDE: default.orig.yml
      
      Fruits:
        Small:
          YELLOW: 12
          GREEN: 13
          PURPLE: 14
    • vendor/default.orig.yml
      Fruits:
        Small:
          RED: 21
          YELLOW: 22
          GREEN: 23
          PURPLE: 24
    • extra.yml
      Fruits:
        Small:
          GREEN: 33
          PURPLE: 34

    Order of overrides: default.orig.yml >> default.yml >> extra.yml >> main.yml

  • Reader code:
    import octoconf
    
    config = octoconf.loads(main_yaml_string)
    print(config)
  • Results:
    {
        'Small': {
            'RED': 21,
            'YELLOW': 12,
            'GREEN': 33,
            'PURPLE': 4,
        },
    }