Skip to main content

Binary Python wheels for all tree sitter languages (Freed-Wu PR).

Project description

This is a fork!

It is based on @Freed_Wu’s pull request which adds support for many additional tree-sitter language parsers beyond the original.

As the package seems unmaintained, I decided to fork it based on the PR. Note that this version may not see additional support and you should switch back to the original once it gets going again.

The package has been renamed to avoid collision with the original.

The Windows and ARM Arch64 packages still only get the original languages, for Windows because the extended commandline busted the link.exe command line length limit, and for ARM Arch64 because the Github action uses QEMU to build on ARM, which is slow, so the additional languages cause the Github runner to time out.

Original README

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.

This package is based on

Install

pip install tree_sitter_languages_freed_wu_pr

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

  1. setup.py — Python package setup.

  2. parsers.json, lockfile.json — Json files that contain 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_freed_wu_pr 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_freed_wu_pr 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-2023 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

tree_sitter_languages_freed_wu_pr-1.11.1-cp312-cp312-win_amd64.whl (6.9 MB view hashes)

Uploaded CPython 3.12 Windows x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp312-cp312-win32.whl (7.0 MB view hashes)

Uploaded CPython 3.12 Windows x86

tree_sitter_languages_freed_wu_pr-1.11.1-cp312-cp312-musllinux_1_1_x86_64.whl (19.2 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp312-cp312-musllinux_1_1_i686.whl (19.8 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

tree_sitter_languages_freed_wu_pr-1.11.1-cp312-cp312-musllinux_1_1_aarch64.whl (6.9 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ ARM64

tree_sitter_languages_freed_wu_pr-1.11.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (19.2 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (19.8 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

tree_sitter_languages_freed_wu_pr-1.11.1-cp312-cp312-macosx_11_0_arm64.whl (25.3 MB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

tree_sitter_languages_freed_wu_pr-1.11.1-cp312-cp312-macosx_10_9_x86_64.whl (22.7 MB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp311-cp311-win_amd64.whl (6.9 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp311-cp311-win32.whl (7.0 MB view hashes)

Uploaded CPython 3.11 Windows x86

tree_sitter_languages_freed_wu_pr-1.11.1-cp311-cp311-musllinux_1_1_x86_64.whl (19.2 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp311-cp311-musllinux_1_1_i686.whl (19.8 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

tree_sitter_languages_freed_wu_pr-1.11.1-cp311-cp311-musllinux_1_1_aarch64.whl (6.9 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ ARM64

tree_sitter_languages_freed_wu_pr-1.11.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (19.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (19.8 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

tree_sitter_languages_freed_wu_pr-1.11.1-cp311-cp311-macosx_11_0_arm64.whl (25.3 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

tree_sitter_languages_freed_wu_pr-1.11.1-cp311-cp311-macosx_10_9_x86_64.whl (22.7 MB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp310-cp310-win_amd64.whl (6.9 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp310-cp310-win32.whl (7.0 MB view hashes)

Uploaded CPython 3.10 Windows x86

tree_sitter_languages_freed_wu_pr-1.11.1-cp310-cp310-musllinux_1_1_x86_64.whl (19.2 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp310-cp310-musllinux_1_1_i686.whl (19.8 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

tree_sitter_languages_freed_wu_pr-1.11.1-cp310-cp310-musllinux_1_1_aarch64.whl (6.9 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ ARM64

tree_sitter_languages_freed_wu_pr-1.11.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (19.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (19.8 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

tree_sitter_languages_freed_wu_pr-1.11.1-cp310-cp310-macosx_11_0_arm64.whl (25.3 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

tree_sitter_languages_freed_wu_pr-1.11.1-cp310-cp310-macosx_10_9_x86_64.whl (22.7 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp39-cp39-win_amd64.whl (6.9 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp39-cp39-win32.whl (7.0 MB view hashes)

Uploaded CPython 3.9 Windows x86

tree_sitter_languages_freed_wu_pr-1.11.1-cp39-cp39-musllinux_1_1_x86_64.whl (19.2 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp39-cp39-musllinux_1_1_i686.whl (19.8 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

tree_sitter_languages_freed_wu_pr-1.11.1-cp39-cp39-musllinux_1_1_aarch64.whl (6.9 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ ARM64

tree_sitter_languages_freed_wu_pr-1.11.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (19.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (19.8 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

tree_sitter_languages_freed_wu_pr-1.11.1-cp39-cp39-macosx_11_0_arm64.whl (25.3 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

tree_sitter_languages_freed_wu_pr-1.11.1-cp39-cp39-macosx_10_9_x86_64.whl (22.7 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp38-cp38-win_amd64.whl (6.9 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp38-cp38-win32.whl (7.0 MB view hashes)

Uploaded CPython 3.8 Windows x86

tree_sitter_languages_freed_wu_pr-1.11.1-cp38-cp38-musllinux_1_1_x86_64.whl (19.2 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp38-cp38-musllinux_1_1_i686.whl (19.8 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

tree_sitter_languages_freed_wu_pr-1.11.1-cp38-cp38-musllinux_1_1_aarch64.whl (6.9 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ ARM64

tree_sitter_languages_freed_wu_pr-1.11.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (19.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (19.8 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

tree_sitter_languages_freed_wu_pr-1.11.1-cp38-cp38-macosx_11_0_arm64.whl (25.3 MB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

tree_sitter_languages_freed_wu_pr-1.11.1-cp38-cp38-macosx_10_9_x86_64.whl (22.7 MB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp37-cp37m-win_amd64.whl (6.9 MB view hashes)

Uploaded CPython 3.7m Windows x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp37-cp37m-win32.whl (7.0 MB view hashes)

Uploaded CPython 3.7m Windows x86

tree_sitter_languages_freed_wu_pr-1.11.1-cp37-cp37m-musllinux_1_1_x86_64.whl (19.2 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp37-cp37m-musllinux_1_1_i686.whl (19.8 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ i686

tree_sitter_languages_freed_wu_pr-1.11.1-cp37-cp37m-musllinux_1_1_aarch64.whl (6.9 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ ARM64

tree_sitter_languages_freed_wu_pr-1.11.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (19.2 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

tree_sitter_languages_freed_wu_pr-1.11.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (19.8 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

tree_sitter_languages_freed_wu_pr-1.11.1-cp37-cp37m-macosx_10_9_x86_64.whl (22.7 MB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

Supported by

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