'Return a VariantMap of preferred variants/values for a spec.'

@classmethod
def preferred_variants(cls, pkg_name):

    for pkg in (pkg_name, 'all'):
        variants = cls._packages_config.get(pkg, {}).get('variants', '')
        if variants:
            break
    if (not isinstance(variants, string_types)):
        variants = '    '.join(variants)
    pkg = spack.repo.get(pkg_name)
    spec = spack.spec.Spec(('%s    %s' % (pkg_name, variants)))
    return dict(((name, variant) for (name, variant) in spec.variants.items() if (name in pkg.variants)))
