Python Bindings for C++¶
This repository demonstrates how to use pybind11 to build Python modules out of C++ code so it can be used in Python like a “normal” Python module.
You can see our example libs/src_cxx/. To make the Python bindings you can simply perform
$ cmake -S ./ -B ./build
$ cd build && make
which fetches and uses pybind11 (see CMakeLists.txt) to make a Python module out of the C++ code.
Deleting C++ From This Repository¶
Not using C++? Don’t want it in your repository? Then you can remove doxygen, breathe and certain files from your repository:
Hint: After you have successfully deleted the C++ parts of the repository,
you can make the documentation without them, e.g. cd ./docs && mkdir build && make html.
To delete the C++ parts of the repository:
Delete the files/directories:
$ rm -rf libs/src_cxx docs/source/src_cxx docs/doxygen CMakeLists.txt tests/test_mock_cxx.py
In the file
docs/source/index.rstdelete:src_cxx/indexfrom the toctree.In the file
.github/workflows/CI.yamldelete:- name: Build Pybind11 module for C++ code run: | cmake -S ./ -B ./build cd build && make
and
- name: Install Doxygen run: /usr/share/miniconda/envs/goodsciproj_env/bin/doxygen --version shell: bash - name: Generate Doxygen Documentation run: | cd docs && mkdir build && mkdir build/doxygen && /usr/share/miniconda/envs/goodsciproj_env/bin/doxygen doxygen/doxygen.dox shell: bash
In
docs/source/conf.pydelete"breathe"fromextenstionsand# Integrate doxygen with sphinx via breathe breathe_projects = { "src_cxx": "../build/doxygen/xml/", } breathe_default_project = "proj"
In
.pre-commit-config.yamldelete:- repo: https://gitlab.com/daverona/pre-commit/cpp rev: 0.8.0 hooks: - id: cpplint args: [--linelength=100, "--filter=-runtime/references,-readability/braces,-build/include,-build/c++11"] types_or: [c, c++, cuda]
In
requirements.txtdeletebreathe.In
environment.yamldelete- conda-forge::doxygen>=1.10.0