Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at 20.09-beta 147 lines 4.9 kB view raw
1From 968ddf2bd773e800e46737fced743bd00af9aa0d Mon Sep 17 00:00:00 2001 2From: William Kral <william.kral@gmail.com> 3Date: Tue, 8 Sep 2020 22:04:24 -0700 4Subject: [PATCH] Vastly simplify setup.py for distro compatibility 5 6--- 7 setup.py | 101 ++----------------------------------------------------- 8 1 file changed, 2 insertions(+), 99 deletions(-) 9 10diff --git a/setup.py b/setup.py 11index cb63f60..87380ed 100644 12--- a/setup.py 13+++ b/setup.py 14@@ -1,114 +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- ["autoreconf", "-i"], 83- ["./configure", "CFLAGS=-fPIC", "--disable-maintainer-mode", "--with-oniguruma=" + oniguruma_lib_install_dir], 84- ["make"], 85- ]) 86- 87- def _build_lib(self, source_url, tarball_path, lib_dir, commands): 88- self._download_tarball( 89- source_url=source_url, 90- tarball_path=tarball_path, 91- lib_dir=lib_dir, 92- ) 93- 94- macosx_deployment_target = sysconfig.get_config_var("MACOSX_DEPLOYMENT_TARGET") 95- if macosx_deployment_target: 96- os.environ['MACOSX_DEPLOYMENT_TARGET'] = macosx_deployment_target 97- 98- def run_command(args): 99- print("Executing: %s" % ' '.join(args)) 100- subprocess.check_call(args, cwd=lib_dir) 101- 102- for command in commands: 103- run_command(command) 104- 105- def _download_tarball(self, source_url, tarball_path, lib_dir): 106- if os.path.exists(tarball_path): 107- os.unlink(tarball_path) 108- print("Downloading {}".format(source_url)) 109- urlretrieve(source_url, tarball_path) 110- print("Downloaded {}".format(source_url)) 111- 112- if os.path.exists(lib_dir): 113- shutil.rmtree(lib_dir) 114- tarfile.open(tarball_path, "r:gz").extractall(dependency_path(".")) 115- 116- 117 jq_extension = Extension( 118 "jq", 119 sources=["jq.c"], 120- include_dirs=[os.path.join(jq_lib_dir, "src")], 121- extra_link_args=["-lm"], 122- extra_objects=[ 123- os.path.join(jq_lib_dir, ".libs/libjq.a"), 124- os.path.join(oniguruma_lib_install_dir, "lib/libonig.a"), 125- ], 126+ libraries=["jq"] 127 ) 128 129 setup( 130@@ -120,8 +25,7 @@ setup( 131 url='http://github.com/mwilliamson/jq.py', 132 python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*', 133 license='BSD 2-Clause', 134- ext_modules = [jq_extension], 135- cmdclass={"build_ext": jq_build_ext}, 136+ ext_modules=[jq_extension], 137 classifiers=[ 138 'Development Status :: 5 - Production/Stable', 139 'Intended Audience :: Developers', 140@@ -137,4 +41,3 @@ setup( 141 'Programming Language :: Python :: 3.8', 142 ], 143 ) 144- 145-- 1462.28.0 147