def make_modules_dict(*dcts, **kwargs):
    """Makes a dictionary suitable to be exposed as the '_modules' of a package.

    This combines dictionaries hierarchically to make a global dict from other
    "sub-dicts", allowing to structure a package with subpackages.

    For example, you could have:
        a/aa.py:
            _modules = {'aa': [Some, Module]}
        a/__init__.py:
            from .aa import _modules as aa_modules
            from .ab import _modules as bb_modules
            _modules = make_modules_dict(aa_modules, bb_modules, namespace='a')
        b.py:
            _modules = {'b': [Other, Modules]}
        init.py:
            from .a import _modules as a_modules
            from .b import _modules as b_modules
            _modules = make_modules_dict(a_modules, b_modules)

    The resulting module hierarchy will be:
        a.aa.Some, a.aa.Module
        b.Other, b.Modules
    """
    namespace = kwargs.pop('namespace', '')
    if kwargs:
        raise TypeError("make_modules_dict got unexpected keyword arguments")
    if namespace:
        build_namespace = lambda n: '%s|%s' % (namespace, n)
    else:
        build_namespace = lambda n: n

    dct = dict()
    for d in dcts:
        if not isinstance(d, dict):
            d = {'': d}

        for subname, sublist in d.iteritems():
            if subname:
                name = build_namespace(subname)
            else:
                name = namespace
            dct.setdefault(name, []).extend(sublist)

    return dct


###############################################################################
dataset/ETHPy150Open VisTrails/VisTrails/vistrails/core/modules/utils.py/make_modules_dict/original