Skip to main content

PyPI version CI codecov

The docblock package reads and parses documentation from C++ header files. It should also work out of the box for C header files, but that is currently untested. It is opinionated and explicitly does not cover all edge cases of the C++ grammar, but hopes to provide sufficient utility for most use cases. The package assumes documentation blocks are formatted using C-style comments, as follows:

/**
 * Text
 */
void func();

That is, the documentation block starts with /* or /**, and ends with */. Any starting * on documentation lines in the block are allowed, but not required unless you care about significant whitespace.

To avoid parsing issues, non-documentation block comments SHOULD NOT use C-style comments.

The docblock package is a pure Python package and depends only on pyparsing. It can be installed as

pip install docblock

Example usage

Consider the following header file test.h:

// test.h

/**
 * Test namespace.
 */
namespace test
{
class Test
{
public:
    /**
     * First constructor
     */
    Test(int x);

    /**
     * Second constructor
     */
    Test(int x, int y);

    /**
     * A method.
     */
    void aMethod() const;
};
};  // namespace test

This file may be parsed as:

from docblock import parse_file

res = parse_file("test.h")

Now, res contains:

>>> print(res)
{
    'test': ['Test namespace.'],
    'test::Test::Test': ['First constructor', 'Second constructor'],
    'test::Test::aMethod': ['A method.']
}

Observe that docblock understands scoping, and returns docstrings using qualified names. For overloads, multiple docstrings are returned: one for each documented overload.

Why docblock?

Parsing documentation from header files is common practice to generate documentation, particularly in mixed-language projects where the C++ components are intended to be used from another language. One tool that simplifies this for C++-to-Python is pybind11_mkdoc. That tool, however, relies on clang and the LLVM project to parse C++ documentation blocks: great if you're already using clang, but very heavy-handed if you do not.

This is where docblock comes in: it is a pure Python package that does not aim to parse all of C++'s grammar, but only extracts the documentation block's content and the function point it documents. That is far easier to implement (not requiring a full compiler), but does mean it will very likely not parse all documentation blocks correctly. Feel free to open an issue if you have an example that is not parsed correctly by docblock.

Metadata

Release files for docblock 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for docblock 0.1.8
File Size Uploaded
docblock-0.1.8.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for docblock 0.1.8
File Interpreter ABI Platform
docblock-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 11.7 kB

Release files / docblock-0.1.8.tar.gz

Download URL docblock-0.1.8.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
29f35c555eb34be24b697fadd923ee2fec6195dc84a5ee5cc37a1975baf9ce51
BLAKE2b-256 checksum
How to use checksums
a81b1b8065cb799d5fa0bedd58bbf87d0bfc437edfb588d43ff1ff95bd14fb42
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.13.12 Linux/6.14.0-1017-azure

Release files / docblock-0.1.8-py3-none-any.whl

Download URL docblock-0.1.8-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
210c8054b2e8e52ed66e81dcb1a4f9808d02a536237477e02a0eeea83f80d79d
BLAKE2b-256 checksum
How to use checksums
293396b18ccfc791ab1a6e09c65c65f0e37cb1922903f0876fafb9db2f7f6ec7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.13.12 Linux/6.14.0-1017-azure

Release history Release notifications | RSS feed

This release

0.1.8 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page