-
Notifications
You must be signed in to change notification settings - Fork 37
/
setup.py
57 lines (39 loc) · 1.4 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
import os
import subprocess
import sys
from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext
from setuptools.command.build_py import build_py
def _find_libgraphqlparser_artifact():
if os.path.exists("./libgraphqlparser/libgraphqlparser.so"):
return "./libgraphqlparser/libgraphqlparser.so"
if os.path.exists("./libgraphqlparser/libgraphqlparser.dylib"):
return "./libgraphqlparser/libgraphqlparser.dylib"
return None
def _build_libgraphqlparser():
os.chdir("./libgraphqlparser/.")
subprocess.run(["cmake", "."], stdout=subprocess.PIPE)
subprocess.run(["make"], stdout=subprocess.PIPE)
os.chdir("..")
artifact_path = _find_libgraphqlparser_artifact()
if not artifact_path:
print("Libgraphqlparser compilation has failed")
sys.exit(-1)
os.rename(
artifact_path,
f"tartiflette/language/parsers/libgraphqlparser/cffi/{os.path.basename(artifact_path)}",
)
class BuildExtCmd(build_ext):
def run(self):
_build_libgraphqlparser()
class BuildPyCmd(build_py):
def run(self):
_build_libgraphqlparser()
super().run()
class LibGraphQLParserExtension(Extension):
def __init__(self):
super().__init__("libgraphqlparser", sources=[])
setup(
cmdclass={"build_ext": BuildExtCmd, "build_py": BuildPyCmd},
ext_modules=[LibGraphQLParserExtension()],
)