Add package_class method to spec.

- Shouldn't call .package from within things like normalize() and
  concretize() beacuse spec may be inconsistent.

- Add `.package_class` property so that we can get at package metadata
  without constructing a Package with a Spec.

- should be faster than `.package` was, anyway. Use where possible.
This commit is contained in:
Todd Gamblin 2016-03-14 04:59:29 -07:00
parent 003fd4d834
commit 05c761dee9
3 changed files with 18 additions and 5 deletions

View File

@ -238,7 +238,7 @@ def concretize_variants(self, spec):
the default variants from the package specification.
"""
changed = False
for name, variant in spec.package.variants.items():
for name, variant in spec.package_class.variants.items():
if name not in spec.variants:
spec.variants[name] = spack.spec.VariantSpec(name, variant.default)
changed = True

View File

@ -316,6 +316,11 @@ def get(self, spec, new=False):
return self.repo_for_pkg(spec).get(spec)
def get_pkg_class(self, pkg_name):
"""Find a class for the spec's package and return the class object."""
return self.repo_for_pkg(pkg_name).get_pkg_class(pkg_name)
@_autospec
def dump_provenance(self, spec, path):
"""Dump provenance information for a spec to a particular path.
@ -550,7 +555,7 @@ def get(self, spec, new=False):
key = hash(spec)
if new or key not in self._instances:
package_class = self._get_pkg_class(spec.name)
package_class = self.get_pkg_class(spec.name)
try:
copy = spec.copy() # defensive copy. Package owns its spec.
self._instances[key] = package_class(copy)
@ -715,7 +720,7 @@ def _get_pkg_module(self, pkg_name):
return self._modules[pkg_name]
def _get_pkg_class(self, pkg_name):
def get_pkg_class(self, pkg_name):
"""Get the class for the package out of its module.
First loads (or fetches from cache) a module for the

View File

@ -353,7 +353,7 @@ def constrain(self, other):
@property
def concrete(self):
return self.spec._concrete or all(
v in self for v in self.spec.package.variants)
v in self for v in self.spec.package_class.variants)
def copy(self):
@ -498,6 +498,14 @@ def package(self):
return spack.repo.get(self)
@property
def package_class(self):
"""Internal package call gets only the class object for a package.
Use this to just get package metadata.
"""
return spack.repo.get_pkg_class(self.name)
@property
def virtual(self):
"""Right now, a spec is virtual if no package exists with its name.
@ -1161,7 +1169,7 @@ def validate_names(self):
# Ensure that variants all exist.
for vname, variant in spec.variants.items():
if vname not in spec.package.variants:
if vname not in spec.package_class.variants:
raise UnknownVariantError(spec.name, vname)