ssato / python-anyconfig

Python library provides common APIs to load and dump configuration files in various formats
MIT License
278 stars 31 forks source link

Loading a toml file loads None object #42

Closed ajays20078 closed 7 years ago

ajays20078 commented 8 years ago

Using anyconfig.load on the below .toml file and dumping it, dumps a empty file.

[servers]

[servers.a] ip = "10.0.3.1" dc = "dc1"

[servers.b] ip = "10.0.2.2" dc = "dc2"

ssato commented 8 years ago

Thanks for your report!

Could you please let me know the details of the steps to reproduce this issue?

ajays20078 commented 8 years ago

Steps to reproduce:

Save the above toml into a file.

then load it using anyconfig.load() and dump using anyconfig.dump() and the dumped file will be empty.

Actually if you print the loaded contents, that itself will be None, so its not loading it properly.

ssato commented 8 years ago

Thanks for your quick response!

I'm investigating this issue like the following. Please let me know if I'm missing something:

In [8]: cnf_s = """[servers]

[servers.a]
ip = "10.0.3.1"
dc = "dc1"

[servers.b]
ip = "10.0.2.2"
dc = "dc2"
"""

In [9]: open("/tmp/00.toml", 'w').write(cnf_s)

In [10]: cnf = anyconfig.load("/tmp/00.toml")

In [11]: anyconfig.dumps(cnf, ac_parser="toml")
Out[11]: '[servers.b]\nip = "10.0.2.2"\ndc = "dc2"\n[servers.a]\nip = "10.0.3.1"\ndc = "dc1"\n'

In [12]: anyconfig.dump(cnf, "/tmp/out.toml")

In [13]: cat /tmp/out.toml
[servers.b]
ip = "10.0.2.2"
dc = "dc2"
[servers.a]
ip = "10.0.3.1"
dc = "dc1"

In [14]: import toml

In [15]: toml
Out[15]: <module 'toml' from '/usr/lib/python2.7/site-packages/toml.pyc'>

In [16]: anyconfig.list_types()
Out[16]:
['bson',
 'configobj',
 'ini',
 'json',
 'msgpack',
 'properties',
 'toml',
 'xml',
 'yaml']

In [17]: "toml" in anyconfig.list_types()
Out[17]: True
ajays20078 commented 8 years ago

!/usr/bin/python

import anyconfig

cnf_s = """[servers]

[servers.a] ip = "10.0.3.1" dc = "dc1"

[servers.b] ip = "10.0.2.2" dc = "dc2" """

open("/tmp/00.toml", 'w').write(cnf_s) cnf = anyconfig.load("/tmp/00.toml") print anyconfig.dumps(cnf, ac_parser="toml")

Output: null

anyconfig version 0.5.0

ssato commented 8 years ago

Thanks for your script to reproduce this issue!

Unfortunately, I still cannot reproduce it with your script. Could you please test with this and let me show its outputs if possible?

#!/usr/bin/python
from __future__ import print_function
import anyconfig
print(anyconfig.list_types())
print(anyconfig.VERSION)

cnf_s = """[servers]

[servers.a]
ip = "10.0.3.1"
dc = "dc1"

[servers.b]
ip = "10.0.2.2"
dc = "dc2"
"""

open("/tmp/00.toml", 'w').write(cnf_s)
cnf = anyconfig.load("/tmp/00.toml")
print(anyconfig.dumps(cnf, ac_parser="toml"))
ajays20078 commented 8 years ago

Output:

['ini', 'json', 'properties', 'xml', 'yaml'] 0.5.0 null

Seems like toml is not in list_types

ajays20078 commented 8 years ago

Installing toml python module fixed the issue. Shouldn't it be installed as a dependency along with anyconfig?

ssato commented 8 years ago

Please take a look at:

I want to minimize requirements of anyconfig as much as I can so I don't want to make toml as must-have requirement of anyconfig. Sorry for the inconvenience.

Maybe it should warn about missing backend with more kind message and I'll try that.

ajays20078 commented 8 years ago

I missed that part in readme, thanks for pointing it out and yeah atleast a warning for the same would help.

ssato commented 8 years ago

Thanks for your understanding and patience. I'll open another issue for the warnings later.

ajays20078 commented 8 years ago

Closing this

ajays20078 commented 8 years ago

There are no warnings/exceptions yet , when this happens. anyconfig silently fails to load toml/yaml whenever dependencies are not installed.

ssato commented 8 years ago

Sorry, I accidentally closed this.

ssato commented 8 years ago

Thanks for bringing up no-warn issue! Sorry, I completely forgot about it for a while. I've just opened another issue #55 to track it.

ssato commented 7 years ago

Let me close this and track the problem in another derived one, #55 .