{ "info": { "author": "Nicolas Laurance", "author_email": "nicolas[dot]laurance[at]gmail[dot]com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": ".. image:: https://travis-ci.org/nlaurance/sourceparse.svg?branch=master\n :target: https://travis-ci.org/nlaurance/sourceparse\n\nsourceparse\n===========\n\na personal adaptation of pyclbr from the standard python lib\n\nlet's say we want to analyze a source file like this one::\n\n >>> source = '''\n ... class MixinUser(Sub2, Mixin):\n ... \"\"\"Overrides method1 and method2\n ... \"\"\"\n ...\n ... def method1(self, foo):\n ... \"\"\" method1 of MixinUser\n ... \"\"\"\n ... return\n ...\n ... @manytimes\n ... @decorated\n ... def method2(self, foo, bar=None):\n ... \"\"\" method2 of MixinUser\n ... \"\"\"\n ... return\n ...\n ... # comment\n ...\n ... def my_function(foo):\n ... \"\"\" Stand-alone function.\n ... \"\"\"\n ... return\n ... '''\n\nOf course we'll start by importing the tool\n\n >>> from sourceparse import CodeCollector\n >>> from pprint import pprint\n\nfor the purpose of this documentation we'll override the _readfile method::\n\n >>> def override(foo): return [s+'\\n' for s in source.split('\\n')]\n ...\n >>> original = CodeCollector._readfile\n >>> CodeCollector._readfile=override\n\n\n\ninstanciation\n-------------\n\nlet's instantiate a parser, normally we would pass a path to the file to analyze::\n\n >>> parser=CodeCollector(\"source\")\n\nAccess to members\n-----------------\n\nClasses\n~~~~~~~\n\nwe can now access a list of the classes defined in the module::\n\n >>> parser.classes\n [Class MixinUser: from 2 to 19\n ]\n\n\nMethods\n~~~~~~~\n\neach class::\n\n >>> mix = parser.classes[0]\n\ncan list its methods::\n\n >>> mix.methods\n [Method method1: from 6 to 10\n , Method method2: from 13 to 19\n \tdecorated from 11 to 13]\n\neach method::\n\n >>> m2 = mix.methods[1]\n\nhas a name::\n\n >>> m2.name\n 'method2'\n\na start line in the file::\n\n >>> m2.from_line\n 13\n\n\nan end line::\n\n >>> m2.to_line\n 19\n\nwa can access its docstring::\n\n >>> m2.docstring\n 'method2 of MixinUser\\n '\n\ndecorators::\n\n >>> m2.decorators\n [' @manytimes\\n', ' @decorated\\n']\n\narguments, excluding self::\n\n >>> m2.args\n ['foo']\n\nand keyword arguments::\n\n >>> m2.kwargs\n {'bar': 'None'}\n\nand its complete source, excluding decorators::\n\n >>> pprint(m2.source)\n [' def method2(self, foo, bar=None):\\n',\n ' \"\"\" method2 of MixinUser\\n',\n ' \"\"\"\\n',\n ' return\\n',\n '\\n',\n '# comment\\n',\n '\\n']\n\n.. note:: The inline comment at the same level is included\n\nFunctions\n~~~~~~~~~\n\nthe module functions provide the same features::\n\n >>> parser.functions\n [Function my_function: from 20 to 24\n ]\n >>> my = parser.functions[0]\n >>> my.decorators\n []\n >>> my.docstring\n 'Stand-alone function.\\n '\n >>> my.args\n ['foo']\n\n >>> my.from_line\n 20\n >>> my.to_line\n 24\n >>> pprint(my.source)\n ['def my_function(foo):\\n',\n ' \"\"\" Stand-alone function.\\n',\n ' \"\"\"\\n',\n ' return\\n',\n '\\n']\n\nlet's put the parser back to normal\n\n>>> CodeCollector._readfile = original", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/nlaurance/sourceparse", "keywords": "source code,analyzer", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "sourceparse", "package_url": "https://pypi.org/project/sourceparse/", "platform": null, "project_url": "https://pypi.org/project/sourceparse/", "project_urls": { "Homepage": "https://github.com/nlaurance/sourceparse" }, "release_url": "https://pypi.org/project/sourceparse/0.2.5/", "requires_dist": null, "requires_python": null, "summary": "utility to inspect python source codes", "version": "0.2.5" }, "last_serial": 1530936, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "291735f226ba76bb8812469b695f8e47", "sha256": "056a2a791c8496df18cc44df875a22153c0c7decff3dfd335af065b1ba69274d" }, "downloads": -1, "filename": "sourceparse-0.1-py2.7.egg", "has_sig": false, "md5_digest": "291735f226ba76bb8812469b695f8e47", "packagetype": "bdist_egg", "python_version": "2.7", "requires_python": null, "size": 2037, "upload_time": "2015-01-04T21:47:30", "url": "https://files.pythonhosted.org/packages/04/da/aed16feafa9bee4623b4b63449048836eda9592012fe032f8b2eb4d191a5/sourceparse-0.1-py2.7.egg" } ], "0.2.3": [ { "comment_text": "", "digests": { "md5": "a04181b12357fe43a145c74de2f2a796", "sha256": "acea59c1db89225cfb67be82857a88e78e3b40c86ba135bfc582805beb5a78b2" }, "downloads": -1, "filename": "sourceparse-0.2.3.tar.gz", "has_sig": false, "md5_digest": "a04181b12357fe43a145c74de2f2a796", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8304, "upload_time": "2015-05-02T22:17:06", "url": "https://files.pythonhosted.org/packages/0d/04/a47fb4c8c622002870e482f4b9bd1c7c557a0da421f2b1877b9af44df974/sourceparse-0.2.3.tar.gz" } ], "0.2.5": [ { "comment_text": "", "digests": { "md5": "6134222c81efe9bfe5ac8acf0c1daf56", "sha256": "15e9286e06074818b5372d859faa6533bd5547a909684f8f7bb72dcab3473752" }, "downloads": -1, "filename": "sourceparse-0.2.5.tar.gz", "has_sig": false, "md5_digest": "6134222c81efe9bfe5ac8acf0c1daf56", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6677, "upload_time": "2015-05-02T22:51:03", "url": "https://files.pythonhosted.org/packages/fc/a8/39526ee300f02553e4f0a91472e762c741f116da88e9789e9b44f60cc232/sourceparse-0.2.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6134222c81efe9bfe5ac8acf0c1daf56", "sha256": "15e9286e06074818b5372d859faa6533bd5547a909684f8f7bb72dcab3473752" }, "downloads": -1, "filename": "sourceparse-0.2.5.tar.gz", "has_sig": false, "md5_digest": "6134222c81efe9bfe5ac8acf0c1daf56", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6677, "upload_time": "2015-05-02T22:51:03", "url": "https://files.pythonhosted.org/packages/fc/a8/39526ee300f02553e4f0a91472e762c741f116da88e9789e9b44f60cc232/sourceparse-0.2.5.tar.gz" } ] }