Patchwork [2,of,7,stable] packaging: be explicit about Python version in rpm spec

login
register
mail settings
Submitter Mads Kiilerich
Date Oct. 27, 2019, 11:37 p.m.
Message ID <6ce451ed79a3132bb639.1572219430@xps>
Download mbox | patch
Permalink /patch/42601/
State Accepted
Headers show

Comments

Mads Kiilerich - Oct. 27, 2019, 11:37 p.m.
# HG changeset patch
# User Mads Kiilerich <mads@kiilerich.com>
# Date 1572208821 -3600
#      Sun Oct 27 21:40:21 2019 +0100
# Branch stable
# Node ID 6ce451ed79a3132bb6390210ca460a106d40b6db
# Parent  496bbefb8fa0f24c789ae98f0b37e98046acb83c
packaging: be explicit about Python version in rpm spec

Fedora 31 has Python3 at /usr/bin/python ... but expect everybody to not just
find python in $PATH but be explicit about whether they want python2 or
python3. mercurial.spec just used 'python' and would fail when it unknowingly
used Python 3 and ended up with Mercurial setup.py reporting "Python 3.7
detected." and talking about the HGPYTHON3 environment variable.

For now, just be explicit about using system python2 as python executable when
building rpms.

Patch

diff --git a/contrib/packaging/mercurial.spec b/contrib/packaging/mercurial.spec
--- a/contrib/packaging/mercurial.spec
+++ b/contrib/packaging/mercurial.spec
@@ -15,7 +15,8 @@ 
 
 %else
 
-%global pythonver %(python -c 'import sys;print(".".join(map(str, sys.version_info[:2])))')
+%global pythonexe python2
+%global pythonver %(%{pythonexe} -c 'import sys;print(".".join(map(str, sys.version_info[:2])))')
 
 %endif
 
@@ -52,7 +53,7 @@  for efficient handling of very large dis
 %if "%{?withpython}"
 %setup -q -n mercurial-%{version}-%{release} -a1 -a2
 # despite the comments in cgi.py, we do this to prevent rpmdeps from picking /usr/local/bin/python up
-sed -i '1c#! /usr/bin/env python' %{pythonname}/Lib/cgi.py
+sed -i '1c#! /usr/bin/env %{pythonexe}' %{pythonname}/Lib/cgi.py
 %else
 %setup -q -n mercurial-%{version}-%{release}
 %endif
@@ -82,9 +83,11 @@  export PYTHONPATH=$PWD/%{docutilsname}
 
 %endif
 
-make all
+make all PYTHON=%{pythonexe}
 make -C contrib/chg
 
+sed -i -e '1s|#!/usr/bin/env python$|#!/usr/bin/env %{pythonexe}|' contrib/hg-ssh
+
 %install
 rm -rf $RPM_BUILD_ROOT
 
@@ -101,14 +104,14 @@  cd %{docutilsname}
 LD_LIBRARY_PATH=$PYPATH $PYPATH/python setup.py install --root="$RPM_BUILD_ROOT"
 cd -
 
-PATH=$PYPATH:$PATH LD_LIBRARY_PATH=$PYPATH make install DESTDIR=$RPM_BUILD_ROOT PREFIX=%{hgpyprefix} MANDIR=%{_mandir}
+PATH=$PYPATH:$PATH LD_LIBRARY_PATH=$PYPATH make install PYTHON=%{pythonexe} DESTDIR=$RPM_BUILD_ROOT PREFIX=%{hgpyprefix} MANDIR=%{_mandir}
 mkdir -p $RPM_BUILD_ROOT%{_bindir}
 ( cd $RPM_BUILD_ROOT%{_bindir}/ && ln -s ../..%{hgpyprefix}/bin/hg . )
 ( cd $RPM_BUILD_ROOT%{_bindir}/ && ln -s ../..%{hgpyprefix}/bin/python2.? %{pythonhg} )
 
 %else
 
-make install DESTDIR=$RPM_BUILD_ROOT PREFIX=%{_prefix} MANDIR=%{_mandir}
+make install PYTHON=%{pythonexe} DESTDIR=$RPM_BUILD_ROOT PREFIX=%{_prefix} MANDIR=%{_mandir}
 
 %endif