From Fedora Project Wiki
mNo edit summary
mNo edit summary
Line 104: Line 104:
<pre>
<pre>
%if 0%{?fedora} && 0%{?fedora} > 27
%if 0%{?fedora} && 0%{?fedora} > 27
%global py2_use 0%{py2_must}
%global py2_use 0%{?py2_must}
%else
%else
%global py2_use 0%{py2_may}
%global py2_use 0%{?py2_may}
%endif
%endif
</pre>
</pre>


And use <code>%py2_use</code> in the conditionals inside the spec file. That way, you don't accidentally drop python2 subpackage from a released Fedora.
And use <code>%py2_use</code> in the conditionals inside the spec file. That way, you don't accidentally drop python2 subpackage from a released Fedora.

Revision as of 18:37, 1 March 2018

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 can use in conditionals. For each Python runtime, there are 2 versions of the macros: a must version (that says whether the packager must package for that runtime if possible) and a may version (that says that if the packager wants to, they may package for that runtime). Note that even if some macro currently expands to 1 an all Fedoras and EPELs, it maight change in the future.

%py3_must %py3_may %py2_must %py2_may
All Fedoras 1 1 0 1
EPEL 7 0 1 0 1
EPEL 6 0 1 0 1

It's up to the packager whether they conditionalize on the must or may macros, or whether they use those macros at all. See some examples 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. It uses the %py3_must etc. macros so it should build on all possible distributions.

In this example, the packager want's to support as many Python stacks as possible. Substitute all py2_may with py2_must for a more forward looking approach.

%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

%description
An python module which provides a convenient example.

%if 0%{?py2_may}
%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 0%{?py3_may}
%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}}

%description -n python%{python3_pkgversion}-%{srcname}
An python module which provides a convenient example.
%endif

%prep
%autosetup -n %{srcname}-%{version}

%build
%{?py2_may:%py2_build}
%{?py3_may:%py3_build}

%install
%{?py2_may:%py2_install}
%{?py3_may:%py3_install}

%check
%{?py2_may:%{__python2} setup.py test}
%{?py3_may:%{__python3} setup.py test}

%if 0%{?py2_may}
%files -n python2-%{srcname}
%license COPYING
%doc README.rst
%{python2_sitelib}/*
%if ! 0%{?py3_may}
%{_bindir}/sample-exec
%endif
%endi

%if 0%{?py3_may}
%files -n python%{python3_pkgversion}-%{srcname}
%license COPYING
%doc README.rst
%{python3_sitelib}/*
%{_bindir}/sample-exec
%endif

%changelog

You may introduce a following section to top of your spec, if you wish to transition from may to must in Fedora 28:

%if 0%{?fedora} && 0%{?fedora} > 27
%global py2_use 0%{?py2_must}
%else
%global py2_use 0%{?py2_may}
%endif

And use %py2_use in the conditionals inside the spec file. That way, you don't accidentally drop python2 subpackage from a released Fedora.