A concrete syntax tree parser and serializer library for Python that preserves many aspects of Python's abstract syntax tree https://libcst.readthedocs.io/
Find a file
2019-07-23 18:57:47 -07:00
.circleci add sphinx autodoc templates and docs CI job 2019-07-22 20:05:27 -07:00
.github add initial PULL_REQUEST_TEMPLATE.md 2019-07-22 19:59:57 -07:00
docs/source reuse README intro section in doc 2019-07-23 18:57:47 -07:00
libcst Rename 'matchers' 2019-07-23 13:13:53 -07:00
stubs Add runtime type validation support 2019-07-22 19:53:49 -07:00
.editorconfig Add config files to make tools easier to use 2019-07-22 19:53:49 -07:00
.flake8 Remove Instagram-specific bits from flake8 config 2019-07-22 20:05:07 -07:00
.gitignore add sphinx autodoc templates and docs CI job 2019-07-22 20:05:27 -07:00
.pyre_configuration add pyre CI job 2019-07-22 20:04:29 -07:00
CODE_OF_CONDUCT.md add Code Of Conduct file 2019-07-22 19:59:50 -07:00
CONTRIBUTING.md add test command and rephrase coding style. 2019-07-22 19:59:57 -07:00
LICENSE first commit 2019-05-29 11:32:49 -07:00
pyproject.toml Add config files to make tools easier to use 2019-07-22 19:53:49 -07:00
README.rst reuse README intro section in doc 2019-07-23 18:57:47 -07:00
requirements-dev.txt add sphinx autodoc templates and docs CI job 2019-07-22 20:05:27 -07:00
requirements.txt Add runtime type validation support 2019-07-22 19:53:49 -07:00
setup.py use rst format for README 2019-07-23 16:10:03 -07:00
tox.ini add sphinx autodoc templates and docs CI job 2019-07-22 20:05:27 -07:00

======
LibCST
======

|circleci_badge|

.. intro-start

.. |circleci_badge| image:: https://circleci.com/gh/Instagram/LibCST/tree/master.svg?style=svg&circle-token=f89ff46c689cf53116308db295a492d687bf5732
   :target: https://circleci.com/gh/Instagram/LibCST/tree/master
   :alt: CircleCI

LibCST is a Concrete Syntax Tree (CST) parser and serializer library for Python Code. It parses Python sources code as CST tree and keeps all formatting detail (comments, whitespaces, parentheses, etc). It's useful for building Code Modifier (codemod) application, code formatter, etc.

.. intro-end

Getting Started
===============

Examining a sample tree
-----------------------

To examine the tree that is parsed from a particular file, do the following:

.. code-block:: shell

    python -m libcst.tool print <some_py_file.py>

Development
-----------

Start by setting up and activating a virtualenv:

.. code-block:: shell

    git clone git@github.com:Instagram/LibCST.git libcst
    cd libcst
    python3 -m venv ../libcst-env/  # just an example, put this wherever you want
    source ../libcst-env/bin/activate
    pip install --upgrade pip  # optional, if you have an old system version of pip
    pip install -r requirements.txt -r requirements-dev.txt
    # If you're done with the virtualenv, you can leave it by running:
    deactivate

We use isort and black to format code. To format changes to be conformant, run
the following in the root:

.. code-block:: shell

    isort -q -y && black libcst/

To run all tests, do the following in the root:

.. code-block:: shell

    tox -e py37

To verify types for the library, do the following in the root:

.. code-block:: shell

    pyre check

To generate documents, do the following in the root:

.. code-block:: shell

    tox -e docs

License
=======

LibCST is MIT licensed, as found in the LICENSE file.