interplane.Get Omega
Read in your language

tree-sitter-omega

aien-dev/tree-sitter-omega

Brought by drakestapleton

branch main Branches Tags History

tree-sitter-omega / setup.py

78 lines · 2396 bytes Raw Blame History
1from os import path
2from sysconfig import get_config_var
3
4from setuptools import Extension, find_packages, setup
5from setuptools.command.build import build
6from setuptools.command.build_ext import build_ext
7from setuptools.command.egg_info import egg_info
8from wheel.bdist_wheel import bdist_wheel
9
10
11class Build(build):
12 def run(self):
13 if path.isdir("queries"):
14 dest = path.join(self.build_lib, "tree_sitter_omega", "queries")
15 self.copy_tree("queries", dest)
16 super().run()
17
18
19class BuildExt(build_ext):
20 def build_extension(self, ext: Extension):
21 if self.compiler.compiler_type != "msvc":
22 ext.extra_compile_args = ["-std=c11", "-fvisibility=hidden"]
23 else:
24 ext.extra_compile_args = ["/std:c11", "/utf-8"]
25 if path.exists("src/scanner.c"):
26 ext.sources.append("src/scanner.c")
27 if ext.py_limited_api:
28 ext.define_macros.append(("Py_LIMITED_API", "0x030A0000"))
29 super().build_extension(ext)
30
31
32class BdistWheel(bdist_wheel):
33 def get_tag(self):
34 python, abi, platform = super().get_tag()
35 if python.startswith("cp") and not get_config_var("Py_GIL_DISABLED"):
36 python, abi = "cp310", "abi3"
37 return python, abi, platform
38
39
40class EggInfo(egg_info):
41 def find_sources(self):
42 super().find_sources()
43 self.filelist.recursive_include("queries", "*.scm")
44 self.filelist.include("src/tree_sitter/*.h")
45 self.filelist.include("src/*.c")
46
47
48setup(
49 packages=find_packages("bindings/python"),
50 package_dir={"": "bindings/python"},
51 package_data={
52 "tree_sitter_omega": ["*.pyi", "py.typed"],
53 "tree_sitter_omega.queries": ["*.scm"],
54 },
55 ext_package="tree_sitter_omega",
56 ext_modules=[
57 Extension(
58 name="_binding",
59 sources=[
60 "bindings/python/tree_sitter_omega/binding.c",
61 "src/parser.c",
62 ],
63 define_macros=[
64 ("PY_SSIZE_T_CLEAN", None),
65 ("TREE_SITTER_HIDE_SYMBOLS", None),
66 ],
67 include_dirs=["src"],
68 py_limited_api=not get_config_var("Py_GIL_DISABLED"),
69 )
70 ],
71 cmdclass={
72 "build": Build,
73 "build_ext": BuildExt,
74 "bdist_wheel": BdistWheel,
75 "egg_info": EggInfo,
76 },
77 zip_safe=False
78)