diff options
author | Adam J. Stewart <ajstewart426@gmail.com> | 2022-08-09 10:09:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-09 10:09:51 -0700 |
commit | d29d5462c6a5046819ec7f1c0ed4a14b15de2018 (patch) | |
tree | 4c55453fa16091b58197c3aa0c64ac6ea10f80de | |
parent | bc32b2c22ca1cb4f5c3af33bddc3eb22a9fb9ae6 (diff) | |
download | spack-d29d5462c6a5046819ec7f1c0ed4a14b15de2018.tar.gz spack-d29d5462c6a5046819ec7f1c0ed4a14b15de2018.tar.bz2 spack-d29d5462c6a5046819ec7f1c0ed4a14b15de2018.tar.xz spack-d29d5462c6a5046819ec7f1c0ed4a14b15de2018.zip |
PythonPackage: add --config-settings support (#31823)
-rw-r--r-- | lib/spack/docs/build_systems/pythonpackage.rst | 50 | ||||
-rw-r--r-- | lib/spack/spack/build_systems/python.py | 45 |
2 files changed, 91 insertions, 4 deletions
diff --git a/lib/spack/docs/build_systems/pythonpackage.rst b/lib/spack/docs/build_systems/pythonpackage.rst index a21648b063..0a35c46419 100644 --- a/lib/spack/docs/build_systems/pythonpackage.rst +++ b/lib/spack/docs/build_systems/pythonpackage.rst @@ -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 ^^^^^^^ diff --git a/lib/spack/spack/build_systems/python.py b/lib/spack/spack/build_systems/python.py index 1a69d79f40..1be1022613 100644 --- a/lib/spack/spack/build_systems/python.py +++ b/lib/spack/spack/build_systems/python.py @@ -22,8 +22,9 @@ from llnl.util.filesystem import ( 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 @@ class PythonPackage(PackageBase): """ 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 @@ class PythonPackage(PackageBase): 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): |