2

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.

danidar
  • 91
  • 2
  • 5
  • 2
    Why not just build two packages? a legacy "packagename-python2" package for python2 and the other just "packagename" for python3 (or whatever's the appropriate naming convention for python packages on Fedora). It's a bad idea to have two packages with exactly the same name but with very different contents and/or dependencies. – cas Nov 30 '21 at 14:16
  • I just need to build for python2 in rhel7 and for python3 in redhat8. I just don't know how to properly use the %bcond_with/without `%if 0%{?rhel} && 0%{?rhel} <= 7 %bcond_with python2 %else %bcond_without python3 %endif ` I tried this but how to configure it? – danidar Dec 06 '21 at 14:16

0 Answers0