'If the spec is already concrete, return.  Otherwise take
the preferred version from spackconfig, and default to the package\'s
version if there are no available versions.
TODO: In many cases we probably want to look for installed
versions of each package and use an installed version
if we can link to it.  The policy implemented here will
tend to rebuild a lot of stuff becasue it will prefer
a compiler in the spec to any compiler already-
installed things were built with.  There is likely
some better policy that finds some middle ground
between these two extremes.'

def concretize_version(self, spec):

    if spec.versions.concrete:
        return False
    pkg = spec.package
    usable = [v for v in pkg.versions if any((v.satisfies(sv) for sv in spec.versions))]
    yaml_prefs = PackagePrefs(spec.name, 'version')
    keyfn = (lambda v: ((- yaml_prefs(v)), pkg.versions.get(Version(v)).get('preferred', False), (not v.isdevelop()), v))
    usable.sort(key=keyfn, reverse=True)
    if usable:
        spec.versions = ver([usable[0]])
    elif ((not spec.versions) or (spec.versions == VersionList([':']))):
        raise NoValidVersionError(spec)
    else:
        last = spec.versions[(-1)]
        if isinstance(last, VersionRange):
            if last.end:
                spec.versions = ver([last.end])
            else:
                spec.versions = ver([last.start])
        else:
            spec.versions = ver([last])
    return True
