conditional


Nameconditional JSON
Version 1.5 PyPI version JSON
download
home_pagehttps://github.com/stefanholek/conditional
SummaryConditionally enter a context manager
upload_time2023-09-14 13:31:39
maintainer
docs_urlhttps://pythonhosted.org/conditional/
authorStefan H. Holek
requires_python!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7
licenseBSD-2-Clause
keywords conditional context manager with
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ===========
conditional
===========
-------------------------------------------------------------------
Conditionally enter a context manager
-------------------------------------------------------------------

Package Contents
================

conditional(condition, contextmanager)
    Enter contextmanager only if condition is true.

Overview
========

The `conditional` context manager comes handy when you always want to
execute a with-block but only conditionally want to apply its context
manager.

If you find yourself writing code like this:

.. code-block:: python

    if CONDITION:
        with CONTEXTMANAGER():
            BODY()
    else:
        BODY()

Consider replacing it with:

.. code-block:: python

    with conditional(CONDITION, CONTEXTMANAGER()):
        BODY()

Typing
======

The context manager ships with type annotations. Type checkers and IDEs can
use this information to implement type safety and auto completion.

Examples
========

Say we want to ignore signals when a pager application is in the
foreground, but not otherwise:

.. code-block:: python

    from conditional import conditional

    with conditional(has_pager(cmd), ignoresignals()):
        os.system(cmd)

Documentation
=============

For further details please refer to the `API Documentation`_.

.. _`API Documentation`: https://conditional.readthedocs.io/en/stable/


Changelog
=========

1.5 - 2023-09-14
----------------

- Add type annotations to the context manager.
  [stefan]

- Update tox.ini for latest tox.
  [stefan]

- Add GitHub CI workflow.
  [stefan]

- Add .readthedocs.yaml file.
  [stefan]

- Pin sphinx and sphinx-rtd-theme versions in docs extra.
  [stefan]

- Add mypy extra which installs mypy.
  [stefan]

1.4 - 2022-03-09
----------------

- Add Python 3.8-3.10 to tox.ini. Remove old Python versions.
  [stefan]

- Replace deprecated ``python setup.py test`` in tox.ini.
  [stefan]

- Remove deprecated ``test_suite`` and ``tests_require`` from setup.py.
  [stefan]

- Move metadata to setup.cfg and add a pyproject.toml file.
  [stefan]

- Include tests in sdist but not in wheel.
  [stefan]

1.3 - 2019-01-28
----------------

- Add MANIFEST.in.
  [stefan]

- Release as wheel.
  [stefan]

1.2 - 2017-02-05
----------------

- Support Python 2.6-3.6 without 2to3.
  [stefan]

- Add a LICENSE file.
  [stefan]

1.1 - 2014-04-19
----------------

- Remove setuptools from install_requires because it isn't.
  [stefan]

1.0 - 2012-05-16
----------------

- Initial release.
  [stefan]

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/stefanholek/conditional",
    "name": "conditional",
    "maintainer": "",
    "docs_url": "https://pythonhosted.org/conditional/",
    "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7",
    "maintainer_email": "",
    "keywords": "conditional,context manager,with",
    "author": "Stefan H. Holek",
    "author_email": "stefan@epy.co.at",
    "download_url": "https://files.pythonhosted.org/packages/8e/a5/9ceac769cb63e0a481e5fab665ea486a40da48ef11727ea2b4feb3362d54/conditional-1.5.tar.gz",
    "platform": null,
    "description": "===========\nconditional\n===========\n-------------------------------------------------------------------\nConditionally enter a context manager\n-------------------------------------------------------------------\n\nPackage Contents\n================\n\nconditional(condition, contextmanager)\n    Enter contextmanager only if condition is true.\n\nOverview\n========\n\nThe `conditional` context manager comes handy when you always want to\nexecute a with-block but only conditionally want to apply its context\nmanager.\n\nIf you find yourself writing code like this:\n\n.. code-block:: python\n\n    if CONDITION:\n        with CONTEXTMANAGER():\n            BODY()\n    else:\n        BODY()\n\nConsider replacing it with:\n\n.. code-block:: python\n\n    with conditional(CONDITION, CONTEXTMANAGER()):\n        BODY()\n\nTyping\n======\n\nThe context manager ships with type annotations. Type checkers and IDEs can\nuse this information to implement type safety and auto completion.\n\nExamples\n========\n\nSay we want to ignore signals when a pager application is in the\nforeground, but not otherwise:\n\n.. code-block:: python\n\n    from conditional import conditional\n\n    with conditional(has_pager(cmd), ignoresignals()):\n        os.system(cmd)\n\nDocumentation\n=============\n\nFor further details please refer to the `API Documentation`_.\n\n.. _`API Documentation`: https://conditional.readthedocs.io/en/stable/\n\n\nChangelog\n=========\n\n1.5 - 2023-09-14\n----------------\n\n- Add type annotations to the context manager.\n  [stefan]\n\n- Update tox.ini for latest tox.\n  [stefan]\n\n- Add GitHub CI workflow.\n  [stefan]\n\n- Add .readthedocs.yaml file.\n  [stefan]\n\n- Pin sphinx and sphinx-rtd-theme versions in docs extra.\n  [stefan]\n\n- Add mypy extra which installs mypy.\n  [stefan]\n\n1.4 - 2022-03-09\n----------------\n\n- Add Python 3.8-3.10 to tox.ini. Remove old Python versions.\n  [stefan]\n\n- Replace deprecated ``python setup.py test`` in tox.ini.\n  [stefan]\n\n- Remove deprecated ``test_suite`` and ``tests_require`` from setup.py.\n  [stefan]\n\n- Move metadata to setup.cfg and add a pyproject.toml file.\n  [stefan]\n\n- Include tests in sdist but not in wheel.\n  [stefan]\n\n1.3 - 2019-01-28\n----------------\n\n- Add MANIFEST.in.\n  [stefan]\n\n- Release as wheel.\n  [stefan]\n\n1.2 - 2017-02-05\n----------------\n\n- Support Python 2.6-3.6 without 2to3.\n  [stefan]\n\n- Add a LICENSE file.\n  [stefan]\n\n1.1 - 2014-04-19\n----------------\n\n- Remove setuptools from install_requires because it isn't.\n  [stefan]\n\n1.0 - 2012-05-16\n----------------\n\n- Initial release.\n  [stefan]\n",
    "bugtrack_url": null,
    "license": "BSD-2-Clause",
    "summary": "Conditionally enter a context manager",
    "version": "1.5",
    "project_urls": {
        "Documentation": "https://conditional.readthedocs.io/en/stable/",
        "Homepage": "https://github.com/stefanholek/conditional"
    },
    "split_keywords": [
        "conditional",
        "context manager",
        "with"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b976300a8286b48ea73808b717d19a6519c757cb5e2da6b8e61c4027f84cd304",
                "md5": "3d3fac1f02b5b1a04a1362d3bbe7b334",
                "sha256": "269ded33f3e4c1cdc3adef3b85a14eae9626f6dc25261e1f36910065a86cfdb2"
            },
            "downloads": -1,
            "filename": "conditional-1.5-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3d3fac1f02b5b1a04a1362d3bbe7b334",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7",
            "size": 4585,
            "upload_time": "2023-09-14T13:31:37",
            "upload_time_iso_8601": "2023-09-14T13:31:37.517745Z",
            "url": "https://files.pythonhosted.org/packages/b9/76/300a8286b48ea73808b717d19a6519c757cb5e2da6b8e61c4027f84cd304/conditional-1.5-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8ea59ceac769cb63e0a481e5fab665ea486a40da48ef11727ea2b4feb3362d54",
                "md5": "92ba7b2a9ce3276c3fd5e0e26e12cd49",
                "sha256": "1ef84f432774acd2b7ae4077d6151bd58408fca95a9568c8c7dbadf44dd502c3"
            },
            "downloads": -1,
            "filename": "conditional-1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "92ba7b2a9ce3276c3fd5e0e26e12cd49",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7",
            "size": 7407,
            "upload_time": "2023-09-14T13:31:39",
            "upload_time_iso_8601": "2023-09-14T13:31:39.159463Z",
            "url": "https://files.pythonhosted.org/packages/8e/a5/9ceac769cb63e0a481e5fab665ea486a40da48ef11727ea2b4feb3362d54/conditional-1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-14 13:31:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "stefanholek",
    "github_project": "conditional",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "conditional"
}
        
Elapsed time: 0.16366s