(source)
return result
Load options dictionary from a yaml file
Load options dictionary from a yaml file
Load options dictionary from a yaml file
def load_yaml_opts(source):
        """ Load options dictionary from a yaml file
        """
        result = {}
        if isinstance(source, str):
            with open(source, 'r') as yaml_file:
                options_dict = yaml.safe_load(yaml_file)
        elif isinstance(source, dict):
            options_dict = source
        else:
            raise TypeError('Unsupported source type: {}'.format(type(source)))
        includes = options_dict.get('__include__', False)
        if includes:
            if type(includes) != list:
                includes = [includes]
            for include in includes:
                filename = '{}/{}'.format(os.path.dirname(source), include)
                if os.path.isfile(filename):
                    parent = Options.load_yaml_opts(filename)
                else:
                    parent = Options.load_yaml_opts(include)
                merge_dictionaries(result, parent)
        merge_dictionaries(result, options_dict)  # to be sure the main options overwrite the parent options
        result.pop('__include__', None)
        result = OptionsDict(result)
        return result
def load_yaml_opts ( source ) : result = { } if isinstance ( source , str ) : with open ( source , 'r' ) as yaml_file : options_dict = yaml . safe_load ( yaml_file ) elif isinstance ( source , dict ) : options_dict = source else : raise TypeError ( 'Unsupported source type: {}' . format ( type ( source ) ) ) includes = options_dict . get ( '__include__' , False ) if includes : if type ( includes ) != list : includes = [ includes ] for include in includes : filename = '{}/{}' . format ( os . path . dirname ( source ) , include ) if os . path . isfile ( filename ) : parent = Options . load_yaml_opts ( filename ) else : parent = Options . load_yaml_opts ( include ) merge_dictionaries ( result , parent ) merge_dictionaries ( result , options_dict ) # to be sure the main options overwrite the parent options result . pop ( '__include__' , None ) result = OptionsDict ( result ) return result