{ "info": { "author": "Moritz \"WanzenBug\" Wanzenb\u00f6ck", "author_email": "moritz.wanzenboeck@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: System :: Logging" ], "description": "# extra-context\n\nSometimes, when you get warnings and exeptions, backtraces are just not enough.\nFor example, you have a loop with 10.000 iterations. In the 1000th iteration there is an \nexception in a function you called. So you would like to have more context for the error message.\n\nThere are 2 options\n* give more context at the site the exception occured\n * Only possible if you control the exception/warning generation\n * Sometimes, there is not enough context to begin with (i.e. you are calling some common utility function)\n\n* Provide additional context as the exception/warning is passed up the call stack\n * Can be \"opt-in\" in user-code, no changes in libraries required.\n * Also works for warnings (which normally don't provide backtrace information)\n\n## Examples\n\nThe main example that inspired writing this library:\n```python\nto_process = { \"file1\": {...}, \"file2\": {...}, ...}\n\nfor k, v in to_process.items():\n cleaned = clean_data(v)\n write_output(k, cleaned)\n```\n\nIf there is an exception or warning somewhere in `clean_data(v)`, the \"context\" i.e. from which\nfile the data came is lost. The backtrace could look something like:\n```\n File \"clean.py\", line 35, in clean_data\nZeroDivisionError: division by zero\n```\n\nNow, with this library you can give extra context to your error messages\n\n```python\nfrom extra_context import provide_extra_context\n\nto_process = { \"file1\": {...}, \"file2\": {...}, ...}\n\nfor k, v in to_process.items():\n with provide_extra_context(filename=k):\n cleaned = clean_data(v)\n write_output(k, cleaned)\n```\n\nThis would report the same error as:\n```\n File \"clean.py\", line 35, in clean_data\nZeroDivisionError: division by zero\n |- In context: filename='file4'\n```\n\n### Decorator\nThere is also a decorator that reports the function arguments in case of an error\n\n```python\nimport warnings\nfrom extra_context import provide_call_context\n\n@provide_call_context\ndef w(x):\n warnings.warn(\"Oops\")\n\nw(42)\n```\n\nThis reports:\n```\nUserWarning: Oops\n |- In context: w(42)\n warnings.warn(\"Oops\")\n``` \n\n\n## License\n\nCopyright 2018 Moritz Wanzenb\u00f6ck\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\ndocumentation files (the \"Software\"), to deal in the Software without restriction, including without limitation\nthe rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the\nSoftware.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\nWARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\nOTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/WanzenBug/extra-context-py", "keywords": "warnings exception context logging", "license": "", "maintainer": "", "maintainer_email": "", "name": "extra-context", "package_url": "https://pypi.org/project/extra-context/", "platform": "", "project_url": "https://pypi.org/project/extra-context/", "project_urls": { "Bug Reports": "https://github.com/WanzenBug/extra-context-py/issues", "Homepage": "https://github.com/WanzenBug/extra-context-py", "Source": "https://github.com/WanzenBug/extra-context-py" }, "release_url": "https://pypi.org/project/extra-context/1.0.0/", "requires_dist": [ "pytest; extra == 'test'" ], "requires_python": "", "summary": "Add additional context to warnings and exceptions", "version": "1.0.0" }, "last_serial": 4468745, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "cf65d8589e1f0a764ac74f4ee8cd68f4", "sha256": "8ee44bc2b6bfaf35815f24319b4cb40ac4cf004c0e6cb861cfe0c1d52dec21f6" }, "downloads": -1, "filename": "extra_context-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "cf65d8589e1f0a764ac74f4ee8cd68f4", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4680, "upload_time": "2018-11-09T09:38:56", "url": "https://files.pythonhosted.org/packages/b0/d8/9f3d7e5ce680769faadb88349f3a39d22c374ebae5a0b167802773c20556/extra_context-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "40051bd9c0b6c89a152f01aa22816d49", "sha256": "58efaf35bc1179593f5d2e03fe31e8d1646284417963bf30c9023298b8932314" }, "downloads": -1, "filename": "extra-context-1.0.0.tar.gz", "has_sig": false, "md5_digest": "40051bd9c0b6c89a152f01aa22816d49", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4319, "upload_time": "2018-11-09T09:39:17", "url": "https://files.pythonhosted.org/packages/c6/ea/f41e829743b564715e891c2a9749cc628eb16d952af0a197947e83fac2e2/extra-context-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "cf65d8589e1f0a764ac74f4ee8cd68f4", "sha256": "8ee44bc2b6bfaf35815f24319b4cb40ac4cf004c0e6cb861cfe0c1d52dec21f6" }, "downloads": -1, "filename": "extra_context-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "cf65d8589e1f0a764ac74f4ee8cd68f4", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4680, "upload_time": "2018-11-09T09:38:56", "url": "https://files.pythonhosted.org/packages/b0/d8/9f3d7e5ce680769faadb88349f3a39d22c374ebae5a0b167802773c20556/extra_context-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "40051bd9c0b6c89a152f01aa22816d49", "sha256": "58efaf35bc1179593f5d2e03fe31e8d1646284417963bf30c9023298b8932314" }, "downloads": -1, "filename": "extra-context-1.0.0.tar.gz", "has_sig": false, "md5_digest": "40051bd9c0b6c89a152f01aa22816d49", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4319, "upload_time": "2018-11-09T09:39:17", "url": "https://files.pythonhosted.org/packages/c6/ea/f41e829743b564715e891c2a9749cc628eb16d952af0a197947e83fac2e2/extra-context-1.0.0.tar.gz" } ] }