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

anyconfig does not load yml files #116

Closed JoshZastrow closed 4 years ago

JoshZastrow commented 4 years ago

I have an example credentials.yml file stored in my project folder conf/local

config/local/credentials.yml

dev_s3:
    aws_access_key_id: token
    aws_secret_access_key: key

Which I verified in a python session:

Python 3.8.3 (v3.8.3:6f8c8320e9, May 13 2020, 16:29:34) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import anyconfig
>>> anyconfig.__version__
'0.9.11'
>>> f = 'config/local/credentials.yml'
>>> os.path.exists(f)
True
>>> from pathlib import Path
>>> fpath = Path(f)
>>> f
'config/local/credentials.yml'
>>> fpath
PosixPath('config/local/credentials.yml')
>>> with open(f, 'r') as fobj:
...     for l in fobj: print(l)
... 
dev_s3:

    aws_access_key_id: token

    aws_secret_access_key: key

However, anyconfig cannot load this file using the load function as suggested in the docs:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/joshua.zastrow/Github/pricing-optimization/tetenv/lib/python3.8/site-packages/anyconfig/api.py", line 484, in load
    return single_load(path_specs, ac_parser=ac_parser, ac_dict=ac_dict,
  File "/Users/joshua.zastrow/Github/pricing-optimization/tetenv/lib/python3.8/site-packages/anyconfig/api.py", line 359, in single_load
    cnf = _single_load(input_, ac_parser=ac_parser, ac_template=ac_template,
  File "/Users/joshua.zastrow/Github/pricing-optimization/tetenv/lib/python3.8/site-packages/anyconfig/api.py", line 285, in _single_load
    psr = find(ioi, forced_type=ac_parser)
  File "/Users/joshua.zastrow/Github/pricing-optimization/tetenv/lib/python3.8/site-packages/anyconfig/api.py", line 212, in find
    return Parsers().find(obj, forced_type=forced_type)
  File "/Users/joshua.zastrow/Github/pricing-optimization/tetenv/lib/python3.8/site-packages/anyconfig/processors.py", line 348, in find
    return find(obj, self.list(), forced_type=forced_type, cls=cls)
  File "/Users/joshua.zastrow/Github/pricing-optimization/tetenv/lib/python3.8/site-packages/anyconfig/processors.py", line 223, in find
    pclss = findall(obj, prs, forced_type=forced_type, cls=cls)
  File "/Users/joshua.zastrow/Github/pricing-optimization/tetenv/lib/python3.8/site-packages/anyconfig/processors.py", line 196, in findall
    pclss = find_by_maybe_file(obj, prs)  # :: [Processor], never []
  File "/Users/joshua.zastrow/Github/pricing-optimization/tetenv/lib/python3.8/site-packages/anyconfig/processors.py", line 172, in find_by_maybe_file
    return find_by_fileext(obj.extension, prs)  # :: [Processor], never []
  File "/Users/joshua.zastrow/Github/pricing-optimization/tetenv/lib/python3.8/site-packages/anyconfig/processors.py", line 155, in find_by_fileext
    raise UnknownFileTypeError("file extension={}".format(fileext))
anyconfig.globals.UnknownFileTypeError: No parser found for file 'file extension=yml'

I did try with the absolute path, which made no difference. Aren't yml's processed by anyconfig?

ssato commented 4 years ago

Is PyYAML installed in your environment? If not, anyconfig cannot load YAML data.

JoshZastrow commented 4 years ago

Ah great -- much appreciated! Didn't realize I needed to install that package separately.

ssato commented 4 years ago

That's good ;-)

Although the doc has a note about it (https://github.com/ssato/python-anyconfig#supported-configuration-formats), maybe it needs some updates and/or fixes. Thanks for your report making me notice about that!