astor


Nameastor JSON
Version 0.8.1 PyPI version JSON
download
home_pagehttps://github.com/berkerpeksag/astor
SummaryRead/rewrite/write Python ASTs
upload_time2019-12-10 01:50:35
maintainer
docs_urlNone
authorPatrick Maupin
requires_python!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7
licenseBSD-3-Clause
keywords ast codegen pep 8
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            =============================
astor -- AST observe/rewrite
=============================

:PyPI: https://pypi.org/project/astor/
:Documentation: https://astor.readthedocs.io
:Source: https://github.com/berkerpeksag/astor
:License: 3-clause BSD
:Build status:
    .. image:: https://secure.travis-ci.org/berkerpeksag/astor.svg
        :alt: Travis CI
        :target: https://travis-ci.org/berkerpeksag/astor/

astor is designed to allow easy manipulation of Python source via the AST.

There are some other similar libraries, but astor focuses on the following areas:

- Round-trip an AST back to Python [1]_:

  - Modified AST doesn't need linenumbers, ctx, etc. or otherwise
    be directly compileable for the round-trip to work.
  - Easy to read generated code as, well, code
  - Can round-trip two different source trees to compare for functional
    differences, using the astor.rtrip tool (for example, after PEP8 edits).

- Dump pretty-printing of AST

  - Harder to read than round-tripped code, but more accurate to figure out what
    is going on.

  - Easier to read than dump from built-in AST module

- Non-recursive treewalk

  - Sometimes you want a recursive treewalk (and astor supports that, starting
    at any node on the tree), but sometimes you don't need to do that.  astor
    doesn't require you to explicitly visit sub-nodes unless you want to:

  - You can add code that executes before a node's children are visited, and/or
  - You can add code that executes after a node's children are visited, and/or
  - You can add code that executes and keeps the node's children from being
    visited (and optionally visit them yourself via a recursive call)

  - Write functions to access the tree based on object names and/or attribute names
  - Enjoy easy access to parent node(s) for tree rewriting

.. [1]
    The decompilation back to Python is based on code originally written
    by Armin Ronacher.  Armin's code was well-structured, but failed on
    some obscure corner cases of the Python language (and even more corner
    cases when the AST changed on different versions of Python), and its
    output arguably had cosmetic issues -- for example, it produced
    parentheses even in some cases where they were not needed, to
    avoid having to reason about precedence.

    Other derivatives of Armin's code are floating around, and typically
    have fixes for a few corner cases that happened to be noticed by the
    maintainers, but most of them have not been tested as thoroughly as
    astor.  One exception may be the version of codegen
    `maintained at github by CensoredUsername`__.  This has been tested
    to work properly on Python 2.7 using astor's test suite, and, as it
    is a single source file, it may be easier to drop into some applications
    that do not require astor's other features or Python 3.x compatibility.

__ https://github.com/CensoredUsername/codegen



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/berkerpeksag/astor",
    "name": "astor",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7",
    "maintainer_email": "",
    "keywords": "ast,codegen,PEP 8",
    "author": "Patrick Maupin",
    "author_email": "pmaupin@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/5a/21/75b771132fee241dfe601d39ade629548a9626d1d39f333fde31bc46febe/astor-0.8.1.tar.gz",
    "platform": "Independent",
    "description": "=============================\nastor -- AST observe/rewrite\n=============================\n\n:PyPI: https://pypi.org/project/astor/\n:Documentation: https://astor.readthedocs.io\n:Source: https://github.com/berkerpeksag/astor\n:License: 3-clause BSD\n:Build status:\n    .. image:: https://secure.travis-ci.org/berkerpeksag/astor.svg\n        :alt: Travis CI\n        :target: https://travis-ci.org/berkerpeksag/astor/\n\nastor is designed to allow easy manipulation of Python source via the AST.\n\nThere are some other similar libraries, but astor focuses on the following areas:\n\n- Round-trip an AST back to Python [1]_:\n\n  - Modified AST doesn't need linenumbers, ctx, etc. or otherwise\n    be directly compileable for the round-trip to work.\n  - Easy to read generated code as, well, code\n  - Can round-trip two different source trees to compare for functional\n    differences, using the astor.rtrip tool (for example, after PEP8 edits).\n\n- Dump pretty-printing of AST\n\n  - Harder to read than round-tripped code, but more accurate to figure out what\n    is going on.\n\n  - Easier to read than dump from built-in AST module\n\n- Non-recursive treewalk\n\n  - Sometimes you want a recursive treewalk (and astor supports that, starting\n    at any node on the tree), but sometimes you don't need to do that.  astor\n    doesn't require you to explicitly visit sub-nodes unless you want to:\n\n  - You can add code that executes before a node's children are visited, and/or\n  - You can add code that executes after a node's children are visited, and/or\n  - You can add code that executes and keeps the node's children from being\n    visited (and optionally visit them yourself via a recursive call)\n\n  - Write functions to access the tree based on object names and/or attribute names\n  - Enjoy easy access to parent node(s) for tree rewriting\n\n.. [1]\n    The decompilation back to Python is based on code originally written\n    by Armin Ronacher.  Armin's code was well-structured, but failed on\n    some obscure corner cases of the Python language (and even more corner\n    cases when the AST changed on different versions of Python), and its\n    output arguably had cosmetic issues -- for example, it produced\n    parentheses even in some cases where they were not needed, to\n    avoid having to reason about precedence.\n\n    Other derivatives of Armin's code are floating around, and typically\n    have fixes for a few corner cases that happened to be noticed by the\n    maintainers, but most of them have not been tested as thoroughly as\n    astor.  One exception may be the version of codegen\n    `maintained at github by CensoredUsername`__.  This has been tested\n    to work properly on Python 2.7 using astor's test suite, and, as it\n    is a single source file, it may be easier to drop into some applications\n    that do not require astor's other features or Python 3.x compatibility.\n\n__ https://github.com/CensoredUsername/codegen\n\n\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "Read/rewrite/write Python ASTs",
    "version": "0.8.1",
    "split_keywords": [
        "ast",
        "codegen",
        "pep 8"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "a43c3b3dee5b722633589c5a37774feb",
                "sha256": "070a54e890cefb5b3739d19f30f5a5ec840ffc9c50ffa7d23cc9fc1a38ebbfc5"
            },
            "downloads": -1,
            "filename": "astor-0.8.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a43c3b3dee5b722633589c5a37774feb",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7",
            "size": 27488,
            "upload_time": "2019-12-10T01:50:33",
            "upload_time_iso_8601": "2019-12-10T01:50:33.628982Z",
            "url": "https://files.pythonhosted.org/packages/c3/88/97eef84f48fa04fbd6750e62dcceafba6c63c81b7ac1420856c8dcc0a3f9/astor-0.8.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "83ab4ee6598f0381d94ed6949a6d6da2",
                "sha256": "6a6effda93f4e1ce9f618779b2dd1d9d84f1e32812c23a29b3fff6fd7f63fa5e"
            },
            "downloads": -1,
            "filename": "astor-0.8.1.tar.gz",
            "has_sig": false,
            "md5_digest": "83ab4ee6598f0381d94ed6949a6d6da2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7",
            "size": 35090,
            "upload_time": "2019-12-10T01:50:35",
            "upload_time_iso_8601": "2019-12-10T01:50:35.510670Z",
            "url": "https://files.pythonhosted.org/packages/5a/21/75b771132fee241dfe601d39ade629548a9626d1d39f333fde31bc46febe/astor-0.8.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2019-12-10 01:50:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "berkerpeksag",
    "github_project": "astor",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": false,
    "tox": true,
    "lcname": "astor"
}
        
Elapsed time: 0.01914s