Compare commits

...

27 Commits

Author SHA1 Message Date
Gregory Becker
540c37cb06 allow lists and dicts since we get them for free 2022-11-04 17:51:58 -07:00
Gregory Becker
be89a18971 becker: show simplification idea 2022-11-04 17:51:58 -07:00
Peter Josef Scheibel
104023e7cb auto style fix 2022-11-04 17:51:58 -07:00
Peter Josef Scheibel
1412251d79 account for attributes that should be deleted (i.e. if they weren't set originally on the package) 2022-11-04 17:51:58 -07:00
Peter Josef Scheibel
186532bac1 style fixes 2022-11-04 17:51:58 -07:00
Peter Josef Scheibel
e09623060b update test to clarify parsing 2022-11-04 17:51:58 -07:00
Peter Josef Scheibel
8dbd7b423b add placeholders for assigning collection types 2022-11-04 17:51:58 -07:00
Peter Josef Scheibel
4f5afbe97b do type inference on strings (this works well for values that are not collections) 2022-11-04 17:51:57 -07:00
Peter Josef Scheibel
469401d4a1 style fix 2022-11-04 17:51:57 -07:00
Peter Josef Scheibel
4bc2d12a68 intermediate work on arbitrary types for pkg_attribute 2022-11-04 17:51:57 -07:00
Peter Josef Scheibel
2b5be8c52a only delete the attribute if it exists 2022-11-04 17:51:57 -07:00
Peter Josef Scheibel
2ad94bc76a make sure to remove old overidden_attrs 2022-11-04 17:51:57 -07:00
Peter Josef Scheibel
56671984b5 only set storage variable on class if there is anything to keep track of 2022-11-04 17:51:57 -07:00
Peter Josef Scheibel
bd40a98ccd Revert "remove new test and see if that's part of the problem (even though it isn't run before the failing test)"
This reverts commit 48c15d2f6be8a0bd88428e015ea41a8c814130f8.
2022-11-04 17:51:57 -07:00
Peter Josef Scheibel
25e875c1d6 remove new test and see if that's part of the problem (even though it isn't run before the failing test) 2022-11-04 17:51:56 -07:00
Peter Josef Scheibel
de59410216 Revert "temporarily undo everything in this PR to check if it could somehow be causing a failure in an unrelated test"
This reverts commit c138b808304d68748308ea21e46a08bb028ab584.
2022-11-04 17:51:56 -07:00
Peter Josef Scheibel
edc3a3d19b temporarily undo everything in this PR to check if it could somehow be causing a failure in an unrelated test 2022-11-04 17:51:56 -07:00
Peter Josef Scheibel
114ad6dd0a auto style fix 2022-11-04 17:51:56 -07:00
Peter Josef Scheibel
3ddc16b1ff add clarifying comment 2022-11-04 17:51:56 -07:00
Peter Josef Scheibel
d38ad41b65 move setattr back to get_pkg_class (since these config settings can affect class-level attrs) 2022-11-04 17:51:56 -07:00
Peter Josef Scheibel
d68e1c976d add note for consideration 2022-11-04 17:51:56 -07:00
Peter Josef Scheibel
821d20cf06 auto style fix 2022-11-04 17:51:55 -07:00
Peter Josef Scheibel
a92eacd3c8 rename 'set' to 'package_attributes' 2022-11-04 17:51:55 -07:00
Peter Josef Scheibel
bb079ee356 move set logic to PackageBase initializer (otherwise, users could instantiate package_class() in other locations and bypass the config) 2022-11-04 17:51:55 -07:00
Peter Josef Scheibel
0b24c820b4 auto style fix 2022-11-04 17:51:55 -07:00
Peter Josef Scheibel
2db85d240a add test; set attributes on instance vs. on class 2022-11-04 17:51:55 -07:00
Peter Josef Scheibel
a8fa5f6ca1 core changes to allow setting git/url attribute on packages 2022-11-04 17:51:55 -07:00
3 changed files with 81 additions and 0 deletions

View File

@@ -1362,6 +1362,41 @@ def get_pkg_class(self, pkg_name):
if not inspect.isclass(cls):
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
def __str__(self):

View File

@@ -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": {
"type": "object",
"default": {},

View File

@@ -179,6 +179,43 @@ def test_preferred_providers(self):
spec = concretize("mpileaks")
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):
""" "Test packages with some version marked as preferred=True"""
spec = Spec("python")