Skip to main content

A test project using pybind11 and CMake

Project description

Usage

python3 -m pip install cubao_cmake_example # install from pypi
python3 -c 'import cubao_cmake_example; print(cubao_cmake_example.add(1, 2))'
python3 -m cubao_cmake_example add 1 2
python3 -m cubao_cmake_example subtract 9 4
$ python3 -m cubao_cmake_example pure_python_func --help
INFO: Showing help with the command '__main__.py pure_python_func -- --help'.

NAME
    __main__.py pure_python_func

SYNOPSIS
    __main__.py pure_python_func <flags>

FLAGS
    --arg1=ARG1
        Type: int
        Default: 42
    --arg2=ARG2
        Type: float
        Default: 3.14
    --arg3=ARG3
        Type: str
        Default: 'you shall not pass'
$ python3 -m cubao_cmake_example pure_python_func --arg1=43234
int: 43234, float: 3.14, str: you shall not pass

See more examples at cubao, e.g.:

  • pybind11-rdp: C++ implementation of the Ramer-Douglas-Peucker algorithm (binding to python via pybind11)
  • concave_hull: A very fast 2D concave hull algorithm, for python

Make a release

On linux

Install docker then

make python_build_all_in_linux
make upload_wheels

On macOS

Install c++ compiler and cmake.

Install conda and envs:

# conda create -y -n py36 python=3.6
# conda create -y -n py37 python=3.7
conda create -y -n py38 python=3.8
conda create -y -n py39 python=3.9
conda create -y -n py310 python=3.10
conda env list

Then

make python_build_all_in_macos
make upload_wheels

On windows

Install visual studio and cmake, (also git for windows, maybe).

Install conda and envs same as on macOS, then:

make python_build_all_in_windows
make upload_wheels

cmake_example for pybind11

Gitter

CI status
MSVC 2015 AppVeyor
conda.recipe Conda Actions Status
pip builds Pip Actions Status
cibuildwheel Wheels Actions Status

An example pybind11 module built with a CMake-based build system. This is useful for C++ codebases that have an existing CMake project structure. This is in many cases superseded by scikit_build_example, which uses scikit-build, a tool from the makers of CMake designed to allow Python packages to be driven from CMake. However, there are still cases where you might want full control over the CMake run; and both of these approaches have some trade-offs not present in a pure setuptools build (see python_example). Python 3.6+ required; see the commit history for older versions of Python.

Prerequisites

  • A compiler with C++11 support
  • Pip 10+ or CMake >= 3.4 (or 3.8+ on Windows, which was the first version to support VS 2015)
  • Ninja or Pip 10+

Installation

Just clone this repository and pip install. Note the --recursive option which is needed for the pybind11 submodule:

git clone --recursive https://github.com/pybind/cmake_example.git
pip install ./cmake_example

With the setup.py file included in this example, the pip install command will invoke CMake and build the pybind11 module as specified in CMakeLists.txt.

Building the documentation

Documentation for the example project is generated using Sphinx. Sphinx has the ability to automatically inspect the signatures and documentation strings in the extension module to generate beautiful documentation in a variety formats. The following command generates HTML-based reference documentation; for other formats please refer to the Sphinx manual:

  • cd cmake_example/docs
  • make html

License

Pybind11 is provided under a BSD-style license that can be found in the LICENSE file. By using, distributing, or contributing to this project, you agree to the terms and conditions of this license.

Test call

import cubao_cmake_example
cubao_cmake_example.add(1, 2)

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

cubao_cmake_example-0.0.3.tar.gz (210.0 kB view hashes)

Uploaded Source

Built Distributions

cubao_cmake_example-0.0.3-cp311-cp311-win_amd64.whl (56.2 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

cubao_cmake_example-0.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (74.2 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

cubao_cmake_example-0.0.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (70.8 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

cubao_cmake_example-0.0.3-cp311-cp311-macosx_11_0_arm64.whl (46.4 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

cubao_cmake_example-0.0.3-cp311-cp311-macosx_10_9_x86_64.whl (48.9 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

cubao_cmake_example-0.0.3-cp310-cp310-win_amd64.whl (56.3 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

cubao_cmake_example-0.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (74.2 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

cubao_cmake_example-0.0.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (70.8 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

cubao_cmake_example-0.0.3-cp310-cp310-macosx_11_0_arm64.whl (46.4 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

cubao_cmake_example-0.0.3-cp310-cp310-macosx_10_9_x86_64.whl (48.9 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

cubao_cmake_example-0.0.3-cp39-cp39-win_amd64.whl (56.2 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

cubao_cmake_example-0.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (74.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

cubao_cmake_example-0.0.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (70.7 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

cubao_cmake_example-0.0.3-cp39-cp39-macosx_11_0_arm64.whl (46.6 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

cubao_cmake_example-0.0.3-cp39-cp39-macosx_10_9_x86_64.whl (49.0 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

cubao_cmake_example-0.0.3-cp38-cp38-win_amd64.whl (56.2 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

cubao_cmake_example-0.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (74.1 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

cubao_cmake_example-0.0.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (70.7 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

cubao_cmake_example-0.0.3-cp38-cp38-macosx_11_0_arm64.whl (46.4 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

cubao_cmake_example-0.0.3-cp38-cp38-macosx_10_9_x86_64.whl (48.9 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

cubao_cmake_example-0.0.3-cp37-cp37m-win_amd64.whl (56.4 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

cubao_cmake_example-0.0.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (75.5 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

cubao_cmake_example-0.0.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (71.9 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

cubao_cmake_example-0.0.3-cp37-cp37m-macosx_10_9_x86_64.whl (49.2 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

cubao_cmake_example-0.0.3-cp36-cp36m-win_amd64.whl (56.4 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

cubao_cmake_example-0.0.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (75.5 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

cubao_cmake_example-0.0.3-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (72.0 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ ARM64

cubao_cmake_example-0.0.3-cp36-cp36m-macosx_10_9_x86_64.whl (49.2 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

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