How to use the confuse.sources.ConfigSource function in confuse

To help you get started, we’ve selected a few confuse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github beetbox / confuse / confuse / core.py View on Github external
def set(self, value):
        self.sources.insert(0, ConfigSource.of(value))
github beetbox / confuse / confuse / sources.py View on Github external
def of(cls, value):
        """Given either a dictionary or a `ConfigSource` object, return
        a `ConfigSource` object. This lets a function accept either type
        of object as an argument.
        """
        if isinstance(value, ConfigSource):
            return value
        elif isinstance(value, dict):
            return ConfigSource(value)
        else:
            raise TypeError(u'source value must be a dict')
github beetbox / confuse / confuse / core.py View on Github external
def add(self, obj):
        self.sources.append(ConfigSource.of(obj))
github beetbox / confuse / confuse / sources.py View on Github external
def of(cls, value):
        """Given either a dictionary or a `ConfigSource` object, return
        a `ConfigSource` object. This lets a function accept either type
        of object as an argument.
        """
        if isinstance(value, ConfigSource):
            return value
        elif isinstance(value, dict):
            return ConfigSource(value)
        else:
            raise TypeError(u'source value must be a dict')
github beetbox / confuse / confuse / core.py View on Github external
def _add_default_source(self):
        """Add the package's default configuration settings. This looks
        for a YAML file located inside the package for the module
        `modname` if it was given.
        """
        if self.modname:
            if self._package_path:
                filename = os.path.join(self._package_path, DEFAULT_FILENAME)
                if os.path.isfile(filename):
                    yaml_data = yaml_util.load_yaml(
                        filename,
                        loader=self.loader,
                    )
                    self.add(ConfigSource(yaml_data, filename, True))
github beetbox / confuse / confuse / core.py View on Github external
def _add_user_source(self):
        """Add the configuration options from the YAML file in the
        user's configuration directory (given by `config_dir`) if it
        exists.
        """
        filename = self.user_config_path()
        if os.path.isfile(filename):
            yaml_data = yaml_util.load_yaml(filename, loader=self.loader) \
                or {}
            self.add(ConfigSource(yaml_data, filename))
github beetbox / confuse / confuse / sources.py View on Github external
def __init__(self, value, filename=None, default=False):
        super(ConfigSource, self).__init__(value)
        if (filename is not None
                and not isinstance(filename, BASESTRING)):
            raise TypeError(u'filename must be a string or None')
        self.filename = filename
        self.default = default