constable


Nameconstable JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://github.com/saurabh0719/constable
SummaryOne decorator for lazy debugging. Inserts print statements directly into your AST.
upload_time2024-04-12 15:03:46
maintainerNone
docs_urlNone
authorSaurabh Pujari
requires_pythonNone
licenseMIT
keywords debugger decorator tracker state tracker variable state timer
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            constable
--------------

constable allows you to monitor the state of specified variables at each assignment operation, providing a step-by-step view of variable changes!

View the `Github repository <https://github.com/saurabh0719/constable>`__ and the `official docs <https://github.com/saurabh0719/constable#README>`__.


How does it work?
~~~~~~~~~~~~~~~~~~

The `constable.trace` decorator uses Python's Abstract Syntax Tree (AST) in much the same way we add `print`(s) to debug states. During runtime, it prepares and inserts `print` statements into the function's AST after every assignment operation (`ast.Assign`, `ast.AugAssign` and `ast.AnnAssign`), and then executes the modified code in a separate namespace with `exec`.


.. code:: sh

    $ pip install constable

Tested for python 3.8 and above.


Usage :
~~~~~~~~~~~~~


Monitoring functions

.. code:: python

    import constable

    @constable.trace(['a', 'b'])
    def example(a, b):
        a = a + b
        c = a
        a = "Experimenting with the AST"
        b = c + b
        a = c + b
        return a

    example(5, 6)


Output :

::

    constable.trace: example:19 -
        a = a + b
        a = 11
        type(a) = <class 'int'>

    constable.trace: example:21 -
        a = "Experimenting with the AST"
        a = Experimenting with the AST
        type(a) = <class 'str'>

    constable.trace: example:22 -
        b = c + b
        b = 17
        type(b) = <class 'int'>

    constable.trace: example:23 -
        a = c + b
        a = 28
        type(a) = <class 'int'>

    constable.trace: example -
        args: (5, 6)
        kwargs: {}
        returned: 28
        execution time: 0.00029278 seconds

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/saurabh0719/constable",
    "name": "constable",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "debugger, decorator, tracker, state tracker, variable state, timer",
    "author": "Saurabh Pujari",
    "author_email": "saurabhpuj99@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/a1/60/3ea2190bebd296243d420a57d6afca4fe2706f5bac423956fbbd2029f7ba/constable-0.3.0.tar.gz",
    "platform": null,
    "description": "constable\n--------------\n\nconstable allows you to monitor the state of specified variables at each assignment operation, providing a step-by-step view of variable changes!\n\nView the `Github repository <https://github.com/saurabh0719/constable>`__ and the `official docs <https://github.com/saurabh0719/constable#README>`__.\n\n\nHow does it work?\n~~~~~~~~~~~~~~~~~~\n\nThe `constable.trace` decorator uses Python's Abstract Syntax Tree (AST) in much the same way we add `print`(s) to debug states. During runtime, it prepares and inserts `print` statements into the function's AST after every assignment operation (`ast.Assign`, `ast.AugAssign` and `ast.AnnAssign`), and then executes the modified code in a separate namespace with `exec`.\n\n\n.. code:: sh\n\n    $ pip install constable\n\nTested for python 3.8 and above.\n\n\nUsage :\n~~~~~~~~~~~~~\n\n\nMonitoring functions\n\n.. code:: python\n\n    import constable\n\n    @constable.trace(['a', 'b'])\n    def example(a, b):\n        a = a + b\n        c = a\n        a = \"Experimenting with the AST\"\n        b = c + b\n        a = c + b\n        return a\n\n    example(5, 6)\n\n\nOutput :\n\n::\n\n    constable.trace: example:19 -\n        a = a + b\n        a = 11\n        type(a) = <class 'int'>\n\n    constable.trace: example:21 -\n        a = \"Experimenting with the AST\"\n        a = Experimenting with the AST\n        type(a) = <class 'str'>\n\n    constable.trace: example:22 -\n        b = c + b\n        b = 17\n        type(b) = <class 'int'>\n\n    constable.trace: example:23 -\n        a = c + b\n        a = 28\n        type(a) = <class 'int'>\n\n    constable.trace: example -\n        args: (5, 6)\n        kwargs: {}\n        returned: 28\n        execution time: 0.00029278 seconds\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "One decorator for lazy debugging. Inserts print statements directly into your AST.",
    "version": "0.3.0",
    "project_urls": {
        "Documentation": "https://github.com/saurabh0719/constable#README",
        "Homepage": "https://github.com/saurabh0719/constable",
        "Source": "https://github.com/saurabh0719/constable"
    },
    "split_keywords": [
        "debugger",
        " decorator",
        " tracker",
        " state tracker",
        " variable state",
        " timer"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c7c3a0f100ed446411ab3f0c47d2cb26f56d9b928b220d26b102bf61b61d80f4",
                "md5": "66bc8443b3e7e44134b17ad697ef9ff4",
                "sha256": "308c2848c1c54eac4f257adbbace1eab445397dd24e8d3414ebe23198c4923c8"
            },
            "downloads": -1,
            "filename": "constable-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "66bc8443b3e7e44134b17ad697ef9ff4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5263,
            "upload_time": "2024-04-12T15:03:45",
            "upload_time_iso_8601": "2024-04-12T15:03:45.249644Z",
            "url": "https://files.pythonhosted.org/packages/c7/c3/a0f100ed446411ab3f0c47d2cb26f56d9b928b220d26b102bf61b61d80f4/constable-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a1603ea2190bebd296243d420a57d6afca4fe2706f5bac423956fbbd2029f7ba",
                "md5": "fd94386458ae8c4349bde11f5c47c04b",
                "sha256": "c197e7ebadf1aed6a5538be9fa847fdf0e0a38357cf093a811091dac9c94d4cb"
            },
            "downloads": -1,
            "filename": "constable-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "fd94386458ae8c4349bde11f5c47c04b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5091,
            "upload_time": "2024-04-12T15:03:46",
            "upload_time_iso_8601": "2024-04-12T15:03:46.921403Z",
            "url": "https://files.pythonhosted.org/packages/a1/60/3ea2190bebd296243d420a57d6afca4fe2706f5bac423956fbbd2029f7ba/constable-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-12 15:03:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "saurabh0719",
    "github_project": "constable",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "constable"
}
        
Elapsed time: 0.22592s