add test; set attributes on instance vs. on class
This commit is contained in:
committed by
Gregory Becker
parent
a8fa5f6ca1
commit
2db85d240a
@@ -1169,7 +1169,7 @@ def get(self, spec):
|
||||
|
||||
package_class = self.get_pkg_class(spec.name)
|
||||
try:
|
||||
return package_class(spec)
|
||||
package_instance = package_class(spec)
|
||||
except spack.error.SpackError:
|
||||
# pass these through as their error messages will be fine.
|
||||
raise
|
||||
@@ -1182,6 +1182,15 @@ def get(self, spec):
|
||||
sys.excepthook(*sys.exc_info())
|
||||
raise FailedConstructorError(spec.fullname, *sys.exc_info())
|
||||
|
||||
# packages.yaml config can override package attributes. This is set
|
||||
# on the instance rather than the class since the configuration can
|
||||
# change between calls to repo.get for the same package.
|
||||
settings = spack.config.get("packages").get(spec.name, {}).get("set", {})
|
||||
for key, val in settings.items():
|
||||
setattr(package_instance, key, val)
|
||||
|
||||
return package_instance
|
||||
|
||||
@autospec
|
||||
def dump_provenance(self, spec, path):
|
||||
"""Dump provenance information for a spec to a particular path.
|
||||
@@ -1362,11 +1371,6 @@ def get_pkg_class(self, pkg_name):
|
||||
if not inspect.isclass(cls):
|
||||
tty.die("%s.%s is not a class" % (pkg_name, class_name))
|
||||
|
||||
# packages.yaml config can override package attributes
|
||||
settings = spack.config.get("packages").get(pkg_name, {}).get("set", {})
|
||||
for key, val in settings.items():
|
||||
setattr(cls, key, val)
|
||||
|
||||
return cls
|
||||
|
||||
def __str__(self):
|
||||
|
||||
@@ -179,6 +179,22 @@ def test_preferred_providers(self):
|
||||
spec = concretize("mpileaks")
|
||||
assert "zmpi" in spec
|
||||
|
||||
def test_config_set_url_for_package(self, mutable_mock_repo):
|
||||
"""Test preferred providers of virtual packages are
|
||||
applied correctly
|
||||
"""
|
||||
update_packages(
|
||||
"mpileaks",
|
||||
"set",
|
||||
{"url": "http://www.somewhereelse.com/mpileaks-1.0.tar.gz"}
|
||||
)
|
||||
spec = concretize("mpileaks")
|
||||
assert spec.package.fetcher[0].url == "http://www.somewhereelse.com/mpileaks-2.3.tar.gz"
|
||||
|
||||
update_packages("mpileaks", "set", {})
|
||||
spec = concretize("mpileaks")
|
||||
assert spec.package.fetcher[0].url == "http://www.llnl.gov/mpileaks-2.3.tar.gz"
|
||||
|
||||
def test_preferred(self):
|
||||
""" "Test packages with some version marked as preferred=True"""
|
||||
spec = Spec("python")
|
||||
|
||||
Reference in New Issue
Block a user