def test_checking_config_equality(): config = Config({'a': 1, 'b': 2}) other_config = Config({'a': 1, 'b': 2}) plain_dict = {'a': 1, 'b': 2} m9dict_value = anyconfig.to_container({'a': 1, 'b': 2}) assert config == other_config assert config == plain_dict assert config == m9dict_value
def __init__(self, config=None, parent=None, schema=None): if config is None: config = get_empty_config() elif isinstance(config, dict) and hasattr(anyconfig, 'to_container'): config = anyconfig.to_container(config) self._wrapped = config self.parent = parent self.schema = schema if self.schema is not None: self.validate()
def try_to_load_config_from_files(conf_path=None): """ Load configurations from given `conf_path`. """ cnf = anyconfig.to_container() cnf.update(**DEFAULTS) if conf_path: try: diff = anyconfig.load(conf_path) cnf.update(diff) except (IOError, OSError): pass return cnf
def _combine(self, configs): """ Perform a prioritized recursive merge of serveral source files and returns a new dict. The merge order is based on the index of the list, meaning that elements at the end of the list will be merged last, and have greater precedence than elements at the beginning. The result is then merged ontop of the defaults. :param configs: A list containing the yaml files to load. :return: dict """ default = self._get_defaults() conf = anyconfig.to_container(default, ac_merge=MERGE_STRATEGY) conf.update( anyconfig.load( configs, ignore_missing=True, ac_merge=MERGE_STRATEGY)) return m9dicts.convert_to(conf)
def load_site_ctxs(ctxs): """ Load context (conf) files from ``ctxs``. :param ctxs: List of context file[s], glob patterns of context files or dirs :: [str] """ conf = anyconfig.to_container() for ctxpath in ctxs: diff = load_site_ctx(ctxpath) if diff: conf.update(diff) else: logging.warn("No config loaded from: %s", ctxpath) if not conf: raise EmptyConfigError("No config available from: " + ','.join(ctxs)) return conf
def merge_dicts(a, b): """ Merges the values of B into A and returns a new dict. Uses the same merge strategy as ``config._combine``. :: dict a b: - c: 0 - c: 2 d: e: "aaa" f: 3 dict b a: 1 b: - c: 3 d: e: "bbb" Will give an object such as:: {'a': 1, 'b': [{'c': 3}], 'd': {'e': "bbb", 'f': 3}} :param a: the target dictionary :param b: the dictionary to import :return: dict """ conf = anyconfig.to_container(a, ac_merge=MERGE_STRATEGY) conf.update(b) return conf
def get_empty_config(): empty_config = anyconfig.to_container({}) return empty_config
def get_empty_config(): if hasattr(anyconfig, 'to_container'): empty_config = anyconfig.to_container({}) else: empty_config = {} return empty_config