{ "info": { "author": "Juan Luis Boya Garc\u00eda", "author_email": "ntrrgc@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Contextualized tracebacks\n=========================\n\nIf you have ever wrote a Python program that processes large input files you probably have been in a situation where you get an error on certain file and line. You may get a traceback telling you have e.g. a ``KeyError`` but still don't know what line in that text file provoked it.\n\nThen you may start adding ``print(line)`` calls every time a line is processed, but that's quirky, clutters your terminal quickly and you'll have to eventually remove it, only to later add it when the next bug hits.\n\nThis module is an alternative to improve this kind of debugging issue, making it clean and robust, whilst providing a easy to use API.\n\nThis module works by providing you with a context object where you can set state variables like file name and line number. When an unhandled exception is raised, this module catches it and prints the value of the state variables along with the traceback.\n\nExample code:\n\n.. code-block:: python\n\n from contextualized import contextualized_tracebacks\n\n def main():\n dcontext.file = 'hello.txt'\n a()\n\n def a():\n dcontext.line = 20\n b()\n\n def b():\n # buggy code\n nonexistent += 1\n\n with contextualized_tracebacks(['file', 'line', 'character']) as dcontext:\n main()\n\nThis program will show this once run:\n\n.. code-block::\n\n Traceback (most recent call last):\n File \"contextualized_example.py\", line 16, in \n main()\n File \"contextualized_example.py\", line 5, in main\n a()\n File \"contextualized_example.py\", line 9, in a\n b()\n File \"contextualized_example.py\", line 13, in b\n nonexistent += 1\n UnboundLocalError: local variable 'nonexistent' referenced before assignment\n The exception was caught on file 'hello.txt', line 20.\n\nThe context information is right after the traceback. Notice how only non ``None`` fields are shown. They also preserve the order from the ``contextualized_tracebacks()`` call.\n\nOverriding the traceback print function\n---------------------------------------\n\nYou can override the default traceback print with the ``print_tb`` argument. For example, this example will print the context **before** the traceback.\n\n.. code-block:: python\n\n from contextualized import contextualized_tracebacks\n\n def main():\n dcontext.file = 'hello.txt'\n a()\n\n def a():\n dcontext.line = 20\n b()\n\n def b():\n # buggy code\n nonexistent += 1\n\n def my_print_tb(context, tb_info):\n import traceback\n import sys\n\n print('An exception was caught on %s.' % context._to_prose(),\n file=sys.stderr)\n traceback.print_exception(*tb_info)\n\n with contextualized_tracebacks(['file', 'line', 'character'],\n print_tb=my_print_tb) as dcontext:\n main()\n\nThis will be the new output:\n\n.. code-block::\n\n An exception was caught on file 'hello.txt', line 20.\n Traceback (most recent call last):\n File \"contextualized_example.py\", line 25, in \n main()\n File \"contextualized_example.py\", line 5, in main\n a()\n File \"contextualized_example.py\", line 9, in a\n b()\n File \"contextualized_example.py\", line 13, in b\n nonexistent += 1\n UnboundLocalError: local variable 'nonexistent' referenced before assignment\n\nLinks\n-----\n\n* `Project home page `_ (GitHub)\n* `Contextualized in PyPI `_\n\nChangelog\n---------\n\n* **1.0**: Initial release.\n* **1.1**: SystemExit exceptions no longer are catched, thus triggering normal ``exit()`` by the interpreter.\n* **1.2**: Modified ``setup.py`` to install successfully with ``LANG=C``.\n* **1.3**: Fixed a bug that caused contextualized not to work in Python 2.\n\nLicense\n-------\n\nThis module is under the MIT License.\n\nCopyright (c) 2015 Juan Luis Boya Garc\u00eda\n\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/ntrrgc/contextualized", "keywords": "traceback,debugging", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "contextualized", "package_url": "https://pypi.org/project/contextualized/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/contextualized/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/ntrrgc/contextualized" }, "release_url": "https://pypi.org/project/contextualized/1.3/", "requires_dist": null, "requires_python": null, "summary": "Get tracebacks with context.", "version": "1.3" }, "last_serial": 2187074, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "c0beabebbe77f67ebeaf6cfeaff839e2", "sha256": "6bf03950f90f8dc4f5c73d86ecec55d71b7a2869481e64e9ed205bf5967228cd" }, "downloads": -1, "filename": "contextualized-1.0.tar.gz", "has_sig": false, "md5_digest": "c0beabebbe77f67ebeaf6cfeaff839e2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4035, "upload_time": "2015-11-19T23:22:38", "url": "https://files.pythonhosted.org/packages/5c/23/c3faa511fd1848629489ad101b06fed3c46ddbdaa01483c625c6adfacd06/contextualized-1.0.tar.gz" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "c935c47c34d6e825e7537aab104294a7", "sha256": "3968823e5594285269d5b7bd3ea4e93502a2215b75010d6d514643fe7922a27b" }, "downloads": -1, "filename": "contextualized-1.1.tar.gz", "has_sig": false, "md5_digest": "c935c47c34d6e825e7537aab104294a7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4159, "upload_time": "2015-11-21T21:26:18", "url": "https://files.pythonhosted.org/packages/61/23/f65e18093c95a365feb89dfb5737d2ccb63b1b2477eb29eecbd177f276fe/contextualized-1.1.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "5d4d83398112cb978da93458fdcfcc68", "sha256": "0fe6727d78b233657a6829afb2979dadd66f97f494b6b32d4eb949f33d367e82" }, "downloads": -1, "filename": "contextualized-1.2.tar.gz", "has_sig": false, "md5_digest": "5d4d83398112cb978da93458fdcfcc68", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4180, "upload_time": "2016-06-01T01:10:37", "url": "https://files.pythonhosted.org/packages/9e/bb/b8c343fabb455a6eea49e99d51db1bc5b0f0d8e7e9319580a9e32a5327c7/contextualized-1.2.tar.gz" } ], "1.3": [ { "comment_text": "", "digests": { "md5": "389668b323d269bf9dcccb9d54b0e367", "sha256": "fe4095a9bc7a34aca0fbde4e24d1b16f6e5488fefbf92fb09bfd29f47a645a6a" }, "downloads": -1, "filename": "contextualized-1.3.tar.gz", "has_sig": false, "md5_digest": "389668b323d269bf9dcccb9d54b0e367", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4216, "upload_time": "2016-06-25T19:23:12", "url": "https://files.pythonhosted.org/packages/60/5c/78c1a7ef91568614fa5e3f5f3d039457b0a10742a094bef926edca889742/contextualized-1.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "389668b323d269bf9dcccb9d54b0e367", "sha256": "fe4095a9bc7a34aca0fbde4e24d1b16f6e5488fefbf92fb09bfd29f47a645a6a" }, "downloads": -1, "filename": "contextualized-1.3.tar.gz", "has_sig": false, "md5_digest": "389668b323d269bf9dcccb9d54b0e367", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4216, "upload_time": "2016-06-25T19:23:12", "url": "https://files.pythonhosted.org/packages/60/5c/78c1a7ef91568614fa5e3f5f3d039457b0a10742a094bef926edca889742/contextualized-1.3.tar.gz" } ] }