loganasherjones / yapconf

Yet Another Python Configuration
http://yapconf.readthedocs.io/en/stable/
MIT License
18 stars 4 forks source link

Dumping boxes doesn't work well #78

Closed loganasherjones closed 6 years ago

loganasherjones commented 6 years ago

There are lots of hidden objects on a Box when yaml attempts to dump them. This is very annoying since our configs are often times Box objects. By default, I should check to make sure that when we are dumping data, if it is a Box to call to_dict on it.

loganasherjones commented 6 years ago

As an example, for the simple ascii_data:

from box import Box

data = {
    'foo': 'bar',
    'db': {'name': 'db_name', 'port': 123},
    'items': [1, 2, 3]
}

When using yapconf to dump, we would get:

>> yapconf.dump_data(Box(data), file_type='yaml')
&id001 !!python/object/new:box.Box
dictitems:
  db: !!python/object/new:box.Box
    dictitems:
      name: db_name
      port: 123
    state:
      _box_config:
        __box_heritage: !!python/tuple
        - *id001
        - db
        __converted: !!set
          name: null
          port: null
        __created: true
        __hash: null
        box_duplicates: ignore
        box_safe_prefix: x
        camel_killer_box: false
        conversion_box: true
        default_box: false
        default_box_attr: &id002 !!python/name:box.Box ''
        frozen_box: false
        modify_tuples_box: false
        ordered_box: false
  foo: bar
  items: !!python/object/new:box.BoxList
    listitems:
    - 1
    - 2
    - 3
    state:
      box_class: *id002
      box_options:
        __box_heritage: !!python/tuple
        - *id001
        - items
        box_duplicates: ignore
        box_safe_prefix: x
        camel_killer_box: false
        conversion_box: true
        default_box: false
        default_box_attr: *id002
        frozen_box: false
        modify_tuples_box: false
        ordered_box: false
      box_org_ref: 140087657129096
state:
  _box_config:
    __box_heritage: null
    __converted: !!set
      db: null
      foo: null
      items: null
    __created: true
    __hash: null
    box_duplicates: ignore
    box_safe_prefix: x
    camel_killer_box: false
    conversion_box: true
    default_box: false
    default_box_attr: *id002
    frozen_box: false
    modify_tuples_box: false
    ordered_box: false

We should expect to get:

db:
  name: db_name
  port: 123
foo: bar
items:
- 1
- 2
- 3