Skip to main content

Modern, PEP 517 compliant build backend for building Python packages with

Project description

Python Wheel Documentation PyPI - Downloads

py-build-cmake

Modern, PEP 517 compliant build backend for building 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
  • 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 following command to get the documentation for all supported options:

python -m py_build_cmake.help

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.0"]
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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-build-cmake-0.1.0.tar.gz (27.1 kB view details)

Uploaded Source

Built Distribution

py_build_cmake-0.1.0-py3-none-any.whl (30.1 kB view details)

Uploaded Python 3

File details

Details for the file py-build-cmake-0.1.0.tar.gz.

File metadata

  • Download URL: py-build-cmake-0.1.0.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for py-build-cmake-0.1.0.tar.gz
Algorithm Hash digest
SHA256 364bf846105cbafc7b6004c94b6bfd8bbe51e605c54e1aeb10a9086ac2735e27
MD5 0fdfaf5b94a2cf56dcbb343758c8292a
BLAKE2b-256 f72317c52b7b619e60a68a95a9b416ccc2888e960224233103d5465aa8f399b6

See more details on using hashes here.

File details

Details for the file py_build_cmake-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for py_build_cmake-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 906eb98290ea1fb8d8b85f7249489f80ea7cc130cd1fb18b9b73545801558587
MD5 2d2479d08209d1e1ffe59024a79ae9e1
BLAKE2b-256 9a0c89c3bb53586b1cccd8ef714b9f794b60fd7147be4582c3194adb35a92e87

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page