Skip to content

Commit

Permalink
Add environment variable for using system libjq and libonig
Browse files Browse the repository at this point in the history
  • Loading branch information
mwilliamson committed Sep 1, 2023
1 parent c2c7ed1 commit 53b4c25
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ jobs:
matrix:
os: [ubuntu-20.04, macos-11]
python-version: [3.5, 3.6, 3.7, 3.8, 3.9, "3.10", "3.11", "3.12-dev", "pypy-3.7"]
use-system-libs: [false]
include:
- os: ubuntu-20.04
python-version: "3.11"
use-system-libs: true

steps:

Expand All @@ -25,6 +30,16 @@ jobs:
- run: "make jq.c"

- run: tox -e py
if: ${{ !matrix.use-system-libs }}

- run: |
# Remove deps to make sure they're not being used
rm -r deps
sudo apt-get install -y libjq-dev libonig-dev
JQPY_USE_SYSTEM_LIBS=1 tox -e py
if: ${{ matrix.use-system-libs }}
build_sdist:
name: Build source distribution
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

1.6.0
-----

* Add support for building with Cython 3.

* Add support for building with the system libjq and libonig instead of building
using the bundled source.

1.5.0
-----

Expand Down
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ On these platforms, you should be able to install jq with a normal pip install:
pip install jq
If a wheel is not available,
the source for jq 1.6 is downloaded over HTTPS and built.
the source for jq 1.6 is built.
This requires:

* Autoreconf
Expand All @@ -26,6 +26,9 @@ This requires:

* Python headers.

Alternatively, set the environment variable ``JQPY_USE_SYSTEM_LIBS`` to ``1`` when installing the package
to use the libjq and libonig versions available on the system rather than building them.

Debian, Ubuntu or relatives
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
25 changes: 19 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _read(fname):
oniguruma_lib_build_dir = _dep_build_path("onig-{}".format(oniguruma_version))
oniguruma_lib_install_dir = _dep_build_path("onig-install-{}".format(oniguruma_version))

class jq_build_ext(build_ext):
class jq_with_deps_build_ext(build_ext):
def run(self):
if not os.path.exists(_dep_build_path(".")):
os.makedirs(_dep_build_path("."))
Expand Down Expand Up @@ -83,15 +83,28 @@ def _extract_tarball(self, tarball_path, lib_dir):
tarfile.open(tarball_path, "r:gz").extractall(_dep_build_path("."))


use_system_libs = bool(os.environ.get("JQPY_USE_SYSTEM_LIBS"))


if use_system_libs:
jq_build_ext = build_ext
link_args_deps = ["-ljq", "-lonig"]
extra_objects = []
else:
jq_build_ext = jq_with_deps_build_ext
link_args_deps = []
extra_objects = [
os.path.join(jq_lib_dir, ".libs/libjq.a"),
os.path.join(oniguruma_lib_install_dir, "lib/libonig.a"),
]


jq_extension = Extension(
"jq",
sources=["jq.c"],
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"),
],
extra_link_args=["-lm"] + link_args_deps,
extra_objects=extra_objects,
)

setup(
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ changedir = {envtmpdir}
deps=-r{toxinidir}/test-requirements.txt
commands=
py.test {toxinidir}/tests
passenv = JQPY_USE_SYSTEM_LIBS

[pytest]
python_files = *_tests.py

0 comments on commit 53b4c25

Please sign in to comment.