Conditionals on Python versions for BuildRequires?
Hi! If I remember correctly, it's not possible to use the %python_version_nodots macro to use a certain build dependency for certain Python versions only, is it? I tried a variant of the snippet here [1] for BuildRequires but that doesn't work. %if %python_version_nodots < 39 BuildRequires: python-importlib_resources %endif Is there any other way to guard BuildRequires against certain Python versions? Or is the python-rpm-macros in SLE-15-SP3 just too old? Adrian
[1] https://en.opensuse.org/openSUSE:Packaging_Python#Conditionals_on_Python_ver...
Hello Adrian, Am 19.04.21 um 16:10 schrieb John Paul Adrian Glaubitz:
Hi!
If I remember correctly, it's not possible to use the %python_version_nodots macro to use a certain build dependency for certain Python versions only, is it?
I tried a variant of the snippet here [1] for BuildRequires but that doesn't work.
%if %python_version_nodots < 39 BuildRequires: python-importlib_resources %endif
BuildRequires is not subject to the python-rpm-macros singlespec generator for flavor subpackages. It is only interpreted as is and only once in the preamble: - %python_version_nodots evaluates to the primary flavor version 38, so the condition is true. - python-importlib_resources is taken as is. But such a "binary" rpm package does not exist. Only python[23]-importlib_resources in SLE/Leap and python3[689]-importlib_resources in TW.
Is there any other way to guard BuildRequires against certain Python versions?
https://en.opensuse.org/openSUSE:Packaging_Python#BuildRequires says: If you need a package under certain conditions, useRPM boolean dependencies <https://rpm.org/user_doc/boolean_dependencies.html>. You can reference the Python version of the expanded flavor itself by using the pseudo|%python|macro (don't define|%python|anywhere else) Adapted to your case: BuildRequires: %{python_module python-importlib_resources if %python-base < 3.9}
Or is the python-rpm-macros in SLE-15-SP3 just too old?
SLE-15-SP3 does only have Python 3.6 packages. BuildRequires needs to be interpreted by the build service. So the the %python_module macro interpreting the special %python is a feature of the prjconf, not only of python-rpm-macros. openSUSE:Factory, devel:languages:python:backports and all projects inheriting their prjconf from either of those have it. Your specific project with a built target for SLE-15-SP3 maybe does not. You can circumvent that by %if 0%{?suse_version} >= 1550 BuildRequires: %{python_module python-importlib_resources if %python-base < 3.9} %else BuildRequires: %{python_module python-importlib_resources} # or simply BuildRequires: python3-importlib_resources %endif Note that https://pypi.org/project/importlib-resources/ says: Users of Python 3.9 and beyond should use the standard library module, since for these versions,importlib_resourcesjust delegates to that module. Thus, it should actually not harm if python39-importlib-resources is installed in the build environment (it exists). This is not necessarily true for other packages, however.
Adrian
[1] https://en.opensuse.org/openSUSE:Packaging_Python#Conditionals_on_Python_ver...
BTW, remember our fallout in January? My SR to python-opentelemetry-api because of aiocontextvars already contained a variant of the solution above. Ben
.. duh, fist python_module parameter without the python- prefix: Am 19.04.21 um 21:43 schrieb Ben Greiner:
BuildRequires: %{python_module importlib_resources if %python-base < 3.9}
%if 0%{?suse_version} >= 1550 BuildRequires: %{python_module importlib_resources if %python-base < 3.9} %else BuildRequires: %{python_module importlib_resources} # or simply BuildRequires: python3-importlib_resources %endif
.. duh, first python_module parameter without the python- prefix: Am 19.04.21 um 21:43 schrieb Ben Greiner:
BuildRequires: %{python_module importlib_resources if %python-base < 3.9} %if 0%{?suse_version} >= 1550 BuildRequires: %{python_module importlib_resources if %python-base < 3.9} %else BuildRequires: %{python_module importlib_resources} # or simply BuildRequires: python3-importlib_resources %endif
participants (3)
-
Ben Greiner
-
Benjamin Greiner
-
John Paul Adrian Glaubitz