Blob Blame History Raw
# This file is used _only_ to override macros which exist in RHEL.
# It should be used very sparingly.

# Override %__python3 here based on %%python3_pkgversion to avoid relying on the finicky
# python3X-rpm-macros packages.
# Backported from https://src.fedoraproject.org/rpms/python-rpm-macros/c/a8b26546eb699afe0dbfcef913a2aa7085fc5afb?branch=rawhide
#
# EPEL specific, RHEL defines this in the python3X-rpm-macros packages
# and the default is /usr/libexec/platform-python.
# Usually, we don't want EPEL packages to use platform-python.
# Packages that want to do that can explicitly override this.
#
# When %%python3_pkgveresion is set to 3 (i.e. the default), we override
# %%__python3 to /usr/bin/python3.6 to ensure that programs are always run with
# python3.6, even if /usr/bin/python3 is a symlink to a different interpreter.
#
# See https://lists.fedoraproject.org/archives/list/epel-devel@lists.fedoraproject.org/thread/RE3PG72B5AX7NTACPDSBGOWCMN7I3OQJ/

%__python3 %{lua:
local bin = "/usr/bin/python"
if rpm.expand("%python3_pkgversion") == "3" then
        bin = bin .. "3.6"
else
        bin = bin .. rpm.expand("%{_python3_pkgversion_with_dot}")
end
print(bin)
}

# Only python3.11-rpm-macros in RHEL 8 has %%py3_check_import defined,
# but the definition is broken (https://bugzilla.redhat.com/2207631).
# Once this issue is resolved, we can move this definition back to macros.epel
# so the python3.11-rpm-macros version overrides this definition but it remains
# available for older Python versions.

%py3_check_import(e:tf:) %{expand:\\\
  %{-e:echo 'WARNING: The -e option of %%%%py3_check_import is not currently supported on EPEL.' >&2}
  %{-t:echo 'WARNING: The -t option of %%%%py3_check_import is not currently supported on EPEL.' >&2}
  %{-f:echo 'WARNING: The -f option of %%%%py3_check_import is not currently supported on EPEL.' >&2}
  (cd %{_topdir} &&\\\
  PATH="%{buildroot}%{_bindir}:$PATH"\\\
  PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}"\\\
  PYTHONDONTWRITEBYTECODE=1\\\
  %{__python3} -c "import %{lua:local m=rpm.expand('%{?*}'):gsub('[%s,]+', ', ');print(m)}"
  )
}

# This is needed for multi-python specfiles that switch around
# %%python3_pkgversion.
#
# python3-rpm-macros sets %%__pytest to the same value as below as of
# https://bugzilla.redhat.com/2091462 and
# https://git.centos.org/rpms/python-rpm-macros/c/90be9a52cea954960e49dcd8cc87f9f330ff9f53?branch=c8s
#
# python39-rpm-macros overrides %%__pytest to /usr/bin/pytest-3.9 which doesn't
# honor the value of python3_pkgversion.
#
# In order to make this work no matter what python3X-rpm-macros packages are
# installed, we override %%__pytest here.

%__pytest /usr/bin/pytest-%{_python3_pkgversion_with_dot}