Skip to content

Commit

Permalink
Merge pull request #794 from douglasjacobsen/spack-env-view
Browse files Browse the repository at this point in the history
Allow customization of the link type in spack environments
  • Loading branch information
rfbgo authored Dec 11, 2024
2 parents 8f1fa37 + 444dfc2 commit 196e345
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 0 deletions.
2 changes: 2 additions & 0 deletions etc/ramble/defaults/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ config:
flags: ''
env_create:
flags: ''
env_view:
link_type: symlink
23 changes: 23 additions & 0 deletions lib/ramble/docs/configuration_files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,35 @@ The current default configuration is as follows:
flags: ''
global
flags: ''
env_view:
link_type: 'symlink'
input_cache: '$ramble/var/ramble/cache'
workspace_dirs: '$ramble/var/ramble/workspaces'
upload:
type: 'BigQuery'
uri: ''
.. _spack-config-option:

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Spack
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The ``spack`` config options within the config configuration section can be used to
customize Spack's behavior. The ``install``, ``concretize``, ``buildcache``,
and ``env_create`` sections can be used to customize the flags passed to these
Spack commands (with ``env_create`` being equivalent to ``spack env create``).

The ``global`` section is used to define flags that should be passed to
``spack`` directly, as in:
``spack {flags} {subcommand}...``

The ``env_view`` section is used to customize the `spack environment views
<https://spack.readthedocs.io/en/latest/environments.html#environment-views>`_
that Ramble creates. Currently, the only accepted option within this section is
``link_type`` which can take any value supported via Spack.

.. _upload-config-option:

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
13 changes: 13 additions & 0 deletions lib/ramble/ramble/schema/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@
},
"additionalProperties": False,
},
"env_view": {
"type": "object",
"default": {
"link_type": "symlink",
},
"properties": {
"link_type": {
"type": "string",
"default": "symlink",
},
},
"additionalProperties": False,
},
},
"additionalProperties": False,
}
Expand Down
2 changes: 2 additions & 0 deletions lib/ramble/ramble/test/data/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ config:
flags: --reuse
concretize:
flags: --reuse
env_view:
link_type: symlink
include:
- test_include: include.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,32 @@ def test_env_configs_apply(tmpdir, capsys, request):
pytest.skip("%s" % e)


@pytest.mark.parametrize("link_type", ["symlink", "hardlink", "copy"])
def test_env_view_link_types(tmpdir, request, link_type, mutable_config):
with ramble.config.override("config:spack:", {"env_view": {"link_type": f"{link_type}"}}):
try:
env_path = str(tmpdir.join(request.node.name))
# Dry run so we don't actually install zlib
sr = SpackRunner(dry_run=True)
sr.create_env(env_path)
sr.activate()
sr.add_spec("zlib")
sr.generate_env_file()

sr.deactivate()

env_file = os.path.join(env_path, "spack.yaml")

assert os.path.exists(env_file)

with open(env_file) as f:
data = f.read()
assert f"link_type: {link_type}" in data

except RunnerError as e:
pytest.skip("%s" % e)


def test_default_concretize_flags(tmpdir, capsys, request):
try:
env_path = tmpdir.join(request.node.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,14 @@ def _env_file_dict(self):
env_file[spack_namespace]["concretizer"] = syaml.syaml_dict()
env_file[spack_namespace]["concretizer"]["unify"] = True

link_type = ramble.config.get("config:spack:env_view:link_type")
env_file[spack_namespace]["view"] = syaml.syaml_dict()
env_file[spack_namespace]["view"]["default"] = syaml.syaml_dict()
env_file[spack_namespace]["view"]["default"]["root"] = os.path.join(
self.env_path, "ramble"
)
env_file[spack_namespace]["view"]["default"]["link_type"] = link_type

env_file[spack_namespace]["specs"] = syaml.syaml_list()
# Ensure the specs content are consistently sorted.
# Otherwise the hash checking may artificially miss due to ordering.
Expand Down

0 comments on commit 196e345

Please sign in to comment.