From d29d5462c6a5046819ec7f1c0ed4a14b15de2018 Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Tue, 9 Aug 2022 10:09:51 -0700 Subject: PythonPackage: add --config-settings support (#31823) --- lib/spack/docs/build_systems/pythonpackage.rst | 50 +++++++++++++++++++++++++- 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 `_ and +See `PEP 517 `__ and `PEP 518 `_ 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 `__ 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 `_. + 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 `_. + 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): -- cgit v1.2.3-60-g2f50