#26 Install the Python package via standardized Python RPM macros
Opened a year ago by churchyard. Modified 6 months ago
rpms/ churchyard/libselinux pyproject  into  rawhide

file modified
+24 -33
@@ -4,7 +4,7 @@ 

  Summary: SELinux library and simple utilities

  Name: libselinux

  Version: 3.5

- Release: 1%{?dist}

+ Release: 2%{?dist}

  License: LicenseRef-Fedora-Public-Domain

  # https://github.com/SELinuxProject/selinux/wiki/Releases

  Source0: https://github.com/SELinuxProject/selinux/releases/download/3.5/libselinux-3.5.tar.gz
@@ -20,7 +20,7 @@ 

  # Patch list end

  BuildRequires: gcc make

  BuildRequires: ruby-devel ruby libsepol-static >= %{libsepolver} swig pcre2-devel xz-devel

- BuildRequires: python3 python3-devel python3-setuptools python3-pip

+ BuildRequires: python3-devel

  BuildRequires: systemd

  Requires: libsepol%{?_isa} >= %{libsepolver} pcre2

  Conflicts: filesystem < 3, selinux-policy-base < 3.13.1-138
@@ -89,6 +89,12 @@ 

  %prep

  %autosetup -p 2 -n libselinux-%{version}

  

+ 

+ %generate_buildrequires

+ cd src  # this is where the setup.py script is

+ %pyproject_buildrequires

+ 

+ 

  %build

  export DISABLE_RPM="y"

  export USE_PCRE2="y"
@@ -96,39 +102,16 @@ 

  %set_build_flags

  CFLAGS="$CFLAGS -fno-semantic-interposition"

  

- # To support building the Python wrapper against multiple Python runtimes

- # Define a function, for how to perform a "build" of the python wrapper against

- # a specific runtime:

- BuildPythonWrapper() {

-   BinaryName=$1

- 

-   # Perform the build from the upstream Makefile:

-   %make_build \

-     PYTHON=$BinaryName \

-     LIBDIR="%{_libdir}" \

-     pywrap

- }

- 

  %make_build LIBDIR="%{_libdir}" swigify

  %make_build LIBDIR="%{_libdir}" all

  

- BuildPythonWrapper %{__python3}

+ cd src

+ %pyproject_wheel

+ cd -

  

  %make_build RUBYINC="%{ruby_inc}" SHLIBDIR="%{_libdir}" LIBDIR="%{_libdir}" LIBSEPOLA="%{_libdir}/libsepol.a" rubywrap

  

  %install

- InstallPythonWrapper() {

-   BinaryName=$1

- 

-   make \

-     PYTHON=$BinaryName \

-     DESTDIR="%{buildroot}" LIBDIR="%{_libdir}" \

-     SHLIBDIR="%{_lib}" BINDIR="%{_bindir}" \

-     SBINDIR="%{_sbindir}" \

-     LIBSEPOLA="%{_libdir}/libsepol.a" \

-     install-pywrap

- }

- 

  rm -rf %{buildroot}

  mkdir -p %{buildroot}%{_tmpfilesdir}

  mkdir -p %{buildroot}%{_libdir}
@@ -137,7 +120,11 @@ 

  install -d -m 0755 %{buildroot}%{_rundir}/setrans

  echo "d %{_rundir}/setrans 0755 root root" > %{buildroot}%{_tmpfilesdir}/libselinux.conf

  

- InstallPythonWrapper %{__python3}

+ %pyproject_install

+ %pyproject_save_files selinux

+ # this is what the make install-pywrap job is doing, TODO move to setup.py

+ ln -sf --relative %{buildroot}%{python3_sitearch}/{selinux/,}_selinux%{python3_ext_suffix}

+ install -m 644 src/selinux.py %{buildroot}%{python3_sitearch}/selinux/__init__.py

  

  %make_install LIBDIR="%{_libdir}" SHLIBDIR="%{_libdir}" BINDIR="%{_bindir}" SBINDIR="%{_sbindir}"

  make DESTDIR="%{buildroot}" RUBYINSTALL=%{ruby_vendorarchdir} install-rubywrap
@@ -205,15 +192,19 @@ 

  %files static

  %{_libdir}/libselinux.a

  

- %files -n python3-libselinux

- %{python3_sitearch}/selinux/

- %{python3_sitearch}/selinux-%{version}*

- %{python3_sitearch}/_selinux*

+ %files -n python3-libselinux -f %{pyproject_files}

+ # manually installed/linked files:

+ %pycached %{python3_sitearch}/selinux/__init__.py

+ %{python3_sitearch}/_selinux%{python3_ext_suffix}

  

  %files ruby

  %{ruby_vendorarchdir}/selinux.so

  

  %changelog

+ * Mon May 22 2023 Miro Hrončok <mhroncok@redhat.com> - 3.5-2

+ - Install the Python package via standardized Python RPM macros

+ - Fixes: rhbz#2209019

+ 

  * Fri Feb 24 2023 Petr Lautrbach <lautrbach@redhat.com> - 3.5-1

  - SELinux userspace 3.5 release

  

This fixes problems with new pip, for example https://bugzilla.redhat.com/2209019

It also ensures the INSTALLER is properly set to rpm, RECORD is not installed etc.

On another hand, this removes the ability to call BuildPythonWrapper/InstallPythonWrapper multiple times.
Calling the macros repeatedly with different %python3_pkgversion set should be doable, but was never tested.

It also duplicates the Makefile partially, but that could be ideally solved in the upstream's setup.py.

https://src.fedoraproject.org/rpms/libselinux/pull-request/27 fixed the current problem, but this still is a valid thing to do -- for example, it sets the INSTALLER correctly (to rpm rather than pip).

So it really depends on whether you would be willing to accept it -- if so, I can rebase.

First I need to understand what is the change about and I would rather see this change in upstream sources so that Fedora rpm does not use its own mechanism to install part of libselinux.

Given that it's not urgent I'm leaving this open and I will investigate it later.

Hello. Should I rebase this or close it?

I would rather avoid using different methods in spec file and upstream. If it's possible, I would prefer to change this upstream. But I need to know what exactly is wrong with the current upstream implementation.

INSTALLER could be changed in the spec file.

RECORD could be removed but reading https://docs.fedoraproject.org/en-US/packaging-guidelines/Python/ -> https://packaging.python.org/en/latest/specifications/recording-installed-packages/#the-dist-info-directory -> RECORD seems to be a legit part of .dist-git

Is there any other problem in the package which needs to be fixed?

If it's possible, I would prefer to change this upstream.

Let's fix the setup-py installation upstream, I agree.

But I need to know what exactly is wrong with the current upstream implementation.

The Makefile involves Python packaging tools and then moves/links files around manually. Ideally, this should not be needed and the installation should be fixed on Python level.


The rest of the changes are spec-only. To delete RECORD and change the INSTALLER, we use the actually documented way of packaging Python stuff into Fedora -- this is not to be done upstream, only in RPM.


RECORD seems to be a legit part of .dist-git

Sorry, I have no idea what you mean. Do you mean a legit part of dist-info? Yes, it is, but removing RECORD is a legitimate (and desired) thing to do when we maintain our content via RPM and not pip. That is why the macros do it.


Is there any other problem in the package which needs to be fixed?

Future compatibility. A fix like https://src.fedoraproject.org/rpms/libselinux/pull-request/27 might be needed in the future because the current spec file calls pip via make and not via Fedora's macros.

Metadata