Skip to content

cmake_example

Example pybind11 module built with a CMake-based build system.

It's a fork of pybind/cmake_example with some modifications:

  • integrate python code along side c++ pybind code
  • release to pypi
  • use markdown document

Usage

Install:

python3 -m pip install cubao_cmake_example # install from pypi
python3 -c 'import cubao_cmake_example; print(cubao_cmake_example.add(1, 2))'

CLI interface: (created with python-fire)

python3 -m cubao_cmake_example add 1 2
python3 -m cubao_cmake_example subtract 9 4

Help:

$ python3 -m cubao_cmake_example --help
INFO: Showing help with the command '__main__.py -- --help'.

NAME
    __main__.py

SYNOPSIS
    __main__.py GROUP | COMMAND

GROUPS
    GROUP is one of the following:

     fire
       The Python Fire module.

COMMANDS
    COMMAND is one of the following:

     add
       add(arg0: int, arg1: int) -> int

     subtract
       subtract(arg0: int, arg1: int) -> int

     pure_python_func
$ python3 -m cubao_cmake_example pure_python_func --help
INFO: Showing help with the command '__main__.py pure_python_func -- --help'.

NAME
    __main__.py pure_python_func

SYNOPSIS
    __main__.py pure_python_func <flags>

FLAGS
    --arg1=ARG1
        Type: int
        Default: 42
    --arg2=ARG2
        Type: float
        Default: 3.14
    --arg3=ARG3
        Type: str
        Default: 'you shall not pass'

$ python3 -m cubao_cmake_example pure_python_func --arg1=43234
int: 43234, float: 3.14, str: you shall not pass

See more projects at cubao.