docs: updates related to extensions (#33837)
This commit is contained in:
parent
e633e57297
commit
fc7a16e77e
@ -1672,9 +1672,13 @@ own install prefix. However, certain packages are typically installed
|
|||||||
`Python <https://www.python.org>`_ packages are typically installed in the
|
`Python <https://www.python.org>`_ packages are typically installed in the
|
||||||
``$prefix/lib/python-2.7/site-packages`` directory.
|
``$prefix/lib/python-2.7/site-packages`` directory.
|
||||||
|
|
||||||
Spack has support for this type of installation as well. In Spack,
|
In Spack, installation prefixes are immutable, so this type of installation
|
||||||
a package that can live inside the prefix of another package is called
|
is not directly supported. However, it is possible to create views that
|
||||||
an *extension*. Suppose you have Python installed like so:
|
allow you to merge install prefixes of multiple packages into a single new prefix.
|
||||||
|
Views are a convenient way to get a more traditional filesystem structure.
|
||||||
|
Using *extensions*, you can ensure that Python packages always share the
|
||||||
|
same prefix in the view as Python itself. Suppose you have
|
||||||
|
Python installed like so:
|
||||||
|
|
||||||
.. code-block:: console
|
.. code-block:: console
|
||||||
|
|
||||||
@ -1712,8 +1716,6 @@ You can find extensions for your Python installation like this:
|
|||||||
py-ipython@2.3.1 py-pygments@2.0.1 py-setuptools@11.3.1
|
py-ipython@2.3.1 py-pygments@2.0.1 py-setuptools@11.3.1
|
||||||
py-matplotlib@1.4.2 py-pyparsing@2.0.3 py-six@1.9.0
|
py-matplotlib@1.4.2 py-pyparsing@2.0.3 py-six@1.9.0
|
||||||
|
|
||||||
==> None activated.
|
|
||||||
|
|
||||||
The extensions are a subset of what's returned by ``spack list``, and
|
The extensions are a subset of what's returned by ``spack list``, and
|
||||||
they are packages like any other. They are installed into their own
|
they are packages like any other. They are installed into their own
|
||||||
prefixes, and you can see this with ``spack find --paths``:
|
prefixes, and you can see this with ``spack find --paths``:
|
||||||
@ -1741,32 +1743,72 @@ directly when you run ``python``:
|
|||||||
ImportError: No module named numpy
|
ImportError: No module named numpy
|
||||||
>>>
|
>>>
|
||||||
|
|
||||||
^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
Using Extensions
|
Using Extensions in Environments
|
||||||
^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
There are multiple ways to get ``numpy`` working in Python. The first is
|
The recommended way of working with extensions such as ``py-numpy``
|
||||||
to use :ref:`shell-support`. You can simply ``load`` the extension,
|
above is through :ref:`Environments <environments>`. For example,
|
||||||
and it will be added to the ``PYTHONPATH`` in your current shell, and
|
the following creates an environment in the current working directory
|
||||||
Python itself will be available in the ``PATH``:
|
with a filesystem view in the ``./view`` directory:
|
||||||
|
|
||||||
|
.. code-block:: console
|
||||||
|
|
||||||
|
$ spack env create --with-view view --dir .
|
||||||
|
$ spack -e . add py-numpy
|
||||||
|
$ spack -e . concretize
|
||||||
|
$ spack -e . install
|
||||||
|
|
||||||
|
We recommend environments for two reasons. Firstly, environments
|
||||||
|
can be activated (requires :ref:`shell-support`):
|
||||||
|
|
||||||
|
.. code-block:: console
|
||||||
|
|
||||||
|
$ spack env activate .
|
||||||
|
|
||||||
|
which sets all the right environment variables such as ``PATH`` and
|
||||||
|
``PYTHONPATH``. This ensures that
|
||||||
|
|
||||||
|
.. code-block:: console
|
||||||
|
|
||||||
|
$ python
|
||||||
|
>>> import numpy
|
||||||
|
|
||||||
|
works. Secondly, even without shell support, the view ensures
|
||||||
|
that Python can locate its extensions:
|
||||||
|
|
||||||
|
.. code-block:: console
|
||||||
|
|
||||||
|
$ ./view/bin/python
|
||||||
|
>>> import numpy
|
||||||
|
|
||||||
|
See :ref:`environments` for a more in-depth description of Spack
|
||||||
|
environments and customizations to views.
|
||||||
|
|
||||||
|
^^^^^^^^^^^^^^^^^^^^
|
||||||
|
Using ``spack load``
|
||||||
|
^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
A more traditional way of using Spack and extensions is ``spack load``
|
||||||
|
(requires :ref:`shell-support`). This will add the extension to ``PYTHONPATH``
|
||||||
|
in your current shell, and Python itself will be available in the ``PATH``:
|
||||||
|
|
||||||
.. code-block:: console
|
.. code-block:: console
|
||||||
|
|
||||||
$ spack load py-numpy
|
$ spack load py-numpy
|
||||||
|
$ python
|
||||||
|
>>> import numpy
|
||||||
|
|
||||||
Now ``import numpy`` will succeed for as long as you keep your current
|
|
||||||
session open.
|
|
||||||
The loaded packages can be checked using ``spack find --loaded``
|
The loaded packages can be checked using ``spack find --loaded``
|
||||||
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
Loading Extensions via Modules
|
Loading Extensions via Modules
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Instead of using Spack's environment modification capabilities through
|
Apart from ``spack env activate`` and ``spack load``, you can load numpy
|
||||||
the ``spack load`` command, you can load numpy through your
|
through your environment modules (using ``environment-modules`` or
|
||||||
environment modules (using ``environment-modules`` or ``lmod``). This
|
``lmod``). This will also add the extension to the ``PYTHONPATH`` in
|
||||||
will also add the extension to the ``PYTHONPATH`` in your current
|
your current shell.
|
||||||
shell.
|
|
||||||
|
|
||||||
.. code-block:: console
|
.. code-block:: console
|
||||||
|
|
||||||
@ -1776,15 +1818,6 @@ If you do not know the name of the specific numpy module you wish to
|
|||||||
load, you can use the ``spack module tcl|lmod loads`` command to get
|
load, you can use the ``spack module tcl|lmod loads`` command to get
|
||||||
the name of the module from the Spack spec.
|
the name of the module from the Spack spec.
|
||||||
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
Extensions in an Environment
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
Another way to use extensions is to create a view, which merges the
|
|
||||||
python installation along with the extensions into a single prefix.
|
|
||||||
See :ref:`environments` for a more in-depth description
|
|
||||||
of environment views.
|
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
Filesystem requirements
|
Filesystem requirements
|
||||||
-----------------------
|
-----------------------
|
||||||
|
@ -724,10 +724,9 @@ extends vs. depends_on
|
|||||||
|
|
||||||
This is very similar to the naming dilemma above, with a slight twist.
|
This is very similar to the naming dilemma above, with a slight twist.
|
||||||
As mentioned in the :ref:`Packaging Guide <packaging_extensions>`,
|
As mentioned in the :ref:`Packaging Guide <packaging_extensions>`,
|
||||||
``extends`` and ``depends_on`` are very similar, but ``extends`` adds
|
``extends`` and ``depends_on`` are very similar, but ``extends`` ensures
|
||||||
the ability to *activate* the package. Activation involves symlinking
|
that the extension and extendee share the same prefix in views.
|
||||||
everything in the installation prefix of the package to the installation
|
This allows the user to import a Python module without
|
||||||
prefix of Python. This allows the user to import a Python module without
|
|
||||||
having to add that module to ``PYTHONPATH``.
|
having to add that module to ``PYTHONPATH``.
|
||||||
|
|
||||||
When deciding between ``extends`` and ``depends_on``, the best rule of
|
When deciding between ``extends`` and ``depends_on``, the best rule of
|
||||||
@ -735,7 +734,7 @@ thumb is to check the installation prefix. If Python libraries are
|
|||||||
installed to ``<prefix>/lib/pythonX.Y/site-packages``, then you
|
installed to ``<prefix>/lib/pythonX.Y/site-packages``, then you
|
||||||
should use ``extends``. If Python libraries are installed elsewhere
|
should use ``extends``. If Python libraries are installed elsewhere
|
||||||
or the only files that get installed reside in ``<prefix>/bin``, then
|
or the only files that get installed reside in ``<prefix>/bin``, then
|
||||||
don't use ``extends``, as symlinking the package wouldn't be useful.
|
don't use ``extends``.
|
||||||
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^
|
||||||
Alternatives to Spack
|
Alternatives to Spack
|
||||||
|
@ -193,10 +193,10 @@ Build system dependencies
|
|||||||
|
|
||||||
As an extension of the R ecosystem, your package will obviously depend
|
As an extension of the R ecosystem, your package will obviously depend
|
||||||
on R to build and run. Normally, we would use ``depends_on`` to express
|
on R to build and run. Normally, we would use ``depends_on`` to express
|
||||||
this, but for R packages, we use ``extends``. ``extends`` is similar to
|
this, but for R packages, we use ``extends``. This implies a special
|
||||||
``depends_on``, but adds an additional feature: the ability to "activate"
|
dependency on R, which is used to set environment variables such as
|
||||||
the package by symlinking it to the R installation directory. Since
|
``R_LIBS`` uniformly. Since every R package needs this, the ``RPackage``
|
||||||
every R package needs this, the ``RPackage`` base class contains:
|
base class contains:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
|
@ -2634,9 +2634,12 @@ extendable package:
|
|||||||
extends('python')
|
extends('python')
|
||||||
...
|
...
|
||||||
|
|
||||||
Now, the ``py-numpy`` package can be used as an argument to ``spack
|
This accomplishes a few things. Firstly, the Python package can set special
|
||||||
activate``. When it is activated, all the files in its prefix will be
|
variables such as ``PYTHONPATH`` for all extensions when the run or build
|
||||||
symbolically linked into the prefix of the python package.
|
environment is set up. Secondly, filesystem views can ensure that extensions
|
||||||
|
are put in the same prefix as their extendee. This ensures that Python in
|
||||||
|
a view can always locate its Python packages, even without environment
|
||||||
|
variables set.
|
||||||
|
|
||||||
A package can only extend one other package at a time. To support packages
|
A package can only extend one other package at a time. To support packages
|
||||||
that may extend one of a list of other packages, Spack supports multiple
|
that may extend one of a list of other packages, Spack supports multiple
|
||||||
@ -2684,9 +2687,8 @@ variant(s) are selected. This may be accomplished with conditional
|
|||||||
...
|
...
|
||||||
|
|
||||||
Sometimes, certain files in one package will conflict with those in
|
Sometimes, certain files in one package will conflict with those in
|
||||||
another, which means they cannot both be activated (symlinked) at the
|
another, which means they cannot both be used in a view at the
|
||||||
same time. In this case, you can tell Spack to ignore those files
|
same time. In this case, you can tell Spack to ignore those files:
|
||||||
when it does the activation:
|
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
@ -2698,7 +2700,7 @@ when it does the activation:
|
|||||||
...
|
...
|
||||||
|
|
||||||
The code above will prevent everything in the ``$prefix/bin/`` directory
|
The code above will prevent everything in the ``$prefix/bin/`` directory
|
||||||
from being linked in at activation time.
|
from being linked in a view.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user