Skip to main content

Reads and parses documentation from header files in pure Python.

Reason this release was yanked:

Known broken, upgrade to 0.1.8

Project description

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.

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

docblock-0.1.7.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

docblock-0.1.7-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file docblock-0.1.7.tar.gz.

File metadata

  • Download URL: docblock-0.1.7.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.9.25 Linux/6.14.0-1017-azure

File hashes

Hashes for docblock-0.1.7.tar.gz
Algorithm Hash digest
SHA256 aaee4f9060f2f549e265120adb2a325208741461d3ecf16beb5d8534dcafa939
MD5 90f90907ec6effc8750431cd8d41155e
BLAKE2b-256 185e3a36cc94a50ff7ace1ae2dc80f6b355dbbe114afc828d57ecba9937d16f9

See more details on using hashes here.

File details

Details for the file docblock-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: docblock-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.9.25 Linux/6.14.0-1017-azure

File hashes

Hashes for docblock-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6e60478e591cf4d32d9d8f8e7c671ccfa149a5e5b6848d01641957df75c6bdf4
MD5 7bfca00fd4cfe109dcbe813751747516
BLAKE2b-256 f6381f2d1275cca1e4e7643ef462cf02c338426056cee6e4c618424b217d4c68

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