Skip to content
An example repo for generating python bindings with cppyy.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bbhash @ bc7dfa0
cmake
pkg_templates Bring in line with cppyy-knn and cookiecutter template, bump version Apr 10, 2019
py Fix template matching regex in pythonizor to admit spaces in typenames Apr 8, 2019
.gitignore Clean things up to work properly with conda Apr 8, 2019
.gitmodules add bbhash as submodule Apr 2, 2019
.travis.yml bump ubuntu version Apr 9, 2019
CMakeLists.txt Bring in line with cppyy-knn and cookiecutter template, bump version Apr 10, 2019
LICENSE Lots of cleanup Apr 5, 2019
README.md add badge [ci-skip] Apr 9, 2019
README.rst First pass working packaging: MANFITEST, setup.cfg, bindings initiali… Apr 4, 2019
interface.hh bring interface template type decs in line with cppyy standards, add … Apr 8, 2019
manifest.cmake Bring in line with cppyy-knn and cookiecutter template, bump version Apr 10, 2019
selection.xml Setup.py and __init__.py templates; reorg findcppyy Apr 4, 2019

README.md

cppyy-bbhash: cppyy-generated bindings for bbhash

Build Status

This repository is both a working set of cppyy bindings for bbhash and an example of a CMake workflow for automatically generating bindings and a python package with cppyy. Although it is based on the bundled cppyy cmake modules, it makes a number of improvements and changes:

  • genreflex and a selection XML are use instead of a direct rootcling invocation. This makes name selection much easier.
  • Python package files are generated using template files. This allows them to be customized for the particular library being wrapped.
  • The python package is more complete: it includes a MANIFEST, LICENSE, and README; it properly recognizes submodules; it includes a tests submodule for bindings tests; it directly copies a python module file and directory structure for its pure python code.
  • The cppyy initializor routine has basic support for packaging cppyy pythonizors. These are stored in the pythonizors/ submodule, in files of the form pythonize_*.py. The pythonizor routines themselves should be named pythonize_<NAMESPACE>_*.py, where <NAMESPACE> refers to the namespace the pythonizor will be added to in the cppyy.py.add_pythonization call. These will be automatically found and added by the initializor.

And example of cppyy's bundled cmake support can be found here; there is also a listing of cppyy example projects in the cppyy documentation.

Repo Structure

  • CMakeLists.txt: The CMake file for bindings generation.
  • selection.xml: The genreflex selection file.
  • interface.hh: The interface header used by genreflex. Should include the headers and template declarations desired in the bindings.
  • cmake/: CMake files for the build. Should not need to be modified.
  • pkg_templates/: Templates for the generated python package. Users can modify the templates to their liking; they will be configured and copied into the build and package directory.
  • py/: Python package structure that will be copied into the generated package. Add any pure python code you'd like include in your bindings package here.
  • py/initializor.py: The cppyy bindings initializor that will be copied in the package. Do not delete!

Example Usage

For this repository with anaconda:

conda create -n cppyy-example python=3 cmake cxx-compiler c-compiler clangdev libcxx libstdcxx-ng libgcc-ng pytest
conda activate cppyy-example 
pip install cppyy clang

git clone https://github.com/camillescott/cppyy-bbhash
cd cppyy-bbhash
git submodule update --init --recursive

mkdir build; cd build
cmake ..
make

python setup.py bdist_wheel
pip install dist/cppyy_bbhash-*.whl

And then to test:

py.test -v cppyy_bbhash/tests/test_bbhash_basic.py

To use this repo as a template for you own bindings, you'll want to modify the selection.xml, interface.hh, and CMakeLists.txt, as well as swap out the submodule.

TODOS

  • The CMake code for finding libclang is a bit fragile in conda environments.
  • Have CMake produce install commands to invoke setup.py and the pip install.
  • Create a PyPA package with a script to generate a repo using this this one as a template.
  • Use git hash in CMake for versioning.
You can’t perform that action at this time.