{ "info": { "author": "Elie ROUDNINSKI", "author_email": "xademax@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Topic :: Software Development :: Code Generators" ], "description": "========\ncalligra\n========\n\n:Author: `Elie ROUDNINSKI `_\n\n**calligra** is a pure Python package that tries to modelize a subset of the C langage syntax in order to reason about C types, from Python scripts.\nIts main goals are to do metaprogrammation and code generation. It does **not parse** C code itself at all.\n\n**calligra** was first designed to (un)serialize complex (but not too complex ...) C structures from JSON.\n\n.. contents::\n :backlinks: none\n\n.. sectnum::\n\nInstallation\n==============\n\nRequirements\n----------------\n\n**calligra** requires Python 3. It has been tested on Python 3.6 on Linux but it should work on 3.4 and 3.6 and on Windows also.\nAt the moment, it does not require any external Python modules/packages, but this might change in the future.\n\nAs **calligra** is intended to generate code, some external dependencies might be needed to compile the generated code.\n\nFrom github\n---------------\n\nYou can clone this repository and install it with setuptools directly::\n\n $ python3 setup.py install --user\n\nFrom pip\n------------\n\nAs every pip available package, you can install it easily with the pip package::\n\n $ python3 -m pip install --user calligra\n\nTests\n-----\n\nTests are available in the source distribution (either from github or from pip) and are located in the |tests/|_ directory.\nYou can run them with setuptools::\n\n $ python3 setup.py test\n\n.. |tests/| replace:: ``tests/``\n.. _tests/: tests/\n\nHowto\n=====\n\nIntroduction\n------------\n\nAs specified before, **calligra** is intended to reason about C types at a Python level.\n\nCurrently, you can modelize the following types:\n\n- primary types like char, int, float, double etc.\n- C strings (char*)\n- enum\n- struct, named and anonymous\n- union, named and anonymous\n\nand the following declaration modifiers:\n\n- pointers\n- array\n\nNested array of pointers or pointers to array are not supported.\n\nAt the moment, you have two choices:\n\n- define everything from Python\n- parse C code with the cparser importer module\n\nIn the future, you will be able to import definitions from:\n\n- JSON Schema\n\nExamples\n--------\n\nLets start with a basic example.\nIn the following code snippets we will be defining a C structure called `person` with 2 members:\n\n- a string `name`\n- an unsigned integer `age`\n\nAnd then we will generate the associated C code.\n\nFirst import the main modules:\n\n.. code-block:: Python\n\n import calligra\n import calligra.stdlib\n\n`calligra` module is where the C type/declaration syntax is modelized.\n`calligra.stdlib` is where standard C types are defined.\n\nThen define the structure:\n\n.. code-block:: Python\n\n namespace = calligra.stdlib.namespace\n person = calligra.struct(namespace, 'person')\n person.add(\n calligra.declaration(\n namespace, namespace.get('char'), 'name', pointer = True\n )\n )\n person.add(\n calligra.declaration(\n namespace, namespace.get('uint8_t'), 'age'\n )\n )\n\nFinally, generate the C code:\n\n.. code-block:: Python\n\n print(person.define())\n\nThis should generate something similar to:\n\n.. code-block:: C\n\n struct person {\n char *name;\n uint8_t age;\n };\n\nMore advanced examples are located in the |examples/|_ directory.\n\n.. |examples/| replace:: ``examples/``\n.. _examples/: examples/\n\nModules\n=======\n\nConversion\n----------\n\nConversion modules are located in the |calligra/convert/|_ directory and are meant to (un)serialize C types to and from another format (like JSON).\n\n.. |calligra/convert/| replace:: ``calligra/convert/``\n.. _calligra/convert/: calligra/convert/\n\nCurrently available conversion modules are:\n\n- `calligra.convert.jansson`: to convert C types to and from JSON using the `Jansson `_ library.\n\nJansson\n~~~~~~~\n\nIn order to use the jansson conversion module, just import the `calligra.convert.jansson` module:\n\n.. code-block:: Python\n\n import calligra.convert.jansson\n\nAfter that, every type should now have a `to_json` and a `from_json` method.\nThose are actually `calligra.functions` object which you can `define` to generate the corresponding C code:\n\n.. code-block:: Python\n\n print(person.to_json.define())\n\nWhich should generate something similar to:\n\n.. code-block:: C\n\n json_t *person_to_json(struct person const *person);\n\nAnd for the function body:\n\n.. code-block:: Python\n\n print(person.to_json.code(body = True))\n\nWhich should generate something similar to (non-contractual code):\n\n.. code-block:: C\n\n json_t *person_to_json(struct person const *person) {\n json_t *json = json_object(), *child;\n if(!json) {\n return NULL;\n }\n /*name*/\n if((person != NULL) && ((*person).name != NULL) && (*(*person).name != 0)) {\n child = json_string((*person).name);\n if(!child || json_object_set_new_nocheck(json, \"name\", child) != 0) {\n if(child) {\n json_decref(child);\n }\n json_decref(json);\n return NULL;\n }\n }\n /*age*/\n if(person != NULL) {\n child = json_integer((*person).age);\n if(!child || json_object_set_new_nocheck(json, \"age\", child) != 0) {\n if(child) {\n json_decref(child);\n }\n json_decref(json);\n return NULL;\n }\n }\n return json;\n }\n\nImporter\n--------\n\nImporter modules are located in the |calligra/importer/|_ directory and are meant to import C types from another format (like C).\n\n.. |calligra/importer/| replace:: ``calligra/importer/``\n.. _calligra/importer/: calligra/importer/\n\nCurrently available importer modules are:\n\n- `calligra.importer.cparser`: to import C types directly from C code using the `pycparser `_ package.", "description_content_type": "", "docs_url": null, "download_url": "https://github.com/marmeladema/calligra/archive/0.3.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/marmeladema/calligra", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "calligra", "package_url": "https://pypi.org/project/calligra/", "platform": "", "project_url": "https://pypi.org/project/calligra/", "project_urls": { "Download": "https://github.com/marmeladema/calligra/archive/0.3.tar.gz", "Homepage": "https://github.com/marmeladema/calligra" }, "release_url": "https://pypi.org/project/calligra/0.3/", "requires_dist": null, "requires_python": ">=3", "summary": "C language metaprogramming and code generation from Python", "version": "0.3" }, "last_serial": 3890383, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "f65d9b7b90f316b0e1068ec1a828685c", "sha256": "eead14a1284a346649e27985e869bec3a59cd2439c1ebbeb034d8450fc5b3725" }, "downloads": -1, "filename": "calligra-0.1.tar.gz", "has_sig": false, "md5_digest": "f65d9b7b90f316b0e1068ec1a828685c", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 14096, "upload_time": "2018-05-12T17:48:12", "url": "https://files.pythonhosted.org/packages/ab/ce/63519e5bf3b774d68ffce4a9e5c0098729168321b3d67960b33855545667/calligra-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "01cf264f9c12be6d15006f916a297fb2", "sha256": "9adaec46c9617fa4a3fddb994adec5c4c5b3a8012f6cb0f952329a6762f71ced" }, "downloads": -1, "filename": "calligra-0.2.tar.gz", "has_sig": false, "md5_digest": "01cf264f9c12be6d15006f916a297fb2", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 16862, "upload_time": "2018-05-22T22:55:55", "url": "https://files.pythonhosted.org/packages/d5/0c/d96b86d7752c0412e5a7d4b2e878fcbb352e4ac96d3f43b03fb9233a6007/calligra-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "d8d700f33402ac7679dc7363fd572598", "sha256": "691ee91430c54a11dc5edf9ee696be813041739c929675488ebb9da45d81df7e" }, "downloads": -1, "filename": "calligra-0.3.tar.gz", "has_sig": false, "md5_digest": "d8d700f33402ac7679dc7363fd572598", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 16919, "upload_time": "2018-05-23T07:40:10", "url": "https://files.pythonhosted.org/packages/5a/4b/62794f4c5f460def18ceb35f212939d7508496cdbe28641a2113080d61dc/calligra-0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d8d700f33402ac7679dc7363fd572598", "sha256": "691ee91430c54a11dc5edf9ee696be813041739c929675488ebb9da45d81df7e" }, "downloads": -1, "filename": "calligra-0.3.tar.gz", "has_sig": false, "md5_digest": "d8d700f33402ac7679dc7363fd572598", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 16919, "upload_time": "2018-05-23T07:40:10", "url": "https://files.pythonhosted.org/packages/5a/4b/62794f4c5f460def18ceb35f212939d7508496cdbe28641a2113080d61dc/calligra-0.3.tar.gz" } ] }