diff --git a/pyproject.toml b/pyproject.toml index 9ec377c..96be34f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,3 @@ -[build-system] -requires = ["setuptools>=43"] -build-backend = "setuptools.build_meta" - [project] name = "tree-sitter" version = "0.25.1" @@ -34,13 +30,17 @@ email = "maxbrunsfeld@gmail.com" [project.optional-dependencies] docs = ["sphinx~=8.1", "sphinx-book-theme"] tests = [ - "tree-sitter-html>=0.23.2", - "tree-sitter-javascript>=0.23.1", - "tree-sitter-json>=0.24.8", - "tree-sitter-python>=0.23.6", - "tree-sitter-rust>=0.23.2", + "tree-sitter-html==0.23.2", + "tree-sitter-javascript==0.25.0", + "tree-sitter-json==0.24.8", + "tree-sitter-python==0.25.0", + "tree-sitter-rust==0.24.0", ] +[build-system] +requires = ["setuptools>=43"] +build-backend = "setuptools.build_meta" + [tool.ruff] target-version = "py310" line-length = 100 diff --git a/setup.py b/setup.py index 7a921fe..76e1ce3 100644 --- a/setup.py +++ b/setup.py @@ -3,6 +3,11 @@ from setuptools import Extension, setup # type: ignore from setuptools.command.build_ext import build_ext +with open("pyproject.toml") as f: + next(f) # skip [project] + next(f) # skip name = "tree-sitter" + version = next(f).replace("version = ", "", 1) + class BuildExt(build_ext): def build_extension(self, ext: Extension): @@ -57,6 +62,7 @@ def build_extension(self, ext: Extension): ("_DEFAULT_SOURCE", None), ("PY_SSIZE_T_CLEAN", None), ("TREE_SITTER_HIDE_SYMBOLS", None), + ("PY_TS_VERSION", version), ], ) ], diff --git a/tree_sitter/__init__.pyi b/tree_sitter/__init__.pyi index f68eac6..43435ab 100644 --- a/tree_sitter/__init__.pyi +++ b/tree_sitter/__init__.pyi @@ -414,3 +414,5 @@ class Range: LANGUAGE_VERSION: Final[int] MIN_COMPATIBLE_LANGUAGE_VERSION: Final[int] + +__version__: Final[str] diff --git a/tree_sitter/binding/module.c b/tree_sitter/binding/module.c index ab9990a..55fb515 100644 --- a/tree_sitter/binding/module.c +++ b/tree_sitter/binding/module.c @@ -158,6 +158,8 @@ PyMODINIT_FUNC PyInit__binding(void) { PyModule_AddIntConstant(module, "MIN_COMPATIBLE_LANGUAGE_VERSION", TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION); + PyModule_AddStringConstant(module, "__version__", PY_TS_VERSION); + #ifdef Py_GIL_DISABLED PyUnstable_Module_SetGIL(module, Py_MOD_GIL_USED); #endif