CPPYGEN
Automatic code generation for pybind11.
Pybind11 is a powerful library that exposes C++ types in Python and vice versa,
This generator will be generate c++ code for pybind11, and make it easy to write a python module using c++.
Installation
pip install cppygen
Usage Guide
After installing cppygen, you can use cppygen command.
cppygen --config_file /path/to/cppygenconfig.toml --cwd /path/to/cwd [--verbose] [--include_directories INCLUDE_DIRECTORIES] [--flags FLAGS]
This command will load config file, and parse C++ code and generate C++ pybind11 Code.
After generating the code. Include the generated header to your program and just write in pybind11 manner. Be sure to link the generated cpp code.
PYBIND11_MODULE(pyshell, m) {
CPPyGen::CPPyGenExport(m);
}
CMake
Use add_custom_command to auto generate.
set(cppygen_generated_hpp ${CMAKE_CURRENT_BINARY_DIR}/cppygen_generated.hpp)
set(cppygen_generated_cpp ${CMAKE_CURRENT_BINARY_DIR}/cppygen_generated.cpp)
find_program(_CPPYGEN_GENERATOR cppygen)
add_custom_command(
OUTPUT ${cppygen_generated_hpp} ${cppygen_generated_cpp}
COMMAND
${_CPPYGEN_GENERATOR} ARGS #
--config_file ${CMAKE_CURRENT_LIST_DIR}/cppygenconfig.toml #
--cwd ${CMAKE_CURRENT_LIST_DIR} #
--verbose
DEPENDS ${SHELL_SOURCES}
COMMENT
"Generating CPPyGen Code To ${cppygen_generated_hpp} and ${cppygen_generated_cpp}"
VERBATIM)
Config
cppygen command does not work without configuration.
Use toml format configuration file.
mode ["header" or "source"] cppygen parse strategy. "source" would parse source files for functions, "header" would parse headers for functions. This option would only affect function export. "header" would be faster.
sources [array of path, required(if soruce mode is on)]
Paths with cppygen will parse. cppygen can extract functions from
sources.
headers [array of path, required]
Paths with cppygen will parse.cppygen can extract structs or classes from
headers.
diagnostic [boolean] Default is "True". An option for outputting diagnostics and detecting errors during parsing.
output_dir [path, required] Output directory of generated code.
search_namespace [string, optional]
Default is "cppygen", this option will define the namespace witch
will be parsed by cppygen. Outside of this namespace would be ignored.
include_directories [array of dir, optional]
These directories will be passed as absolute paths to parser include flags.
Same as flags =["-I/abs_path/to/dir"]
flags [array of string, optional] Parser compile options.
libclang_path [path, optional]
Path to libclang shared library.
call_guards [array of string, optional] Add call_guard to exported function and member function, this option is useful when you want to add some call_guard to all C++ function.
include_headers [array of filename, optional]
deprecated cppygen does not resolve include paths, thus if you want to export C++
classes you should specify include filenames.
Examples
See the examples directry for sample projects.
Function
namespace cppygen {
/**
* pyname: py_foo
* description: some description
**/
void foo() {
}
}
This function will export to python as "py_foo".
description would be python docstring.
Env
CPPYGEN_LIBCLANG_PATH # Path to clang shared library. (e.g. /usr/lib/llvm-15/lib/libclang-15.so)
CPPYGEN_COMPILE_FLAGS # additional flags to parse file
Metadata
Release files for cppygen 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| cppygen-0.1.8.tar.gz | 44.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cppygen-0.1.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 92.2 kB
Release files / cppygen-0.1.8.tar.gz
| Download URL | cppygen-0.1.8.tar.gz |
|---|---|
| Size | 44.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
74859f9a79160a2066f927b580f35a1c138f53ba6fc9117fdb0870d83854e678
|
|
BLAKE2b-256 checksum How to use checksums |
7b00e8cff0b15b4ce3d91c1d4229a6c197b81a45a488b9cba64a317452ebccd7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / cppygen-0.1.8-py3-none-any.whl
| Download URL | cppygen-0.1.8-py3-none-any.whl |
|---|---|
| Size | 47.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
225544cc7a3cef6e45673bac4711b1ba26311ea9997d9d28d0fc1248a7662620
|
|
BLAKE2b-256 checksum How to use checksums |
717012bd7207fae387794d2c7a2db5a544feeff99026e55f3a01f2eb8b034acf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Security for cppygen 0.1.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.