From fe1fab9aeea942826425fb1890fc1c957b95abb8 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Wed, 7 Oct 2015 15:32:07 -0700 Subject: [PATCH] For #1617, fix laziness with a new subclass --- beets/__init__.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/beets/__init__.py b/beets/__init__.py index 4c8fa25df..e507ea2af 100644 --- a/beets/__init__.py +++ b/beets/__init__.py @@ -24,14 +24,23 @@ __author__ = 'Adrian Sampson ' Library = beets.library.Library -config = confit.LazyConfig('beets', __name__) -try: - included_filenames = config['include'].get(list) -except confit.NotFoundError: - included_filenames = [] +class IncludeLazyConfig(confit.LazyConfig): + """A version of Confit's LazyConfig that also merges in data from + YAML files specified in an `include` setting. + """ + def read(self, user=True, defaults=True): + super(IncludeLazyConfig, self).read(user, defaults) -for filename in included_filenames: - filename = os.path.join(config.config_dir(), filename) - if os.path.isfile(filename): - config.set_file(filename) + try: + included_filenames = self['include'].get(list) + except confit.NotFoundError: + included_filenames = [] + + for filename in included_filenames: + filename = os.path.join(self.config_dir(), filename) + if os.path.isfile(filename): + self.set_file(filename) + + +config = IncludeLazyConfig('beets', __name__)