For packagers who like to share a common spec file between Fedora and EPELs, the following macros are defined in EPEL and Fedora that you MAY use to initialize %with pythonX
bconds. For each Python runtime, there is a %pyX_bcond_if
macro that takes one argument: either required
or available
, based on that it will create the appropriate %with pythonX
bcond. Note that even if some bcond currently behaves the same on all Fedoras and EPELs, it might change in the future.
required
means: build for this runtime only if the guidelines say it's MUSTavailable
means: build for this runtime if it is possible
Note that bcond definitions are based on the option they create, e.g. %bcond_without python2
means build with Python 2 by default and create --without python2
switch that disables it.
%py3_bcond_if required |
%py3_bcond_if available |
%py2_bcond_if required |
%py2_bcond_if available
| |
---|---|---|---|---|
All Fedoras | %bcond_without python3 |
%bcond_without python3 |
%bcond_with python2 |
%bcond_without python2
|
EPEL 7 | %bcond_with python3 |
%bcond_without python3 |
%bcond_with python2 |
%bcond_without python2
|
EPEL 6 | %bcond_with python3 |
%bcond_without python3 |
%bcond_with python2 |
%bcond_without python2
|
It's up to the packager whether they use available
or required
. Dropping python2 packages from Fedora is highly encouraged, however keep in mind that you shouldn't do it in a released version of Fedora. See an example of this in the appendix.
(The following examples go into appendix:)
Example common spec file with the must/may macros
The following is a very simple spec file for a module building for both python2 and python3 in Fedoras and EPEL based on the default bconds described above (TODO, change to a link). The packager here decided that starting form Fedora 28, the python2 subpackage is to be no longer build if not necesery. This way, the packager ensures the package will not disappear from a released Fedora where it once was.
%global srcname example 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: https://files.pythonhosted.org/packages/source/e/%{srcname}/%{srcname}-%{version}.tar.gz BuildArch: noarch %if 0%{?fedora} < 28 && 0%{?rhel} < 7 # Build for python2 if it MAY be done (we need to preserve the python2 package in stable versions) %py2_bcond_if available %else # Build for python2 only if it MUST be done %py2_bcond_if required %endif # Build for python3 if it MAY be done %py3_bcond_if available %description An python module which provides a convenient example. %if %{with python2} %package -n python2-%{srcname} Summary: %{summary} BuildRequires: python2-devel BuildRequires: python2-pytest %{?python_provide:%python_provide python2-%{srcname}} %description -n python2-%{srcname} An python module which provides a convenient example. %endif %if %{with python3} %package -n python%{python3_pkgversion}-%{srcname} Summary: %{summary} BuildRequires: python%{python3_pkgversion}-devel BuildRequires: python%{python3_pkgversion}-pytest %{?python_provide:%python_provide python%{python3_pkgversion}-%{srcname}} %if %{without python2} Obsoletes: python2-%{srcname} < %{version}-%{release} Obsoletes: python-%{srcname} < %{version}-%{release} %endif %description -n python%{python3_pkgversion}-%{srcname} An python module which provides a convenient example. %endif %prep %autosetup -n %{srcname}-%{version} %build %{?with_python2:py2_build} %{?with_python3:py3_build} %install %{?with_python2:py2_install} %{?with_python3:py3_install} %check %{?with_python2:%{__python2} setup.py test} %{?with_python3:%{__python3} setup.py test} %if %{with python2} %files -n python2-%{srcname} %license COPYING %doc README.rst %{python2_sitelib}/* %if %{without python3} %{_bindir}/sample-exec %endif %endif %if %{with python3} %files -n python%{python3_pkgversion}-%{srcname} %license COPYING %doc README.rst %{python3_sitelib}/* %{_bindir}/sample-exec %endif %changelog
How to test
(not to be part of the guidelines, just this draft)
TBD