-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
63 lines (47 loc) · 1.38 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import logging
from setuptools import setup, Extension, Command
from Cython.Build import cythonize
from setuptools.command.build import build
import subprocess
logger = logging.getLogger(__name__)
this_dir = os.path.abspath(os.path.dirname(__file__))
libpg_dir = os.path.join(this_dir, "libpg_query")
ext_dir = "src/pg_query"
compile_envs = {
"DEBUG": "1",
}
COMPILE_ARGS = [
"-Og",
"-DDEBUG",
"-fno-omit-frame-pointer",
]
LINK_ARGS = []
class Generate(Command):
description = "Generate the pg_query extension"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
logger.info("Generating pg_query extension")
for k, v in compile_envs.items():
os.environ[k] = v
subprocess.run(["make", "-C", libpg_dir, "clean"], check=True)
subprocess.run(["make", "-C", libpg_dir, "all"], check=True)
class CustomBuild(build):
sub_commands = [("generate", None), *build.sub_commands]
ext = Extension(
"pg_query",
sources=[os.path.join(ext_dir, "__init__.py")],
include_dirs=[libpg_dir, ext_dir],
libraries=["pg_query"],
library_dirs=[libpg_dir],
extra_compile_args=COMPILE_ARGS,
extra_link_args=LINK_ARGS,
)
setup(
ext_modules=cythonize([ext], language_level=3),
cmdclass={"build": CustomBuild, "generate": Generate},
)