feat(bindings): add query constants to python

This commit is contained in:
ObserverOfTime 2024-03-04 14:35:57 +02:00 committed by Amaan Qureshi
parent 4a8be390f0
commit fd0e1c7b5b
No known key found for this signature in database
GPG key ID: E67890ADC4227273
6 changed files with 58 additions and 10 deletions

View file

@ -1,5 +1,42 @@
"CAMEL_PARSER_NAME grammar for tree-sitter"
"""CAMEL_PARSER_NAME grammar for tree-sitter"""
from importlib.resources import files as _files
from ._binding import language
__all__ = ["language"]
def _get_query(name, file):
query = _files(f"{__package__}.queries") / file
globals()[name] = query.read_text()
return globals()[name]
def __getattr__(name):
# NOTE: uncomment these to include any queries that this grammar contains:
# if name == "HIGHLIGHTS_QUERY":
# return _get_query("HIGHLIGHTS_QUERY", "highlights.scm")
# if name == "INJECTIONS_QUERY":
# return _get_query("INJECTIONS_QUERY", "injections.scm")
# if name == "LOCALS_QUERY":
# return _get_query("LOCALS_QUERY", "locals.scm")
# if name == "TAGS_QUERY":
# return _get_query("TAGS_QUERY", "tags.scm")
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
__all__ = [
"language",
# "HIGHLIGHTS_QUERY",
# "INJECTIONS_QUERY",
# "LOCALS_QUERY",
# "TAGS_QUERY",
]
def __dir__():
return sorted(__all__ + [
"__all__", "__builtins__", "__cached__", "__doc__", "__file__",
"__loader__", "__name__", "__package__", "__path__", "__spec__",
])

View file

@ -1 +1,10 @@
from typing import Final
# NOTE: uncomment these to include any queries that this grammar contains:
# HIGHLIGHTS_QUERY: Final[str]
# INJECTIONS_QUERY: Final[str]
# LOCALS_QUERY: Final[str]
# TAGS_QUERY: Final[str]
def language() -> int: ...

View file

@ -35,7 +35,7 @@ pub fn language() -> Language {
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
// Uncomment these to include any queries that this grammar contains
// NOTE: uncomment these to include any queries that this grammar contains:
// pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
// pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm");

View file

@ -4,7 +4,7 @@ typedef struct TSLanguage TSLanguage;
TSLanguage *tree_sitter_LOWER_PARSER_NAME(void);
static PyObject* _binding_language(PyObject *self, PyObject *args) {
static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) {
return PyLong_FromVoidPtr(tree_sitter_LOWER_PARSER_NAME());
}

View file

@ -14,7 +14,7 @@ classifiers = [
"Topic :: Text Processing :: Linguistic",
"Typing :: Typed"
]
requires-python = ">=3.8"
requires-python = ">=3.9"
license.text = "MIT"
readme = "README.md"
@ -22,8 +22,8 @@ readme = "README.md"
Homepage = "https://github.com/tree-sitter/tree-sitter-PARSER_NAME"
[project.optional-dependencies]
core = ["tree-sitter~=0.21"]
core = ["tree-sitter~=0.22"]
[tool.cibuildwheel]
build = "cp38-*"
build = "cp39-*"
build-frontend = "build"

View file

@ -18,7 +18,7 @@ class BdistWheel(bdist_wheel):
def get_tag(self):
python, abi, platform = super().get_tag()
if python.startswith("cp"):
python, abi = "cp38", "abi3"
python, abi = "cp39", "abi3"
return python, abi, platform
@ -40,13 +40,15 @@ setup(
],
extra_compile_args=[
"-std=c11",
"-fvisibility=hidden",
] if system() != "Windows" else [
"/std:c11",
"/utf-8",
],
define_macros=[
("Py_LIMITED_API", "0x03080000"),
("PY_SSIZE_T_CLEAN", None)
("Py_LIMITED_API", "0x03090000"),
("PY_SSIZE_T_CLEAN", None),
("TREE_SITTER_HIDE_SYMBOLS", None),
],
include_dirs=["src"],
py_limited_api=True,