/pybind11_cmake

The goal of this repository to work with pybind11 and CMake. Here, my plan is to introduce advanced C++ binding.

Primary LanguageC++

C++ Datatypes <--> Pybind11

CI Documentation Status

THe goal if this project is to interface C++ type with Python. Pybind11 is used for this interfacing feature. CMaek is used as build tool.

Required Repositories

  • This project is dependent on pybind11 which is used in this project as a helper repository.
  • To clone and use pybind11 follow the following approach.
    • Go to the directory where pybind11_cmake project will be cloned and clone it with the following command

      git clone https://github.com/atifkarim/pybind11_cmake.git
    • Now keep pybind11 in the same level of the current project. I have kept it in a common repository named forked repo

      mkdir forked_repo && cd forked_repo
      git clone https://github.com/pybind/pybind11.git
    • Finally the directory structure will be as like as follows

      forked_repo/
      └── pybind11
      pybind11_cmake/
  • To clone and prepare the repository by following current structure one can use this script

Required python package

  • Necessary python files are located in example/py dorectory
  • Used pipreqs module to create requirements.txt file to install necessary python module

    Remember, python module generated by pybind11 will not be counted here

  • To use pipreqs
    • pip install pipreqs -> Source
    • Usage to create requirements.txt file: pipreqs example/py/

Building project

To build the project necessary commands are written in run_project.sh file which is located in the root of the project. Execute it from the terminal by writing ./run_project.sh.

Documentation

This RTD Site is used to host the documentation of the project

Containerization

This project is available in Docker. See this to use the docker image.

Command to run docker image

  • After preparing docker environment in your system, pull the docker image

    docker pull atifkarim/test_image_pybind11_cmake
  • After pulling check images list by docker images command

  • Now, run it using the following command

    • Without interactive terminal
      docker run atifkarim/test_image_pybind11_cmake
    • Without interactive terminal
      docker run -it atifkarim/test_image_pybind11_cmake bash
      • Now, here you can see the file prepare_project.sh.
      • Make it executable by running chmod +x prepare_project.sh
      • Now run that file by using ./prepare_project.sh.
      • This command will clone required repo and execute cpp, py file. Later, developer can do further development here.
      • I have found the required repo by going to home directory cd ~

Planning

Here my planning is written regarding the project

Building project issue

  1. Sometimes CMAKE faces issue while building project regarding finding appropriate python package. See this. Possible solution:

    cmake .. -DPYTHON_EXECUTABLE=/usr/bin/python3.8

    or,

    cmake .. -DPYTHON_EXECUTABLE=$(which python)