tag-expressions


Nametag-expressions JSON
Version 2.0.1 PyPI version JSON
download
home_pagehttp://github.com/timofurrer/tag-expressions
SummaryBuilt-in functions, types, exceptions, and other objects.
upload_time2024-11-23 15:48:00
maintainerNone
docs_urlNone
authorTimo Furrer
requires_pythonNone
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            tag-expressions
===============

Package to evaluate logical tag expressions by using a modified version of the `Shunting Yard algorithm <https://en.wikipedia.org/wiki/Shunting-yard_algorithm>`_.
This package is a Python port of cucumbers tag expression.

It's also used by `radish <https://github.com/radish-bdd/radish>`_.

|Build Status| |PyPI package version| |PyPI python versions|


Installing
----------

.. code:: bash

    $ pip install tag-expressions

Here is a tease
---------------


.. code:: python

    >>> from tagexpressions import parse
    >>>
    >>> expression = '( a and b ) or ( c and d )'
    >>> compiled_expression = parse(expression)
    >>> print(compiled_expression)
    ( ( a and b ) or ( c and d ) )
    >>>
    >>> data = ['a', 'b', 'c', 'd']
    >>> assert compiled_expression.evaluate(data) == True
    >>>
    >>> data = ['a', 'c']
    >>> assert compiled_expression.evaluate(data) == False
    >>>
    >>>
    >>> expression = 'not a or b and not c or not d or e and f'
    >>> compiled_expression = parse(expression)
    >>> print(compiled_expression)
    ( ( ( not ( a ) or ( b and not ( c ) ) ) or not ( d ) ) or ( e and f ) )
    >>>
    >>> data = ['b', 'e', 'f']
    >>> assert compiled_expression.evaluate(data) == True
    >>>
    >>> data = ['a', 'c', 'd']
    >>> assert compiled_expression.evaluate(data) == False


Usage
-----

Available operators
~~~~~~~~~~~~~~~~~~~

* **or** - "or" conjunction of two given variables
* **and** - "and" conjunction of two given variables
* **not** - negation of a single variable

Every other token given in an *infix* is considered a variable.

Operator precedence
~~~~~~~~~~~~~~~~~~~

From high to low:

* ()
* or
* and
* not

.. |Build Status| image:: https://github.com/timofurrer/tag-expressions/actions/workflows/build.yml/badge.svg
   :target: https://github.com/timofurrer/tag-expressions/actions/workflows/build.yml
.. |PyPI package version| image:: https://badge.fury.io/py/tag-expressions.svg
   :target: https://badge.fury.io/py/tag-expressions
.. |PyPI python versions| image:: https://img.shields.io/pypi/pyversions/tag-expressions.svg
   :target: https://pypi.python.org/pypi/tag-expressions

            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/timofurrer/tag-expressions",
    "name": "tag-expressions",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Timo Furrer",
    "author_email": "tuxtimo@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/74/ef/4a21b9ea08301762a18a1f5b0c84909c7a6dacf75c4eb359915d46348e73/tag_expressions-2.0.1.tar.gz",
    "platform": null,
    "description": "tag-expressions\n===============\n\nPackage to evaluate logical tag expressions by using a modified version of the `Shunting Yard algorithm <https://en.wikipedia.org/wiki/Shunting-yard_algorithm>`_.\nThis package is a Python port of cucumbers tag expression.\n\nIt's also used by `radish <https://github.com/radish-bdd/radish>`_.\n\n|Build Status| |PyPI package version| |PyPI python versions|\n\n\nInstalling\n----------\n\n.. code:: bash\n\n    $ pip install tag-expressions\n\nHere is a tease\n---------------\n\n\n.. code:: python\n\n    >>> from tagexpressions import parse\n    >>>\n    >>> expression = '( a and b ) or ( c and d )'\n    >>> compiled_expression = parse(expression)\n    >>> print(compiled_expression)\n    ( ( a and b ) or ( c and d ) )\n    >>>\n    >>> data = ['a', 'b', 'c', 'd']\n    >>> assert compiled_expression.evaluate(data) == True\n    >>>\n    >>> data = ['a', 'c']\n    >>> assert compiled_expression.evaluate(data) == False\n    >>>\n    >>>\n    >>> expression = 'not a or b and not c or not d or e and f'\n    >>> compiled_expression = parse(expression)\n    >>> print(compiled_expression)\n    ( ( ( not ( a ) or ( b and not ( c ) ) ) or not ( d ) ) or ( e and f ) )\n    >>>\n    >>> data = ['b', 'e', 'f']\n    >>> assert compiled_expression.evaluate(data) == True\n    >>>\n    >>> data = ['a', 'c', 'd']\n    >>> assert compiled_expression.evaluate(data) == False\n\n\nUsage\n-----\n\nAvailable operators\n~~~~~~~~~~~~~~~~~~~\n\n* **or** - \"or\" conjunction of two given variables\n* **and** - \"and\" conjunction of two given variables\n* **not** - negation of a single variable\n\nEvery other token given in an *infix* is considered a variable.\n\nOperator precedence\n~~~~~~~~~~~~~~~~~~~\n\nFrom high to low:\n\n* ()\n* or\n* and\n* not\n\n.. |Build Status| image:: https://github.com/timofurrer/tag-expressions/actions/workflows/build.yml/badge.svg\n   :target: https://github.com/timofurrer/tag-expressions/actions/workflows/build.yml\n.. |PyPI package version| image:: https://badge.fury.io/py/tag-expressions.svg\n   :target: https://badge.fury.io/py/tag-expressions\n.. |PyPI python versions| image:: https://img.shields.io/pypi/pyversions/tag-expressions.svg\n   :target: https://pypi.python.org/pypi/tag-expressions\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Built-in functions, types, exceptions, and other objects.",
    "version": "2.0.1",
    "project_urls": {
        "Homepage": "http://github.com/timofurrer/tag-expressions"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8bae5d7ca47dcb8e043110da47b2ff8615b77f2c52bc1502c2c8c1ab713e1096",
                "md5": "a029c6d90ae2f786e4656cb30ee33ed3",
                "sha256": "2b7e544a5b7ed963082e2cd0f0fabca7e914638b679d0c04da125094e7cfa26d"
            },
            "downloads": -1,
            "filename": "tag_expressions-2.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a029c6d90ae2f786e4656cb30ee33ed3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5471,
            "upload_time": "2024-11-23T15:47:58",
            "upload_time_iso_8601": "2024-11-23T15:47:58.324849Z",
            "url": "https://files.pythonhosted.org/packages/8b/ae/5d7ca47dcb8e043110da47b2ff8615b77f2c52bc1502c2c8c1ab713e1096/tag_expressions-2.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "74ef4a21b9ea08301762a18a1f5b0c84909c7a6dacf75c4eb359915d46348e73",
                "md5": "fbc2b2a956711ab9b085eaa0b2965add",
                "sha256": "11b4b07c01feb0bdc9196f8239f0c0d9fedc2c6c8a99032c6f2c831b2d772e48"
            },
            "downloads": -1,
            "filename": "tag_expressions-2.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "fbc2b2a956711ab9b085eaa0b2965add",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6142,
            "upload_time": "2024-11-23T15:48:00",
            "upload_time_iso_8601": "2024-11-23T15:48:00.403895Z",
            "url": "https://files.pythonhosted.org/packages/74/ef/4a21b9ea08301762a18a1f5b0c84909c7a6dacf75c4eb359915d46348e73/tag_expressions-2.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-23 15:48:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "timofurrer",
    "github_project": "tag-expressions",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "tag-expressions"
}
        
Elapsed time: 1.26583s