Modern, PEP 517 compliant build backend for creating Python packages with
Project description
py-build-cmake
Modern, PEP 517 compliant build backend for creating Python packages with extensions built using CMake.
Features
- Build and package C, C++ or Fortran extension modules for Python using CMake
- Declarative configuration using
pyproject.toml
(PEP 621), compatible with flit - Editable/development installations for Python modules (PEP 660)
- Compatible with pybind11 and nanobind
- Generate stubs for type checking and autocompletion
- Customizable CMake configuration, build and installation options
- Support for multiple installation configurations and components
- Cross-compilation support
- No dependency on setuptools
Installation
The py-build-cmake package is available on PyPI:
pip install py-build-cmake
Documentation
The documentation can be found on https://tttapa.github.io/py-build-cmake.
The format of the configuration file is explained in Config.md.
Alternatively, use the command-line interface to get the documentation for all supported options:
py-build-cmake config format
Usage
If you don't have one already, add a pyproject.toml
configuration file to your
project's repository. Specify the metadata required by PEP 621,
and tell py-build-cmake how to build your project. For example:
[project] # Project metadata
name = "example-project"
readme = "README.md"
requires-python = ">=3.7"
license = { "file" = "LICENSE" }
authors = [{ "name" = "Pieter P", "email" = "pieter.p.dev@outlook.com" }]
keywords = ["some", "keywords"]
classifiers = ["Topic :: Scientific/Engineering"]
urls = { "Documentation" = "https://tttapa.github.io/py-build-cmake" }
dependencies = ["numpy"]
dynamic = ["version", "description"]
[build-system] # How pip and other frontends should build this project
requires = ["py-build-cmake~=0.1.4"]
build-backend = "py_build_cmake.build"
[tool.py-build-cmake.module] # Where to find the Python module to package
directory = "src-python"
[tool.py-build-cmake.sdist] # What to include in source distributions
include = ["CMakeLists.txt", "src/*"]
[tool.py-build-cmake.cmake] # How to build the CMake project
build_type = "RelWithDebInfo"
source_path = "src"
build_args = ["-j"]
install_components = ["python_modules"]
[tool.py-build-cmake.stubgen] # Whether and how to generate typed stub files
The README of examples/minimal
describes this configuration file in much more detail.
Then use pip
, build
or another PEP 517 compatible frontend to build and/or install the package.
Build sdist and wheel packages you can upload to PyPI:
python -m build . # find the sdist and wheel file in the 'dist' folder
Install the package in the current environment:
pip install . # normal installation
pip install -e . # editable installation
Examples
For an introduction to py-build-cmake, see examples/minimal
for a detailed overview of the configuration files and the directory structure,
using a very simple Python module as an example.
For a more advanced, real-world example, see examples/pybind11-project
.
If you are interested in packaging C/C++/Fortran programs using py-build-cmake,
have a look at examples/minimal-program
.
Projects using py-build-cmake
If you need more examples, you can look at the following projects using py-build-cmake as their Python build backend:
Planned features
-
Entry point support - Namespace package support (PEP 420)
- Doxygen and Sphinx support
-
macOS support
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file py-build-cmake-0.1.4.tar.gz
.
File metadata
- Download URL: py-build-cmake-0.1.4.tar.gz
- Upload date:
- Size: 29.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d7c5cd3386c09f19865540a5cb0dddb437c2016b43e7166ba9cab9af22d9458 |
|
MD5 | 05877b62cd00f69d3fb73811464cba47 |
|
BLAKE2b-256 | 1ab6e2c296a72d7affc87d2b5864ae93bd88f0f09283c487f236eb35fd5917e2 |
File details
Details for the file py_build_cmake-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: py_build_cmake-0.1.4-py3-none-any.whl
- Upload date:
- Size: 33.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e32b85056f9be7f7da08a764925905b67d6477be51a6f02072c8f43d54563e37 |
|
MD5 | 687d1ea3bf17504381ceadd79db641cd |
|
BLAKE2b-256 | cfe9a98375edca5ff7975ac744a6d5af04d804884863a8644560b9b6fc653851 |