# Path: sacred/config/config_summary.py
# class ConfigSummary(dict):
#     def __init__(
#         self, added=(), modified=(), typechanged=(), ignored_fallbacks=(), docs=()
#     ):
#         super().__init__()
#         self.added = set(added)
#         self.modified = set(modified)  # TODO: test for this member
#         self.typechanged = dict(typechanged)
#         self.ignored_fallbacks = set(ignored_fallbacks)  # TODO: test
#         self.docs = dict(docs)
#         self.ensure_coherence()
# 
#     def update_from(self, config_mod, path=""):
#         added = config_mod.added
#         updated = config_mod.modified
#         typechanged = config_mod.typechanged
#         self.added &= {join_paths(path, a) for a in added}
#         self.modified |= {join_paths(path, u) for u in updated}
#         self.typechanged.update(
#             {join_paths(path, k): v for k, v in typechanged.items()}
#         )
#         self.ensure_coherence()
#         for k, v in config_mod.docs.items():
#             if not self.docs.get(k, ""):
#                 self.docs[k] = v
# 
#     def update_add(self, config_mod, path=""):
#         added = config_mod.added
#         updated = config_mod.modified
#         typechanged = config_mod.typechanged
#         self.added |= {join_paths(path, a) for a in added}
#         self.modified |= {join_paths(path, u) for u in updated}
#         self.typechanged.update(
#             {join_paths(path, k): v for k, v in typechanged.items()}
#         )
#         self.docs.update(
#             {
#                 join_paths(path, k): v
#                 for k, v in config_mod.docs.items()
#                 if path == "" or k != "seed"
#             }
#         )
#         self.ensure_coherence()
# 
#     def ensure_coherence(self):
#         # make sure parent paths show up as updated appropriately
#         self.modified |= {p for a in self.added for p in iter_prefixes(a)}
#         self.modified |= {p for u in self.modified for p in iter_prefixes(u)}
#         self.modified |= {p for t in self.typechanged for p in iter_prefixes(t)}
# 
#         # make sure there is no overlap
#         self.added -= set(self.typechanged.keys())
#         self.modified -= set(self.typechanged.keys())
#         self.modified -= self.added
# 
# Path: sacred/config/utils.py
# def dogmatize(obj):
#     if isinstance(obj, dict):
#         return DogmaticDict({key: dogmatize(val) for key, val in obj.items()})
#     elif isinstance(obj, list):
#         return DogmaticList([dogmatize(value) for value in obj])
#     elif isinstance(obj, tuple):
#         return tuple(dogmatize(value) for value in obj)
#     else:
#         return obj
# 
# def normalize_or_die(obj):
#     if isinstance(obj, dict):
#         res = dict()
#         for key, value in obj.items():
#             assert_is_valid_key(key)
#             res[key] = normalize_or_die(value)
#         return res
#     elif isinstance(obj, (list, tuple)):
#         return list([normalize_or_die(value) for value in obj])
#     return normalize_numpy(obj)
# 
# def undogmatize(obj):
#     if isinstance(obj, DogmaticDict):
#         return dict({key: undogmatize(value) for key, value in obj.items()})
#     elif isinstance(obj, DogmaticList):
#         return list([undogmatize(value) for value in obj])
#     elif isinstance(obj, tuple):
#         return tuple(undogmatize(value) for value in obj)
#     else:
#         return obj
# 
# def recursive_fill_in(config, preset):
#     for key in preset:
#         if key not in config:
#             config[key] = preset[key]
#         elif isinstance(config[key], dict) and isinstance(preset[key], dict):
#             recursive_fill_in(config[key], preset[key])


from sacred.config.config_summary import ConfigSummary
from sacred.config.utils import (
    dogmatize,
    normalize_or_die,
    undogmatize,
    recursive_fill_in,
)
#!/usr/bin/env python
# coding=utf-8



class ConfigDict:
    def __init__(self, d):
        self._conf = normalize_or_die(d)

    def __call__(self, fixed=None, preset=None, fallback=None):
        result = dogmatize(fixed or {})
        recursive_fill_in(result, self._conf)

# Path: sacred/config/config_summary.py
# class ConfigSummary(dict):
#     def __init__(
#         self, added=(), modified=(), typechanged=(), ignored_fallbacks=(), docs=()
#     ):
#         super().__init__()
#         self.added = set(added)
#         self.modified = set(modified)  # TODO: test for this member
#         self.typechanged = dict(typechanged)
#         self.ignored_fallbacks = set(ignored_fallbacks)  # TODO: test
#         self.docs = dict(docs)
#         self.ensure_coherence()
# 
#     def update_from(self, config_mod, path=""):
#         added = config_mod.added
#         updated = config_mod.modified
#         typechanged = config_mod.typechanged
#         self.added &= {join_paths(path, a) for a in added}
#         self.modified |= {join_paths(path, u) for u in updated}
#         self.typechanged.update(
#             {join_paths(path, k): v for k, v in typechanged.items()}
#         )
#         self.ensure_coherence()
#         for k, v in config_mod.docs.items():
#             if not self.docs.get(k, ""):
#                 self.docs[k] = v
# 
#     def update_add(self, config_mod, path=""):
#         added = config_mod.added
#         updated = config_mod.modified
#         typechanged = config_mod.typechanged
#         self.added |= {join_paths(path, a) for a in added}
#         self.modified |= {join_paths(path, u) for u in updated}
#         self.typechanged.update(
#             {join_paths(path, k): v for k, v in typechanged.items()}
#         )
#         self.docs.update(
#             {
#                 join_paths(path, k): v
#                 for k, v in config_mod.docs.items()
#                 if path == "" or k != "seed"
#             }
#         )
#         self.ensure_coherence()
# 
#     def ensure_coherence(self):
#         # make sure parent paths show up as updated appropriately
#         self.modified |= {p for a in self.added for p in iter_prefixes(a)}
#         self.modified |= {p for u in self.modified for p in iter_prefixes(u)}
#         self.modified |= {p for t in self.typechanged for p in iter_prefixes(t)}
# 
#         # make sure there is no overlap
#         self.added -= set(self.typechanged.keys())
#         self.modified -= set(self.typechanged.keys())
#         self.modified -= self.added
# 
# Path: sacred/config/utils.py
# def dogmatize(obj):
#     if isinstance(obj, dict):
#         return DogmaticDict({key: dogmatize(val) for key, val in obj.items()})
#     elif isinstance(obj, list):
#         return DogmaticList([dogmatize(value) for value in obj])
#     elif isinstance(obj, tuple):
#         return tuple(dogmatize(value) for value in obj)
#     else:
#         return obj
# 
# def normalize_or_die(obj):
#     if isinstance(obj, dict):
#         res = dict()
#         for key, value in obj.items():
#             assert_is_valid_key(key)
#             res[key] = normalize_or_die(value)
#         return res
#     elif isinstance(obj, (list, tuple)):
#         return list([normalize_or_die(value) for value in obj])
#     return normalize_numpy(obj)
# 
# def undogmatize(obj):
#     if isinstance(obj, DogmaticDict):
#         return dict({key: undogmatize(value) for key, value in obj.items()})
#     elif isinstance(obj, DogmaticList):
#         return list([undogmatize(value) for value in obj])
#     elif isinstance(obj, tuple):
#         return tuple(undogmatize(value) for value in obj)
#     else:
#         return obj
# 
# def recursive_fill_in(config, preset):
#     for key in preset:
#         if key not in config:
#             config[key] = preset[key]
#         elif isinstance(config[key], dict) and isinstance(preset[key], dict):
#             recursive_fill_in(config[key], preset[key])


# Path: sacred/config/config_dict.py
from sacred.config.config_summary import ConfigSummary
from sacred.config.utils import (
    dogmatize,
    normalize_or_die,
    undogmatize,
    recursive_fill_in,
)

#!/usr/bin/env python
# coding=utf-8



class ConfigDict:
    def __init__(self, d):
        self._conf = normalize_or_die(d)

    def __call__(self, fixed=None, preset=None, fallback=None):
        result = dogmatize(fixed or {})
        recursive_fill_in(result, self._conf)

        recursive_fill_in(result, preset or {})