twobraids/configman — Issue #30: json not working exactly like ini
Author: peterbe
Created: 2011-11-18 18:42:51+00:00
State: open

I wrote this program:

```python
import getopt
from configman import Namespace, ConfigurationManager

def create_config():
namespace = Namespace()
namespace.add_option(
'tip',
default=20,
)
import decimal
namespace.add_option(
'amount',
from_string_converter=decimal.Decimal
)
value_sources = ('tipcalc.ini', getopt, )
config_manager = ConfigurationManager([namespace], value_sources)
return config_manager.get_config()

if __name__ == '__main__':
config = create_config()
print repr(config.tip)
print repr(config.amount)
```

Then this works: ``$ python tipcalc.py --help``

However, if I make it ``.json`` as a value source instead; i.e. I change the ``value_sources = ...`` line:

```python
import getopt
from configman import Namespace, ConfigurationManager

def create_config():
namespace = Namespace()
namespace.add_option(
'tip',
default=20,
)
import decimal
namespace.add_option(
'amount',
from_string_converter=decimal.Decimal
)
value_sources = ('tipcalc.json', getopt, )
config_manager = ConfigurationManager([namespace], value_sources)
return config_manager.get_config()

if __name__ == '__main__':
config = create_config()
print repr(config.tip)
print repr(config.amount)
```

Running this I get this error:

```
$ python tipcalc.py --help
Traceback (most recent call last):
File "tipcalc.py", line 25, in
config = create_config()
File "tipcalc.py", line 20, in create_config
config_manager = ConfigurationManager([namespace], value_sources)
File "/Users/peterbe/virtualenvs/socorro/lib/python2.6/site-packages/configman/config_manager.py", line 102, in __init__
self)
File "/Users/peterbe/virtualenvs/socorro/lib/python2.6/site-packages/configman/value_sources/__init__.py", line 99, in wrap
raise AllHandlersFailedException(errors)
configman.value_sources.source_exceptions.AllHandlersFailedException: Cannot load json: [Errno 2] No such file or directory: 'tipcalc.json'; ConfigParser doesn't know how to handle tipcalc.json.; couldn't interpret tipcalc.json as a context file: [Errno 2] No such file or directory: 'tipcalc.json'
```