diff --git a/Cargo.toml b/Cargo.toml index dd1aaa2..a6400e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ include = [ "queries/*", "src/*", "tree-sitter.json", - "LICENSE", + "/LICENSE", ] [lib] diff --git a/bindings/python/tests/test_binding.py b/bindings/python/tests/test_binding.py index 469c40f..fafbd80 100644 --- a/bindings/python/tests/test_binding.py +++ b/bindings/python/tests/test_binding.py @@ -1,12 +1,12 @@ from unittest import TestCase -import tree_sitter +from tree_sitter import Language, Parser import tree_sitter_embedded_template class TestLanguage(TestCase): def test_can_load_grammar(self): try: - tree_sitter.Language(tree_sitter_embedded_template.language()) + Parser(Language(tree_sitter_embedded_template.language())) except Exception: self.fail("Error loading EmbeddedTemplate grammar") diff --git a/package.json b/package.json index 4cbea80..779e9cc 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "*.wasm" ], "dependencies": { - "node-addon-api": "^8.3.1", + "node-addon-api": "^8.5.0", "node-gyp-build": "^4.8.4" }, "devDependencies": { diff --git a/setup.py b/setup.py index c6f1678..d4ffb2e 100644 --- a/setup.py +++ b/setup.py @@ -1,40 +1,34 @@ from os import path -from platform import system from sysconfig import get_config_var from setuptools import Extension, find_packages, setup from setuptools.command.build import build +from setuptools.command.build_ext import build_ext from setuptools.command.egg_info import egg_info from wheel.bdist_wheel import bdist_wheel -sources = [ - "bindings/python/tree_sitter_embedded_template/binding.c", - "src/parser.c", -] -if path.exists("src/scanner.c"): - sources.append("src/scanner.c") - -macros: list[tuple[str, str | None]] = [ - ("PY_SSIZE_T_CLEAN", None), - ("TREE_SITTER_HIDE_SYMBOLS", None), -] -if limited_api := not get_config_var("Py_GIL_DISABLED"): - macros.append(("Py_LIMITED_API", "0x030A0000")) - -if system() != "Windows": - cflags = ["-std=c11", "-fvisibility=hidden"] -else: - cflags = ["/std:c11", "/utf-8"] - class Build(build): def run(self): if path.isdir("queries"): - dest = path.join(self.build_lib, "tree_sitter_embedded_template", "queries") + dest = path.join(self.build_lib, "tree_sitter_embedded-template", "queries") self.copy_tree("queries", dest) super().run() +class BuildExt(build_ext): + def build_extension(self, ext: Extension): + if self.compiler.compiler_type != "msvc": + ext.extra_compile_args = ["-std=c11", "-fvisibility=hidden"] + else: + ext.extra_compile_args = ["/std:c11", "/utf-8"] + if path.exists("src/scanner.c"): + ext.sources.append("src/scanner.c") + if ext.py_limited_api: + ext.define_macros.append(("Py_LIMITED_API", "0x030A0000")) + super().build_extension(ext) + + class BdistWheel(bdist_wheel): def get_tag(self): python, abi, platform = super().get_tag() @@ -61,17 +55,23 @@ def find_sources(self): ext_modules=[ Extension( name="_binding", - sources=sources, - extra_compile_args=cflags, - define_macros=macros, + sources=[ + "bindings/python/tree_sitter_embedded_template/binding.c", + "src/parser.c", + ], + define_macros=[ + ("PY_SSIZE_T_CLEAN", None), + ("TREE_SITTER_HIDE_SYMBOLS", None), + ], include_dirs=["src"], - py_limited_api=limited_api, + py_limited_api=not get_config_var("Py_GIL_DISABLED"), ) ], cmdclass={ "build": Build, + "build_ext": BuildExt, "bdist_wheel": BdistWheel, "egg_info": EggInfo, }, - zip_safe=False, + zip_safe=False )