From d9c3ec94566dc9b4adc99a8572525e4b48e082bb Mon Sep 17 00:00:00 2001 From: psakievich Date: Fri, 19 Jul 2024 00:32:01 -0600 Subject: [PATCH] Extend spack version backward compatibility (#614) * Attempt to get all tests passing with older spack versions * Update CI version * Tweak configuration * Style * Add ci exclusion --- .github/workflows/tests.yml | 11 ++++-- manager/environment_utils.py | 35 ++++++++----------- manager/manager_cmds/includes_creator.py | 7 +++- ...test_spack_manager_environment_manifest.py | 2 ++ 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 21a17383..371110bb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -19,8 +19,10 @@ jobs: fail-fast: false matrix: python-version: [3.8, 3.9, 3.12] - - spack-version: [v0.21.2, v0.22.0, v0.22.1, develop] + spack-version: [v0.20.3, v0.21.2, v0.22.0, v0.22.1, develop] + exclude: + - python-version: 3.12 + spack-version: v0.20.3 steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} @@ -80,7 +82,10 @@ jobs: fail-fast: false matrix: python-version: [3.8, 3.9] - spack-version: [v0.21.2, v0.22.0, v0.22.1, develop] + spack-version: [v0.20.3, v0.21.2, v0.22.0, v0.22.1, develop] + exclude: + - python-version: 3.12 + spack-version: v0.20.3 steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} diff --git a/manager/environment_utils.py b/manager/environment_utils.py index 1326e435..497c5ace 100644 --- a/manager/environment_utils.py +++ b/manager/environment_utils.py @@ -7,13 +7,20 @@ import spack.environment.environment as senv -__attrs__ = ["configuration", "pristine_configuration"] - # TODO spack version dependent code class SpackManagerEnvironmentManifest(senv.EnvironmentManifestFile): """Spack-Manager extension to the manifest file for prototyping""" + def version_compatible_config_generator(self): + """generator to deal with all the ways to get the in memory configs across versions""" + for attr in ["yaml_content", "pristine_yaml_content"]: + if hasattr(self, attr): + yaml = getattr(self, attr) + yield yaml["spack"] + else: + continue + def set_config_value(self, root, key, value=None): """Set/overwrite a config value @@ -22,18 +29,14 @@ def set_config_value(self, root, key, value=None): key: next level where we will be updating value: value to set """ - for attr in __attrs__: - if hasattr(self, attr): - configuration = getattr(self, attr) - else: - continue + for configuration in self.version_compatible_config_generator(): if value: if root not in configuration: configuration[root] = {} configuration.get(root, {})[key] = value else: configuration[root] = key - self.changed = True + self.changed = True def append_includes(self, value): """Add to the includes in the manifest @@ -41,15 +44,11 @@ def append_includes(self, value): Args: value: value to add at the end of the list """ - for attr in __attrs__: - if hasattr(self, attr): - configuration = getattr(self, attr) - else: - continue + for configuration in self.version_compatible_config_generator(): if "include" not in configuration: configuration["include"] = [] configuration.get("include", []).append(value) - self.changed = True + self.changed = True def prepend_includes(self, value): """Add to the includes in the manifest @@ -57,12 +56,8 @@ def prepend_includes(self, value): Args: value: value to add at the beginning of the list """ - for attr in __attrs__: - if hasattr(self, attr): - configuration = getattr(self, attr) - else: - continue + for configuration in self.version_compatible_config_generator(): if "include" not in configuration: configuration["include"] = [] configuration.get("include", [])[:0] = [value] - self.changed = True + self.changed = True diff --git a/manager/manager_cmds/includes_creator.py b/manager/manager_cmds/includes_creator.py index 01539be2..07b2e122 100644 --- a/manager/manager_cmds/includes_creator.py +++ b/manager/manager_cmds/includes_creator.py @@ -19,6 +19,11 @@ except ImportError: from spack.config import ConfigScope as DirScope +try: + from spack.config import SECTION_SCHEMAS as sc_section_schemas +except ImportError: + from spack.config import section_schemas as sc_section_schemas + class IncludesCreator: def __init__(self): @@ -36,7 +41,7 @@ def write_includes(self, filename, path=None): filename = os.path.abspath(os.path.join(path, filename)) abspath = os.path.abspath(filename) # TODO this is spack version dependent - sections = list(spack.config.SECTION_SCHEMAS.keys()) + sections = list(sc_section_schemas.keys()) data = syaml.syaml_dict() try: for s in sections: diff --git a/tests/test_spack_manager_environment_manifest.py b/tests/test_spack_manager_environment_manifest.py index 787acf32..35807191 100644 --- a/tests/test_spack_manager_environment_manifest.py +++ b/tests/test_spack_manager_environment_manifest.py @@ -15,7 +15,9 @@ def test_smManifestCanSetConfig(tmpdir): f.write("spack:\n specs: []") testManifest = smem(tmpdir.strpath) + assert list(testManifest.version_compatible_config_generator()) testManifest.set_config_value("config", "install_tree", {"root": "$env/opt"}) + assert "config" in testManifest.yaml_content["spack"] testManifest.append_includes("include.yaml") testManifest.prepend_includes("first_include.yaml") testManifest.flush()