diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e8eb8a11..21a17383 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 }} @@ -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 @@ -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 }} diff --git a/manager/__init__.py b/manager/__init__.py index 7969510e..257e0b8f 100644 --- a/manager/__init__.py +++ b/manager/__init__.py @@ -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)) diff --git a/manager/environment_utils.py b/manager/environment_utils.py index ae1e6337..1326e435 100644 --- a/manager/environment_utils.py +++ b/manager/environment_utils.py @@ -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 @@ -20,19 +22,18 @@ 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 @@ -40,12 +41,15 @@ def append_includes(self, value): 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 @@ -53,9 +57,12 @@ def prepend_includes(self, value): 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 diff --git a/manager/manager_cmds/create_dev_env.py b/manager/manager_cmds/create_dev_env.py index 0e445de9..40a2bbe7 100644 --- a/manager/manager_cmds/create_dev_env.py +++ b/manager/manager_cmds/create_dev_env.py @@ -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 diff --git a/manager/manager_cmds/external.py b/manager/manager_cmds/external.py index dbcff98f..fbf86e19 100644 --- a/manager/manager_cmds/external.py +++ b/manager/manager_cmds/external.py @@ -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 diff --git a/manager/manager_cmds/includes_creator.py b/manager/manager_cmds/includes_creator.py index a865d139..01539be2 100644 --- a/manager/manager_cmds/includes_creator.py +++ b/manager/manager_cmds/includes_creator.py @@ -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): @@ -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): diff --git a/tests/test_create_dev_env.py b/tests/test_create_dev_env.py index 56dd11aa..516dca7e 100644 --- a/tests/test_create_dev_env.py +++ b/tests/test_create_dev_env.py @@ -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"]) @@ -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): @@ -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"] == [] diff --git a/tests/test_create_env.py b/tests/test_create_env.py index 57d1d4c7..af0556c4 100644 --- a/tests/test_create_env.py +++ b/tests/test_create_env.py @@ -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): @@ -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): @@ -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): diff --git a/tests/test_external.py b/tests/test_external.py index 2911eb5a..36202d45 100644 --- a/tests/test_external.py +++ b/tests/test_external.py @@ -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])