{ "info": { "author": "Sanhe Hu", "author_email": "husanhe@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: MacOS", "Operating System :: Microsoft :: Windows", "Operating System :: Unix", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5" ], "description": ".. image:: https://travis-ci.org/MacHu-GWU/autocompvar-project.svg?branch=master\r\n\r\n.. image:: https://img.shields.io/pypi/v/autocompvar.svg\r\n\r\n.. image:: https://img.shields.io/pypi/l/autocompvar.svg\r\n\r\n.. image:: https://img.shields.io/pypi/pyversions/autocompvar.svg\r\n\r\n\r\nWelcome to autocompvar Documentation\r\n===============================================================================\r\nIn most of the case, put constant value in your code. Because when you see the value, you don't know what does that mean in behind. A better way is to define a constant, and use that constant variable.\r\n\r\nBut sometimes, you have a great amount of constant, and you need to put that in your code anywhere. It's really hard to remember all constant name. Especially, sometimes they are nested.\r\n\r\n``autocompvar`` allows developer to create a Constant def script from data, and then you don't need to remember anything anymore.\r\n\r\n\r\n**Quick Links**\r\n-------------------------------------------------------------------------------\r\n- `GitHub Homepage `_\r\n- `Online Documentation `_\r\n- `PyPI download `_\r\n- `Install `_\r\n- `Issue submit and feature request `_\r\n- `API reference and source code `_\r\n\r\n\r\n**Example**\r\n-------------------------------------------------------------------------------\r\nSuppose you have a RPG game. You need to write some application that query stuff using item id. But the hell is to remember what is what! If you just use constant, then your code is unmaintainable!\r\n\r\n.. code-block:: console\r\n\r\n ItemType\r\n |--- Weapon: subclass_id=1, name=weapon\r\n |--- Sword: id=1, name=sword\r\n |--- Dagger: id=2, name=dagger\r\n |--- Armor: subclass_id=2, name=armor\r\n |--- Plate: id=1, name=plate\r\n |--- Cloth: id=2, name=cloth\r\n\r\nIdeally, you want this:\r\n\r\n.. code-block:: python\r\n\r\n # define your constant here\r\n >>> from itemtype import itemtype\r\n \r\n # when you type itemtype.name, it gives you all available subclass\r\n # when you type itemtype.name____weapon, it gives you all attributes\r\n >>> itemtype.name____weapon.subclass_id\r\n 1\r\n\r\n >>> itemtype.name____weapon.name____dagger.id\r\n 2\r\n\r\n # or you can use a function interface to program that\r\n >>> itemtype.name____armor.getattr_by_id(2).name\r\n cloth\r\n\r\n\r\nReal Code\r\n-------------------------------------------------------------------------------\r\n(**Code example can be found at**: https://github.com/MacHu-GWU/autocompvar-project/blob/master/example.py)\r\n\r\nFirst, import autocompvar, prepare your data, and generate code.\r\n\r\n.. code-block:: python\r\n\r\n #!/usr/bin/env python\r\n # -*- coding: utf-8 -*-\r\n\r\n from __future__ import print_function\r\n from autocompvar.metadata import gen_code\r\n\r\n # classname\r\n # attrs: all attributes you need to define\r\n # keys: indexable attributes, like int, string field that are unique\r\n # data: the data to create instance of this class\r\n # collection: subclass list\r\n data = {\r\n \"classname\": \"ItemType\",\r\n \"attrs\": [],\r\n \"collection\": [\r\n {\r\n \"classname\": \"SubClass\",\r\n \"attrs\": [\"id\", \"name\"],\r\n \"keys\": [\"name\"],\r\n \"data\": {\"id\": 1, \"name\": \"weapon\"},\r\n \"collection\": [\r\n {\r\n \"classname\": \"Weapon\",\r\n \"attrs\": [\"id\", \"name\"],\r\n \"keys\": [\"name\"],\r\n \"data\": {\"id\": 1, \"name\": \"sword\"},\r\n },\r\n {\r\n \"classname\": \"Weapon\",\r\n \"attrs\": [\"id\", \"name\"],\r\n \"keys\": [\"name\"],\r\n \"data\": {\"id\": 2, \"name\": \"dagger\"},\r\n },\r\n ],\r\n },\r\n {\r\n \"classname\": \"SubClass\",\r\n \"attrs\": [\"id\", \"name\"],\r\n \"keys\": [\"name\"],\r\n \"data\": {\"id\": 2, \"name\": \"armor\"},\r\n \"collection\": [\r\n {\r\n \"classname\": \"Armor\",\r\n \"attrs\": [\"id\", \"name\"],\r\n \"keys\": [\"name\"],\r\n \"data\": {\"id\": 1, \"name\": \"plate\"},\r\n },\r\n {\r\n \"classname\": \"Armor\",\r\n \"attrs\": [\"id\", \"name\"],\r\n \"keys\": [\"name\"],\r\n \"data\": {\"id\": 2, \"name\": \"armor\"},\r\n },\r\n ],\r\n },\r\n ],\r\n }\r\n\r\n code = gen_code(data)\r\n print(code)\r\n\r\nThen you have a importable script that able to do ``from your_module import item_type``:\r\n\r\n.. code-block:: python\r\n\r\n #!/usr/bin/env python\r\n # -*- coding: utf-8 -*-\r\n\r\n from autocompvar.base import Base\r\n\r\n class ItemType(Base):\r\n __attrs__ = []\r\n __keys__ = []\r\n\r\n def __init__(self):\r\n pass\r\n \r\n\r\n class SubClass(Base):\r\n __attrs__ = ['id', 'name']\r\n __keys__ = ['name']\r\n\r\n def __init__(self, id=None, name=None):\r\n self.id = id\r\n self.name = name\r\n \r\n\r\n class Weapon(Base):\r\n __attrs__ = ['id', 'name']\r\n __keys__ = ['name']\r\n\r\n def __init__(self, id=None, name=None):\r\n self.id = id\r\n self.name = name\r\n \r\n\r\n class Armor(Base):\r\n __attrs__ = ['id', 'name']\r\n __keys__ = ['name']\r\n\r\n def __init__(self, id=None, name=None):\r\n self.id = id\r\n self.name = name\r\n \r\n\r\n\r\n item_type = ItemType()\r\n\r\n sub_class_name_weapon = SubClass(name='weapon', id=1)\r\n\r\n weapon_name_sword = Weapon(name='sword', id=1)\r\n sub_class_name_weapon.name____sword = weapon_name_sword\r\n\r\n weapon_name_dagger = Weapon(name='dagger', id=2)\r\n sub_class_name_weapon.name____dagger = weapon_name_dagger\r\n item_type.name____weapon = sub_class_name_weapon\r\n\r\n sub_class_name_armor = SubClass(name='armor', id=2)\r\n\r\n armor_name_plate = Armor(name='plate', id=1)\r\n sub_class_name_armor.name____plate = armor_name_plate\r\n\r\n armor_name_armor = Armor(name='armor', id=2)\r\n sub_class_name_armor.name____armor = armor_name_armor\r\n item_type.name____armor = sub_class_name_armor\r\n\r\n\r\nNow you can easily with any constant like this:\r\n\r\n.. code-block:: python\r\n\r\n >>> print(item_type.name____weapon.name____sword.id)\r\n 1\r\n >>> print(item_type.name____armor.name____cloth.name)\r\n cloth\r\n\r\n\r\n.. _install:\r\n\r\nInstall\r\n-------------------------------------------------------------------------------\r\n\r\n``autocompvar`` is released on PyPI, so all you need is:\r\n\r\n.. code-block:: console\r\n\r\n $ pip install autocompvar\r\n\r\nTo upgrade to latest version:\r\n\r\n.. code-block:: console\r\n\r\n $ pip install --upgrade autocompvar", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/MacHu-GWU/autocompvar-project/tarball/2017-02-24", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/MacHu-GWU/autocompvar-project", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "autocompvar", "package_url": "https://pypi.org/project/autocompvar/", "platform": "Windows", "project_url": "https://pypi.org/project/autocompvar/", "project_urls": { "Download": "https://github.com/MacHu-GWU/autocompvar-project/tarball/2017-02-24", "Homepage": "https://github.com/MacHu-GWU/autocompvar-project" }, "release_url": "https://pypi.org/project/autocompvar/0.0.3/", "requires_dist": null, "requires_python": "", "summary": "make your data importable", "version": "0.0.3" }, "last_serial": 2666506, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "3d1788f163482eb6cb6caaf40a2dcc27", "sha256": "163a04924d1f39a3c264e7e63ea6968d43dd7c8af85eac0d0e68d1c99ec766a9" }, "downloads": -1, "filename": "autocompvar-0.0.1.zip", "has_sig": false, "md5_digest": "3d1788f163482eb6cb6caaf40a2dcc27", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 31556, "upload_time": "2017-02-08T05:49:40", "url": "https://files.pythonhosted.org/packages/fa/a3/d517849aaf21d8efc23ba05332261fc8d3432fba36f8b4e061edc89da34c/autocompvar-0.0.1.zip" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "9fd97d3a6d910ec7efc875c306ba1ad3", "sha256": "acb1e4657fc45920948600ef41e1522d8a7045b81a798df7889675c834325410" }, "downloads": -1, "filename": "autocompvar-0.0.2.tar.gz", "has_sig": false, "md5_digest": "9fd97d3a6d910ec7efc875c306ba1ad3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21382, "upload_time": "2017-02-09T22:17:42", "url": "https://files.pythonhosted.org/packages/da/68/6de2da0c61a5246e1c57fb3f9bd492f98e03d120ed728da347f9559bbf22/autocompvar-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "73dd53f40ba380dd401731bcfc25b92c", "sha256": "cca5d6281ac85b573ed8d6cd9c4abfee696c34bec2d402e71cb1319429d9ab04" }, "downloads": -1, "filename": "autocompvar-0.0.3.tar.gz", "has_sig": false, "md5_digest": "73dd53f40ba380dd401731bcfc25b92c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 42505, "upload_time": "2017-02-24T19:49:17", "url": "https://files.pythonhosted.org/packages/ad/3b/4b780a9f6515fe23953f577b8114219a5cfab298dbf5cecc6dccee3ffb22/autocompvar-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "73dd53f40ba380dd401731bcfc25b92c", "sha256": "cca5d6281ac85b573ed8d6cd9c4abfee696c34bec2d402e71cb1319429d9ab04" }, "downloads": -1, "filename": "autocompvar-0.0.3.tar.gz", "has_sig": false, "md5_digest": "73dd53f40ba380dd401731bcfc25b92c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 42505, "upload_time": "2017-02-24T19:49:17", "url": "https://files.pythonhosted.org/packages/ad/3b/4b780a9f6515fe23953f577b8114219a5cfab298dbf5cecc6dccee3ffb22/autocompvar-0.0.3.tar.gz" } ] }