Skip to content

Commit 4d72690

Browse files
committed
Additional edits to environments for readability enhancements
1 parent a990c96 commit 4d72690

1 file changed

Lines changed: 63 additions & 46 deletions

File tree

tutorial_environments.rst

Lines changed: 63 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ After deactivating, we can see everything installed in this Spack instance:
132132
Installing packages
133133
^^^^^^^^^^^^^^^^^^^
134134

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``.
136136

137137
Let's try the usual install commands we learned earlier:
138138

139139
.. literalinclude:: outputs/environments/env-fail-install-1.out
140140
:language: console
141141

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 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.
143143

144144
``spack add`` allows us to queue up several specs to be installed together.
145145
Let's try it:
@@ -148,7 +148,7 @@ Let's try it:
148148
:language: console
149149

150150
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.
152152

153153
Now, let's install:
154154

@@ -202,13 +202,21 @@ So, adding specs to an environment at a later point in time will not cause exist
202202
Using packages
203203
^^^^^^^^^^^^^^
204204

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**.
207207

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:
209210

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:
212220

213221
.. literalinclude:: outputs/environments/use-tcl-1.out
214222
:language: console
@@ -225,89 +233,98 @@ We can now run ``tclsh`` just like you would any other program that is in your p
225233
hello world!
226234
% exit
227235
228-
^^^^^^^^^^^^^^^^^^^^^
229-
Uninstalling packages
230-
^^^^^^^^^^^^^^^^^^^^^
236+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
237+
Uninstalling Packages from Environments
238+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
239+
240+
One of Spack's key features is that you can safely uninstall packages from specific environments without affecting other environments.
241+
This works because Spack environments only create links to shared package installations—they don't contain the actual package files.
231242

232-
We can uninstall packages from an environment without affecting other environments.
233-
This is possible since, while Spack shares common installations, environments only link to those installations.
243+
Let's demonstrate this capability by creating a second environment.
244+
Imagine we have two projects:
234245

235-
Let's demonstrate this feature by creating another environment.
236-
Suppose ``myproject`` requires ``trilinos`` but we have another project that has it installed but no longer requires it.
246+
* ``myproject`` - requires ``trilinos``
247+
* ``myproject2`` - previously needed ``trilinos`` but no longer requires it
237248

238-
Start by creating a ``myproject2`` environment with the installed packages ``scr`` and ``trilinos``.
249+
Let's start by creating the ``myproject2`` environment and installing both ``scr`` and ``trilinos``:
239250

240251
.. literalinclude:: outputs/environments/env-create-2.out
241252
:language: console
242253

243254

244-
Now we have two environments.
245-
The ``myproject`` environment has ``tcl`` and ``trilinos`` while the ``myproject2`` environment has ``scr`` and ``trilinos``.
255+
Now we have two environments with different package combinations:
246256

247-
Now let's try to uninstall ``trilinos`` from ``myproject2`` and review the contents of the environment:
257+
* The ``myproject`` environment contains ``tcl`` and ``trilinos``
258+
* The ``myproject2`` environment contains ``scr`` and ``trilinos``
259+
260+
Now let's attempt to uninstall ``trilinos`` from ``myproject2`` and examine what happens:
248261

249262
.. literalinclude:: outputs/environments/env-uninstall-1.out
250263
:language: console
251264

252265

253-
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``:
255269

256270
.. literalinclude:: outputs/environments/env-remove-1.out
257271
:language: console
258272

259-
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.
262275

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.
264277

265278
.. literalinclude:: outputs/environments/env-swap-1.out
266279
:language: console
267280

268281

269282
Phew!
270-
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.
272284

273285
.. note::
274286

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``.
279289

280290
-----------------------
281291
The ``spack.yaml`` file
282292
-----------------------
283293

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+
288299
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.
289300

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``:
291302

292303
.. literalinclude:: outputs/environments/config-get-1.out
293304
:emphasize-lines: 8-13
294305

295-
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.
296307

297308
There are several important parts of this file:
298309

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.
304315

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``.
306317

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:
310319

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
327+
incompatible versions of dependencies.
311328

312329
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
313330
Editing environment configuration

0 commit comments

Comments
 (0)