-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathsetup.py
117 lines (98 loc) · 3.46 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env python
import io
import lib2to3.main
import os
import platform
import shutil
import subprocess
import sys
import sysconfig
import tarfile
from os.path import abspath, dirname, join
from pathlib import Path
from setuptools import setup
from setuptools.command.build_ext import _build_ext
from setuptools.extension import Extension
dependencies_dir_path = join(abspath(dirname(__file__)), "dependencies")
onig_tarball_path = join(dependencies_dir_path, "onig-6.9.0.tar.gz")
onig_install_path = join(dependencies_dir_path, "onig_install")
onig_source_path = join(dependencies_dir_path, "onig-6.9.0")
jq_tarball_path = join(dependencies_dir_path, "jq-1.5.tar.gz")
jq_install_path = join(dependencies_dir_path, "jq_install")
jq_source_path = join(dependencies_dir_path, "jq-jq-1.5")
class build_ext(_build_ext):
def run(self):
self._build_oniguruma()
self._build_libjq()
_build_ext.run(self)
def _build_oniguruma(self):
self._safe_rmtree(onig_install_path)
self._safe_rmtree(onig_source_path)
self._extract_tarball(onig_tarball_path, dependencies_dir_path)
for f in Path(onig_source_path).glob("src/*.py"):
lib2to3.main.main(
"lib2to3.fixes", args=["-w", "--no-diffs", "-f", "print", str(f)]
)
self._build_lib(
lib_dir=onig_source_path,
commands=[
[
"./configure",
"CFLAGS=-fPIC",
"--disable-shared",
"--prefix",
onig_install_path,
],
["make"],
["make", "install"],
],
)
def _build_libjq(self):
self._safe_rmtree(jq_install_path)
self._safe_rmtree(jq_source_path)
self._extract_tarball(jq_tarball_path, dependencies_dir_path)
self._build_lib(
lib_dir=jq_source_path,
commands=[
["autoreconf", "-i"],
[
"./configure",
"CFLAGS=-fPIC",
"--disable-maintainer-mode",
"--enable-all-static",
"--disable-shared",
"--with-oniguruma=" + onig_install_path,
"--prefix",
jq_install_path,
],
["make", "install-libLTLIBRARIES", "install-includeHEADERS"],
],
)
def _build_lib(self, lib_dir, commands):
macosx_deployment_target = sysconfig.get_config_var("MACOSX_DEPLOYMENT_TARGET")
if macosx_deployment_target:
os.environ["MACOSX_DEPLOYMENT_TARGET"] = str(macosx_deployment_target)
for command in commands:
subprocess.check_call(command, cwd=lib_dir)
def _extract_tarball(self, tarball_path, workdir_path):
tarfile.open(tarball_path, "r:gz").extractall(workdir_path)
def _safe_rmtree(self, d):
try:
shutil.rmtree(d)
except OSError:
pass
libraries = ["jq", "onig"]
if platform.architecture()[1] == "WindowsPE":
libraries.append("shlwapi")
pyjq = Extension(
"_pyjq",
sources=["_pyjq.c"],
include_dirs=["dependencies/jq_install/include"],
libraries=libraries,
library_dirs=["dependencies/jq_install/lib", "dependencies/onig_install/lib"],
)
setup(
ext_modules=[pyjq],
cmdclass={"build_ext": build_ext},
package_data={"": [onig_tarball_path, jq_tarball_path]},
)