From d0c366b2f4390e0e7ebc558ced5a202bf1b6cddb Mon Sep 17 00:00:00 2001
From: Sebastião Guerra <sebastiao.luiz.guerra@gmail.com>
Date: Sat, 26 Sep 2026 11:32:35 -0300
Subject: RPM Python bindings: use distribution Python on openSUSE
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Use the distribution-provided Python for the RPM Python bindings instead of
hardcoding Python 3.11 on openSUSE.

Add setuptools to sip4-tqt for distutils compatibility. Keep setuptools and
the build/install environment fixes for pytdeextensions, and use %{__python}
when rewriting its Python shebangs.

Validated the full sip4-tqt -> pytqt -> pytde -> pytdeextensions chain on
openSUSE Tumbleweed with Python 3.13 in OBS.

Signed-off-by: Sebastião Guerra <sebastiao.luiz.guerra@gmail.com>
---
 redhat/dependencies/pytqt/pytqt.spec                  |  6 ------
 redhat/dependencies/sip4-tqt/sip4-tqt.spec            |  7 +------
 redhat/libraries/pytde/pytde.spec                     |  5 -----
 redhat/libraries/pytdeextensions/pytdeextensions.spec | 10 ++++++++++
 4 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/redhat/dependencies/pytqt/pytqt.spec b/redhat/dependencies/pytqt/pytqt.spec
index 05e3c9885..3bf887bba 100644
--- a/redhat/dependencies/pytqt/pytqt.spec
+++ b/redhat/dependencies/pytqt/pytqt.spec
@@ -73,18 +73,12 @@ BuildRequires:	libtqscintilla-devel >= %{?epoch:%{epoch}:}1.7.1
 BuildRequires:	gcc-c++
 
 # PYTHON support
-%if 0%{?suse_version}
-%global python python311
-%global __python /usr/bin/python3.11
-%global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")
-%else
 %if "%{python}" == ""
 %global python python3
 %endif
 %global __python %__python3
 %global python_sitearch %{python3_sitearch}
 %{!?python_sitearch:%global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")}
-%endif
 BuildRequires:	%{python}
 BuildRequires:	%{python}-devel
 
diff --git a/redhat/dependencies/sip4-tqt/sip4-tqt.spec b/redhat/dependencies/sip4-tqt/sip4-tqt.spec
index 406f10d51..7bbda63e5 100644
--- a/redhat/dependencies/sip4-tqt/sip4-tqt.spec
+++ b/redhat/dependencies/sip4-tqt/sip4-tqt.spec
@@ -77,20 +77,15 @@ BuildRequires:  bison
 BuildRequires:	flex
 
 # PYTHON support
-%if 0%{?suse_version}
-%global python python311
-%global __python /usr/bin/python3.11
-%global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")
-%else
 %if "%{python}" == ""
 %global python python3
 %endif
 %global __python %__python3
 %global python_sitearch %{python3_sitearch}
 %{!?python_sitearch:%global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")}
-%endif
 BuildRequires:	%{python}
 BuildRequires:	%{python}-devel
+BuildRequires:	%{python}-setuptools
 
 # YACC support
 %if 0%{?rhel} >= 8 || 0%{?fedora} >= 31
diff --git a/redhat/libraries/pytde/pytde.spec b/redhat/libraries/pytde/pytde.spec
index 81ae21b66..e310bc20f 100644
--- a/redhat/libraries/pytde/pytde.spec
+++ b/redhat/libraries/pytde/pytde.spec
@@ -66,14 +66,9 @@ BuildRequires:	gcc-c++
 %if "%{python}" == ""
 %global python python3
 %endif
-%if 0%{?suse_version}
-%global __python /usr/bin/python3.11
-%global python_sitearch %{_libdir}/python3.11/site-packages
-%else
 %global __python %__python3
 %global python_sitearch %{python3_sitearch}
 %{!?python_sitearch:%global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")}
-%endif
 BuildRequires:	%{python}
 BuildRequires:	%{python}-devel
 
diff --git a/redhat/libraries/pytdeextensions/pytdeextensions.spec b/redhat/libraries/pytdeextensions/pytdeextensions.spec
index 467c6f143..72b706ea3 100644
--- a/redhat/libraries/pytdeextensions/pytdeextensions.spec
+++ b/redhat/libraries/pytdeextensions/pytdeextensions.spec
@@ -83,6 +83,7 @@ Requires:		sip4-tqt >= 4.10.5
 %{!?python_sitearch:%global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")}
 BuildRequires:	%{python}
 BuildRequires:	%{python}-devel
+BuildRequires:	%{python}-setuptools
 
 
 Obsoletes:		trinity-pykdeextensions < %{?epoch:%{epoch}:}%{version}-%{release}
@@ -197,10 +198,17 @@ done
   -e "s|/usr/bin/python|/usr/bin/env %{python}|"
 %endif
 
+%if 0%{?suse_version}
+find . -type f -name '*.py' -exec %__sed -i \
+  -e '1s|^#!/usr/bin/python$|#!%{__python}|' \
+  -e '1s|^#!/usr/bin/env python$|#!%{__python}|' {} +
+%endif
+
 
 %build
 unset QTDIR QTINC QTLIB
 export PATH="%{tde_bindir}:${PATH}"
+export PYTHONPATH="%{python_sitearch}:${PYTHONPATH}"
 
 %__mkdir_p build
 %__python ./setup.py build_libpythonize
@@ -209,6 +217,8 @@ export PATH="%{tde_bindir}:${PATH}"
 %install
 unset QTDIR QTINC QTLIB
 export PATH="%{tde_bindir}:${PATH}"
+export PYTHONPATH="%{python_sitearch}:${PYTHONPATH}"
+export LD_LIBRARY_PATH="%{tde_libdir}:${LD_LIBRARY_PATH}"
 
 # Avoids 'error: byte-compiling is disabled.' on Mandriva/Mageia
 export PYTHONDONTWRITEBYTECODE=
-- 
cgit v1.2.3

