Test CPPLib integration
Project description
C++ and Python Library
This is a template repository used to create C++/Python libraries. This is for individual who want to write a standalone C++ library that can also be bound to Python using Pybind11 for better performance. This repository additionally takes care of the intricate world of building binary wheels automatically and publishing to PyPI, including linux and windows. I have tried my best to use good tools and practices in this repo to provide a clean codebase for others to start their project on. What you see in this repo is not all my work, but lessons/code I have learned after observing others work.
Key Features
- C++ Library is independent of Python Extension, i.e. can be dropped into pure C++ projects.
- Cross platform using Modern CMake.
- Benchmark (Nanobench) and Testing (doctest) built in.
- Good handling of thirdparty dependencies using CMake
FetchContent
. - Documentation for both C++ and Python created using Sphinx, Doxygen, Breathe, and Exhale. The documentation is unified into one website.
- Integration of CMake into
setup.py
so thatpip install
works for python users wanting to build manually (CMake must be installed still).- Note that the C++ Library and even the python extension can still be built with standard CMake procedures, see Build with CMake
- Automatic building of python binary wheels using github actions, see Workflow
This repo relies upon using Modern CMake to build both the C++ and Python Extension libraries. I find that integrating it all in CMake leads to a much nicer developer experience. External users building the library will need CMake installed which may be a consideration before using this template repo as a starting point. However, this repo has a github workflow setup to automatically build python binary wheels for you and upload to PyPI for a variety of python versions/OS/architectures! Please see workflows
Instructions For Using Template
git clone https://github.com/JeremyBYU/cpp-pybind-skel.git
Rename Files
You will want to rename files and library names with a simple find and replace
using your IDE/editor. Lets say you named your project SimpleImageFilters
with an associates short acronym of SIF
. Then simply find and replace in this repository the following (case sensitivity matters):
CPPLib
->SimpleImageFilters
- C++ Top Namespace and CMake Project NameCPPLIB
->SIMPLEIMAGEFILTERS
- Same but uppercase, used in CMakeCPPL
->SIF
- Acronym used in CMake alias for projectcpplib
->simpleimagefilters
- Python Library Extension Name
A helper python script, rename_project.py
is provided if desired.
Note: you don't have to use the naming convention proposed above and may use any you would like. I think the most important thing is simply that the Python extension target is different then C++ library target.
Build Manually with CMake
Building happens entirely with CMake.
C++
mkdir cmake-build && cd cmake-build
cmake ..
- Note - For windows also add-DCMAKE_GENERATOR_PLATFORM=x64
cmake --build . -j$(nproc) --config Release
Build options:
CPPL_BUILD_BENCHMARKS:BOOL=ON // CPPL - Build Benchmarks
CPPL_BUILD_EXAMPLES:BOOL=ON // CPPL - Build Examples
CPPL_BUILD_PYMODULE:BOOL=ON // CPPL -Build Python Module
CPPL_BUILD_TESTS:BOOL=ON // CPPL - Build Tests
CPPL_BUILD_WERROR:BOOL=OFF // CPPL - Add Werror flag to build (turns warnings into errors)
CPPL_WITH_OPENMP:BOOL=ON // CPPL - Build with OpenMP Support
Python
This is meant for advanced python users who are actively developing the extension.
- Install conda or create a python virtual environment (Why?). I recommend conda for Windows users.
- Perform
CMake
build as described above cd cmake-build && cmake --build . --target python-package --config Release
cd lib/python_package && pip install -e .
You can build a binary wheel that you can distribute to users with your exact same platform by
cmake --build . --target pip-package --config Release
The wheel should then be at cmake-build\lib\python_package\pip_package
. Note you can alternatively build using Python setup.py
Build Manually with Python
The root directory setup.py
file has been modified to build with CMake. This is meant for python users that need to build manually (for some reason) but are not actively developing or changing the code.
- Install conda or create a python virtual environment (Why?). I recommend conda for Windows users.
pip install .
- Call from root directory
That should be it!
Install with Python
If you only care about installing the python extension you can install from the binary wheels generated by the github action workflows. The binary wheels are uploaded to PyPi. Therefore, after configuring the workflow and tagging a version, you can install as:
pip install cpplib
- Changecpplib
to whatever your python extension will end up being.
Workflows
Several github action workflows are included in this repository. The first is the binary wheel creation and uploading to pypi.
Binary Wheel
This workflow file generates the binary wheels and uploads to PyPI. You will need to configure your github repository with a token access to publish to PyPI
and PyPITest
. Please read here about what is expected. Note that this workflow only run on the master branch, and publishing only occurs on tagged releases.
Documentation
C++ classes and functions are documented in their header files. Associated Python functions/classes which are bound with Pybind11 are re-documented. This is for two reasons:
- The function/class API might actually be slightly different in arguments and return types (e.g., list vs. std::vector) and more detail/nuance may be desired in one form of the other.
- I have no idea how to share them.
For Python, I am using this method to inject further documentation into functions/classes which was developed by Intel at Open3D. They provide a function that can transform an input map
of arg/description pairs and convert to Googles Python Docstring format.
Documentation Website Generation
Documentation building has been taken from Open3D with some small modification. Python and C++ documentation is generated using Sphinx
into the same website. The C++ API is actually integrated into sphinx using breathe/exhale
. Please see docs/builddocs.rst
.
Release Steps
- Make all necessary changes
python scripts/manage_versions.py --bump patch
pip install .
cd src_docs && python make_docs.py && cd ..
- commit changes
python scripts/manage_versions.py --tag
git push origin dev --tags
FAQ
Q: ERROR: Could not install packages due to an EnvironmentError
A: Remove the build
directory
Acknowledgements
I have learned a lot by listening/watching/reading about C++. I can't list them all but the following links had the most influence in developing this repo.
- Open3D - Much of this repo comes from following their practices. After having made many C++/Python projects I find this code structure to be the best for hybrid projects.
- Modern CMake - An invaluable resource which has taught me about CMake.
- Mapbox hpp-skel - A great starting point for header-only libraries. Almost everything MapBox makes is gold to me.
- Parselmouth - A great resource on using github workflows!
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 Distributions
File details
Details for the file cpplib-1.0.3.tar.gz
.
File metadata
- Download URL: cpplib-1.0.3.tar.gz
- Upload date:
- Size: 30.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5df480926d014ef56dd14711ea021f53f322c09111fd4d2f8c7e717b975837a0 |
|
MD5 | bd8433076eaab7d6f8797e598a5e000a |
|
BLAKE2b-256 | a04aadf101391db78d2e965c522223f512e38657231d3b4c584fa0886eca2343 |
File details
Details for the file cpplib-1.0.3-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: cpplib-1.0.3-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 132.3 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81fee23e513529b3b2ce0fbca3b99d612d5422bd0ed5b631f5e35816d26c3590 |
|
MD5 | 71f188fb68f5e65e5f77198fce81e32f |
|
BLAKE2b-256 | 91919cbae130add6db7b244f8c9d77b07b6e5642b88458428f77a191185ccee9 |
File details
Details for the file cpplib-1.0.3-cp39-cp39-manylinux2010_x86_64.whl
.
File metadata
- Download URL: cpplib-1.0.3-cp39-cp39-manylinux2010_x86_64.whl
- Upload date:
- Size: 217.1 kB
- Tags: CPython 3.9, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3196b733aa2169358eb35d46983dab6d6be5ae5afdb0268696755d7d16d07016 |
|
MD5 | 8d7b037276828aba395559d7db7b062d |
|
BLAKE2b-256 | 32cc0ca33cd0596ac2668a4224ca023a8770061ff5a8174e371fd34779e4b794 |
File details
Details for the file cpplib-1.0.3-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: cpplib-1.0.3-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 132.2 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12a3687036cc3c740fff1d44a242a4239d0b24918aaf44f77c25541e9271b79f |
|
MD5 | 47b9c9c37281fa05e6525035e9fa9582 |
|
BLAKE2b-256 | 94e5734a634a410bb0dca7608a335ac9fd9dfa50433a258ba9579e6d1d014c2e |
File details
Details for the file cpplib-1.0.3-cp38-cp38-manylinux2010_x86_64.whl
.
File metadata
- Download URL: cpplib-1.0.3-cp38-cp38-manylinux2010_x86_64.whl
- Upload date:
- Size: 217.2 kB
- Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35ba5c9db44fd6c90c761ac9d276c5c482802cafb2715e3747fde9ed3707f914 |
|
MD5 | 8cbf13059e3c0f1095c00b8e7a6c7b1e |
|
BLAKE2b-256 | 0400681f3720290515fa52a6ceac8ec9c46b9c9c6c8676556e89564fcfcc2a72 |
File details
Details for the file cpplib-1.0.3-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: cpplib-1.0.3-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 132.8 kB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3dbfac06d29b6d0acbb6fe958c4e15790c97ced449181bafc18df229ffc7eb7 |
|
MD5 | 6d8d0106359504433c68dfd8fc6da689 |
|
BLAKE2b-256 | b7fe967a0bf8b967528e49cce714b355aee08dab90727b27dcdc6296c0eb33e6 |
File details
Details for the file cpplib-1.0.3-cp37-cp37m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: cpplib-1.0.3-cp37-cp37m-manylinux2010_x86_64.whl
- Upload date:
- Size: 214.2 kB
- Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4b7674d7d70163efc0419613a94b20d0b56ef331cadf929215d613b9f86692b |
|
MD5 | 7e03d72f4dbf9c645f56165f3033acbf |
|
BLAKE2b-256 | 5a65b0ad1ef885c53c3c5aa764cbda6ea2d73e0c217903a0af17223c2fdc430c |
File details
Details for the file cpplib-1.0.3-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: cpplib-1.0.3-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 132.6 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e527afea1e09b0d84f9b8829f87e7e01dea9409a9b5b87607975683177b958f4 |
|
MD5 | 6cccf6116ea54a88997ee34008facc5a |
|
BLAKE2b-256 | 13c14b95f1ce6b4c79ffb28b4554f66d864a0cee1493f6851f5d522838482c4c |
File details
Details for the file cpplib-1.0.3-cp36-cp36m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: cpplib-1.0.3-cp36-cp36m-manylinux2010_x86_64.whl
- Upload date:
- Size: 214.5 kB
- Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b654270158ce8a70f5f53b431580afef854987d8a24c3afff828031b9e01dd6d |
|
MD5 | 631636f882499b354439d11e9699d01d |
|
BLAKE2b-256 | 55a91d5d181f1744cd0eeac74c74dfd80cc36fb0a868615148fc95c58e01fda6 |