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
Benjamin Woodruff d4551da477 Improve setup.py compatibility
- Add `libcst/__init__.py` back which I accidentally deleted in another
  commit.
- Add `*.egg-info/` to the gitignore, because `libcst.egg-info` is it's
  created by pip/setuptools when locally installing libcst, and it's
  annoying.
- Changed the version number from `0.1.dev` to `0.1.dev0`, since pip was
  warning that it was normalizing the version number from the former to
  the later.
- Add a `python_requires` field, since we know that libcst only works on
  3.6+.
- Add an `install_requires`. Pip uses this to find dependencies, and
  ignores `requirements.txt` (since `requirements.txt` is really only
  intended to be a freeze file).
- Add the dataclasses backport as a dependency for Python 3.6. I
  validated that installing and using libcst works in both 3.6 and 3.7.

**Test Plan:**

```
$ python3 -m venv libcst-install-test  # my system python is 3.7

$ libcst-install-test/bin/pip install --upgrade pip ipython
Cache entry deserialization failed, entry ignored
Collecting pip
  Using cached
  be401c0032/pip-19.1.1-py2.py3-none-any.whl
Collecting ipython
...  # lots of output

$ ~/libcst-install-test/bin/pip install ~/libcst/
Processing ./libcst
Requirement already satisfied: parso in
./libcst-install-test/lib/python3.7/site-packages (from
libcst==0.1.dev0) (0.4.0)
Collecting typing_extensions (from libcst==0.1.dev0)
  Using cached
  c66e553258/typing_extensions-3.7.2-py3-none-any.whl
Installing collected packages: typing-extensions, libcst
  Running setup.py install for libcst ... done
  Successfully installed libcst-0.1.dev0 typing-extensions-3.7.2

$ ~/libcst-install-test/bin/ipython
Python 3.7.3 (default, Apr  3 2019, 05:39:12)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.5.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from libcst import parser

In [2]: parser.parse_expression("None")
Out[2]:
Name(
    value='None',
    lpar=[],
    rpar=[],
)

In [3]:
```

I then repeated the same with a copy of CPython 3.6 that I built from
source.
2019-06-06 15:37:27 -07:00
libcst Improve setup.py compatibility 2019-06-06 15:37:27 -07:00
stubs Initial export of LibCST to github. 2019-05-31 14:16:53 -07:00
.gitignore Improve setup.py compatibility 2019-06-06 15:37:27 -07:00
LICENSE first commit 2019-05-29 11:32:49 -07:00
README.md Initial export of LibCST to github. 2019-05-31 14:16:53 -07:00
requirements.txt Initial export of LibCST to github. 2019-05-31 14:16:53 -07:00
setup.py Improve setup.py compatibility 2019-06-06 15:37:27 -07:00

LibCST

TODO: Add documentation.

Auto-formatting code with isort and Black

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

isort -q -w 88 -m 3 -tc -fgw 0 -lai 2 -ca -ns __init__.py -y ; black --target-version py36 libcst/

Running tests

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

find -name "test_*.py" -printf '%P\n' | xargs python3 -m unittest

Verifying types with Pyre

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

pyre --source-directory . --search-path stubs/ check

Examining a sample tree

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

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