2020-04-24 23:36:52 +00:00
|
|
|
diff --git a/setup.py b/setup.py
|
2022-12-02 08:20:57 +00:00
|
|
|
index 01cc813..15e9048 100644
|
2020-04-24 23:36:52 +00:00
|
|
|
--- a/setup.py
|
|
|
|
+++ b/setup.py
|
2022-12-02 08:20:57 +00:00
|
|
|
@@ -1,97 +1,18 @@
|
2020-04-24 23:36:52 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import os
|
|
|
|
-import subprocess
|
|
|
|
-import tarfile
|
|
|
|
-import shutil
|
2020-09-25 04:45:31 +00:00
|
|
|
-import sysconfig
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
from setuptools import setup
|
2020-09-25 04:45:31 +00:00
|
|
|
-from setuptools.command.build_ext import build_ext
|
|
|
|
from setuptools.extension import Extension
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
-
|
2022-12-02 08:20:57 +00:00
|
|
|
-def _path_in_dir(relative_path):
|
2020-04-24 23:36:52 +00:00
|
|
|
- return os.path.abspath(os.path.join(os.path.dirname(__file__), relative_path))
|
2020-09-25 04:45:31 +00:00
|
|
|
-
|
2022-12-02 08:20:57 +00:00
|
|
|
-def _dep_source_path(relative_path):
|
|
|
|
- return os.path.join(_path_in_dir("deps"), relative_path)
|
|
|
|
-
|
|
|
|
-def _dep_build_path(relative_path):
|
|
|
|
- return os.path.join(_path_in_dir("_deps/build"), relative_path)
|
2020-09-25 04:45:31 +00:00
|
|
|
-
|
2022-12-02 08:20:57 +00:00
|
|
|
def _read(fname):
|
2020-04-24 23:36:52 +00:00
|
|
|
return open(os.path.join(os.path.dirname(__file__), fname)).read()
|
|
|
|
|
|
|
|
|
2022-12-02 08:20:57 +00:00
|
|
|
-jq_lib_tarball_path = _dep_source_path("jq-1.6.tar.gz")
|
|
|
|
-jq_lib_dir = _dep_build_path("jq-1.6")
|
2020-04-24 23:36:52 +00:00
|
|
|
-
|
2020-09-25 04:45:31 +00:00
|
|
|
-oniguruma_version = "6.9.4"
|
2022-12-02 08:20:57 +00:00
|
|
|
-oniguruma_lib_tarball_path = _dep_source_path("onig-{}.tar.gz".format(oniguruma_version))
|
|
|
|
-oniguruma_lib_build_dir = _dep_build_path("onig-{}".format(oniguruma_version))
|
|
|
|
-oniguruma_lib_install_dir = _dep_build_path("onig-install-{}".format(oniguruma_version))
|
2020-04-24 23:36:52 +00:00
|
|
|
-
|
|
|
|
-class jq_build_ext(build_ext):
|
|
|
|
- def run(self):
|
2022-12-02 08:20:57 +00:00
|
|
|
- if not os.path.exists(_dep_build_path(".")):
|
|
|
|
- os.makedirs(_dep_build_path("."))
|
2020-04-24 23:36:52 +00:00
|
|
|
- self._build_oniguruma()
|
|
|
|
- self._build_libjq()
|
|
|
|
- build_ext.run(self)
|
2020-09-25 04:45:31 +00:00
|
|
|
-
|
2020-04-24 23:36:52 +00:00
|
|
|
- def _build_oniguruma(self):
|
|
|
|
- self._build_lib(
|
|
|
|
- tarball_path=oniguruma_lib_tarball_path,
|
|
|
|
- lib_dir=oniguruma_lib_build_dir,
|
|
|
|
- commands=[
|
|
|
|
- ["./configure", "CFLAGS=-fPIC", "--prefix=" + oniguruma_lib_install_dir],
|
|
|
|
- ["make"],
|
|
|
|
- ["make", "install"],
|
|
|
|
- ])
|
2020-09-25 04:45:31 +00:00
|
|
|
-
|
|
|
|
-
|
2020-04-24 23:36:52 +00:00
|
|
|
- def _build_libjq(self):
|
|
|
|
- self._build_lib(
|
|
|
|
- tarball_path=jq_lib_tarball_path,
|
|
|
|
- lib_dir=jq_lib_dir,
|
|
|
|
- commands=[
|
2021-05-20 23:08:51 +00:00
|
|
|
- ["./configure", "CFLAGS=-fPIC -pthread", "--disable-maintainer-mode", "--with-oniguruma=" + oniguruma_lib_install_dir],
|
2020-04-24 23:36:52 +00:00
|
|
|
- ["make"],
|
|
|
|
- ])
|
2020-09-25 04:45:31 +00:00
|
|
|
-
|
2022-12-02 08:20:57 +00:00
|
|
|
- def _build_lib(self, tarball_path, lib_dir, commands):
|
|
|
|
- self._extract_tarball(
|
2020-09-25 04:45:31 +00:00
|
|
|
- tarball_path=tarball_path,
|
|
|
|
- lib_dir=lib_dir,
|
|
|
|
- )
|
2020-04-24 23:36:52 +00:00
|
|
|
-
|
|
|
|
- macosx_deployment_target = sysconfig.get_config_var("MACOSX_DEPLOYMENT_TARGET")
|
|
|
|
- if macosx_deployment_target:
|
2021-05-20 23:08:51 +00:00
|
|
|
- os.environ['MACOSX_DEPLOYMENT_TARGET'] = str(macosx_deployment_target)
|
2020-04-24 23:36:52 +00:00
|
|
|
-
|
|
|
|
- def run_command(args):
|
|
|
|
- print("Executing: %s" % ' '.join(args))
|
|
|
|
- subprocess.check_call(args, cwd=lib_dir)
|
2020-09-25 04:45:31 +00:00
|
|
|
-
|
2020-04-24 23:36:52 +00:00
|
|
|
- for command in commands:
|
|
|
|
- run_command(command)
|
2020-09-25 04:45:31 +00:00
|
|
|
-
|
2022-12-02 08:20:57 +00:00
|
|
|
- def _extract_tarball(self, tarball_path, lib_dir):
|
2020-09-25 04:45:31 +00:00
|
|
|
- if os.path.exists(lib_dir):
|
|
|
|
- shutil.rmtree(lib_dir)
|
2022-12-02 08:20:57 +00:00
|
|
|
- tarfile.open(tarball_path, "r:gz").extractall(_dep_build_path("."))
|
2020-04-24 23:36:52 +00:00
|
|
|
-
|
|
|
|
-
|
|
|
|
jq_extension = Extension(
|
|
|
|
"jq",
|
|
|
|
sources=["jq.c"],
|
2020-09-25 04:45:31 +00:00
|
|
|
- include_dirs=[os.path.join(jq_lib_dir, "src")],
|
|
|
|
- extra_link_args=["-lm"],
|
2020-04-24 23:36:52 +00:00
|
|
|
- extra_objects=[
|
|
|
|
- os.path.join(jq_lib_dir, ".libs/libjq.a"),
|
|
|
|
- os.path.join(oniguruma_lib_install_dir, "lib/libonig.a"),
|
|
|
|
- ],
|
2020-09-25 04:45:31 +00:00
|
|
|
+ libraries=["jq"]
|
2020-04-24 23:36:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
setup(
|
2022-12-02 08:20:57 +00:00
|
|
|
@@ -104,7 +25,6 @@ def _extract_tarball(self, tarball_path, lib_dir):
|
|
|
|
python_requires='>=3.5',
|
2020-04-24 23:36:52 +00:00
|
|
|
license='BSD 2-Clause',
|
2021-05-20 23:08:51 +00:00
|
|
|
ext_modules = [jq_extension],
|
2020-04-24 23:36:52 +00:00
|
|
|
- cmdclass={"build_ext": jq_build_ext},
|
|
|
|
classifiers=[
|
2020-09-25 04:45:31 +00:00
|
|
|
'Development Status :: 5 - Production/Stable',
|
2020-04-24 23:36:52 +00:00
|
|
|
'Intended Audience :: Developers',
|