'Returns a list of candidate virtual dep providers and external
packages that coiuld be used to concretize a spec.
Preferred specs come first in the list.'

def _valid_virtuals_and_externals(self, spec):

    candidates = [spec]
    pref_key = (lambda spec: 0)
    if spec.virtual:
        candidates = spack.repo.providers_for(spec)
        if (not candidates):
            raise UnsatisfiableProviderSpecError(candidates[0], spec)
        spec_w_prefs = find_spec(spec, (lambda p: PackagePrefs.has_preferred_providers(p.name, spec.name)), spec)
        pref_key = PackagePrefs(spec_w_prefs.name, 'providers', spec.name)
    usable = OrderedDict()
    for cspec in candidates:
        if is_spec_buildable(cspec):
            usable[cspec] = True
        externals = spec_externals(cspec)
        for ext in externals:
            if ext.satisfies(spec):
                usable[ext] = True
    if (not usable):
        raise NoBuildError(spec)
    return sorted(usable, key=(lambda spec: ((not spec.external), pref_key(spec), spec.name, reverse_order(spec.versions), spec)))
