$darkmode
LuPNT 0.1
LuPNT
bindings

Python bindings of the lupnt library

How to add a new python bindings

Suppose you want to add the python bindings to "XXX.cpp" and "XXX.h"

  1. Define void init_xxx(py::module &m) in MainBindings.cpp
  2. Add init_xxx(m) in the PYBIND11_MODULE in MainBindings.cpp
  3. Create PyXXX.cpp in the bindings/ folder
  4. In PythonXXX.cpp, define your bindings as follows. Refer to the official document on how to write the bindings. ``` #include <pybind11/pybind11.h> #include <lupnt/path/to/XXX.h>

    namespace py = pybind11; using namespace LPT;

    void init_state(py::module &m){ /* define your bindings here */ } ```

  5. Compile using CMAKE (nothing special needed, the lupnt project CMAKE will build the bindings as well)
    • If the compiler cannot find the python library, add the following to .vscode/settings.json ``` { // cmake settings "cmake.configureArgs": [ "-DPYTHON_INCLUDE_DIRS=path1string", "-DPYTHON_LIBRARIES=path2string" "-DBUILD_EXAMPLES=ON" ] } ``
  6. Install the updated python library to local from the root directory of this project. Don't forget to create a new local environment and activate it (python3 -m venv venv, and. venv/bin/activateorsource .venv/bin/activate) if you don't want to install it globally. `` pip install . ``
  7. Create a test undertest_python/
  8. Test your bindings withpython3 -m pytest test_python`

References and Examples