pythonfedorarpm-speccentos8rhel8

How do I install `python39-rpm-macros` for Fedora 35?


How do I select the Python version when building a RPM from a .spec file on Fedora 35?

The CentOS/RHEL documentation says

Configure the particular Python 3 version in the BuildRequires of the SPEC file to python36-rpm-macros, python38-rpm-macros, or python39-rpm-macros.

CHAPTER 40. PACKAGING PYTHON 3 RPMS

Fedora only has a python3.9 package and python3-rpm-macros package.

How can I set the Python version? How can I make this selection portable between Fedora, RHEL, and other Enterprise Linux flavors?

Attempt at solution

%define __python3 /usr/bin/python3.9
%{?fedora:BuildRequires: python3.9}
%{?rhel:BuildRequires: python39-devel}

Is this correct?


Solution

  • %global python_minimum_version 3.9.0
    
    %{?fedora:Requires: python3 >= %{python_minimum_version}}
    %{?rhel:Requires: python39 >= %{python_minimum_version}}
    
    %{?fedora:BuildRequires: python3-devel >= %{python_minimum_version}}
    # yes, I do crazy things in the rpm build, and I need pip
    %{?fedora:BuildRequires: python3-pip}
    # without wheel the installed files lack `python_qpid_proton-0.37.0.dist-info`
    %{?fedora:BuildRequires: python3-wheel}
    %{?rhel:BuildRequires: python39-devel >= %{python_minimum_version}}
    %{?rhel:BuildRequires: python39-pip}
    %{?rhel:BuildRequires: python39-wheel}
    %{?rhel:BuildRequires: python39-rpm-macros}
    

    This seems to produce a package that behaves well on both Fedora and CentOS Stream 8.

    On Fedora, latest Python is used, and on CentOS I get Python 3.9 and the #! lines in script get rewritten to use that Python 3.9 automatically.

    I consider this a success.