You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorial_environments.rst
+63-46Lines changed: 63 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -132,14 +132,14 @@ After deactivating, we can see everything installed in this Spack instance:
132
132
Installing packages
133
133
^^^^^^^^^^^^^^^^^^^
134
134
135
-
Now that we understand how creation and activation work, let's go back to our ``myproject`` enviornment and *install* a couple of packages, specifically, ``tcl`` and ``trilinos``.
135
+
Now that we understand how creation and activation work, let's go back to our ``myproject`` environment and *install* a couple of packages, specifically, ``tcl`` and ``trilinos``.
136
136
137
137
Let's try the usual install commands we learned earlier:
Environments are special in that we must *add* specs to the an environment before we can install them. This additional step helps prevent us from accidentally modifying a shared enviornment when installing new software.
142
+
Environments are special in that we must *add* specs to the an environment before we can install them. This additional step helps prevent us from accidentally modifying a shared environment when installing new software.
143
143
144
144
``spack add`` allows us to queue up several specs to be installed together.
145
145
Let's try it:
@@ -148,7 +148,7 @@ Let's try it:
148
148
:language: console
149
149
150
150
Now, ``tcl`` and ``trilinos`` have been registered as **root specs** in our environment. **Root specs** are packages that we've explicitly requested to be installed in an environment.
151
-
They're called **"roots"** because they sit at the top of the dependency graph—when Spack installs these packages, with their respective depenedency packages sitting below them.
151
+
They're called **"roots"** because they sit at the top of the dependency graph—when Spack installs these packages, with their respective dependency packages sitting below them.
152
152
153
153
Now, let's install:
154
154
@@ -202,13 +202,21 @@ So, adding specs to an environment at a later point in time will not cause exist
202
202
Using packages
203
203
^^^^^^^^^^^^^^
204
204
205
-
Environments provide a convenient way for using installed packages.
206
-
When we run ``spack env activate`` Spack by default prepends packages in the environment to our ``PATH``, ``MANPATH``, and ``CMAKE_PREFIX_PATH`` environment variables.
205
+
Spack environments provide a convenient way to use your installed packages by automatically making them available in your shell environment.
206
+
This is accomplished through a feature called **environment views**.
207
207
208
-
Let's try it out to get a better sense of how views are constructed and added to our shell environment.
208
+
An environment view is a directory structure mirroring a standard linux root filesystem with directories like ``/bin`` and ``/usr`` that contain symbolic links to all the packages installed in your Spack environment.
209
+
When you activate an environment with ``spack env activate``, Spack automatically:
209
210
210
-
We just installed ``tcl`` into our ``myproject`` environment. ``Tcl`` includes a shell-like application called ``tclsh``.
211
-
To can see the path to ``tclsh`` let's use ``which``:
211
+
* Prepends the view's ``bin`` directory to your ``PATH`` environment variable
212
+
* Adds the view's ``man`` directory to your ``MANPATH`` for manual pages
213
+
* Updates ``CMAKE_PREFIX_PATH`` to include the view's root directory
214
+
215
+
This means that executables, libraries, and other files from your environment's packages become immediately accessible from your command line, just as if they were installed system-wide.
216
+
217
+
Let's explore how views work using the ``tcl`` package we just installed in our ``myproject`` environment. The Tcl package includes a shell-like application called ``tclsh``.
218
+
219
+
To can see the path to ``tclsh`` let's use the ``which`` command:
We can see that ``trilinos`` won't be uninstalled because it is still referenced in another environment managed by Spack.
254
-
If we want to remove it from the roots list, we need to use ``spack remove``:
266
+
Notice that ``trilinos`` won't be uninstalled because it's still referenced in ``myproject``. This safety feature prevents accidental removal of packages that other environments depend on.
267
+
268
+
Instead, if we want to remove ``trilinos`` from the ``myproject2`` environment (without affecting it in other environments), we need to use ``spack remove``:
When the spec is first removed, we see that it is no longer a root but is still present in the installed specs.
260
-
Once we reconcretize, the vestigial spec is removed.
261
-
Now, it is no longer a root and will need to be re-added before being installed as part of this environment.
273
+
After running ``spack remove`` we'll see that ``trilinos`` is no longer a root but is still present in the installed specs.
274
+
Reconcretizing the environment, we'll see the vestigial ``trilinos`` and its dependencies will be pruned and will no longer be listed in the environment at all.
262
275
263
-
We know ``trilinos`` is still needed for the ``myproject`` environment, so let's switch back to confirm that it is still installed in that environment.
276
+
We know ``trilinos`` is still needed for the ``myproject`` environment, so let's switch back to that environment to confirm that it is still installed.
We see that ``myproject`` still has ``trilinos`` as a root spec.
271
-
Spack uses reference counting to ensure that we don't remove ``trilinos`` when it is still needed by ``myproject``.
283
+
We can see that ``myproject`` still has ``trilinos`` as a root spec.
272
284
273
285
.. note::
274
286
275
-
Trilinos would only have been uninstalled by Spack if it were
276
-
no longer needed by any environments or their package dependencies.
277
-
278
-
You can also uninstall a package and remove it from the environment in one go with ``spack uninstall --remove trilinos``.
287
+
You can also uninstall a package and remove it from the environment
288
+
in one go with ``spack uninstall --remove trilinos``.
279
289
280
290
-----------------------
281
291
The ``spack.yaml`` file
282
292
-----------------------
283
293
284
-
An environment is more than just a list of root specs.
285
-
It includes *configuration* settings that affect the way Spack behaves when the environment is activated.
286
-
So far, ``myproject`` relies on configuration defaults that can be overridden.
287
-
Here we'll look at how to add specs and ensure all the packages depending on ``mpi`` build with ``mpich``.
294
+
An environment is more than just a list of root specs -- it includes **configuration settings** that control how Spack behaves when the environment it activated.
295
+
So far, ``myproject`` relies on configuration defaults, but these can be overridden to customize our environment's behavior.
296
+
297
+
In this section, we'll learn how to enforce that all the packages in our environment depending on ``mpi`` build with ``mpich`` by modifying our configuration.
298
+
288
299
We can customize the selection of the ``mpi`` provider using `concretization preferences <https://spack.readthedocs.io/en/latest/build_settings.html#concretization-preferences>`_ to change the behavior of the concretizer.
289
300
290
-
Let's start by looking at the configuration of our environment using ``spack config get``:
301
+
Let's start by examining our environment's configuration using ``spack config get``:
The output shows the special ``spack.yaml`` configuration file that Spack uses to store the environment configuration.
306
+
The output shows the special ``spack.yaml`` configuration file that Spack uses to store environment configurations.
296
307
297
308
There are several important parts of this file:
298
309
299
-
* ``specs:``: the list of specs to install
300
-
* ``view:``: this controls whether the environment has a *view*. You can
301
-
set it to ``false`` to disable view generation.
302
-
* ``concretizer:unify:``: This controls how the specs in the environment
303
-
are concretized.
310
+
* ``specs:``: The list of package specs to install in the environment.
311
+
* ``view:``: Controls whether the environment generates a *view* (the
312
+
directory tree with symlinks to installed packages we discussed earlier).
313
+
* ``concretizer:unify:``: Determines how package specs in the environment are
314
+
concretized together to reduce duplicated dependencies when possible.
304
315
305
-
The ``specs`` list should look familiar; these are the specs we've been modifying with ``spack add``.
316
+
The ``specs`` list should look familiar -- these are the package specs we've been modifying previously with ``spack add`` and ``spack install``.
306
317
307
-
``concretizer:unify:true``, the default, means that they are concretized *together*, so that there is only one version of each package in the environment.
308
-
Other options for ``unify`` are ``false`` and ``when_possible``. ``false`` means that the specs are concretized *independently*, so that there may be multiple versions of the same package in the environment. ``when_possible`` lies between these options.
309
-
In this case, Spack will unify as many packages in the environment, but will not fail if it cannot unify all of them.
318
+
The ``concretizer:unify:true`` setting controls how Spack resolves dependencies across packages specs in an environment:
310
319
320
+
* ``true`` (default): specs are concretized *together*, ensuring
321
+
there is only one version of each package in the environment.
322
+
* ``false``: specs are concretized *independently* from each other,
323
+
potentially allowing multiple versions of the package to appear in the
324
+
environment twice.
325
+
* ``when_possible``: A middle ground -- Spack attempts to unify dependencies
326
+
as possible but will backoff to allow duplicates when root specs require
0 commit comments