Skip to content

HealthyPear/cpp_project_with_python_bindings

Repository files navigation

my-package

CI

This project template is designed for C++ projects providing Python3 bindings.

This project is built from C++ using scikit-build-core <https://scikit-build-core.readthedocs.io/en/latest/index.html>_ to make a bridge between CMake and the Python build system and make Python modules with CMake.

The Python bindings are built with nanobind <https://nanobind.readthedocs.io/en/latest/index.html>_.

The template builds over nanobind_example <https://github.com/wjakob/nanobind_example>_ plus a set of personal preferences that can be easily disabled or re-configured.

Installation

Since there is no release yet, the only installation available is the development version.

Tip

The use of a virtual environment is recommended; a conda environment file is provided (if you start from scratch is recommended to install the Miniforge3 distribution which comes with mamba as a faster alternative to conda). In the following instructions this is the assumed setup.

  1. create a new repository from this template
  2. clone your newly created repository
  3. cd your_repo_name
  4. search and replace globally my-package and my_package with the equivalent of your project name identifiers
  5. conda env create -f environment.yml (mamba is recommended over conda if available)
  6. pip install .[dev]
  7. pre-commit install

Update

  1. Switch to the default branch and update it (git switch main && git pull)
  2. activate the development virtual environment (conda activate your-env-name)
  3. update it (conda env update --file environment.yml --prune)
  4. re-install the package (pip install .[dev])

Documentation

The documentation is based on and build using,

Documentation can be compiled locally with make -C docs html (a clean target is also available).

Development

The development process is based on a pre-commit configuration.

Linting and formatting are performed using ruff.

Testing for the Python interface is performed with pytest while that for the C++ interface needs to be added.

GitHub Actions

  • Continuous integration pipeline to test pip installation and Python testing suite

About

A template repository for a C++ project with Python bindings using nanobind and scikit-build-core

Topics

Resources

License

Stars

Watchers

Forks