Skip to content

Commit

Permalink
feat(bindings): add query constants to python
Browse files Browse the repository at this point in the history
  • Loading branch information
ObserverOfTime committed Mar 17, 2024
1 parent 647d2e5 commit 9bd1ae5
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 13 deletions.
19 changes: 17 additions & 2 deletions cli/src/generate/templates/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
"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"]
# NOTE: uncomment these to include any queries that this grammar contains:

# HIGHLIGHTS_QUERY = _files(f"{__package__}.queries").joinpath("highlights.scm").read_text()
# INJECTIONS_QUERY = _files(f"{__package__}.queries").joinpath("injections.scm").read_text()
# LOCALS_QUERY = _files(f"{__package__}.queries").joinpath("locals.scm").read_text()
# TAGS_QUERY = _files(f"{__package__}.queries").joinpath("tags.scm").read_text()

__all__ = [
"language",
# "HIGHLIGHTS_QUERY",
# "INJECTIONS_QUERY",
# "LOCALS_QUERY",
# "TAGS_QUERY",
]
9 changes: 9 additions & 0 deletions cli/src/generate/templates/__init__.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
2 changes: 1 addition & 1 deletion cli/src/generate/templates/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion cli/src/generate/templates/py-binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
6 changes: 3 additions & 3 deletions cli/src/generate/templates/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ classifiers = [
"Topic :: Text Processing :: Linguistic",
"Typing :: Typed"
]
requires-python = ">=3.8"
requires-python = ">=3.9"
license.text = "MIT"
readme = "README.md"

[project.urls]
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"
15 changes: 9 additions & 6 deletions cli/src/generate/templates/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -38,12 +38,15 @@ def get_tag(self):
"src/parser.c",
# NOTE: if your language uses an external scanner, add it here.
],
extra_compile_args=(
["-std=c11"] if system() != 'Windows' else []
),
extra_compile_args=[
"-std=c11",
"-fvisibility=hidden",
] if system() != "Windows" else [],
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),
("TREE_SITTER_REUSE_ALLOCATOR", None),
],
include_dirs=["src"],
py_limited_api=True,
Expand Down

0 comments on commit 9bd1ae5

Please sign in to comment.