Compare commits
27 Commits
develop-20
...
features/c
Author | SHA1 | Date | |
---|---|---|---|
![]() |
540c37cb06 | ||
![]() |
be89a18971 | ||
![]() |
104023e7cb | ||
![]() |
1412251d79 | ||
![]() |
186532bac1 | ||
![]() |
e09623060b | ||
![]() |
8dbd7b423b | ||
![]() |
4f5afbe97b | ||
![]() |
469401d4a1 | ||
![]() |
4bc2d12a68 | ||
![]() |
2b5be8c52a | ||
![]() |
2ad94bc76a | ||
![]() |
56671984b5 | ||
![]() |
bd40a98ccd | ||
![]() |
25e875c1d6 | ||
![]() |
de59410216 | ||
![]() |
edc3a3d19b | ||
![]() |
114ad6dd0a | ||
![]() |
3ddc16b1ff | ||
![]() |
d38ad41b65 | ||
![]() |
d68e1c976d | ||
![]() |
821d20cf06 | ||
![]() |
a92eacd3c8 | ||
![]() |
bb079ee356 | ||
![]() |
0b24c820b4 | ||
![]() |
2db85d240a | ||
![]() |
a8fa5f6ca1 |
@@ -1362,6 +1362,41 @@ def get_pkg_class(self, pkg_name):
|
|||||||
if not inspect.isclass(cls):
|
if not inspect.isclass(cls):
|
||||||
tty.die("%s.%s is not a class" % (pkg_name, class_name))
|
tty.die("%s.%s is not a class" % (pkg_name, class_name))
|
||||||
|
|
||||||
|
new_cfg_settings = (
|
||||||
|
spack.config.get("packages").get(pkg_name, {}).get("package_attributes", {})
|
||||||
|
)
|
||||||
|
|
||||||
|
overidden_attrs = getattr(cls, "overidden_attrs", {})
|
||||||
|
attrs_exclusively_from_config = getattr(cls, "attrs_exclusively_from_config", [])
|
||||||
|
# Clear any prior changes to class attributes in case the config has
|
||||||
|
# since changed
|
||||||
|
for key, val in overidden_attrs.items():
|
||||||
|
setattr(cls, key, val)
|
||||||
|
for key in attrs_exclusively_from_config:
|
||||||
|
delattr(cls, key)
|
||||||
|
|
||||||
|
# Keep track of every class attribute that is overidden by the config:
|
||||||
|
# if the config changes between calls to this method, we make sure to
|
||||||
|
# restore the original config values (in case the new config no longer
|
||||||
|
# sets attributes that it used to)
|
||||||
|
new_overidden_attrs = {}
|
||||||
|
new_attrs_exclusively_from_config = set()
|
||||||
|
for key, val in new_cfg_settings.items():
|
||||||
|
if hasattr(cls, key):
|
||||||
|
new_overidden_attrs[key] = getattr(cls, key)
|
||||||
|
else:
|
||||||
|
new_attrs_exclusively_from_config.add(key)
|
||||||
|
|
||||||
|
setattr(cls, key, val)
|
||||||
|
if new_overidden_attrs:
|
||||||
|
setattr(cls, "overidden_attrs", dict(new_overidden_attrs))
|
||||||
|
elif hasattr(cls, "overidden_attrs"):
|
||||||
|
delattr(cls, "overidden_attrs")
|
||||||
|
if new_attrs_exclusively_from_config:
|
||||||
|
setattr(cls, "attrs_exclusively_from_config", new_attrs_exclusively_from_config)
|
||||||
|
elif hasattr(cls, "attrs_exclusively_from_config"):
|
||||||
|
delattr(cls, "attrs_exclusively_from_config")
|
||||||
|
|
||||||
return cls
|
return cls
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@@ -82,6 +82,15 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
# If 'get_full_repo' is promoted to a Package-level
|
||||||
|
# attribute, it could be useful to set it here
|
||||||
|
"package_attributes": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": False,
|
||||||
|
"patternProperties": {
|
||||||
|
r"\w+": {},
|
||||||
|
},
|
||||||
|
},
|
||||||
"providers": {
|
"providers": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"default": {},
|
"default": {},
|
||||||
|
@@ -179,6 +179,43 @@ def test_preferred_providers(self):
|
|||||||
spec = concretize("mpileaks")
|
spec = concretize("mpileaks")
|
||||||
assert "zmpi" in spec
|
assert "zmpi" in spec
|
||||||
|
|
||||||
|
def test_config_set_pkg_property_url(self, mutable_mock_repo):
|
||||||
|
"""Test setting an attribute that is explicitly-handled in the schema"""
|
||||||
|
update_packages(
|
||||||
|
"mpileaks",
|
||||||
|
"package_attributes",
|
||||||
|
{"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", "package_attributes", {})
|
||||||
|
spec = concretize("mpileaks")
|
||||||
|
assert spec.package.fetcher[0].url == "http://www.llnl.gov/mpileaks-2.3.tar.gz"
|
||||||
|
|
||||||
|
def test_config_set_pkg_property_new(self, mutable_mock_repo):
|
||||||
|
"""Test that you can set arbitrary attributes on the Package class"""
|
||||||
|
update_packages(
|
||||||
|
"mpileaks",
|
||||||
|
"package_attributes",
|
||||||
|
{"x": 1, "y": True, "z": "yesterday"},
|
||||||
|
)
|
||||||
|
spec = concretize("mpileaks")
|
||||||
|
assert spec.package.x == 1
|
||||||
|
assert spec.package.y is True
|
||||||
|
assert spec.package.z == "yesterday"
|
||||||
|
|
||||||
|
update_packages("mpileaks", "package_attributes", {})
|
||||||
|
spec = concretize("mpileaks")
|
||||||
|
with pytest.raises(AttributeError):
|
||||||
|
spec.package.x
|
||||||
|
|
||||||
|
def test_config_set_pkg_property_collection_unsupported(self, mutable_mock_repo):
|
||||||
|
"""Test that an error is raised if you attempt to assign a list value"""
|
||||||
|
update_packages("mpileaks", "package_attributes", {"x": ["a", "b"]})
|
||||||
|
with pytest.raises(ConfigError):
|
||||||
|
concretize("mpileaks")
|
||||||
|
|
||||||
def test_preferred(self):
|
def test_preferred(self):
|
||||||
""" "Test packages with some version marked as preferred=True"""
|
""" "Test packages with some version marked as preferred=True"""
|
||||||
spec = Spec("python")
|
spec = Spec("python")
|
||||||
|
Reference in New Issue
Block a user