Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

empty custom config hangs when loading #22

Closed
havok2063 opened this issue Nov 10, 2020 · 2 comments · Fixed by #23
Closed

empty custom config hangs when loading #22

havok2063 opened this issue Nov 10, 2020 · 2 comments · Fixed by #23
Assignees
Labels
bug Something isn't working

Comments

@havok2063
Copy link
Contributor

When a custom config file is present but empty, sdsstools hangs when loading. My guess is it's entered into a form of recursive reading loop. I'd expect an empty config file to resolve to a blank dictionary object during merge with its parent in package/etc/xxx.yml

To reproduce:

  • create an empty custom config, e.g. ~/.config/sdss/tree.yml
  • try to load the config file with sdsstools.get_config("tree")

Traceback upon key interrupt

from sdsstools import get_config, get_logger, get_package_version

config=get_config('tree')
^C---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-2-e5a3198d9f43> in <module>
----> 1 config=get_config('tree')

~/anaconda3/envs/treetest/lib/python3.7/site-packages/sdsstools/configuration.py in get_config(name, config_file, allow_user, user_path, config_envvar, merge_mode, default_envvars)
    174     if merge_mode == 'update':
    175         return Configuration(custom_config_fn, base_config=config_file,
--> 176                              default_envvars=default_envvars)
    177     else:
    178         return Configuration(custom_config_fn, base_config=None,

~/anaconda3/envs/treetest/lib/python3.7/site-packages/sdsstools/configuration.py in __init__(self, config, base_config, default_envvars)
    211         __ENVVARS__ = default_envvars
    212
--> 213         self.load(config)
    214
    215     def _parse_config(self, config, use_base=True):

~/anaconda3/envs/treetest/lib/python3.7/site-packages/sdsstools/configuration.py in load(self, config)
    244             self.CONFIG_FILE = None
    245
--> 246         super().__init__(self._parse_config(config))
    247
    248         # Save name of the configuration file (if the input is a file).

~/anaconda3/envs/treetest/lib/python3.7/site-packages/sdsstools/configuration.py in _parse_config(self, config, use_base)
    225                 raise ValueError('Invalid config of type {}'.format(type(config)))
    226
--> 227         return merge_config(self._parse_config(config, use_base=False), self._BASE)
    228
    229     def load(self, config=None):

~/anaconda3/envs/treetest/lib/python3.7/site-packages/sdsstools/configuration.py in _parse_config(self, config, use_base)
    221                 return config
    222             elif isinstance(config, (str, pathlib.Path)):
--> 223                 return read_yaml_file(config)
    224             else:
    225                 raise ValueError('Invalid config of type {}'.format(type(config)))

~/anaconda3/envs/treetest/lib/python3.7/site-packages/sdsstools/configuration.py in read_yaml_file(path, use_extends, loader)
     58         fp.seek(0)
     59         while True:
---> 60             line = fp.readline()
     61             if line.strip().startswith('#!extends'):
     62                 base_file = line.strip().split()[1]

~/anaconda3/envs/treetest/lib/python3.7/codecs.py in decode(self, input, final)
    317         raise NotImplementedError
    318
--> 319     def decode(self, input, final=False):
    320         # decode input (taking the buffer into account)
    321         data = self.buffer + input

KeyboardInterrupt:
@havok2063 havok2063 added the bug Something isn't working label Nov 10, 2020
@albireox
Copy link
Member

Mmm, interesting. It seems this fails because of some come I added to allow extending a YAML from a different YAML. It should be fairly easy to fix and test.

@albireox
Copy link
Member

I released this as 0.4.5 if you want to upgrade.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants