Skip to content

Commit

Permalink
Extend spack version backward compatibility (#614)
Browse files Browse the repository at this point in the history
* Attempt to get all tests passing with older spack versions

* Update CI version

* Tweak configuration

* Style

* Add ci exclusion
  • Loading branch information
psakievich committed Jul 19, 2024
1 parent aab715e commit d9c3ec9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 24 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand Down
35 changes: 15 additions & 20 deletions manager/environment_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,47 +29,35 @@ 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
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
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
7 changes: 6 additions & 1 deletion manager/manager_cmds/includes_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_spack_manager_environment_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit d9c3ec9

Please sign in to comment.