Skip to content

Commit

Permalink
Fixes for changes in core spack (#610)
Browse files Browse the repository at this point in the history
* Fixes for changes in core spack

Address changes to spack environments and scopes
See:
- spack/spack#45044
- spack/spack#45135

* Fixes

* Style ci

* Style
  • Loading branch information
psakievich authored Jul 16, 2024
1 parent 034f0ff commit c615178
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 53 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ jobs:
fail-fast: false
matrix:
python-version: [3.8, 3.9, 3.12]
spack-version: [v0.21.2, v0.22.0, develop]

spack-version: [v0.21.2, v0.22.0, v0.22.1, develop]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down Expand Up @@ -65,7 +66,8 @@ jobs:
run: |
ls -lh "$PWD/spack"
ls -lh "$PWD/spack/.github/"
cp ${GITHUB_WORKSPACE}/spack/.github/workflows/style/requirements.txt "$PWD"
if [ -f ${GITHUB_WORKSPACE}/spack/.github/workflows/style/requirements.txt ]; then cp ${GITHUB_WORKSPACE}/spack/.github/workflows/style/requirements.txt "$PWD"; fi
if [ -f ${GITHUB_WORKSPACE}/spack/.github/workflows/requirements/style/requirements.txt ]; then cp ${GITHUB_WORKSPACE}/spack/.github/workflows/requirements/style/requirements.txt "$PWD"; fi
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install extension
Expand All @@ -78,7 +80,7 @@ jobs:
fail-fast: false
matrix:
python-version: [3.8, 3.9]
spack-version: [v0.21.2, v0.22.0, develop]
spack-version: [v0.21.2, v0.22.0, v0.22.1, develop]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
1 change: 0 additions & 1 deletion manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def remove_project_via_index(index):
config_yaml["spack-manager"]["projects"].pop(index)
write_config()
else:
breakpoint()
raise MissingProjectException("No project is registered with the index {0}".format(index))


Expand Down
59 changes: 33 additions & 26 deletions manager/environment_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

import spack.environment.environment as senv

__attrs__ = ["configuration", "pristine_configuration"]


# TODO spack version dependent code
class SpackManagerEnvironmentManifest(senv.EnvironmentManifestFile):
"""Spack-Manager extensiont to the manifest file for prototyping"""
"""Spack-Manager extension to the manifest file for prototyping"""

def set_config_value(self, root, key, value=None):
"""Set/overwrite a config value
Expand All @@ -20,42 +22,47 @@ def set_config_value(self, root, key, value=None):
key: next level where we will be updating
value: value to set
"""
if value:
if root not in self.pristine_configuration:
self.pristine_configuration[root] = {}
if root not in self.configuration:
self.configuration[root] = {}

self.pristine_configuration.get(root, {})[key] = value
self.configuration.get(root, {})[key] = value
else:
self.pristine_configuration[root] = key
self.configuration[root] = key

self.changed = True
for attr in __attrs__:
if hasattr(self, attr):
configuration = getattr(self, attr)
else:
continue
if value:
if root not in configuration:
configuration[root] = {}
configuration.get(root, {})[key] = value
else:
configuration[root] = key
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
"""
if "include" not in self.pristine_configuration:
self.pristine_configuration["include"] = []
self.configuration["include"] = []
self.pristine_configuration.get("include", []).append(value)
self.configuration.get("include", []).append(value)
self.changed = True
for attr in __attrs__:
if hasattr(self, attr):
configuration = getattr(self, attr)
else:
continue
if "include" not in configuration:
configuration["include"] = []
configuration.get("include", []).append(value)
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
"""
if "include" not in self.pristine_configuration:
self.pristine_configuration["include"] = []
self.configuration["include"] = []
self.pristine_configuration.get("include", [])[:0] = [value]
self.configuration.get("include", [])[:0] = [value]
self.changed = True
for attr in __attrs__:
if hasattr(self, attr):
configuration = getattr(self, attr)
else:
continue
if "include" not in configuration:
configuration["include"] = []
configuration.get("include", [])[:0] = [value]
self.changed = True
2 changes: 1 addition & 1 deletion manager/manager_cmds/create_dev_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def create_dev_env(parser, args):
s.versions = spack.version.VersionList([version])

dev_args = []
yaml = env.manifest.pristine_yaml_content
yaml = env.manifest.yaml_content
# kind of hacky, but spack will try to re-clone
# if we don't give the --path argument even though
# it is already in the spack.yaml
Expand Down
2 changes: 1 addition & 1 deletion manager/manager_cmds/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

def include_entry_exists(env, name):
manifest = SpackManagerEnvironmentManifest(env.manifest.manifest_dir)
includes = manifest.pristine_configuration.get("include", [])
includes = manifest.configuration.get("include", [])
for entry in includes:
if entry == name:
return True
Expand Down
7 changes: 6 additions & 1 deletion manager/manager_cmds/includes_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
import spack.config
import spack.util.spack_yaml as syaml

try:
from spack.config import DirectoryConfigScope as DirScope
except ImportError:
from spack.config import ConfigScope as DirScope


class IncludesCreator:
def __init__(self):
Expand All @@ -23,7 +28,7 @@ def add_scope(self, name, path):
"""
scopes should be added in order from lowest to highest precident
"""
scope = spack.config.ConfigScope(name, os.path.abspath(path))
scope = DirScope(name, os.path.abspath(path))
self.config.push_scope(scope)

def write_includes(self, filename, path=None):
Expand Down
14 changes: 7 additions & 7 deletions tests/test_create_dev_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ def test_newEnvironmentKeepingUserSpecifiedYAML(tmpdir, on_moonlight, monkeypatc
)
)
e = ev.Environment(tmpdir.strpath)
print(e.manifest.pristine_yaml_content)
print(e.manifest.yaml_content)
print(list(e.user_specs))
assert os.path.isfile(str(tmpdir.join("spack.yaml")))
assert os.path.isfile(str(tmpdir.join("include.yaml")))
assert "path" in e.manifest.pristine_yaml_content["spack"]["develop"]["amr-wind"]
assert "path" in e.manifest.pristine_yaml_content["spack"]["develop"]["nalu-wind"]
assert "path" in e.manifest.yaml_content["spack"]["develop"]["amr-wind"]
assert "path" in e.manifest.yaml_content["spack"]["develop"]["nalu-wind"]
# mocked out call that would update yaml with trilinos info but
# assuming it works fine
arg_capture.assert_any_call(["--path", amr_path.strpath, "amr-wind@main"])
Expand All @@ -103,9 +103,9 @@ def test_nonConcreteSpecsDontGetCloned(tmpdir, monkeypatch, arg_capture):
)
arg_capture.assert_call_matches(-1, ["exawind@master"])
e = ev.Environment(tmpdir.strpath)
assert "nalu-wind" in e.manifest.pristine_yaml_content["spack"]["specs"]
assert "exawind@master" in e.manifest.pristine_yaml_content["spack"]["specs"]
assert "amr-wind" in e.manifest.pristine_yaml_content["spack"]["specs"]
assert "nalu-wind" in e.manifest.yaml_content["spack"]["specs"]
assert "exawind@master" in e.manifest.yaml_content["spack"]["specs"]
assert "amr-wind" in e.manifest.yaml_content["spack"]["specs"]


def test_noSpecsIsNotAnErrorGivesBlankEnv(tmpdir, monkeypatch, arg_capture):
Expand All @@ -115,4 +115,4 @@ def test_noSpecsIsNotAnErrorGivesBlankEnv(tmpdir, monkeypatch, arg_capture):
assert arg_capture.num_calls == 0
e = ev.Environment(tmpdir.strpath)
assert len(e.user_specs) == 0
assert e.manifest.pristine_yaml_content["spack"]["specs"] == []
assert e.manifest.yaml_content["spack"]["specs"] == []
19 changes: 7 additions & 12 deletions tests/test_create_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,11 @@ def test_specsCanBeAddedToExisitingYaml(tmpdir, on_moonlight):
)

e = env.Environment(env_root)
assert e.manifest.pristine_yaml_content["spack"]["specs"][0] == "amr-wind"
assert e.manifest.pristine_yaml_content["spack"]["specs"][1] == "nalu-wind"
assert (
e.manifest.pristine_yaml_content["spack"]["develop"]["amr-wind"]["spec"]
== "amr-wind@main"
)
assert (
e.manifest.pristine_yaml_content["spack"]["develop"]["amr-wind"]["path"] == "/tst/dir"
)
assert "view" not in e.manifest.pristine_yaml_content["spack"].keys()
assert e.manifest.yaml_content["spack"]["specs"][0] == "amr-wind"
assert e.manifest.yaml_content["spack"]["specs"][1] == "nalu-wind"
assert e.manifest.yaml_content["spack"]["develop"]["amr-wind"]["spec"] == "amr-wind@main"
assert e.manifest.yaml_content["spack"]["develop"]["amr-wind"]["path"] == "/tst/dir"
assert "view" not in e.manifest.yaml_content["spack"].keys()


def test_existingYamlViewIsNotOverwritten(tmpdir):
Expand All @@ -99,7 +94,7 @@ def test_existingYamlViewIsNotOverwritten(tmpdir):
manager("create-env", "-d", env_root, "-y", "test.yaml", "-s", "amr-wind", "nalu-wind")

e = env.Environment(env_root)
assert e.manifest.pristine_yaml_content["spack"]["view"]
assert e.manifest.yaml_content["spack"]["view"]


def test_specs_can_have_spaces(tmpdir):
Expand All @@ -120,7 +115,7 @@ def test_unify_in_yaml_preserved(tmpdir):

manager("create-env", "-y", "template.yaml")
e = env.Environment(tmpdir.strpath)
assert "when_possible" == e.manifest.pristine_yaml_content["spack"]["concretizer"]["unify"]
assert "when_possible" == e.manifest.yaml_content["spack"]["concretizer"]["unify"]


def test_local_source_tree_can_be_added_to_env(tmpdir):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def impl_mock(*args):
external(None, args)
# check that the include entry was added to the spack.yaml
assert mock_write.num_calls == 1
includes = e.pristine_configuration.get("include", [])
includes = e.configuration.get("include", [])
assert 1 == len(includes)
assert "externals.yaml" == str(includes[0])

Expand Down

0 comments on commit c615178

Please sign in to comment.