Sample Header Ad - 728x90

build rpm for python2 if python3 is not installed

2 votes
1 answer
908 views
I want to package a python application which can run on both python2 and python3 for we have still old systems running python2. the default should be python3 but in case of python3 is not installed. I would like to build it for python2. without changing the name: i have followed the instruction here: https://docs.fedoraproject.org/en-US/packaging-guidelines/Python_Appendix/#_conditionalizing_the_python_2_parts and I tried this: %global srcname example # Disable python2 by default %bcond_with python2 Name: python-%{srcname} Version: 1.2.3 Release: 1%{?dist} Summary: An example python module License: MIT URL: https://pypi.python.org/pypi/%{srcname} Source0: %pypi_source BuildArch: noarch %global _description %{expand: A python module which provides a convenient example.} %description %_description %if %{with python2} %package -n python2-%{srcname} Summary: %{summary} BuildRequires: python2-devel %description -n python2-%{srcname} %_description %endif %package -n python3-%{srcname} Summary: %{summary} BuildRequires: python3-devel %description -n python3-%{srcname} %_description %prep %autosetup -n %{srcname}-%{version} %build %if %{with python2} %py2_build %endif %py3_build %install # Must do the python2 install first because the scripts in /usr/bin are # overwritten with every setup.py install, and in general we want the # python3 version to be the default. %if %{with python2} %py2_install %endif %py3_install %check %if %{with python2} %{python2} setup.py test %endif %{python3} setup.py test %if %{with python2} %files -n python2-%{srcname} %license COPYING %doc README.rst %{python2_sitelib}/%{srcname}/ %{python2_sitelib}/%{srcname}-*.egg-info/ %endif %files -n python3-%{srcname} %license COPYING %doc README.rst %{python3_sitelib}/%{srcname}/ %{python3_sitelib}/%{srcname}-*.egg-info/ %{_bindir}/sample-exec %changelog but It always tries to build both which fails furthermore i need to change the package name eg python2-%{srcname}. I need them to have the same names it is not a python module it is a standalone program.
Asked by danidar (201 rep)
Nov 30, 2021, 07:56 AM
Last activity: Nov 9, 2023, 08:03 PM