]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
build: install the Python binding as a wheel via pip
authorTobias Oetiker <tobi@oetiker.ch>
Tue, 19 May 2026 16:13:30 +0000 (18:13 +0200)
committerTobias Oetiker <tobi@oetiker.ch>
Tue, 19 May 2026 16:13:30 +0000 (18:13 +0200)
setup.py install was removed in setuptools 80. Build the binding as a
wheel (setup.py bdist_wheel) and install it with pip into a fixed,
distribution-independent directory ($libdir/python3/site-packages),
replacing both the removed command and Debian's "local/" install
scheme that made the module land in an inconsistent location.

The extension RPATH now comes from the RRDTOOL_RPATH environment
variable, so no build_ext --rpath flag is needed. rrdtool-env.sh points
PYTHONPATH at the fixed directory, and the rpm and deb release jobs
gain python3-pip/python3-wheel build deps plus an `import rrdtool`
runtime smoke test.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
.github/workflows/release.yml
CHANGES
bindings/Makefile.am
bindings/python/setup.py
conftools/rrdtool-env.sh.in
conftools/rrdtool-opt.spec

index 59d259bb936cdabc3dd5dae8f3765f8c29b5f034..9096562b4e132da32942df0aace4af435fdd2e21 100644 (file)
@@ -300,7 +300,7 @@ jobs:
               freetype-devel libpng-devel zlib-devel \
               libxml2-devel glib2-devel libdbi-devel \
               perl-devel perl-ExtUtils-MakeMaker \
-              python3-devel python3-setuptools \
+              python3-devel python3-setuptools python3-pip python3-wheel \
               tcl-devel \
               lua-devel \
               ruby ruby-devel
@@ -364,8 +364,8 @@ jobs:
         run: |
           set -e
           # Install the distro rrdtool first to prove DB-level coexistence.
-          # ruby is pulled in so the bundled ruby binding can be smoke-tested.
-          dnf install -y rrdtool ruby
+          # ruby/python3 are pulled in so the bundled bindings can be smoke-tested.
+          dnf install -y rrdtool ruby python3
           # Install our /opt package alongside it.
           dnf install -y ./out/rrdtool-1-opt-${VERSION}-*.rpm
           # Both packages must be in the rpm database at the same time.
@@ -385,6 +385,9 @@ jobs:
           test "$(command -v rrdtool)" = /opt/rrdtool/bin/rrdtool
           # The relocated ruby binding must load via the RUBYLIB it sets.
           ruby -e 'require "RRD"; puts "ruby binding OK"'
+          # The pip-installed python binding must import via the PYTHONPATH it
+          # sets, find librrd through the wheel's embedded RPATH, and run.
+          python3 -c 'import rrdtool; print("python binding OK:", rrdtool.__file__, "librrd", rrdtool.lib_version())'
 
   # ---------------------------------------------------------------------------
   # build-deb: per-distro container, builds a .deb via fpm from a staged
@@ -435,7 +438,7 @@ jobs:
               libcairo2-dev libpango1.0-dev libxml2-dev libglib2.0-dev libdbi-dev \
               libfreetype6-dev libpng-dev zlib1g-dev \
               libperl-dev \
-              python3-dev python3-setuptools \
+              python3-dev python3-setuptools python3-pip python3-wheel \
               tcl-dev \
               lua5.4 liblua5.4-dev \
               ruby ruby-dev rubygems-integration
@@ -563,8 +566,8 @@ jobs:
         run: |
           set -e
           # Install the distro rrdtool first to prove DB-level coexistence.
-          # ruby is pulled in so the bundled ruby binding can be smoke-tested.
-          apt-get install -y rrdtool ruby
+          # ruby/python3 are pulled in so the bundled bindings can be smoke-tested.
+          apt-get install -y rrdtool ruby python3
           # Install our /opt package alongside it.
           apt-get install -y ./out/rrdtool-1-opt_*.deb
           # Both packages must be in the dpkg database at the same time.
@@ -584,6 +587,9 @@ jobs:
           test "$(command -v rrdtool)" = /opt/rrdtool/bin/rrdtool
           # The relocated ruby binding must load via the RUBYLIB it sets.
           ruby -e 'require "RRD"; puts "ruby binding OK"'
+          # The pip-installed python binding must import via the PYTHONPATH it
+          # sets, find librrd through the wheel's embedded RPATH, and run.
+          python3 -c 'import rrdtool; print("python binding OK:", rrdtool.__file__, "librrd", rrdtool.lib_version())'
 
   # ---------------------------------------------------------------------------
   # publish: only job that mutates the repo. Runs only after every build job
diff --git a/CHANGES b/CHANGES
index 3f6b502867b6be3e3a468d37ed8739a377e7ae43..94ccc97e1d9db9bb34071655fc3e867df24d7296 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,7 @@ RRDtool - master ...
 Bugfixes
 --------
 * The Linux .deb packages were missing the Lua language binding @oetiker
+* The Python binding is now installed with pip into a consistent, distribution-independent location @oetiker
 
 Features
 --------
index 5834411b8e431545ecab3289e3e5a6438f7e0d6b..549059134e0aec8d8a72a8f93a92b90cb2c7ec7e 100644 (file)
@@ -10,7 +10,7 @@ endif
 SUBDIRS = $(SUB_tcl) $(SUB_lua)
 
 if ENABLE_RPATH
-PYTHON_RPATH=--rpath=$(libdir)
+PYTHON_RPATH_LIBDIR=$(libdir)
 PERL_RPATH=RPATH=$(libdir)
 endif
 
@@ -38,12 +38,11 @@ install-data-local:
            && ( cd ${builddir}/ruby \
                 && $(MAKE) EPREFIX=$(DESTDIR)$(exec_prefix) $(RUBY_MAKE_OPTIONS) install ) \
            || true
-       $(AM_V_GEN)test -d ${builddir}/python/build \
-           && ( cd ${builddir}/python \
-                && env BUILDLIBDIR=${abs_top_builddir}/src/.libs \
-                  $(PYTHON) ${abs_srcdir}/python/setup.py install \
-                     --skip-build --root=$(DESTDIR)/// --prefix=$(prefix) \
-                     --exec-prefix=$(exec_prefix)) \
+       $(AM_V_GEN)test -f ${builddir}/python/dist/*.whl \
+           && ( $(PYTHON) -m pip install --upgrade --no-index --no-deps \
+                  --no-cache-dir --disable-pip-version-check \
+                  --target=$(DESTDIR)$(libdir)/python3/site-packages \
+                  ${builddir}/python/dist/*.whl ) \
            || true
 
 # rules for building the ruby module
@@ -62,19 +61,19 @@ ruby:
              ABS_TOP_BUILDDIR=${abs_top_builddir} \
              $(RUBY_MAKE_OPTIONS) RUBYARCHDIR= )
 
-# rules for building the python module
+# Build the python module as a wheel. It lands in ${builddir}/python/dist/
+# and is installed from there (via pip) by install-data-local. RRDTOOL_RPATH
+# tells setup.py to embed the install libdir as the extension's RPATH.
 python:
        -mkdir -p ${builddir}/$@
        cd ${builddir}/$@ \
          && ( test -e rrdtoolmodule.c || ln -s ${abs_srcdir}/$@/rrdtoolmodule.c ) \
+         && rm -rf build dist rrdtool.egg-info \
           && env \
                ABS_TOP_SRCDIR=${abs_top_srcdir} \
                ABS_TOP_BUILDDIR=${abs_top_builddir} \
-               $(PYTHON) ${abs_srcdir}/$@/setup.py build_ext $(PYTHON_RPATH) \
-          && env \
-               ABS_TOP_SRCDIR=${abs_top_srcdir} \
-               ABS_TOP_BUILDDIR=${abs_top_builddir} \
-               $(PYTHON) ${abs_srcdir}/$@/setup.py build
+               RRDTOOL_RPATH=$(PYTHON_RPATH_LIBDIR) \
+               $(PYTHON) ${abs_srcdir}/$@/setup.py bdist_wheel
 
 # rules for building the perl module
 perl-piped:
@@ -119,5 +118,5 @@ clean-local:
           && cd ${builddir}/ruby \
           && ( $(MAKE) clean || true ) \
           && rm -f Makefile )
-       -rm -rf ${builddir}/python/build
+       -rm -rf ${builddir}/python/build ${builddir}/python/dist ${builddir}/python/rrdtool.egg-info
 ##END##
index 904acf2f59cf34a1f81eea57c6dd7e0c8199862a..724cbd060850a2de01b1c410a5ac787828efab6f 100644 (file)
@@ -15,12 +15,23 @@ package_version = '0.1.10'
 
 
 def main():
-    module = Extension('rrdtool',
-                       sources=['rrdtoolmodule.c'],
-                       library_dirs=[os.path.join(TOP_BUILDDIR, 'src', '.libs')],
-                       include_dirs=[os.path.join(TOP_BUILDDIR, 'src'),
-                                     os.path.join(TOP_SRCDIR, 'src')],
-                       libraries=['rrd'])
+    # rrdtool is built as part of the /opt/rrdtool bundle, where the extension
+    # must locate librrd at runtime through an embedded RPATH. The autotools
+    # build passes the install libdir via the RRDTOOL_RPATH environment
+    # variable. When this package is built by other means (a plain
+    # `pip install`), the variable is simply unset and no RPATH is embedded.
+    ext_kwargs = dict(
+        sources=['rrdtoolmodule.c'],
+        library_dirs=[os.path.join(TOP_BUILDDIR, 'src', '.libs')],
+        include_dirs=[os.path.join(TOP_BUILDDIR, 'src'),
+                      os.path.join(TOP_SRCDIR, 'src')],
+        libraries=['rrd'],
+    )
+    rpath = os.environ.get('RRDTOOL_RPATH', '')
+    if rpath:
+        ext_kwargs['runtime_library_dirs'] = [rpath]
+
+    module = Extension('rrdtool', **ext_kwargs)
 
     kwargs = dict(
         name='rrdtool',
index af53a592abab3052b0bdac7404975ae303349b3d..f3f415f45fc69fcd84f2f9db519426bdb7bde292 100644 (file)
@@ -15,8 +15,11 @@ export PKG_CONFIG_PATH="$ROOT/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
 
 export PERL5LIB="$ROOT/lib/perl${PERL5LIB:+:$PERL5LIB}"
 
-PY_SP=$(ls -d "$ROOT"/lib*/python*/site-packages 2>/dev/null | head -1)
-[ -n "$PY_SP" ] && export PYTHONPATH="$PY_SP${PYTHONPATH:+:$PYTHONPATH}"
+# The python binding is installed (as a wheel, via `pip install --target`)
+# into a fixed, distro-independent directory by the rrdtool build — see
+# bindings/Makefile.am. No interpreter-scheme guessing needed.
+PY_SP="$ROOT/lib/python3/site-packages"
+[ -d "$PY_SP" ] && export PYTHONPATH="$PY_SP${PYTHONPATH:+:$PYTHONPATH}"
 
 RB_ARCH=$(ls -d "$ROOT"/lib/ruby/*-* 2>/dev/null | head -1)
 if [ -n "$RB_ARCH" ]; then
index 2afb09dddd015557274110c89fa7fd07eb8b2cf2..e1ac91e2581e581c61dfbe03852484e8c3af86f7 100644 (file)
@@ -44,7 +44,7 @@ BuildRequires:  freetype-devel, libpng-devel, zlib-devel
 BuildRequires:  libxml2-devel, glib2-devel, libdbi-devel
 # binding build-deps
 BuildRequires:  perl-devel, perl-ExtUtils-MakeMaker
-BuildRequires:  python3-devel
+BuildRequires:  python3-devel, python3-setuptools, python3-pip, python3-wheel
 BuildRequires:  tcl-devel
 BuildRequires:  lua-devel
 BuildRequires:  ruby, ruby-devel