{ "info": { "author": "anatoly techtonik", "author_email": "techtonik@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: Public Domain", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Topic :: Software Development", "Topic :: Software Development :: Disassemblers" ], "description": "Get information from Python module without executing it. \n\nThis is a tool and a library to work with Abstract Syntax Tree\n(AST) of source code in Python. It can be used to explore AST,\ninspect nodes and process them.\n\nWhen used from command line, ``astdump.py`` can generate\n``setup.py`` for your module or print its structure.\n\n\nWhat is AST\n-----------\n\nThere is a good talk `What would you do with an AST?\n`_ by Matthew J Desmarais\nwith information that you will find useful.\n\n`astdump` package provides dataset_ with generated examples of\nAST representation for various Python snippets. Feel free to\nclone repository and experiment with the code - it is safe and\nversion controlled.\n\nFor the curious, structure of Python abstract tree is defined in\nhttp://hg.python.org/cpython/file/v2.7.6/Parser/Python.asdl\n\n\nCommand line usage\n------------------\n\n::\n\n $ ./astdump.py \n Usage: astdump.py [options] \n\n AST dump tool to inspect Python source code without importing it. Can\n extract values of top level vars, automatically generate setup.py and\n dump structure of an Abstract Syntax Tree in readable format.\n\n Options:\n -h, --help show this help message and exit\n --topvars get top level variables\n --generate generate setup.py for a given filename\n\n\nRead top level variables from Python module without importing::\n\n $ ./astdump.py --topvars astdump.py\n __author__ = 'anatoly techtonik '\n __description__ = 'Extract information from Python module without importing it.'\n __license__ = 'Public Domain'\n __version__ = '3.0'\n\nAutomatically generate `setup.py`::\n\n $ ./astdump.py --generate astdump.py\n #!/usr/bin/env python\n from distutils.core import setup\n\n setup(\n name = 'astdump',\n version = '3.0',\n author = 'anatoly techtonik',\n author_email = 'techtonik@gmail.com',\n description = 'Extract information from Python module without importing it.',\n license = 'Public Domain',\n\n py_modules=['astdump'],\n )\n\n'prettyprint' AST tree::\n\n $ ./astdump.py setup.py\n Module\n ImportFrom\n alias\n Expr\n Call\n Name\n Load\n keyword\n Str\n keyword\n Str\n ...\n keyword\n Str\n keyword\n List\n Str\n Load\n\n\nLibrary Usage\n-------------\n``top_level_vars(filename)``\n Return name/value pairs for top level variables for the script specified as\n `filename`.\n Only string and int values are supported.\n\n::\n\n >>> import astdump\n >>> astdump.top_level_vars(\"astdump.py\")\n {'__version__': '3.0', '__description__': 'Extract information from Python\n module without importing it.', '__license__': 'Public Domain', '__author__\n ': 'anatoly techtonik '}\n\n\n``indented(text, printres=True)``\n Print indented AST for the Python code specified in `text` variable. The goal\n is to print AST as pretty as possible, so the output is likely to change. If\n `printres` is false, return string instead.\n\n::\n\n >>> import astdump\n >>> astdump.indented('2+3')\n Module\n Expr\n BinOp\n Num\n Add\n Num\n\n``dumpattrs(node, indent=0, oneline=False, output=sys.stdout)``\n Dump attributes of given node to `output` (sys.stdout by default).\n If `oneline` is set, format output as one line. Otherwise dump one\n attribute per line with the given `indent`.\n\n::\n\n >>> from astdump import dumpattrs as dat\n >>> import ast\n >>> root = ast.parse('2+3')\n >>> root\n <_ast.Module at 0x35f8790>\n >>> dat(root)\n body: [<_ast.Expr object at 0x035F8730>]\n >>> dat(root.body[0])\n value: <_ast.BinOp object at 0x035F8850>\n\n\nLinks\n-----\n\n.. # Tools that use Python AST\n\n- `pss `_ - filetype aware grep for sources, with colors, public domain\n- `redhawk `_ - AST aware grep, BSD license\n\n- `PythonJS `_ - Python to JavaScript translator using AST, license BSD-3\n\n- `astviewer `_ - MIT licensed ASTree viewer in Qt (PySide)\n- `snakefood `_ - Python Dependency Graphs\n\n\n.. # Blogs\n\n- http://eli.thegreenplace.net/2014/07/29/ast-matchers-and-clang-refactoring-tools/\n- https://julien.danjou.info/blog/2015/python-ast-checking-method-declaration\n\n\n.. # Discussions\n\n- `python-ideas `_ -\n original mail about static module/package inspection that started it all\n- `python-static-type-checking `_ -\n Group about static analysis of Python programs\n- `issue19557 `_ on Python bug tracker\n about incomplete official AST documentation \n\n\nChanges\n-------\n4.3 (2016-02-14)\n * fix Python 3 installation error (issue #2)\n\n4.2 (2014-08-15)\n * read __url__ for setup.py generator\n\n4.1 (2014-08-15)\n * setup.py generator tries to use module docstring for\n short description if __description__ is not set\n\n4.0 (2014-06-25)\n * fix setup.py generator for Python 3 (broken in 3.3)\n * API changes:\n\n * TreeDumper() callbacks now receive ``stack`` of\n parent nodes instead of depth ``level``\n * TreeDumper().level is renamed to TreeDumper().limit\n * added TreeDumper().stack list to access parent nodes\n * made TreeDumper().depth a read-only property, which\n returns current length of stack\n\n3.3 (2014-03-21)\n * setup.py generator is rewritten to look up missing\n attributes on PyPI, add classifiers and README read()\n for long description\n\n3.2 (2013-11-27)\n * API change:\n\n * ``dumpattrs(node)`` helper to print node attributes\n\n3.1 (2013-11-20)\n * fix missing dataset/ dir from source distribution\n\n3.0 (2013-11-19)\n * added dataset/ dir with snippets, output examples and\n update.py that regenerates them. See dataset/README.txt\n * API changes:\n\n * added ``indented(text)`` to dump indented AST, only\n shows nodes for now\n * ``indented(text, printres=False)`` returns string\n instead of printing\n * made TreeDumper() silent by default. It just walks.\n\n * fixed pip install, added MANIFEST.in, added trove\n categories, thanks to Jonathan Eunice (pull request #1)\n\n2.0 (2013-11-10)\n * API change:\n\n * remove --dump option, AST is dumped by default\n * add --topvars option for previous behaviour\n\n1.2 (2013-11-10)\n * fix default output for Python 2 (broken in 1.1)\n\n1.1 (2013-09-16)\n * support Python 3\n\n1.0 (2012-03-29)\n * API change:\n \n * ``get_top_vars(node)`` is replaced with ``top_level_vars(filename)``\n\n\nRelease checklist\n-----------------\n| [ ] update version in astdump.py \n| [ ] run dataset/update.py for Python 2 and 3\n| [ ] update README.rst\n| [ ] python astdump.py --generate astdump.py >setup.py\n| [ ] check that setup.py contains unix linefeeds\n| [ ] setup.py sdist register upload\n| [ ] hg tag\n\n\n.. _dataset: https://bitbucket.org/techtonik/astdump/src/tip/dataset/", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/techtonik/astdump", "keywords": "", "license": "Public Domain", "maintainer": "", "maintainer_email": "", "name": "astdump", "package_url": "https://pypi.org/project/astdump/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/astdump/", "project_urls": { "Homepage": "https://bitbucket.org/techtonik/astdump" }, "release_url": "https://pypi.org/project/astdump/4.3/", "requires_dist": null, "requires_python": "", "summary": "Extract information from Python modules without importing", "version": "4.3" }, "last_serial": 1955214, "releases": { "3.3": [ { "comment_text": "", "digests": { "md5": "e7e9dd538a63bc8a524b735ed009913c", "sha256": "c0b1da2cd0e62ec64d6c563f5ee7e5b2ce418e507c3ac69476c92661b1701d77" }, "downloads": -1, "filename": "astdump-3.3.zip", "has_sig": false, "md5_digest": "e7e9dd538a63bc8a524b735ed009913c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16109, "upload_time": "2014-03-21T05:36:16", "url": "https://files.pythonhosted.org/packages/67/8e/a77c0ffc0aeb29617750d7e2c402d83c0e20014346814f8c3adc3925788a/astdump-3.3.zip" } ], "4.0": [ { "comment_text": "", "digests": { "md5": "f5bfa3dc5c5f47bc478dfbb522b25b5c", "sha256": "9af3a0ec7f4570b6fb826e54b655eea53817f987f7168b9b4d4502b658558be7" }, "downloads": -1, "filename": "astdump-4.0.zip", "has_sig": false, "md5_digest": "f5bfa3dc5c5f47bc478dfbb522b25b5c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17118, "upload_time": "2014-06-25T10:36:36", "url": "https://files.pythonhosted.org/packages/08/0a/26a2b27ce378a3b58466f24d21bbfe26dd7e788556788702813400904dfd/astdump-4.0.zip" } ], "4.1": [ { "comment_text": "", "digests": { "md5": "874c7ec56bc64d91b58ad4943b079585", "sha256": "da8f63dd9c0d94a094a7a6667cee6e5e445f3c1e04da8ac44f07a79699f0d710" }, "downloads": -1, "filename": "astdump-4.1.zip", "has_sig": false, "md5_digest": "874c7ec56bc64d91b58ad4943b079585", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17288, "upload_time": "2014-08-15T14:52:16", "url": "https://files.pythonhosted.org/packages/aa/43/b43a30c8ccbc5e67f94ee6a7daf39813c8fdcf806b1eb4fe1d0e00b27f49/astdump-4.1.zip" } ], "4.2": [ { "comment_text": "", "digests": { "md5": "7b4f143b3f3c05139a20a62229745cd3", "sha256": "8f3037dee85ad52467bfb9427d4a9aa1860d2a4cba73b96cc47f32d4be6fe464" }, "downloads": -1, "filename": "astdump-4.2.zip", "has_sig": false, "md5_digest": "7b4f143b3f3c05139a20a62229745cd3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17329, "upload_time": "2014-08-15T15:25:59", "url": "https://files.pythonhosted.org/packages/62/fd/54044a366e922b795defc473d26ba52f52aec5a83ef4442e10b9e94b029e/astdump-4.2.zip" } ], "4.3": [ { "comment_text": "", "digests": { "md5": "b00fdfd2ea75029570c23d2c47ba7ee8", "sha256": "902b317dd9191175febd2b38e300c523a162e61a22cc345f606ef9e717f7d0e6" }, "downloads": -1, "filename": "astdump-4.3.zip", "has_sig": false, "md5_digest": "b00fdfd2ea75029570c23d2c47ba7ee8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19361, "upload_time": "2016-02-14T04:33:12", "url": "https://files.pythonhosted.org/packages/d2/4e/11b9e32bea3bba07f4f44cab9334623b77e6dd61595a7a306861cce2e538/astdump-4.3.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b00fdfd2ea75029570c23d2c47ba7ee8", "sha256": "902b317dd9191175febd2b38e300c523a162e61a22cc345f606ef9e717f7d0e6" }, "downloads": -1, "filename": "astdump-4.3.zip", "has_sig": false, "md5_digest": "b00fdfd2ea75029570c23d2c47ba7ee8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19361, "upload_time": "2016-02-14T04:33:12", "url": "https://files.pythonhosted.org/packages/d2/4e/11b9e32bea3bba07f4f44cab9334623b77e6dd61595a7a306861cce2e538/astdump-4.3.zip" } ] }