header2whatever


Nameheader2whatever JSON
Version 0.4.8 PyPI version JSON
download
home_pagehttps://github.com/virtualroadside/header2whatever
SummaryGenerate files from C/C++ headers using jinja2 templates
upload_time2022-12-05 03:25:46
maintainer
docs_urlNone
authorDustin Spicuzza
requires_python
licenseApache 2.0
keywords c++ cpp codegen generator header jinja2 template
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            header2whatever (h2w)
=====================

Generate arbitrary files from C/C++ header files using CppHeaderParser to read
the input files and Jinja2 templates to generate the outputs.

This grew out of a desire to generate pybind11 wrapping code from C++ header
files. pybind11gen was created, but then I wanted to generate more things...

There are still rough edges, and the documentation is mostly nonexistent, but
pull requests with fixes/improvements are very welcome!

As of 0.3.0, h2w requires Python 3.3+

Install
-------

::

    pip install header2whatever

Usage
=====

First, you need to create a jinja2 template that represents whatever you want
to generate from the header file. For example, maybe you want to describe the
functions in yaml::

    ---
    {% for header in headers %}
    {% for fn in header.functions %}
    {{ fn.name }}:
      returns: {{ fn.returns }}
      params:
      {% for param in fn.parameters %}
      - { name: {{ param.name }}, type: "{{ param.type }}" }
      {% endfor %}

    {% endfor %}
    {% endfor %}

And let's say you have the following header file ``foo.h``::

    void some_fn(int i);
    int returns_int(int p1, char* p2);

You can execute the following::

    h2w foo.h -o foo.yml

And you'll get the following output::

    ---
    returns_int:
      returns: int
      params:
      - { name: p1, type: "int" }
      - { name: p2, type: "char *" }

    some_fn:
      returns: void
      params:
      - { name: i, type: "int" }

As you can see, while this is a silly example, this approach is very flexible
and fairly powerful.

Currently, the data structure passed to the template isn't documented -- but
it's a filtered version of whatever CppHeaderParser outputs when it parses a
header.

See the examples folder for more examples.

Batch mode
----------

If you need to process multiple files, or just want to record the parameters for
autogenerating a file without writing a shell script, batch mode is useful. You
pass two parameters: a yaml file with the configuration, and an output directory
to write the files to.


Using data from external sources
--------------------------------

Sometimes you want to mix in data that CppHeaderParser can't give you. If you
pass the ``--yaml`` option, it will load the yaml into a dictionary and make it
available to the template as the 'data' variable.

You can also pass key=value parameters via the ``--param`` option, and
the specified keys will be available to the template.

Custom processing
-----------------

When you need to do more complex logic that a jinja2 template just isn't
appropriate for, you can specify a python file to load custom hooks from.

See [the default hooks](header2whatever/default_hooks.py) for documentation.

License
=======

Apache 2

Author
======

Dustin Spicuzza (dustin@virtualroadside.com)



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/virtualroadside/header2whatever",
    "name": "header2whatever",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "c++ cpp codegen generator header jinja2 template",
    "author": "Dustin Spicuzza",
    "author_email": "dustin@virtualroadside.com",
    "download_url": "https://files.pythonhosted.org/packages/e4/91/2f3982a76ece3b14543612408929da953cc60c5b91d365f0b08b1f630bc0/header2whatever-0.4.8.tar.gz",
    "platform": null,
    "description": "header2whatever (h2w)\n=====================\n\nGenerate arbitrary files from C/C++ header files using CppHeaderParser to read\nthe input files and Jinja2 templates to generate the outputs.\n\nThis grew out of a desire to generate pybind11 wrapping code from C++ header\nfiles. pybind11gen was created, but then I wanted to generate more things...\n\nThere are still rough edges, and the documentation is mostly nonexistent, but\npull requests with fixes/improvements are very welcome!\n\nAs of 0.3.0, h2w requires Python 3.3+\n\nInstall\n-------\n\n::\n\n    pip install header2whatever\n\nUsage\n=====\n\nFirst, you need to create a jinja2 template that represents whatever you want\nto generate from the header file. For example, maybe you want to describe the\nfunctions in yaml::\n\n    ---\n    {% for header in headers %}\n    {% for fn in header.functions %}\n    {{ fn.name }}:\n      returns: {{ fn.returns }}\n      params:\n      {% for param in fn.parameters %}\n      - { name: {{ param.name }}, type: \"{{ param.type }}\" }\n      {% endfor %}\n\n    {% endfor %}\n    {% endfor %}\n\nAnd let's say you have the following header file ``foo.h``::\n\n    void some_fn(int i);\n    int returns_int(int p1, char* p2);\n\nYou can execute the following::\n\n    h2w foo.h -o foo.yml\n\nAnd you'll get the following output::\n\n    ---\n    returns_int:\n      returns: int\n      params:\n      - { name: p1, type: \"int\" }\n      - { name: p2, type: \"char *\" }\n\n    some_fn:\n      returns: void\n      params:\n      - { name: i, type: \"int\" }\n\nAs you can see, while this is a silly example, this approach is very flexible\nand fairly powerful.\n\nCurrently, the data structure passed to the template isn't documented -- but\nit's a filtered version of whatever CppHeaderParser outputs when it parses a\nheader.\n\nSee the examples folder for more examples.\n\nBatch mode\n----------\n\nIf you need to process multiple files, or just want to record the parameters for\nautogenerating a file without writing a shell script, batch mode is useful. You\npass two parameters: a yaml file with the configuration, and an output directory\nto write the files to.\n\n\nUsing data from external sources\n--------------------------------\n\nSometimes you want to mix in data that CppHeaderParser can't give you. If you\npass the ``--yaml`` option, it will load the yaml into a dictionary and make it\navailable to the template as the 'data' variable.\n\nYou can also pass key=value parameters via the ``--param`` option, and\nthe specified keys will be available to the template.\n\nCustom processing\n-----------------\n\nWhen you need to do more complex logic that a jinja2 template just isn't\nappropriate for, you can specify a python file to load custom hooks from.\n\nSee [the default hooks](header2whatever/default_hooks.py) for documentation.\n\nLicense\n=======\n\nApache 2\n\nAuthor\n======\n\nDustin Spicuzza (dustin@virtualroadside.com)\n\n\n",
    "bugtrack_url": null,
    "license": "Apache 2.0",
    "summary": "Generate files from C/C++ headers using jinja2 templates",
    "version": "0.4.8",
    "split_keywords": [
        "c++",
        "cpp",
        "codegen",
        "generator",
        "header",
        "jinja2",
        "template"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "e9f9870e3d55588a4aba48116eaacedb",
                "sha256": "ff3ccdc3159027f4b15e271977946adaf60d939ea0950b0245b7d725a5741402"
            },
            "downloads": -1,
            "filename": "header2whatever-0.4.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e9f9870e3d55588a4aba48116eaacedb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 81076,
            "upload_time": "2022-12-05T03:25:44",
            "upload_time_iso_8601": "2022-12-05T03:25:44.719226Z",
            "url": "https://files.pythonhosted.org/packages/03/3f/6e342843b42162ff82c8412f17686cdc90e0d39322731c53316f1ed7f017/header2whatever-0.4.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "89add5da1bc8d49ca910bcdebc0987c7",
                "sha256": "7ecdbcc3eb79a546cf89505749d106615b6897014f0d602d59aced2ce16dcbc6"
            },
            "downloads": -1,
            "filename": "header2whatever-0.4.8.tar.gz",
            "has_sig": false,
            "md5_digest": "89add5da1bc8d49ca910bcdebc0987c7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 78383,
            "upload_time": "2022-12-05T03:25:46",
            "upload_time_iso_8601": "2022-12-05T03:25:46.233907Z",
            "url": "https://files.pythonhosted.org/packages/e4/91/2f3982a76ece3b14543612408929da953cc60c5b91d365f0b08b1f630bc0/header2whatever-0.4.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-05 03:25:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "virtualroadside",
    "github_project": "header2whatever",
    "lcname": "header2whatever"
}
        
Elapsed time: 0.01784s