From 22d4612d94af7e1d4cf6f202231807e5db1cc042 Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Mon, 1 Aug 2022 22:55:41 -0700 Subject: Add meson Python build backend (#31809) --- lib/spack/docs/build_systems/pythonpackage.rst | 87 +++++++++++++--------- .../builtin/packages/py-meson-python/package.py | 23 ++++++ .../repos/builtin/packages/py-meson/package.py | 24 ++++++ .../packages/py-pyproject-metadata/package.py | 19 +++++ 4 files changed, 117 insertions(+), 36 deletions(-) create mode 100644 var/spack/repos/builtin/packages/py-meson-python/package.py create mode 100644 var/spack/repos/builtin/packages/py-meson/package.py create mode 100644 var/spack/repos/builtin/packages/py-pyproject-metadata/package.py diff --git a/lib/spack/docs/build_systems/pythonpackage.rst b/lib/spack/docs/build_systems/pythonpackage.rst index de79324de1..a21648b063 100644 --- a/lib/spack/docs/build_systems/pythonpackage.rst +++ b/lib/spack/docs/build_systems/pythonpackage.rst @@ -48,9 +48,10 @@ important to understand. **build backend** Libraries used to define how to build a wheel. Examples include `setuptools `__, - `flit `_, - `poetry `_, and - `hatchling `_. + `flit `_, + `poetry `_, + `hatchling `_, and + `meson `_. ^^^^^^^^^^^ Downloading @@ -174,9 +175,9 @@ package. The "Project description" tab may also contain a longer description of the package. Either of these can be used to populate the package docstring. -^^^^^^^^^^^^^ -Build backend -^^^^^^^^^^^^^ +^^^^^^^^^^^^ +Dependencies +^^^^^^^^^^^^ Once you've determined the basic metadata for a package, the next step is to determine the build backend. ``PythonPackage`` uses @@ -219,7 +220,28 @@ See `PEP 517 `_ and information on the design of ``pyproject.toml``. Depending on which build backend a project uses, there are various -places that run-time dependencies can be listed. +places that run-time dependencies can be listed. Most modern build +backends support listing dependencies directly in ``pyproject.toml``. +Look for dependencies under the following keys: + +* ``requires-python`` under ``[project]`` + + This specifies the version of Python that is required + +* ``dependencies`` under ``[project]`` + + These packages are required for building and installation. You can + add them with ``type=('build', 'run')``. + +* ``[project.optional-dependencies]`` + + This section includes keys with lists of optional dependencies + needed to enable those features. You should add a variant that + optionally adds these dependencies. This variant should be ``False`` + by default. + +Some build backends may have additional locations where dependencies +can be found. """"""""" distutils @@ -245,9 +267,9 @@ If the ``pyproject.toml`` lists ``setuptools.build_meta`` as a ``build-backend``, or if the package has a ``setup.py`` that imports ``setuptools``, or if the package has a ``setup.cfg`` file, then it uses setuptools to build. Setuptools is a replacement for the -distutils library, and has almost the exact same API. Dependencies -can be listed in the ``setup.py`` or ``setup.cfg`` file. Look for the -following arguments: +distutils library, and has almost the exact same API. In addition to +``pyproject.toml``, dependencies can be listed in the ``setup.py`` or +``setup.cfg`` file. Look for the following arguments: * ``python_requires`` @@ -292,25 +314,22 @@ listed directly in the ``pyproject.toml`` file. Older versions of flit used to store this info in a ``flit.ini`` file, so check for this too. -Either of these files may contain keys like: +In addition to the default ``pyproject.toml`` keys listed above, +older versions of flit may use the following keys: -* ``requires-python`` - - This specifies the version of Python that is required - -* ``dependencies`` or ``requires`` +* ``requires`` under ``[tool.flit.metadata]`` These packages are required for building and installation. You can add them with ``type=('build', 'run')``. -* ``project.optional-dependencies`` or ``requires-extra`` +* ``[tool.flit.metadata.requires-extra]`` This section includes keys with lists of optional dependencies needed to enable those features. You should add a variant that optionally adds these dependencies. This variant should be False by default. -See https://flit.readthedocs.io/en/latest/pyproject_toml.html for +See https://flit.pypa.io/en/latest/pyproject_toml.html for more information. """""" @@ -332,27 +351,22 @@ hatchling """"""""" If the ``pyproject.toml`` lists ``hatchling.build`` as the -``build-backend``, it uses the hatchling build system. Look for -dependencies under the following keys: - -* ``requires-python`` - - This specifies the version of Python that is required +``build-backend``, it uses the hatchling build system. Hatchling +uses the default ``pyproject.toml`` keys to list dependencies. -* ``project.dependencies`` - - These packages are required for building and installation. You can - add them with ``type=('build', 'run')``. +See https://hatch.pypa.io/latest/config/dependency/ for more +information. -* ``project.optional-dependencies`` +""""" +meson +""""" - This section includes keys with lists of optional dependencies - needed to enable those features. You should add a variant that - optionally adds these dependencies. This variant should be ``False`` - by default. +If the ``pyproject.toml`` lists ``mesonpy`` as the ``build-backend``, +it uses the meson build system. Meson uses the default +``pyproject.toml`` keys to list dependencies. -See https://hatch.pypa.io/latest/config/dependency/ for more -information. +See https://meson-python.readthedocs.io/en/latest/usage/start.html +for more information. """""" wheels @@ -692,6 +706,7 @@ For more information on build and installation frontend tools, see: For more information on build backend tools, see: * setuptools: https://setuptools.pypa.io/ -* flit: https://flit.readthedocs.io/ +* flit: https://flit.pypa.io/ * poetry: https://python-poetry.org/ * hatchling: https://hatch.pypa.io/latest/ +* meson: https://meson-python.readthedocs.io/ diff --git a/var/spack/repos/builtin/packages/py-meson-python/package.py b/var/spack/repos/builtin/packages/py-meson-python/package.py new file mode 100644 index 0000000000..7f3b6e76da --- /dev/null +++ b/var/spack/repos/builtin/packages/py-meson-python/package.py @@ -0,0 +1,23 @@ +# Copyright 2013-2022 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +from spack.package import * + + +class PyMesonPython(PythonPackage): + """Meson Python build backend (PEP 517).""" + + homepage = "https://github.com/FFY00/mesonpy" + pypi = "meson_python/meson_python-0.7.0.tar.gz" + + version("0.7.0", sha256="9fcfa350f44ca80dd4f5f9c3d251725434acf9a07d9618f382e6cc4629dcbe84") + + depends_on("python@3.7:", type=("build", "run")) + depends_on("py-meson@0.62:", type=("build", "run")) + depends_on("py-ninja", type=("build", "run")) + depends_on("py-pyproject-metadata@0.5:", type=("build", "run")) + depends_on("py-tomli@1:", type=("build", "run")) + depends_on("py-typing-extensions@3.7.4:", when="^python@:3.7", type=("build", "run")) + depends_on("py-colorama", when="platform=windows", type=("build", "run")) diff --git a/var/spack/repos/builtin/packages/py-meson/package.py b/var/spack/repos/builtin/packages/py-meson/package.py new file mode 100644 index 0000000000..2009ccc179 --- /dev/null +++ b/var/spack/repos/builtin/packages/py-meson/package.py @@ -0,0 +1,24 @@ +# Copyright 2013-2022 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +from spack.package import * + + +class PyMeson(PythonPackage): + """A high performance build system. + + Meson is a cross-platform build system designed to be both as fast and as user + friendly as possible. It supports many languages and compilers, including GCC, + Clang, PGI, Intel, and Visual Studio. Its build definitions are written in a simple + non-Turing complete DSL. + """ + + homepage = "https://mesonbuild.com/" + pypi = "meson/meson-0.62.2.tar.gz" + + version("0.62.2", sha256="a7669e4c4110b06b743d57cc5d6432591a6677ef2402139fe4f3d42ac13380b0") + + depends_on("python@3.7:", type=("build", "run")) + depends_on("py-setuptools@42:", type="build") diff --git a/var/spack/repos/builtin/packages/py-pyproject-metadata/package.py b/var/spack/repos/builtin/packages/py-pyproject-metadata/package.py new file mode 100644 index 0000000000..312ff58e25 --- /dev/null +++ b/var/spack/repos/builtin/packages/py-pyproject-metadata/package.py @@ -0,0 +1,19 @@ +# Copyright 2013-2022 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +from spack.package import * + + +class PyPyprojectMetadata(PythonPackage): + """PEP 621 metadata parsing.""" + + homepage = "https://github.com/FFY00/python-pyproject-metadata" + pypi = "pyproject-metadata/pyproject-metadata-0.6.1.tar.gz" + + version("0.6.1", sha256="b5fb09543a64a91165dfe85796759f9e415edc296beb4db33d1ecf7866a862bd") + + depends_on("python@3.7:", type=("build", "run")) + depends_on("py-setuptools@42:", type="build") + depends_on("py-packaging@19:", type=("build", "run")) -- cgit v1.2.3-60-g2f50