# Path: sacred/config/config_files.py
# def save_config_file(config, filename):
#     handler = get_handler(filename)
#     with open(filename, "w" + handler.mode) as f:
#         handler.dump(config, f)
# 
# Path: sacred/serializer.py
# def flatten(obj):
#     return _json.loads(json.encode(obj, keys=True))
# 
# Path: sacred/utils.py
# PATHCHANGE = object()
# 
# def iterate_flattened_separately(dictionary, manually_sorted_keys=None):
#     """
#     Recursively iterate over the items of a dictionary in a special order.
# 
#     First iterate over manually sorted keys and then over all items that are
#     non-dictionary values (sorted by keys), then over the rest
#     (sorted by keys), providing full dotted paths for every leaf.
#     """
#     manually_sorted_keys = manually_sorted_keys or []
# 
#     def get_order(key_and_value):
#         key, value = key_and_value
#         if key in manually_sorted_keys:
#             return 0, manually_sorted_keys.index(key)
#         elif not is_non_empty_dict(value):
#             return 1, key
#         else:
#             return 2, key
# 
#     for key, value in sorted(dictionary.items(), key=get_order):
#         if is_non_empty_dict(value):
#             yield key, PATHCHANGE
#             for k, val in iterate_flattened_separately(value, manually_sorted_keys):
#                 yield join_paths(key, k), val
#         else:
#             yield key, value


import copy
import pprint
import pydoc
import re
import sys
from collections import namedtuple, OrderedDict
from colorama import Fore, Style
from sacred.config import save_config_file
from sacred.serializer import flatten
from sacred.utils import PATHCHANGE, iterate_flattened_separately

    print("\nSources:")
    for source, digest in _run.experiment_info["sources"]:
        print("  {:<43}  {}".format(source, digest))

    if _run.experiment_info["repositories"]:
        repos = _run.experiment_info["repositories"]
        print("\nVersion Control:")
        for repo in repos:
            mod = COLOR_DIRTY + "M" if repo["dirty"] else " "
            print("{} {:<43}  {}".format(mod, repo["url"], repo["commit"]) + ENDC)
    print("")


def save_config(_config, _log, config_filename="config.json"):
    """
    Store the updated configuration in a file.

    By default uses the filename "config.json", but that can be changed by
    setting the config_filename config entry.
    """
    # Copy the config to make it mutable
    _config = copy.deepcopy(_config)
    if "config_filename" in _config:
        del _config["config_filename"]
    _log.info('Saving config to "{}"'.format(config_filename))
    save_config_file(flatten(_config), config_filename)


def _iterate_marked(cfg, config_mods):

# Path: sacred/config/config_files.py
# def save_config_file(config, filename):
#     handler = get_handler(filename)
#     with open(filename, "w" + handler.mode) as f:
#         handler.dump(config, f)
# 
# Path: sacred/serializer.py
# def flatten(obj):
#     return _json.loads(json.encode(obj, keys=True))
# 
# Path: sacred/utils.py
# PATHCHANGE = object()
# 
# def iterate_flattened_separately(dictionary, manually_sorted_keys=None):
#     """
#     Recursively iterate over the items of a dictionary in a special order.
# 
#     First iterate over manually sorted keys and then over all items that are
#     non-dictionary values (sorted by keys), then over the rest
#     (sorted by keys), providing full dotted paths for every leaf.
#     """
#     manually_sorted_keys = manually_sorted_keys or []
# 
#     def get_order(key_and_value):
#         key, value = key_and_value
#         if key in manually_sorted_keys:
#             return 0, manually_sorted_keys.index(key)
#         elif not is_non_empty_dict(value):
#             return 1, key
#         else:
#             return 2, key
# 
#     for key, value in sorted(dictionary.items(), key=get_order):
#         if is_non_empty_dict(value):
#             yield key, PATHCHANGE
#             for k, val in iterate_flattened_separately(value, manually_sorted_keys):
#                 yield join_paths(key, k), val
#         else:
#             yield key, value


# Path: sacred/commands.py
import copy
import pprint
import pydoc
import re
import sys
from collections import namedtuple, OrderedDict
from colorama import Fore, Style
from sacred.config import save_config_file
from sacred.serializer import flatten
from sacred.utils import PATHCHANGE, iterate_flattened_separately


    print("\nSources:")
    for source, digest in _run.experiment_info["sources"]:
        print("  {:<43}  {}".format(source, digest))

    if _run.experiment_info["repositories"]:
        repos = _run.experiment_info["repositories"]
        print("\nVersion Control:")
        for repo in repos:
            mod = COLOR_DIRTY + "M" if repo["dirty"] else " "
            print("{} {:<43}  {}".format(mod, repo["url"], repo["commit"]) + ENDC)
    print("")


def save_config(_config, _log, config_filename="config.json"):
    """
    Store the updated configuration in a file.

    By default uses the filename "config.json", but that can be changed by
    setting the config_filename config entry.
    """
    # Copy the config to make it mutable
    _config = copy.deepcopy(_config)
    if "config_filename" in _config:
        del _config["config_filename"]
    _log.info('Saving config to "{}"'.format(config_filename))
    save_config_file(flatten(_config), config_filename)


def _iterate_marked(cfg, config_mods):

    for path, value in iterate_flattened_separately(cfg, ["__doc__"]):