Skip to content

Commit

Permalink
feat: support Python 3.12 again
Browse files Browse the repository at this point in the history
Only Language.build_library will not be supported
  • Loading branch information
ObserverOfTime committed Mar 14, 2024
1 parent 52f29fa commit bda83ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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]
Expand Down
16 changes: 10 additions & 6 deletions tree_sitter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit bda83ca

Please sign in to comment.