at 23.05-pre 4.8 kB view raw
1From bef841b73ba7c9a79211146798ac888fce9bb55a Mon Sep 17 00:00:00 2001 2From: "Robert T. McGibbon" <rmcgibbo@gmail.com> 3Date: Fri, 7 May 2021 19:14:20 -0400 4Subject: [PATCH 1/1] Vastly simplify setup.py for distro compatibility 5 6--- 7 setup.py | 98 +------------------------------------------------------- 8 1 file changed, 1 insertion(+), 97 deletions(-) 9 10diff --git a/setup.py b/setup.py 11index 663792c..3ebcabe 100644 12--- a/setup.py 13+++ b/setup.py 14@@ -1,113 +1,19 @@ 15 #!/usr/bin/env python 16 17 import os 18-import subprocess 19-import tarfile 20-import shutil 21-import sysconfig 22 23-import requests 24 from setuptools import setup 25-from setuptools.command.build_ext import build_ext 26 from setuptools.extension import Extension 27 28 29-def urlretrieve(source_url, destination_path): 30- response = requests.get(source_url, stream=True) 31- if response.status_code != 200: 32- raise Exception("status code was: {}".format(response.status_code)) 33- 34- with open(destination_path, "wb") as fileobj: 35- for chunk in response.iter_content(chunk_size=128): 36- fileobj.write(chunk) 37- 38-def path_in_dir(relative_path): 39- return os.path.abspath(os.path.join(os.path.dirname(__file__), relative_path)) 40- 41-def dependency_path(relative_path): 42- return os.path.join(path_in_dir("_deps"), relative_path) 43- 44 def read(fname): 45 return open(os.path.join(os.path.dirname(__file__), fname)).read() 46 47 48-jq_lib_tarball_path = dependency_path("jq-lib-1.6.tar.gz") 49-jq_lib_dir = dependency_path("jq-1.6") 50- 51-oniguruma_version = "6.9.4" 52-oniguruma_lib_tarball_path = dependency_path("onig-{}.tar.gz".format(oniguruma_version)) 53-oniguruma_lib_build_dir = dependency_path("onig-{}".format(oniguruma_version)) 54-oniguruma_lib_install_dir = dependency_path("onig-install-{}".format(oniguruma_version)) 55- 56-class jq_build_ext(build_ext): 57- def run(self): 58- if not os.path.exists(dependency_path(".")): 59- os.makedirs(dependency_path(".")) 60- self._build_oniguruma() 61- self._build_libjq() 62- build_ext.run(self) 63- 64- def _build_oniguruma(self): 65- self._build_lib( 66- source_url="https://github.com/kkos/oniguruma/releases/download/v{0}/onig-{0}.tar.gz".format(oniguruma_version), 67- tarball_path=oniguruma_lib_tarball_path, 68- lib_dir=oniguruma_lib_build_dir, 69- commands=[ 70- ["./configure", "CFLAGS=-fPIC", "--prefix=" + oniguruma_lib_install_dir], 71- ["make"], 72- ["make", "install"], 73- ]) 74- 75- 76- def _build_libjq(self): 77- self._build_lib( 78- source_url="https://github.com/stedolan/jq/releases/download/jq-1.6/jq-1.6.tar.gz", 79- tarball_path=jq_lib_tarball_path, 80- lib_dir=jq_lib_dir, 81- commands=[ 82- ["./configure", "CFLAGS=-fPIC -pthread", "--disable-maintainer-mode", "--with-oniguruma=" + oniguruma_lib_install_dir], 83- ["make"], 84- ]) 85- 86- def _build_lib(self, source_url, tarball_path, lib_dir, commands): 87- self._download_tarball( 88- source_url=source_url, 89- tarball_path=tarball_path, 90- lib_dir=lib_dir, 91- ) 92- 93- macosx_deployment_target = sysconfig.get_config_var("MACOSX_DEPLOYMENT_TARGET") 94- if macosx_deployment_target: 95- os.environ['MACOSX_DEPLOYMENT_TARGET'] = str(macosx_deployment_target) 96- 97- def run_command(args): 98- print("Executing: %s" % ' '.join(args)) 99- subprocess.check_call(args, cwd=lib_dir) 100- 101- for command in commands: 102- run_command(command) 103- 104- def _download_tarball(self, source_url, tarball_path, lib_dir): 105- if os.path.exists(tarball_path): 106- os.unlink(tarball_path) 107- print("Downloading {}".format(source_url)) 108- urlretrieve(source_url, tarball_path) 109- print("Downloaded {}".format(source_url)) 110- 111- if os.path.exists(lib_dir): 112- shutil.rmtree(lib_dir) 113- tarfile.open(tarball_path, "r:gz").extractall(dependency_path(".")) 114- 115- 116 jq_extension = Extension( 117 "jq", 118 sources=["jq.c"], 119- include_dirs=[os.path.join(jq_lib_dir, "src")], 120- extra_link_args=["-lm"], 121- extra_objects=[ 122- os.path.join(jq_lib_dir, ".libs/libjq.a"), 123- os.path.join(oniguruma_lib_install_dir, "lib/libonig.a"), 124- ], 125+ libraries=["jq"] 126 ) 127 128 setup( 129@@ -120,7 +26,6 @@ setup( 130 python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*', 131 license='BSD 2-Clause', 132 ext_modules = [jq_extension], 133- cmdclass={"build_ext": jq_build_ext}, 134 classifiers=[ 135 'Development Status :: 5 - Production/Stable', 136 'Intended Audience :: Developers', 137@@ -137,4 +42,3 @@ setup( 138 'Programming Language :: Python :: 3.9', 139 ], 140 ) 141- 142-- 1432.29.3 144