Skip to main content

Binary Python wheels for all tree sitter languages.

Project description

Binary Python wheels for all tree sitter languages.

py-tree-sitter is a fantastic library that provides Python bindings for the even more fantastic tree-sitter parsing library.

py-tree-sitter-languages provides binary Python wheels for all tree sitter languages. The binary wheels remove the need to download and compile support for individual languages.

Install

pip install tree_sitter_languages

Source installs are not supported. To see how the binary wheels are built, look at:

  1. setup.py — Python package setup.

  2. repos.txt — Text file that contains a list of included language repositories and their commit hashes.

  3. build.py — Python script to download and build the language repositories.

  4. .github/workflows/release.yml — GitHub action to invoke cibuildwheel and release to PyPI.

Usage

from tree_sitter_languages import get_language, get_parser

language = get_language('python')
parser = get_parser('python')

That’s the whole API!

Refer to py-tree-sitter for the language and parser API. Notice the Language.build_library(...) step can be skipped! The binary wheel includes the language binary.

Demo

Want to know something crazy? Python lacks multi-line comments. Whhaaa!?!

It’s really not such a big deal. Instead of writing:

"""
My awesome
multi-line
comment.
"""

Simply write:

# My awesome
# multi-line
# comment.

So multi-line comments are made by putting multiple single-line comments in sequence. Amazing!

Now, how to find all the strings being used as comments?

Start with some example Python code:

example = """
#!shebang
# License blah blah (Apache 2.0)
"This is a module docstring."

a = 1

'''This
is
not
a
multiline
comment.'''

b = 2

class Test:
    "This is a class docstring."

    'This is bogus.'

    def test(self):
        "This is a function docstring."

        "Please, no."

        return 1

c = 3
"""

Notice a couple things:

  1. Python has module, class, and function docstrings that bare a striking resemblance to the phony string comments.

  2. Python supports single-quoted, double-quoted, triple-single-quoted, and triple-double-quoted strings (not to mention prefixes for raw strings, unicode strings, and more).

Creating a regular expression to capture the phony string comments would be exceedingly difficult!

Enter tree-sitter:

from tree_sitter_languages import get_language, get_parser

language = get_language('python')
parser = get_parser('python')

Tree-sitter creates an abstract syntax tree (actually, a concrete syntax tree) and supports queries:

tree = parser.parse(example.encode())
node = tree.root_node
print(node.sexp())

Look for statements that are a single string expression:

stmt_str_pattern = '(expression_statement (string)) @stmt_str'
stmt_str_query = language.query(stmt_str_pattern)
stmt_strs = stmt_str_query.captures(node)
stmt_str_points = set(
    (node.start_point, node.end_point) for node, _ in stmt_strs
)
print(stmt_str_points)

Now, find those statement string expressions that are actually module, class, or function docstrings:

doc_str_pattern = """
    (module . (comment)* . (expression_statement (string)) @module_doc_str)

    (class_definition
        body: (block . (expression_statement (string)) @class_doc_str))

    (function_definition
        body: (block . (expression_statement (string)) @function_doc_str))
"""
doc_str_query = language.query(doc_str_pattern)
doc_strs = doc_str_query.captures(node)
doc_str_points = set(
    (node.start_point, node.end_point) for node, _ in doc_strs
)

With the set of string expression statements and the set of docstring statements, the locations of all phony string comments is:

comment_strs = stmt_str_points - doc_str_points
print(sorted(comment_strs))

License

Copyright 2022 Grant Jenks

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

The project also includes the following other projects distributed in binary form:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tree_sitter_languages_arm64-1.6.0-cp311-cp311-musllinux_1_1_aarch64.whl (5.9 MB view details)

Uploaded CPython 3.11musllinux: musl 1.1+ ARM64

tree_sitter_languages_arm64-1.6.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

tree_sitter_languages_arm64-1.6.0-cp310-cp310-musllinux_1_1_aarch64.whl (5.9 MB view details)

Uploaded CPython 3.10musllinux: musl 1.1+ ARM64

tree_sitter_languages_arm64-1.6.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

tree_sitter_languages_arm64-1.6.0-cp39-cp39-musllinux_1_1_aarch64.whl (5.9 MB view details)

Uploaded CPython 3.9musllinux: musl 1.1+ ARM64

tree_sitter_languages_arm64-1.6.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

tree_sitter_languages_arm64-1.6.0-cp38-cp38-musllinux_1_1_aarch64.whl (5.9 MB view details)

Uploaded CPython 3.8musllinux: musl 1.1+ ARM64

tree_sitter_languages_arm64-1.6.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

tree_sitter_languages_arm64-1.6.0-cp37-cp37m-musllinux_1_1_aarch64.whl (5.9 MB view details)

Uploaded CPython 3.7mmusllinux: musl 1.1+ ARM64

tree_sitter_languages_arm64-1.6.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ ARM64

tree_sitter_languages_arm64-1.6.0-cp36-cp36m-musllinux_1_1_aarch64.whl (5.9 MB view details)

Uploaded CPython 3.6mmusllinux: musl 1.1+ ARM64

tree_sitter_languages_arm64-1.6.0-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.4 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ ARM64

File details

Details for the file tree_sitter_languages_arm64-1.6.0-cp311-cp311-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_languages_arm64-1.6.0-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 7e6f36fdc344dd62d2cf24ff226eeabc9f1922ce0df2d3cc90124f6ff0cc720a
MD5 dbd446486e1fb33d0883788587fd6d1f
BLAKE2b-256 5475c5138a4ea49db86277090bb0e1ee75dac085158c932ace616a928333c13d

See more details on using hashes here.

File details

Details for the file tree_sitter_languages_arm64-1.6.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_languages_arm64-1.6.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ca213e170e902b3b53c38b786bee37e5104a11378527885ede7b7a8f3905d683
MD5 030a484714d8cf26e4e2c44e80c9def4
BLAKE2b-256 4b86cb43a35a5b0bcc916709cca970a6bc63115971eae0cb5e8a84c5a778a045

See more details on using hashes here.

File details

Details for the file tree_sitter_languages_arm64-1.6.0-cp310-cp310-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_languages_arm64-1.6.0-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 84893dbb000236103027b8bb9a8822f2fcf0ff624e1f09634fe04c5111b3fc4a
MD5 66307253b6415b355ec92ca7fa87ba99
BLAKE2b-256 115896338926d2e46549348432cdeab08718b78c15e4e88eb0b9f29d0a70378c

See more details on using hashes here.

File details

Details for the file tree_sitter_languages_arm64-1.6.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_languages_arm64-1.6.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b754eaf871ed851ac2b622a7708c7fa3b5474987baec667af2b00e337a516bdd
MD5 2eb2ff6a6f8d3d71f33ffce3cc9a90a4
BLAKE2b-256 97a85ed4da85b751f429d05f44332cfe59ad4e19cb4315f46a86142398e0574b

See more details on using hashes here.

File details

Details for the file tree_sitter_languages_arm64-1.6.0-cp39-cp39-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_languages_arm64-1.6.0-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 03560c4067e3077b004f52502c497bf105f816e9706563683a06f59e59e03c3b
MD5 6b3427df7e15f54c9cdb8b122e7897e2
BLAKE2b-256 cd29b80ccd3a6f81d751fb0b601f53bcf9f06f0994053c52f766a48d21f2108f

See more details on using hashes here.

File details

Details for the file tree_sitter_languages_arm64-1.6.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_languages_arm64-1.6.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 836425a716a4606241c77bcf617504905984f02c7ad75f9ccc7d9d5a2004f429
MD5 6dfd4f2d8a9887577f00fb04391c4fad
BLAKE2b-256 048ad7f7b6e216fe1ec3947885971a92aac4a4338a36e8db5ef3ccf995150cb9

See more details on using hashes here.

File details

Details for the file tree_sitter_languages_arm64-1.6.0-cp38-cp38-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_languages_arm64-1.6.0-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 2086a16bd6301bfddf70f4a250a2cfef7789ab355c5c7c4100d16f3b01496612
MD5 6ca193b5de6d149b18cedc19b4ffa83d
BLAKE2b-256 8e8ee5e2c2ed0e33828de073d6e9c097b3725d6a172270ee211a8d4140d5a5e8

See more details on using hashes here.

File details

Details for the file tree_sitter_languages_arm64-1.6.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_languages_arm64-1.6.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 81d388996105b4043747f31777b24722591500789995655735b8ad4326effc25
MD5 7b4cb4b0a7e88953073500c20a53c164
BLAKE2b-256 6c740afa600e6ae2898f7f99956c1ff43db96d796a3d6106d5049fe98f222e7f

See more details on using hashes here.

File details

Details for the file tree_sitter_languages_arm64-1.6.0-cp37-cp37m-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_languages_arm64-1.6.0-cp37-cp37m-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 c4fbcda17b231b84b4fa0839f3be8bbf31e1219f39d1b67030053758974f73bd
MD5 2af8e78a2de29b3e2b75fb3a23fe7f9a
BLAKE2b-256 e0f4cebacc6c9da976c069844a59858b84a27d7efcc3e616b507038b3add2499

See more details on using hashes here.

File details

Details for the file tree_sitter_languages_arm64-1.6.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_languages_arm64-1.6.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b35ff527e1589390452f2f852dd624c6d23a6a2852bae7c582a832b7cb0ca4c6
MD5 bcc11377328fe3580be276d33afa8dd9
BLAKE2b-256 a06d275d7f0e689be2bf2dafed73f605609cf598d3dfcdc26c44762289c2340a

See more details on using hashes here.

File details

Details for the file tree_sitter_languages_arm64-1.6.0-cp36-cp36m-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_languages_arm64-1.6.0-cp36-cp36m-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 85e4078de042dd3328dd24a55de60345ee5bef9c9aa690cbd7bcd58c64001975
MD5 66b37dc19fcf6f1263060b9e2b589999
BLAKE2b-256 30d1fd738aa848b286043a530e9fd8ab2a813cde7133bd67e11a52918a8ac3ee

See more details on using hashes here.

File details

Details for the file tree_sitter_languages_arm64-1.6.0-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_languages_arm64-1.6.0-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 84c017545a6b6637265cc665cef396e2df7bd3d28e93f128f24eee911517c4b9
MD5 aad5e1742c1764692a3ed2e94b2321e0
BLAKE2b-256 66c4eb00f373179056b7afc295361eff526cc573bfab7a85b28667908ecef6d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page