{ "info": { "author": "Silly Freak", "author_email": "sillyfreak.ck@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)", "Programming Language :: Python :: 3.6", "Topic :: Software Development" ], "description": "GSL - Generator Scripting Library\n=================================\n\nGSL is inspired by, but completely independent of, `iMatix' GSL`_ (Generator scripting language).\nIt is a Python-based tool for model-oriented programming, which you can read about `here`_,\nagain borrowing from iMatix.\n\nIn contrast to iMatix' GSL, this tool does not use its own scripting language but Python;\nwith Python 3.6's `f-strings`_, it is very appropriate for code generation tasks.\nGSL's focus lies on reading the source models and making them available in a convenient form,\nand providing utilities that are useful during code generation,\nespecially for output handling and string manipulation.\n\n.. _iMatix' GSL: https://github.com/imatix/gsl\n.. _here: https://github.com/imatix/gsl#model-oriented-programming\n.. _f-strings: https://www.python.org/dev/peps/pep-0498/\n\nInstallation\n------------\n\nInstalling a release\n^^^^^^^^^^^^^^^^^^^^\n\nGSL is available on pypi.\nDepending on whether you want to use YAML or ANTLR models, install the extras::\n\n pip install gsl[antlr,yaml]\n\nInstalling for development\n^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nFirst, clone the project and install dependencies and extras::\n\n pip install -e git+https://github.com/SillyFreak/gsl#egg=gsl[dev,antlr,yaml]\n # or, alternatively\n pip install invoke antlr4-python3-runtime ruamel.yaml\n git clone https://github.com/SillyFreak/gsl\n\nWe recommend using ``pip``, because that will also make the ``g4v`` shell command available.\n\nThen, if you plan on using the ``g4v`` tool (which requires ANTLR), generate its parser and visitor::\n\n cd env/src/gsl/\n # or, alternatively\n cd gsl\n\n invoke g4v-antlr g4v-g4v\n\n.. note::\n The ``g4v-g4v`` task overwrites the ``G4VVisitor.py`` file, which is part of the ``g4v`` tool itself.\n If you break that file, you will have to reset it from git before ``g4v-g4v`` works again.\n\n The same applies to incompatible changes to ``g4v``: if you extend the tool in an incompatible way,\n you will have to bootstrap ``G4VVisitor.py`` yourself.\n\nMinimal usage example\n---------------------\n\nModel-oriented programming's benefits become most visible for complex use cases;\nstill, here is a small example that shows core features of GSL::\n\n from gsl import pseudo_tuple, lines, print_to\n from gsl.yaml import YAML\n\n Class = pseudo_tuple('Class', ('name', 'members',))\n Field = pseudo_tuple('Field', ('name',))\n Method = pseudo_tuple('Method', ('name',))\n\n def load_model():\n yaml = YAML(typ='safe')\n yaml.register_class(Class)\n yaml.register_class(Field)\n yaml.register_class(Method)\n return yaml.load(\"\"\"\\\n - !Class\n name: HelloWorld\n members:\n - !Field\n name: foo\n - !Method\n name: bar\n \"\"\")\n\n def generate_code(model):\n for class_model in model:\n generate_class_code(class_model)\n\n def generate_class_code(class_model):\n def field_code(field):\n yield from lines(f\"\"\"\\\n private int {field.name};\"\"\")\n\n def method_code(method):\n yield from lines(f\"\"\"\\\n public void {method.name}() {{\n // TODO\n }}\"\"\")\n\n @print_to(f\"{class_model.name}.java\")\n def code():\n yield from lines(f\"\"\"\\\n public class {class_model.name} {{\"\"\")\n for member in class_model.members:\n yield from lines(f\"\"\"\\\n\n \"\"\")\n if isinstance(member, Field):\n yield from field_code(member)\n elif isinstance(member, Method):\n yield from method_code(member)\n yield from lines(f\"\"\"\\\n }}\"\"\")\n\n generate_code(load_model())\n\nOutput::\n\n public class HelloWorld {\n\n private int foo;\n\n public void bar() {\n // TODO\n }\n }\n\nSome of the things seen here are:\n\n- the use of ``pseudo_tuple`` together with YAML type tags to produce a high-level model.\n ``namedtuple`` wouldn't work here, because it is immutable\n (the YAML library separates construction and initialization of nodes to support cycles).\n Pseudo tuples are modifiable and allow auxiliary fields,\n giving you the option to augment the model with inferred information.\n- ``yield`` and ``yield from`` to create the actual code piece by piece,\n without pushing side effects like ``print`` into the guts of the code generator.\n By yielding code line by line instead of writing outright to a file,\n it is easy to post-process code before writing it out.\n- f-strings and a code style convention using multiline strings that aligns output code with the beginning of lines.\n- separation of concerns by using different functions, and a naming convention that helps understanding these concerns:\n\n - ``generate_code`` generates all code for this module.\n In this case there is only one class to generate,\n but there could be multiple classes or different kinds of sources to print with no problem.\n - ``generate_..._code`` functions generate a single kind of source code.\n - ``..._code`` generator functions create the actual code by yielding it line by line.\n We use nested functions here, as fields and methods are only used for class code,\n but code reuse is of course easily possible.\n - The ``code`` generator function is a particular case.\n The ``@print_to(filename)`` decorator calls it immediately and writes all lines to the given file.\n In that sense, the whole function works like a ``with`` block, where the block body is a generator function.\n\nIf you're thinking most of this is plain Python and some coding conventions, nothing gsl specific: you're right!\nPython 3.6 is already a great tool with great development environments,\nand it would be a shame to take that power away from you.\nGSL just provides some useful tools that, combined with Python and some conventions,\nallow you to do model oriented programming at high velocity.\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/SillyFreak/gsl", "keywords": "code generation", "license": "AGPLv3+", "maintainer": "", "maintainer_email": "", "name": "gsl", "package_url": "https://pypi.org/project/gsl/", "platform": "", "project_url": "https://pypi.org/project/gsl/", "project_urls": { "Homepage": "https://github.com/SillyFreak/gsl" }, "release_url": "https://pypi.org/project/gsl/0.0.3/", "requires_dist": [ "antlr4-python3-runtime; extra == 'antlr'", "invoke; extra == 'dev'", "ruamel.yaml; extra == 'yaml'" ], "requires_python": "", "summary": "General Scripting Library", "version": "0.0.3" }, "last_serial": 3912024, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "3eb805abba0310f3746022a04ee33059", "sha256": "d921f82f02c55e7e89fc3ae090f1b0f0ef3cd86cf01d7343876cc5721e871582" }, "downloads": -1, "filename": "gsl-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "3eb805abba0310f3746022a04ee33059", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 37483, "upload_time": "2017-11-29T11:09:00", "url": "https://files.pythonhosted.org/packages/4d/b1/19ad88ad163442ddbba4198adf84e475e368dcd628bbd2d99d64368ca1eb/gsl-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2fcbbab52c9154db5aaf9873bd087eaa", "sha256": "689b7e7aae935a7f04ed330a5ef7c730d61b3ce3c08d6afd06031c4003c49572" }, "downloads": -1, "filename": "gsl-0.0.1.tar.gz", "has_sig": false, "md5_digest": "2fcbbab52c9154db5aaf9873bd087eaa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 42611, "upload_time": "2017-11-29T11:09:01", "url": "https://files.pythonhosted.org/packages/41/2d/c355df8dfb7a4182a3a28886156d972669233833a79c714cb44db99a10e9/gsl-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "d13a4597516cdadd191ee8973454f8b8", "sha256": "6f18530a8a272999e89f8f731293a6ed2f9daf5402f75261aa8fe212b67cce8f" }, "downloads": -1, "filename": "gsl-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "d13a4597516cdadd191ee8973454f8b8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 39025, "upload_time": "2018-05-28T15:23:36", "url": "https://files.pythonhosted.org/packages/ed/7d/157c414fec51cef5b36facd32e9c0bd8be0fc1c6cb39e9b94a31771a1461/gsl-0.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3c64572a80c6bf1dc697a391e67ddf0b", "sha256": "e903096580f951e9aa8e71e763b0443ad95d3c3bcee1f5b569966dbe8c91d15b" }, "downloads": -1, "filename": "gsl-0.0.2.tar.gz", "has_sig": false, "md5_digest": "3c64572a80c6bf1dc697a391e67ddf0b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 43989, "upload_time": "2018-05-28T15:23:38", "url": "https://files.pythonhosted.org/packages/88/e8/5b1a9ba424a5313e2086782d0b36fea78d6b1f359d729750a45e4e06948b/gsl-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "a54e2ba5ab202e6a78942485328df774", "sha256": "081c77375bf65cb759a3e5129275b8806be18648452f50f7c420f40dac60529a" }, "downloads": -1, "filename": "gsl-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "a54e2ba5ab202e6a78942485328df774", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 39432, "upload_time": "2018-05-30T09:02:49", "url": "https://files.pythonhosted.org/packages/ee/1e/14d4c4657bc7130b900c65033861ee0db508d2d9206f4223f5da7c855acc/gsl-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "13c7b481170644ba04b4a9d39b996404", "sha256": "85a6071e00a284510c963b97ab74ef8a3e7d1786c5f52dc2ff444cbb7d94ee3c" }, "downloads": -1, "filename": "gsl-0.0.3.tar.gz", "has_sig": false, "md5_digest": "13c7b481170644ba04b4a9d39b996404", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 44404, "upload_time": "2018-05-30T09:02:51", "url": "https://files.pythonhosted.org/packages/01/36/a8a99ab67918beb6ee8722fb6c27512796a5ff8ed4c10036f787eef51569/gsl-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a54e2ba5ab202e6a78942485328df774", "sha256": "081c77375bf65cb759a3e5129275b8806be18648452f50f7c420f40dac60529a" }, "downloads": -1, "filename": "gsl-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "a54e2ba5ab202e6a78942485328df774", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 39432, "upload_time": "2018-05-30T09:02:49", "url": "https://files.pythonhosted.org/packages/ee/1e/14d4c4657bc7130b900c65033861ee0db508d2d9206f4223f5da7c855acc/gsl-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "13c7b481170644ba04b4a9d39b996404", "sha256": "85a6071e00a284510c963b97ab74ef8a3e7d1786c5f52dc2ff444cbb7d94ee3c" }, "downloads": -1, "filename": "gsl-0.0.3.tar.gz", "has_sig": false, "md5_digest": "13c7b481170644ba04b4a9d39b996404", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 44404, "upload_time": "2018-05-30T09:02:51", "url": "https://files.pythonhosted.org/packages/01/36/a8a99ab67918beb6ee8722fb6c27512796a5ff8ed4c10036f787eef51569/gsl-0.0.3.tar.gz" } ] }