{ "info": { "author": "Chris Martin", "author_email": "ch.martin@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "Usage\n-----\n\nThis library contains only the context manager ``optional_import``:\n\n.. code:: python\n\n >>> from optional_import import optional_import\n\nA successful import works as usual:\n\n.. code:: python\n\n >>> with optional_import():\n ... import collections\n >>> type(collections)\n \n\nIf the import does not exist, ``optional_import`` suppresses the\n``ImportError`` that would otherwise be raised.\n\n.. code:: python\n\n >>> import unicorns\n Traceback (most recent call last):\n ...\n ImportError: No module named unicorns\n\n >>> with optional_import():\n ... import unicorns\n\n >>> unicorns\n Traceback (most recent call last):\n ...\n NameError: name 'unicorns' is not defined\n\n\nExample: Django local settings\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nA common pattern in Django is to put default settings in ``settings.py``,\nput optional site-specific settings in ``settings_local.py``, and import\n``*`` from the local settings file if it exists.\n\n.. code:: python\n\n with optional_import():\n from .settings_local import *\n\n\nWhy not just catch ``ImportError``?\n-----------------------------------\n\nOptional imports can almost be achieved simply by catching ``ImportError``:\n\n.. code:: python\n\n try:\n import foo\n except ImportError:\n pass\n\nBut this approach introduces a problem: If ``foo`` exists but raises\n``ImportError``, we want that error to be raised, but instead it is\nswallowed by the ``except`` clause.\n\nWith ``optional_import``, the error is raised as desired. In the following\nexample, the ``bad`` module tries to import a nonexistent package ``unicorns``:\n\n.. code:: python\n\n >>> with optional_import():\n ... import bad\n Traceback (most recent call last):\n ...\n ImportError: No module named unicorns", "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/cardforcoin/optional_import", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "optional_import", "package_url": "https://pypi.org/project/optional_import/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/optional_import/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/cardforcoin/optional_import" }, "release_url": "https://pypi.org/project/optional_import/1.2/", "requires_dist": null, "requires_python": null, "summary": "Import something if it exists.", "version": "1.2" }, "last_serial": 1129998, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "88fde520ed2ee8f5848a97eb626800f9", "sha256": "0762ea1cf0fe8b6bf57364859ed72215af1f13eaf5e01cd67e1b1d366aaf71ef" }, "downloads": -1, "filename": "optional_import-1.0.tar.gz", "has_sig": false, "md5_digest": "88fde520ed2ee8f5848a97eb626800f9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2137, "upload_time": "2014-06-18T19:20:24", "url": "https://files.pythonhosted.org/packages/29/de/01d8ec7c9af7679b0ad861dbfd832cf4233046d927cdf2b55ae24cc5299a/optional_import-1.0.tar.gz" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "0b4f9eb6d6d87fa0ece014455ba0ccd0", "sha256": "4c24efe1553a8330edbb84b253e9c8d7baa1f8c893095e679618ce5e88bf3083" }, "downloads": -1, "filename": "optional_import-1.1.tar.gz", "has_sig": false, "md5_digest": "0b4f9eb6d6d87fa0ece014455ba0ccd0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2124, "upload_time": "2014-06-18T19:43:52", "url": "https://files.pythonhosted.org/packages/94/ab/10d23ad45716cbee8349f0182511d6c42c0e0d88e3877693188cce28a726/optional_import-1.1.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "eccd26664b97e9db881e161a458a67dd", "sha256": "cd651eb9824a93d586905a4c54c19a9f2865f59201b022dcd32a8fc71f1faf86" }, "downloads": -1, "filename": "optional_import-1.2.tar.gz", "has_sig": false, "md5_digest": "eccd26664b97e9db881e161a458a67dd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2359, "upload_time": "2014-06-19T03:40:22", "url": "https://files.pythonhosted.org/packages/de/c6/cbbda50cb62ade7d16acaaa5d1b1a34589281ee8b24d54ba36d5d6d35811/optional_import-1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "eccd26664b97e9db881e161a458a67dd", "sha256": "cd651eb9824a93d586905a4c54c19a9f2865f59201b022dcd32a8fc71f1faf86" }, "downloads": -1, "filename": "optional_import-1.2.tar.gz", "has_sig": false, "md5_digest": "eccd26664b97e9db881e161a458a67dd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2359, "upload_time": "2014-06-19T03:40:22", "url": "https://files.pythonhosted.org/packages/de/c6/cbbda50cb62ade7d16acaaa5d1b1a34589281ee8b24d54ba36d5d6d35811/optional_import-1.2.tar.gz" } ] }