nixpkgs/pkgs/development/python-modules/jq/jq-py-setup.patch

148 lines
4.8 KiB
Diff
Raw Normal View History

2020-09-09 06:18:08 +01:00
From 968ddf2bd773e800e46737fced743bd00af9aa0d Mon Sep 17 00:00:00 2001
From: William Kral <william.kral@gmail.com>
Date: Tue, 8 Sep 2020 22:04:24 -0700
Subject: [PATCH] Vastly simplify setup.py for distro compatibility
---
2020-09-09 06:18:08 +01:00
setup.py | 101 ++-----------------------------------------------------
1 file changed, 2 insertions(+), 99 deletions(-)
diff --git a/setup.py b/setup.py
2020-09-09 06:18:08 +01:00
index cb63f60..87380ed 100644
--- a/setup.py
+++ b/setup.py
2020-09-09 06:18:08 +01:00
@@ -1,114 +1,19 @@
#!/usr/bin/env python
import os
-import subprocess
-import tarfile
-import shutil
2020-09-09 06:18:08 +01:00
-import sysconfig
2020-09-09 06:18:08 +01:00
-import requests
from setuptools import setup
2020-09-09 06:18:08 +01:00
-from setuptools.command.build_ext import build_ext
from setuptools.extension import Extension
-def urlretrieve(source_url, destination_path):
- response = requests.get(source_url, stream=True)
- if response.status_code != 200:
- raise Exception("status code was: {}".format(response.status_code))
-
2020-09-09 06:18:08 +01:00
- with open(destination_path, "wb") as fileobj:
- for chunk in response.iter_content(chunk_size=128):
- fileobj.write(chunk)
-
-def path_in_dir(relative_path):
- return os.path.abspath(os.path.join(os.path.dirname(__file__), relative_path))
2020-09-09 06:18:08 +01:00
-
-def dependency_path(relative_path):
- return os.path.join(path_in_dir("_deps"), relative_path)
-
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
2020-09-09 06:18:08 +01:00
-jq_lib_tarball_path = dependency_path("jq-lib-1.6.tar.gz")
-jq_lib_dir = dependency_path("jq-1.6")
-
2020-09-09 06:18:08 +01:00
-oniguruma_version = "6.9.4"
-oniguruma_lib_tarball_path = dependency_path("onig-{}.tar.gz".format(oniguruma_version))
-oniguruma_lib_build_dir = dependency_path("onig-{}".format(oniguruma_version))
-oniguruma_lib_install_dir = dependency_path("onig-install-{}".format(oniguruma_version))
-
-class jq_build_ext(build_ext):
- def run(self):
2020-09-09 06:18:08 +01:00
- if not os.path.exists(dependency_path(".")):
- os.makedirs(dependency_path("."))
- self._build_oniguruma()
- self._build_libjq()
- build_ext.run(self)
2020-09-09 06:18:08 +01:00
-
- def _build_oniguruma(self):
- self._build_lib(
2020-09-09 06:18:08 +01:00
- source_url="https://github.com/kkos/oniguruma/releases/download/v{0}/onig-{0}.tar.gz".format(oniguruma_version),
- 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-09 06:18:08 +01:00
-
-
- def _build_libjq(self):
- self._build_lib(
2020-09-09 06:18:08 +01:00
- source_url="https://github.com/stedolan/jq/releases/download/jq-1.6/jq-1.6.tar.gz",
- tarball_path=jq_lib_tarball_path,
- lib_dir=jq_lib_dir,
- commands=[
- ["autoreconf", "-i"],
- ["./configure", "CFLAGS=-fPIC", "--disable-maintainer-mode", "--with-oniguruma=" + oniguruma_lib_install_dir],
- ["make"],
- ])
2020-09-09 06:18:08 +01:00
-
- def _build_lib(self, source_url, tarball_path, lib_dir, commands):
2020-09-09 06:18:08 +01:00
- self._download_tarball(
- source_url=source_url,
- tarball_path=tarball_path,
- lib_dir=lib_dir,
- )
-
- macosx_deployment_target = sysconfig.get_config_var("MACOSX_DEPLOYMENT_TARGET")
- if macosx_deployment_target:
- os.environ['MACOSX_DEPLOYMENT_TARGET'] = macosx_deployment_target
-
- def run_command(args):
- print("Executing: %s" % ' '.join(args))
- subprocess.check_call(args, cwd=lib_dir)
2020-09-09 06:18:08 +01:00
-
- for command in commands:
- run_command(command)
2020-09-09 06:18:08 +01:00
-
- def _download_tarball(self, source_url, tarball_path, lib_dir):
- if os.path.exists(tarball_path):
- os.unlink(tarball_path)
2020-09-09 06:18:08 +01:00
- print("Downloading {}".format(source_url))
- urlretrieve(source_url, tarball_path)
2020-09-09 06:18:08 +01:00
- print("Downloaded {}".format(source_url))
-
- if os.path.exists(lib_dir):
- shutil.rmtree(lib_dir)
- tarfile.open(tarball_path, "r:gz").extractall(dependency_path("."))
-
-
jq_extension = Extension(
"jq",
sources=["jq.c"],
2020-09-09 06:18:08 +01:00
- include_dirs=[os.path.join(jq_lib_dir, "src")],
- extra_link_args=["-lm"],
- extra_objects=[
- os.path.join(jq_lib_dir, ".libs/libjq.a"),
- os.path.join(oniguruma_lib_install_dir, "lib/libonig.a"),
- ],
2020-09-09 06:18:08 +01:00
+ libraries=["jq"]
)
setup(
2020-09-09 06:18:08 +01:00
@@ -120,8 +25,7 @@ setup(
url='http://github.com/mwilliamson/jq.py',
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
license='BSD 2-Clause',
2020-09-09 06:18:08 +01:00
- ext_modules = [jq_extension],
- cmdclass={"build_ext": jq_build_ext},
2020-09-09 06:18:08 +01:00
+ ext_modules=[jq_extension],
classifiers=[
2020-09-09 06:18:08 +01:00
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
2020-09-09 06:18:08 +01:00
@@ -137,4 +41,3 @@ setup(
'Programming Language :: Python :: 3.8',
],
)
-
--
2020-09-09 06:18:08 +01:00
2.28.0