dean89
dean89

Reputation: 141

Multiple python3 versions inside RPM package with .spec file

I am trying to build a RPM package with two added python3 versions. I have built a Docker container that is using Rockylinux 8 that comes with python3.6. Now I added two more versions 3.9 and 3.11 using:

dnf download --source python3.11-requests
rpm -ivh python3.11-requests-2.28.1-1.el8.src.rpm

and:

dnf download --source python39-requests
rpm -ivh python-requests-2.25.0-2.module+el8.8.0+1554+fb04b4e8.src.rpm

This is the .spec file that I am using but if I try to build it, it builds it with only version 3.11 and ommit 3.9:

%global underscore() %(echo %1 | sed 's/-/_/g')

%global sum A simple python library for interacting with the Messaging APP
%global desc A simple python library for interacting with the Messaging APP


Name:           my-fake-library
Summary:        %{sum}
Version:        0.6.1
Release:        1%{?dist}

Group:          Development/Libraries
License:        ASL 2.0
URL:            https://github.com/fake-git/my-fake-library.git
Source0:        %{name}-%{version}.tar.gz

BuildArch:      noarch


%description
%{desc}

%define __python3 /usr/bin/python3.9                                                                                            
%define python3_pkgversion 3.9

%package -n python%{python3_pkgversion}-%{name}
Obsoletes:     fake-library
Provides:      fake-library
Summary:       %{sum}
BuildRequires: python3-devel     python3-setuptools
Requires:      python3-requests
AutoReq: no
%description -n python%{python3_pkgversion}-%{name}
%{desc}
%{?python_provide:%python3_provide python3-%{name}}


%define __python3 /usr/bin/python3.11                                                                                            
%define python3_pkgversion 3.11

%package -n python%{python3_pkgversion}-%{name}
Summary: %{sum}
BuildRequires: python3-devel    python3-setuptools
Requires:      python3-requests
AutoReq: no
%description -n python%{python3_pkgversion}-%{name}
%{desc}
%{?python_provide:%python3_provide python3-%{name}}


%prep
%setup -q


%build
%{py3_build}


%install
rm -rf %{buildroot}
%{py3_install "--record=INSTALLED_FILES_PY39" }
%{py3_install "--record=INSTALLED_FILES_PY311" }

%files -n python%{python3_pkgversion}-%{name} -f INSTALLED_FILES_PY39
%doc examples/ README.md
%defattr(-,root,root,-)
%{python3_sitelib}/*


%files -n python%{python3_pkgversion}-%{name} -f INSTALLED_FILES_PY311
%doc examples/ README.md
%defattr(-,root,root,-)
%{python3_sitelib}/*

What am I doing wrong? Thx!

Upvotes: 0

Views: 641

Answers (1)

dean89
dean89

Reputation: 141

I think I achieved what I wanted. With this adjusted code I got two python3 packages with versions that I need, python3-3.11-fake-library-0.6.1-1.el8.noarch.rpm and python3-3.9-fake-library-0.6.1-1.el8.noarch.rpm.

%global underscore() %(echo %1 | sed 's/-/_/g')

%global python3_pkgversion_1 3.9
%global python3_pkgversion_2 3.11


Name:           fake-library
Summary:        %{sum}
Version:        0.6.1
Release:        1%{?dist}

Group:          Development/Libraries
License:        ASL 2.0
URL:            https://github.com/fake-git/my-fake-library.git
Source0:        %{name}-%{version}.tar.gz

BuildArch:      noarch

%description
%{desc}

%package -n python3-%{python3_pkgversion_1}-%{name}
Summary:       %{sum}
BuildRequires: python39-devel    python39-setuptools
Requires:      python39-requests
AutoReq: no
%description -n python3-%{python3_pkgversion_1}-%{name}
%{desc}
%{?python_provide:%python_provide python3-%{python3_pkgversion_1}-%{name}}

%package -n python3-%{python3_pkgversion_2}-%{name}
Summary:       %{sum}
BuildRequires: python3.11-devel    python3.11-setuptools
Requires:      python3.11-requests
AutoReq: no
%description -n python3-%{python3_pkgversion_2}-%{name}
%{desc}
%{?python_provide:%python_provide python3-%{python3_pkgversion_2}-%{name}}

%prep
%setup -q

%build
python3.9 setup.py build
python3.11 setup.py build

%install
rm -rf %{buildroot}
python3.9 setup.py install --root=%{buildroot} --record=INSTALLED_FILES_PY3_3.9
python3.11 setup.py install --root=%{buildroot} --record=INSTALLED_FILES_PY3_3.11

%files -n python3-%{python3_pkgversion_1}-%{name} -f INSTALLED_FILES_PY3_3.9
%doc examples/ README.md
%defattr(-,root,root,-)
/usr/lib/python3.9/site-packages/*

%files -n python3-%{python3_pkgversion_2}-%{name} -f INSTALLED_FILES_PY3_3.11
%doc examples/ README.md
%defattr(-,root,root,-)
/usr/lib/python3.11/site-packages/*

Upvotes: 0

Related Questions