{ "info": { "author": "Brian Skinn", "author_email": "bskinn@alum.mit.edu", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3 :: Only", "Topic :: Software Development" ], "description": "tempvars: A context manager for handling temporary variables\n============================================================\n\n**Current Development Version:**\n\n.. image:: https://travis-ci.org/bskinn/tempvars.svg?branch=dev\n :target: https://travis-ci.org/bskinn/tempvars\n\n.. image:: https://codecov.io/gh/bskinn/tempvars/branch/dev/graph/badge.svg\n :target: https://codecov.io/gh/bskinn/tempvars\n\n**Most Recent Stable Release:**\n\n.. image:: https://img.shields.io/pypi/v/tempvars.svg\n :target: https://pypi.org/project/tempvars\n\n.. image:: https://img.shields.io/pypi/pyversions/tempvars.svg\n\n**Info:**\n\n.. image:: https://img.shields.io/readthedocs/tempvars/v1.0.1.svg\n :target: http://tempvars.readthedocs.io/en/v1.0.1/\n\n.. image:: https://img.shields.io/github/license/mashape/apistatus.svg\n :target: https://github.com/bskinn/tempvars/blob/master/LICENSE.txt\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n :target: https://github.com/ambv/black\n\n----\n\n**Use Jupyter Notebook?**\n\n**Constantly run into problems from obsolete variables hanging around\nin the namespace?**\n\n``tempvars`` *can help.*\n\nDeveloping in Jupyter notebooks can sometimes be frustrating.\nFor example, it's aggravating to debug a worksheet for half an hour,\nonly to discover that a carried-over variable name was hanging around\nin the notebook namespace and causing problems.\nOr, to open a notebook that \"worked fine\" the last\ntime it was used, but only because of random, obsolete variables that happened\nto be lingering in the namespace.\nWrapping notebook code in functions/classes is an effective way of avoiding\nthese sorts of problems, but it's rarely effective or efficient to\ndo this in the initial exploratory phase of in-notebook development.\n\n``TempVars`` is a context manager that helps to avoid these pitfalls by\nclearing selected identifiers from the namespace for the duration of\nits scope, then restoring them afterwards (or not, if desired).\nFurther, any variables created within the managed context\nthat match the ``TempVars`` filtering criteria are removed from\nthe namespace upon exiting, ensuring these values do not spuriously\ncontribute to following code. For convenience, all variables\nremoved from the namespace at entry and exit\nare stored for later reference (see example code below).\n\nDue to the way Python handles non-global scopes, ``TempVars``\ncan only be used at the global scope. *Any attempt\nto use* ``TempVars`` *in non-global contexts will\nresult in a* ``RuntimeError``. Viable use-cases include Jupyter notebooks,\nthe IPython and basic Python REPLs, and the outermost scope of executed and\nimported modules. Preliminary testing indicates it also works with\n`cauldron-notebook `__, though\nit may be less helpful there due to its step-local scoping paradigm\n(shared values must be passed around via ``cauldron.shared``).\n\n----\n\nAfter installing with ``pip install tempvars``, import as:\n\n.. code:: python\n\n >>> from tempvars import TempVars\n\nFor typical use in a Jupyter notebook cell, the recommended approach\nis to pick a marker to use on all variables that are to be temporary,\nand enclose the entire cell in a ``TempVars`` context. For example,\none could prefix all temporary variables with `t_` and make use\nof the `starts` argument:\n\n.. code:: python\n\n >>> foo = 5\n >>> with TempVars(starts=['t_']):\n ... print(foo)\n ... t_bar = 8\n ... print(foo + t_bar)\n 5\n 13\n >>> print('t_bar' in dir())\n False\n\nA similar effect can be achieved with a suffix such as `_t` and\nthe `ends` argument.\n\nTemporary variable masking can also be introduced to existing\ncode in a more selective fashion via the `names` argument:\n\n.. code:: python\n\n >>> foo = 5\n >>> bar = 7\n >>> with TempVars(names=['bar']):\n ... print(foo)\n ... print('bar' in dir())\n 5\n False\n >>> print(foo * bar)\n 35\n\nSetting the `restore` argument to ``False`` instructs ``TempVars``\nnot to restore any masked variables to the namespace after its\ncontext exits. This is potentially useful to avoid carryover of\ncommon helper variables (`arr`, `df`, `i`, etc.) to downstream cells\nthat may have been created earlier in a notebook:\n\n.. code:: python\n\n >>> for k in ['foo', 'bar']:\n ... pass\n >>> print(k)\n bar\n >>> with TempVars(names=['k'], restore=False):\n ... print('k' in dir())\n False\n >>> print('k' in dir())\n False\n\n``TempVars`` stores the values of variables it removes from the namespace,\nshould they need to be accessed. A bound `with`/`as` statement must be\nused in order to enable this:\n\n.. code:: python\n\n >>> foo = 5\n >>> with TempVars(names=['foo']) as tv:\n ... print('foo' in dir())\n ... print(tv.stored_nsvars['foo'])\n ... foo = 8\n ... print(foo)\n False\n 5\n 8\n >>> print(foo)\n 5\n >>> print(tv.retained_tempvars['foo'])\n 8\n\n----\n\n\nAvailable on `PyPI `__: ``pip install tempvars``.\n\nFull documentation at\n`Read the Docs `__.\n\nSource on `GitHub `__.\nBug reports and feature requests are welcomed at the\n`Issues `__ page there.\nIf you like the idea of an enhancement already in the Issues list,\nplease comment to say so; it'll help with prioritization.\n\nCopyright (c) Brian Skinn 2017-2018\n\nLicense: The MIT License. See `LICENSE.txt `__\nfor full license terms.", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://www.github.com/bskinn/tempvars", "keywords": "", "license": "MIT License", "maintainer": "", "maintainer_email": "", "name": "tempvars", "package_url": "https://pypi.org/project/tempvars/", "platform": "", "project_url": "https://pypi.org/project/tempvars/", "project_urls": { "Homepage": "https://www.github.com/bskinn/tempvars" }, "release_url": "https://pypi.org/project/tempvars/1.0.1/", "requires_dist": null, "requires_python": ">=3.4", "summary": "Context manager for handling temporary variables in Jupyter Notebook, IPython, etc.", "version": "1.0.1" }, "last_serial": 4486798, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "c2ed1403940e974d3c0350467b56ab88", "sha256": "6d5b053ce6237c2b3ab2a4d137e3b250244bcb11ab8588fc576de03ceb3ecb65" }, "downloads": -1, "filename": "tempvars-1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "c2ed1403940e974d3c0350467b56ab88", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9010, "upload_time": "2017-10-19T18:24:41", "url": "https://files.pythonhosted.org/packages/a1/2a/12ea6dd1c2baf9f6432c476f68a493c1e13d53bb2850b88c01ea360ee9cc/tempvars-1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9c919a9ffdaf9d03217962ba68e77990", "sha256": "31e3992e41a75adc7a988872a96b57f7ba035c4b1ecfe35e8972853962d3bd75" }, "downloads": -1, "filename": "tempvars-1.0.tar.gz", "has_sig": false, "md5_digest": "9c919a9ffdaf9d03217962ba68e77990", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7793, "upload_time": "2017-10-19T18:24:23", "url": "https://files.pythonhosted.org/packages/ec/f9/0f36ea55ffa182c3fd47ff96d40017a1c912645035f884f6585eb3c7f91a/tempvars-1.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "5ce5cc0342b6c601d961e666766896c9", "sha256": "1ac7b3c2c6a77b57997c61a86b57a0acfbb68ce969a0187a020adbea8501ef58" }, "downloads": -1, "filename": "tempvars-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "5ce5cc0342b6c601d961e666766896c9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.4", "size": 7979, "upload_time": "2018-11-14T19:47:55", "url": "https://files.pythonhosted.org/packages/f7/fd/c7bcf9e587fe2edf7df533f2c02df7a910f0a7f975aa90c15e6073a7a858/tempvars-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "02f88fc3061a06d492d779d1bf0ea259", "sha256": "14ebf82073098134dfe870d86e547471e122f5eed238501f46d0c36f93040852" }, "downloads": -1, "filename": "tempvars-1.0.1.tar.gz", "has_sig": false, "md5_digest": "02f88fc3061a06d492d779d1bf0ea259", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 9077, "upload_time": "2018-11-14T19:47:45", "url": "https://files.pythonhosted.org/packages/2d/44/32295c80c0d59ea11d82ca30ae40f5021551ed72eed7aa64c9a84b6235a0/tempvars-1.0.1.tar.gz" } ], "1.0b1": [ { "comment_text": "", "digests": { "md5": "90a1619b1ad8b01f82e3d3de4b601bd1", "sha256": "1b5865421061d0624cbcd97108599e4b52c1ac528556fdd7c0b851a65aa1b20d" }, "downloads": -1, "filename": "tempvars-1.0b1-py3.5.egg", "has_sig": false, "md5_digest": "90a1619b1ad8b01f82e3d3de4b601bd1", "packagetype": "bdist_egg", "python_version": "3.5", "requires_python": null, "size": 7307, "upload_time": "2017-09-19T17:49:44", "url": "https://files.pythonhosted.org/packages/89/7c/da9f031d111714f5889733ab4be9437642707429c4f982350969fcd42c6f/tempvars-1.0b1-py3.5.egg" }, { "comment_text": "", "digests": { "md5": "32115712d278124d5ee73c97ff8fa1af", "sha256": "969a7202cad41b0b383ea70f71b7a5624d92f6e4efa27264a0b6a31095c6aff5" }, "downloads": -1, "filename": "tempvars-1.0b1-py3-none-any.whl", "has_sig": false, "md5_digest": "32115712d278124d5ee73c97ff8fa1af", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7624, "upload_time": "2017-09-20T19:45:06", "url": "https://files.pythonhosted.org/packages/ff/29/89675be8d99dde1577fac1a7aa3b8a17afc5bbaf588497de754bfe647f6e/tempvars-1.0b1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "94081c59e82bbfe7305ddcc23411678c", "sha256": "ed8383ae182aaebcb2dd71967f83e7bde658251957375ec62a62a89da50799eb" }, "downloads": -1, "filename": "tempvars-1.0b1.tar.gz", "has_sig": false, "md5_digest": "94081c59e82bbfe7305ddcc23411678c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6047, "upload_time": "2017-09-19T17:46:31", "url": "https://files.pythonhosted.org/packages/d8/ef/20d37a0c7d4597e184cc029d6c4cf07465ced0ff78c78dac4768456948ce/tempvars-1.0b1.tar.gz" } ], "1.0b2": [ { "comment_text": "", "digests": { "md5": "371a37b622393a1498a50e5469a320e3", "sha256": "64b47fbc6b434105fdc33cdfbcf7865c8ff8169e352c02e48b729e126261f2de" }, "downloads": -1, "filename": "tempvars-1.0b2-py3-none-any.whl", "has_sig": false, "md5_digest": "371a37b622393a1498a50e5469a320e3", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8418, "upload_time": "2017-10-02T02:21:35", "url": "https://files.pythonhosted.org/packages/d4/4f/f160cc438089844f92c30f74db8a2351c6bd7b5d20af3ddbe296e4deca15/tempvars-1.0b2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9c07516b2a3ea881bc2949da1673a6ef", "sha256": "4b8513a734e33ce53c06442bb4a0cdb69547db6d3001fcac02ff29f64d8fcadb" }, "downloads": -1, "filename": "tempvars-1.0b2.tar.gz", "has_sig": false, "md5_digest": "9c07516b2a3ea881bc2949da1673a6ef", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6932, "upload_time": "2017-10-02T02:21:24", "url": "https://files.pythonhosted.org/packages/94/ae/470b3a642f6f3bf6862b97b0a6e5869545c3088e46ef53a804fc6906d821/tempvars-1.0b2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5ce5cc0342b6c601d961e666766896c9", "sha256": "1ac7b3c2c6a77b57997c61a86b57a0acfbb68ce969a0187a020adbea8501ef58" }, "downloads": -1, "filename": "tempvars-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "5ce5cc0342b6c601d961e666766896c9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.4", "size": 7979, "upload_time": "2018-11-14T19:47:55", "url": "https://files.pythonhosted.org/packages/f7/fd/c7bcf9e587fe2edf7df533f2c02df7a910f0a7f975aa90c15e6073a7a858/tempvars-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "02f88fc3061a06d492d779d1bf0ea259", "sha256": "14ebf82073098134dfe870d86e547471e122f5eed238501f46d0c36f93040852" }, "downloads": -1, "filename": "tempvars-1.0.1.tar.gz", "has_sig": false, "md5_digest": "02f88fc3061a06d492d779d1bf0ea259", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 9077, "upload_time": "2018-11-14T19:47:45", "url": "https://files.pythonhosted.org/packages/2d/44/32295c80c0d59ea11d82ca30ae40f5021551ed72eed7aa64c9a84b6235a0/tempvars-1.0.1.tar.gz" } ] }