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.3.tar.gz (8.7 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.3-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: doxystub-0.0.3.tar.gz
  • Upload date:
  • Size: 8.7 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.3.tar.gz
Algorithm Hash digest
SHA256 6ea7d1d7efd8d172a700143a65dce5e53268072b01a7de85458615d21829018d
MD5 86f3d35962d4d57ce6911ed5d056b2b4
BLAKE2b-256 3f17d0568e8ed03d9f3bb46dcac39bb1935742bc62d74645ab51dc824e1e3242

See more details on using hashes here.

File details

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

File metadata

  • Download URL: doxystub-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.5 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e50a851397c1263a60b356e16ee44579de36a5d715c0ab85bc9d5aae456ad034
MD5 cef94a0da9b5b6093ddb432d8a37743f
BLAKE2b-256 3a9ed8f4cea13f54bdf62f4fba24990d03346ef42ea084982a5dd54445eca1e6

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