def _normalize_packages_yaml(packages_yaml):
    normalized_yaml = copy.copy(packages_yaml)
    for pkg_name in packages_yaml:
        is_virtual = spack.repo.path.is_virtual(pkg_name)
        if ((pkg_name == 'all') or (not is_virtual)):
            continue
        data = normalized_yaml.pop(pkg_name)
        is_buildable = data.get('buildable', True)
        if (not is_buildable):
            for provider in spack.repo.path.providers_for(pkg_name):
                entry = normalized_yaml.setdefault(provider.name, {})
                entry['buildable'] = False
        externals = data.get('externals', [])
        keyfn = (lambda x: spack.spec.Spec(x['spec']).name)
        for (provider, specs) in itertools.groupby(externals, key=keyfn):
            entry = normalized_yaml.setdefault(provider, {})
            entry.setdefault('externals', []).extend(specs)
    return normalized_yaml
def _normalize_packages_yaml(packages_yaml):
    normalized_yaml = copy.copy(packages_yaml)
    for pkg_name in packages_yaml:
        is_virtual = spack.repo.path.is_virtual(pkg_name)
        if ((pkg_name == 'all') or (not is_virtual)):
            continue
        data = normalized_yaml.pop(pkg_name)
        is_buildable = data.get('buildable', True)
        if (not is_buildable):
            for provider in spack.repo.path.providers_for(pkg_name):
                entry = normalized_yaml.setdefault(provider.name, {})
                entry['buildable'] = False
        externals = data.get('externals', [])
        keyfn = (lambda x: spack.spec.Spec(x['spec']).name)
        for (provider, specs) in itertools.groupby(externals, key=keyfn):
            entry = normalized_yaml.setdefault(provider, {})
            entry.setdefault('externals', []).extend(specs)
    return normalized_yaml