Skip to main content

Stubs generator based on Doxygen+Boost.Python

Project description

Doxystub

What is it ?

This package generates stubs (.pyi file) for a python module created with Boost Python, leveraging doxygen documentation.

Requirement

To function, doxystub needs to know the mapping between C++ and Python classes. To that end, you should wrap your calls to class_ as follow:

// doxystub.h
#pragma once

#include <boost/python.hpp>

/**
 * This wrapper adds a __cxx_class__ method on the exposed class, allowing to retrieve the original
 * C++ type of the object from Python.
 */
template <class W, class X1 = boost::python::detail::not_specified, class X2 = boost::python::detail::not_specified,
          class X3 = boost::python::detail::not_specified, typename... Args>
boost::python::class_<W, X1, X2, X3> class__(Args... args)
{
  return boost::python::class_<W, X1, X2>(args...).def(
      "__cxx_class__", +[]() { return boost::core::demangle(typeid(W).name()); });
}

Simply keep the above snippet in a header file, and use class__ instead of class_ to expose your classes. This will provide the __cxx_class__ method, used by doxystub to retrieve the mapping with C++ types.

Usage

You can install doxystub using pip:

pip install doxystub

And then use it as follows:

doxystub -m my_module -d path/to/doxygen -o my_module.pyi

In CMakeLists.txt

The following snippet can be used to trigger stubs generation at the end of your build

add_custom_command(
    TARGET my_module POST_BUILD
    COMMAND doxystub
        --module my_module
        --doxygen_directory "${CMAKE_CURRENT_SOURCE_DIR}"
        --output "${CMAKE_BINARY_DIR}/${PYTHON_SITELIB}/my_module.pyi"
    WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/${PYTHON_SITELIB}"
    COMMENT "Generating stubs..."
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

doxystub-0.0.2.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

doxystub-0.0.2-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file doxystub-0.0.2.tar.gz.

File metadata

  • Download URL: doxystub-0.0.2.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for doxystub-0.0.2.tar.gz
Algorithm Hash digest
SHA256 000899dc73e22c19beb0b5fe47e4a5a74dfcd5f9e2cadf0b6bd109001957f56e
MD5 a423375eca9d8d0903e0f6465ae2c1b5
BLAKE2b-256 b01558b5fc61363ad00b062e6815a3850005344462144d476e9d934f9184ef1e

See more details on using hashes here.

File details

Details for the file doxystub-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: doxystub-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for doxystub-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 473a144e1eba49c2c75bf085b6b04d4bfda05df6f6bacd7dced99506e6057ada
MD5 a1eb67b98ae9d8b99f404d9213c394ea
BLAKE2b-256 32e79c61765c773afbd8f6470c93d5fa785ec403544a2642c1fcc92ac22c2fe6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page