diff --git a/pyproject.toml b/pyproject.toml index 4994637..1557737 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "tree-sitter" -version = "0.21.0" +version = "0.21.1" description = "Python bindings for the Tree-Sitter parsing library" keywords = ["incremental", "parsing", "tree-sitter"] classifiers = [ @@ -17,7 +17,7 @@ classifiers = [ "Topic :: Text Processing :: Linguistic", "Typing :: Typed", ] -requires-python = ">=3.8,<3.12" +requires-python = ">=3.8" readme = "README.md" [project.urls] diff --git a/tree_sitter/__init__.py b/tree_sitter/__init__.py index 17ae7fb..86ea7a6 100644 --- a/tree_sitter/__init__.py +++ b/tree_sitter/__init__.py @@ -5,7 +5,7 @@ from os import path from platform import system from tempfile import TemporaryDirectory -from typing import Callable, List, Optional, Union +from typing import List, Optional, Union from warnings import warn from tree_sitter._binding import ( @@ -83,10 +83,14 @@ def build_library(output_path: str, repo_paths: List[str]) -> bool: if max(source_mtimes) <= output_mtime: return False - # local import saves import time in the common case that nothing is - # compiled - from distutils.ccompiler import new_compiler - from distutils.unixccompiler import UnixCCompiler + # local import saves import time in the common case that nothing is compiled + try: + from distutils.ccompiler import new_compiler + from distutils.unixccompiler import UnixCCompiler + except ImportError as err: + raise RuntimeError( + "Failed to import distutils. You may need to install setuptools." + ) from err compiler = new_compiler() if isinstance(compiler, UnixCCompiler): @@ -126,7 +130,7 @@ def __init__(self, path_or_ptr: Union[str, int], name: str): _deprecate("Language(path, name)", "Language(ptr, name)") self.name = name self.lib = cdll.LoadLibrary(path_or_ptr) - language_function: Callable[[], int] = getattr(self.lib, "tree_sitter_%s" % name) + language_function = getattr(self.lib, "tree_sitter_%s" % name) language_function.restype = c_void_p self.language_id = language_function() elif isinstance(path_or_ptr, int):