PythonPackage: add --config-settings support (#31823)
This commit is contained in:
@@ -215,7 +215,7 @@ Note that ``py-wheel`` is already listed as a build dependency in the
|
||||
need to specify a specific version requirement or change the
|
||||
dependency type.
|
||||
|
||||
See `PEP 517 <https://www.python.org/dev/peps/pep-0517/>`_ and
|
||||
See `PEP 517 <https://www.python.org/dev/peps/pep-0517/>`__ and
|
||||
`PEP 518 <https://www.python.org/dev/peps/pep-0518/>`_ for more
|
||||
information on the design of ``pyproject.toml``.
|
||||
|
||||
@@ -412,6 +412,34 @@ packages. However, the installation instructions for a package may
|
||||
suggest passing certain flags to the ``setup.py`` call. The
|
||||
``PythonPackage`` class has two techniques for doing this.
|
||||
|
||||
"""""""""""""""
|
||||
Config settings
|
||||
"""""""""""""""
|
||||
|
||||
These settings are passed to
|
||||
`PEP 517 <https://peps.python.org/pep-0517/>`__ build backends.
|
||||
For example, ``py-scipy`` package allows you to specify the name of
|
||||
the BLAS/LAPACK library you want pkg-config to search for:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
depends_on('py-pip@22.1:', type='build')
|
||||
|
||||
def config_settings(self, spec, prefix):
|
||||
return {
|
||||
'blas': spec['blas'].libs.names[0],
|
||||
'lapack': spec['lapack'].libs.names[0],
|
||||
}
|
||||
|
||||
|
||||
.. note::
|
||||
|
||||
This flag only works for packages that define a ``build-backend``
|
||||
in ``pyproject.toml``. Also, it is only supported by pip 22.1+,
|
||||
which requires Python 3.7+. For packages that still support Python
|
||||
3.6 and older, ``install_options`` should be used instead.
|
||||
|
||||
|
||||
""""""""""""""
|
||||
Global options
|
||||
""""""""""""""
|
||||
@@ -431,6 +459,16 @@ has an optional dependency on ``libyaml`` that can be enabled like so:
|
||||
return options
|
||||
|
||||
|
||||
.. note::
|
||||
|
||||
Direct invocation of ``setup.py`` is
|
||||
`deprecated <https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html>`_.
|
||||
This flag forces pip to use a deprecated installation procedure.
|
||||
It should only be used in packages that don't define a
|
||||
``build-backend`` in ``pyproject.toml`` or packages that still
|
||||
support Python 3.6 and older.
|
||||
|
||||
|
||||
"""""""""""""""
|
||||
Install options
|
||||
"""""""""""""""
|
||||
@@ -451,6 +489,16 @@ allows you to specify the directories to search for ``libyaml``:
|
||||
return options
|
||||
|
||||
|
||||
.. note::
|
||||
|
||||
Direct invocation of ``setup.py`` is
|
||||
`deprecated <https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html>`_.
|
||||
This flag forces pip to use a deprecated installation procedure.
|
||||
It should only be used in packages that don't define a
|
||||
``build-backend`` in ``pyproject.toml`` or packages that still
|
||||
support Python 3.6 and older.
|
||||
|
||||
|
||||
^^^^^^^
|
||||
Testing
|
||||
^^^^^^^
|
||||
|
@@ -22,8 +22,9 @@
|
||||
from llnl.util.lang import classproperty, match_predicate
|
||||
|
||||
from spack.directives import depends_on, extends
|
||||
from spack.error import NoHeadersError, NoLibrariesError
|
||||
from spack.error import NoHeadersError, NoLibrariesError, SpecError
|
||||
from spack.package_base import PackageBase, run_after
|
||||
from spack.version import Version
|
||||
|
||||
|
||||
class PythonPackage(PackageBase):
|
||||
@@ -155,13 +156,43 @@ def build_directory(self):
|
||||
"""
|
||||
return self.stage.source_path
|
||||
|
||||
def config_settings(self, spec, prefix):
|
||||
"""Configuration settings to be passed to the PEP 517 build backend.
|
||||
|
||||
Requires pip 22.1+, which requires Python 3.7+.
|
||||
|
||||
Args:
|
||||
spec (spack.spec.Spec): build spec
|
||||
prefix (spack.util.prefix.Prefix): installation prefix
|
||||
|
||||
Returns:
|
||||
dict: dictionary of KEY, VALUE settings
|
||||
"""
|
||||
return {}
|
||||
|
||||
def install_options(self, spec, prefix):
|
||||
"""Extra arguments to be supplied to the setup.py install command."""
|
||||
"""Extra arguments to be supplied to the setup.py install command.
|
||||
|
||||
Args:
|
||||
spec (spack.spec.Spec): build spec
|
||||
prefix (spack.util.prefix.Prefix): installation prefix
|
||||
|
||||
Returns:
|
||||
list: list of options
|
||||
"""
|
||||
return []
|
||||
|
||||
def global_options(self, spec, prefix):
|
||||
"""Extra global options to be supplied to the setup.py call before the install
|
||||
or bdist_wheel command."""
|
||||
or bdist_wheel command.
|
||||
|
||||
Args:
|
||||
spec (spack.spec.Spec): build spec
|
||||
prefix (spack.util.prefix.Prefix): installation prefix
|
||||
|
||||
Returns:
|
||||
list: list of options
|
||||
"""
|
||||
return []
|
||||
|
||||
def install(self, spec, prefix):
|
||||
@@ -169,6 +200,14 @@ def install(self, spec, prefix):
|
||||
|
||||
args = PythonPackage._std_args(self) + ["--prefix=" + prefix]
|
||||
|
||||
for key, value in self.config_settings(spec, prefix).items():
|
||||
if spec["py-pip"].version < Version("22.1"):
|
||||
raise SpecError(
|
||||
"'{}' package uses 'config_settings' which is only supported by "
|
||||
"pip 22.1+. Add the following line to the package to fix this:\n\n"
|
||||
' depends_on("py-pip@22.1:", type="build")'.format(spec.name)
|
||||
)
|
||||
args.append("--config-settings={}={}".format(key, value))
|
||||
for option in self.install_options(spec, prefix):
|
||||
args.append("--install-option=" + option)
|
||||
for option in self.global_options(spec, prefix):
|
||||
|
Reference in New Issue
Block a user