def build_version_dict(self, possible_pkgs, specs):
    'Declare any versions in specs not declared in packages.'
    self.declared_versions = collections.defaultdict(list)
    self.possible_versions = collections.defaultdict(set)
    self.deprecated_versions = collections.defaultdict(set)
    packages_yaml = spack.config.get('packages')
    packages_yaml = _normalize_packages_yaml(packages_yaml)
    for pkg_name in possible_pkgs:
        pkg = spack.repo.get(pkg_name)

        def key_fn(item):
            (version, info) = item
            return (info.get('preferred', False), (not version.isdevelop()), version)
        for (idx, item) in enumerate(sorted(pkg.versions.items(), key=key_fn, reverse=True)):
            (v, version_info) = item
            self.possible_versions[pkg_name].add(v)
            self.declared_versions[pkg_name].append(DeclaredVersion(version=v, idx=idx, origin=version_provenance.package_py))
            deprecated = version_info.get('deprecated', False)
            if deprecated:
                self.deprecated_versions[pkg_name].add(v)
        version_preferences = packages_yaml.get(pkg_name, {}).get('version', [])
        for (idx, v) in enumerate(version_preferences):
            self.declared_versions[pkg_name].append(DeclaredVersion(version=v, idx=idx, origin=version_provenance.packages_yaml))
    for spec in specs:
        for dep in spec.traverse():
            if dep.versions.concrete:
                self.declared_versions[dep.name].append(DeclaredVersion(version=dep.version, idx=0, origin=version_provenance.spec))
                self.possible_versions[dep.name].add(dep.version)
Declare any versions in specs not declared in packages.
def build_version_dict(self, possible_pkgs, specs):
    
    self.declared_versions = collections.defaultdict(list)
    self.possible_versions = collections.defaultdict(set)
    self.deprecated_versions = collections.defaultdict(set)
    packages_yaml = spack.config.get('packages')
    packages_yaml = _normalize_packages_yaml(packages_yaml)
    for pkg_name in possible_pkgs:
        pkg = spack.repo.get(pkg_name)

        def key_fn(item):
            (version, info) = item
            return (info.get('preferred', False), (not version.isdevelop()), version)
        for (idx, item) in enumerate(sorted(pkg.versions.items(), key=key_fn, reverse=True)):
            (v, version_info) = item
            self.possible_versions[pkg_name].add(v)
            self.declared_versions[pkg_name].append(DeclaredVersion(version=v, idx=idx, origin=version_provenance.package_py))
            deprecated = version_info.get('deprecated', False)
            if deprecated:
                self.deprecated_versions[pkg_name].add(v)
        version_preferences = packages_yaml.get(pkg_name, {}).get('version', [])
        for (idx, v) in enumerate(version_preferences):
            self.declared_versions[pkg_name].append(DeclaredVersion(version=v, idx=idx, origin=version_provenance.packages_yaml))
    for spec in specs:
        for dep in spec.traverse():
            if dep.versions.concrete:
                self.declared_versions[dep.name].append(DeclaredVersion(version=dep.version, idx=0, origin=version_provenance.spec))
                self.possible_versions[dep.name].add(dep.version)