From 8dbd7b423b685d8e3e1913ebdc2197301e0640e3 Mon Sep 17 00:00:00 2001 From: Peter Josef Scheibel Date: Fri, 21 Oct 2022 15:02:06 -0600 Subject: [PATCH] add placeholders for assigning collection types --- lib/spack/spack/repo.py | 6 ++++++ lib/spack/spack/schema/packages.py | 11 +++++++++-- lib/spack/spack/test/concretize_preferences.py | 14 +++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/spack/spack/repo.py b/lib/spack/spack/repo.py index 1d2eb4a083a..05ae85be04d 100644 --- a/lib/spack/spack/repo.py +++ b/lib/spack/spack/repo.py @@ -1374,6 +1374,12 @@ def get_pkg_class(self, pkg_name): # sets attributes that it used to) new_overidden_attrs = {} for key, val in new_cfg_settings.items(): + if hasattr(cls, key): + new_overidden_attrs[key] = getattr(cls, key) + if isinstance(val, list): + raise spack.config.ConfigError("Unsupported attribute value: list") + elif isinstance(val, dict): + raise spack.config.ConfigError("Unsupported attribute value: dict") if key not in ["git", "url", "submodules"]: # Infer type val = yaml.load(val) diff --git a/lib/spack/spack/schema/packages.py b/lib/spack/spack/schema/packages.py index 57a20e6ee57..cae3fd52e8d 100644 --- a/lib/spack/spack/schema/packages.py +++ b/lib/spack/spack/schema/packages.py @@ -99,8 +99,15 @@ }, }, "patternProperties": { - r"\w[\w-]*": { - "type": "string", + r"\w+": { + "oneOf": [ + {"type": "string"}, + {"type": "array", "items": {"type": "string"}}, + { + "type": "object", + "patternProperties": {r"\w+": {"type": "string"}}, + }, + ] }, }, }, diff --git a/lib/spack/spack/test/concretize_preferences.py b/lib/spack/spack/test/concretize_preferences.py index a80cb1a8590..4d9b2a4a767 100644 --- a/lib/spack/spack/test/concretize_preferences.py +++ b/lib/spack/spack/test/concretize_preferences.py @@ -179,7 +179,7 @@ def test_preferred_providers(self): spec = concretize("mpileaks") assert "zmpi" in spec - def test_config_set_url_for_package(self, mutable_mock_repo): + def test_config_set_pkg_property_url(self, mutable_mock_repo): """Test preferred providers of virtual packages are applied correctly """ @@ -195,10 +195,8 @@ def test_config_set_url_for_package(self, mutable_mock_repo): spec = concretize("mpileaks") assert spec.package.fetcher[0].url == "http://www.llnl.gov/mpileaks-2.3.tar.gz" - def test_config_set_package_property(self, mutable_mock_repo): - """Test preferred providers of virtual packages are - applied correctly - """ + 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", @@ -208,6 +206,12 @@ def test_config_set_package_property(self, mutable_mock_repo): assert spec.package.x == 1 assert spec.package.y == True + def test_config_set_pkg_property_collecton_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): + spec = concretize("mpileaks") + def test_preferred(self): """ "Test packages with some version marked as preferred=True""" spec = Spec("python")