Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend spack version backward compatibility #614

Merged
merged 5 commits into from
Jul 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Attempt to get all tests passing with older spack versions
psakievich committed Jul 19, 2024
commit 72cb54d81835fca16b6ddecf1bd9d2d30c7a2452
39 changes: 19 additions & 20 deletions manager/environment_utils.py
Original file line number Diff line number Diff line change
@@ -6,14 +6,25 @@
# for more details.

import spack.environment.environment as senv

__attrs__ = ["configuration", "pristine_configuration"]
try:
from spack.environment.environment import config_dict
except ImportError:
pass


# 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 config_dict(self)
else:
continue

def set_config_value(self, root, key, value=None):
"""Set/overwrite a config value

@@ -22,47 +33,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
@@ -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:
2 changes: 2 additions & 0 deletions tests/test_spack_manager_environment_manifest.py
Original file line number Diff line number Diff line change
@@ -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()