{ "info": { "author": "James E. King III", "author_email": "jking@apache.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Security", "Topic :: System :: Shells", "Topic :: Utilities" ], "description": "# tempenv\n\n[![Build Status](https://travis-ci.org/jeking3/tempenv.svg?branch=master)](https://travis-ci.org/jeking3/tempenv)\n[![codecov](https://codecov.io/gh/jeking3/tempenv/branch/master/graph/badge.svg)](https://codecov.io/gh/jeking3/tempenv)\n\nManage environment variables in a temporary scope.\n\nSome products use environment variables as a primary means to supply\ncredentials. To ensure the lifetime of exposed credentials is short,\nwrap them in a TemporaryEnvironment so that they are automatically\ndestroyed on scope exit.\n\nYou can:\n\n- Set or unset environment variables inside a ``with`` code block,\n- Get a warning if the code block modifies one of the environment\n variables,\n- Optionally bypass restoration of the original environment variable\n value if the code block modifies the environment variable.\n\n## Install\n\nInstall the latest version of tempenv:\n\n```\n pip install tempenv\n```\n\n## Examples\n\nSet some environment variables temporarily\n(see [example_set_test.py](tests/example_set_test.py)):\n\n```\n def test_set(self):\n user_before = os.environ.get(\"USER\")\n with TemporaryEnvironment({\"USER\": \"nobody\", \"OTHER\": \"foo\"}):\n assert os.environ.get(\"USER\") == \"nobody\"\n assert os.environ.get(\"OTHER\") == \"foo\"\n assert os.environ.get(\"USER\") == user_before\n```\n\nChanging the value to ``None`` will unset the environment variable during\nthe code block\n(see [example_unset_test.py](tests/example_unset_test.py)):\n\n```\n def test_unset(self):\n os.environ[\"DEBUG\"] = \"1\"\n with TemporaryEnvironment({\"DEBUG\": None}):\n assert \"DEBUG\" not in os.environ\n assert \"DEBUG\" in os.environ\n```\n\nChanging a temporary environment variable during the scope will cause a\nwarning\n(see [example_overwrite_test.py](tests/example_overwrite_test.py)):\n\n```\n def test_overwritten_in_context(self):\n with self.assertWarnsRegex(EnvironmentVariableChangedWarning, \"FOO\"):\n with TemporaryEnvironment({\"FOO\": \"BAR\"}):\n os.environ[\"FOO\"] = \"SAM\"\n```\n\nIf you set the optional argument ``restore_if_changed=False`` then a change\nduring the scope of the TemporaryEnvironment will not issue a warning and will\nnot restore to the original value\n(see [example_ignore_test.py](tests/example_ignore_test.py)):\n\n```\n def test_ignored_overwrite_in_context(self):\n os.environ[\"FOO\"] = \"BAR\"\n with TemporaryEnvironment({\"FOO\": \"SAM\"}, restore_if_changed=False):\n os.environ[\"FOO\"] = \"DEAN\"\n assert os.environ[\"FOO\"] == \"DEAN\"\n```\n\nYou can use TemporaryEnvironment in a unittest scope as follows\n(see [example_unittest_test.py](tests/example_unittest_test.py)):\n\n```\n @TemporaryEnvironment({\"USER\": \"Crowley\"})\n def test_check(self):\n assert os.environ.get(\"USER\") == \"Crowley\"\n```\n\n## License\n\nReleased under the Apache Software License, Version 2.0 (see `LICENSE`):\n\n```\n Copyright (C) 2019 James E. King III (@jeking3) \n```\n\n## History\n\n### v0.2.0\n\n- Added decorator support.\n- Updated README with more examples.\n\n### v0.1.0\n\n- Initial release.\n\n## Bugs\n\nPlease report any bugs that you find [here](https://github.com/jeking3/tempenv/issues).\nOr, even better, fork the repository on [GitHub](https://github.com/jeking3/tempenv)\nand create a pull request (PR). We welcome all changes, big or small, and we\nwill help you make the PR if you are new to `git` (just ask on the issue and/or\nsee `CONTRIBUTING.rst`).\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "https://github.com/jeking3/tempenv/archive/master.zip", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/jeking3/tempenv", "keywords": "temporary,environment variable,context manager", "license": "Apache License 2.0", "maintainer": "", "maintainer_email": "", "name": "tempenv", "package_url": "https://pypi.org/project/tempenv/", "platform": "", "project_url": "https://pypi.org/project/tempenv/", "project_urls": { "Download": "https://github.com/jeking3/tempenv/archive/master.zip", "Homepage": "https://github.com/jeking3/tempenv" }, "release_url": "https://pypi.org/project/tempenv/0.2.0/", "requires_dist": null, "requires_python": ">=3.6", "summary": "Environment Variable Context Manager", "version": "0.2.0" }, "last_serial": 5944517, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "dc4565189bf0886470cfc7211285d254", "sha256": "7280b97e6e8bfca4fe6f43335144dcaa659090691d901c6d4e24e56c493040f4" }, "downloads": -1, "filename": "tempenv-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "dc4565189bf0886470cfc7211285d254", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 6372, "upload_time": "2019-05-30T20:21:02", "url": "https://files.pythonhosted.org/packages/fe/45/ad634c42059dd33b13b9b0be3f42f047c9367716a23682833bbdf3c74661/tempenv-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "eb435bc0787e1733842ffb01a4ef398c", "sha256": "5a8fbfaa3cb4bfe6b62061336cb86b61b11b32816d6a16608c544fffd8fb4ae5" }, "downloads": -1, "filename": "tempenv-0.1.0.tar.gz", "has_sig": false, "md5_digest": "eb435bc0787e1733842ffb01a4ef398c", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 8423, "upload_time": "2019-05-30T20:21:05", "url": "https://files.pythonhosted.org/packages/d7/92/ced750743f9221bd3b7df70918d0c00e7873929ede1239fdfda5728acea5/tempenv-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "20ae4ca91a0dec3a95827a7a761883d1", "sha256": "5e9e92ab4c617f4ee552f93558a0e2e657394f24da46c604da64febdba3b6e4d" }, "downloads": -1, "filename": "tempenv-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "20ae4ca91a0dec3a95827a7a761883d1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 9210, "upload_time": "2019-10-08T12:17:09", "url": "https://files.pythonhosted.org/packages/4d/25/16e00d06e720b8cd7cdffb43b2661fc0cea377c587dc083765453410f967/tempenv-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7365a6cdaaa4ecd200ff68b81ab5c5f6", "sha256": "8c1055537f43b0835e6f946eda9c7c4729a76361c7798d5f394cd57b8a8e1ce4" }, "downloads": -1, "filename": "tempenv-0.2.0.tar.gz", "has_sig": false, "md5_digest": "7365a6cdaaa4ecd200ff68b81ab5c5f6", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 9864, "upload_time": "2019-10-08T12:17:10", "url": "https://files.pythonhosted.org/packages/42/8c/8fe8043f382201517094ea6fb3dc64edabbc6bf7a9508991b461286d0877/tempenv-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "20ae4ca91a0dec3a95827a7a761883d1", "sha256": "5e9e92ab4c617f4ee552f93558a0e2e657394f24da46c604da64febdba3b6e4d" }, "downloads": -1, "filename": "tempenv-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "20ae4ca91a0dec3a95827a7a761883d1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 9210, "upload_time": "2019-10-08T12:17:09", "url": "https://files.pythonhosted.org/packages/4d/25/16e00d06e720b8cd7cdffb43b2661fc0cea377c587dc083765453410f967/tempenv-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7365a6cdaaa4ecd200ff68b81ab5c5f6", "sha256": "8c1055537f43b0835e6f946eda9c7c4729a76361c7798d5f394cd57b8a8e1ce4" }, "downloads": -1, "filename": "tempenv-0.2.0.tar.gz", "has_sig": false, "md5_digest": "7365a6cdaaa4ecd200ff68b81ab5c5f6", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 9864, "upload_time": "2019-10-08T12:17:10", "url": "https://files.pythonhosted.org/packages/42/8c/8fe8043f382201517094ea6fb3dc64edabbc6bf7a9508991b461286d0877/tempenv-0.2.0.tar.gz" } ] }