#1 Make %py3_dist respect %python3_pkgversion
Closed 2 years ago by churchyard. Opened 2 years ago by churchyard.
rpms/ churchyard/python-rpm-macros c8s-bz2090007  into  c8s

file modified
+19 -1
@@ -41,10 +41,28 @@ 

          end\

  }

  

+ # RHEL 9+ and Fedora compatibility macro

+ # Only use in macro backports, not intended to be used in spec files!

+ # In the future, the %%python3_pkgversion macro has a dot, e.g. 3.9 or 3.11

+ # However, in RHEL 8 at least, it does not, e.g. 38, 39

+ # This is a helpful macro that determines the proper "Python version" string with dot

+ # from %%python3_pkgversion without actually having Python installed.

+ # For values other than 3X, it should expand to %%python3_pkgversion unchanged.

+ # Examples of %%python3_pkgversion -> %%_python3_pkgversion_with_dot:

+ #   3    -> 3

+ #   38   -> 3.8

+ #   39   -> 3.9

+ #   310  -> 3.10

+ #   3.12 -> 3.12

+ #   4    -> 4

+ #   412  -> 412

+ %_python3_pkgversion_with_dot %{lua:print((rpm.expand("%python3_pkgversion"):gsub('^3(%d)', '3.%1')))}

+ 

  # Creates Python 3 dist tag(s) after converting names to canonical format

  #   Needs to first put all arguments into a list, because invoking a different

  #   macro (%py_dist_name) overwrites them

  %py3_dist() %{lua:\

+         python3_pkgversion_with_dot = rpm.expand("%_python3_pkgversion_with_dot")\

          args = {}\

          arg = 1\

          while (true) do\
@@ -57,7 +75,7 @@ 

          end\

          for arg, name in ipairs(args) do\

                  canonical = rpm.expand("%py_dist_name " .. name);\

-                 print("python3dist(" .. canonical .. ") ");\

+                 print("python" .. python3_pkgversion_with_dot .. "dist(" .. canonical .. ") ");\

          end\

  }

  

file modified
+5 -1
@@ -1,6 +1,6 @@ 

  Name:           python-rpm-macros

  Version:        3

- Release:        41%{?dist}

+ Release:        42%{?dist}

  Summary:        The unversioned Python RPM macros

  

  License:        MIT
@@ -73,6 +73,10 @@ 

  

  

  %changelog

+ * Wed May 25 2022 Miro Hrončok <mhroncok@redhat.com> - 3-42

+ - Make %%py3_dist respect %%python3_pkgversion

+ Resolves: rhbz#2090007

+ 

  * Mon Feb 01 2021 Lumír Balhar <lbalhar@redhat.com> - 3-41

  - Fix dependencies between subpackages

  Resolves: rhbz#1892797

By default, %{py3_dist foo} generates python3dist(foo).
This change makes it respect %python3_pkgversion so when
it is redefined as X.Y, %{py3_dist foo} generates pythonX.Y(foo).

This is a modified backport of https://src.fedoraproject.org/rpms/python-rpm-macros/c/638f809f4c15b8b14dfc1f6f8c3c08b0d2ba0b70

In addition, :gsub('^3(%d)', '3.%1') was added.
It makes sure that values of %python3_pkgversion without dot
are converted to values with dots.
In RHEL 8, at least until Python 3.9, the %python3_pkgversion value is 39.
It is written in a way that allows us to use 3.10 for the next version if desired.

$ rpm --define 'python3_pkgversion 3' --eval '%{py3_dist heh}'
python3dist(heh)

$ rpm --define 'python3_pkgversion 3.8' --eval '%{py3_dist heh}'
python3.8dist(heh)

$ rpm --define 'python3_pkgversion 38' --eval '%{py3_dist heh}'
python3.8dist(heh)

$ rpm --define 'python3_pkgversion 3.12' --eval '%{py3_dist heh}'
python3.12dist(heh)

$ rpm --define 'python3_pkgversion 312' --eval '%{py3_dist heh}'
python3.12dist(heh)

The default behavior is reasonable:

$ rpm -q python36-rpm-macros
package python36-rpm-macros is not installed
$ rpm -q python38-rpm-macros
package python38-rpm-macros is not installed
$ rpm -q python39-rpm-macros
package python39-rpm-macros is not installed
$ rpm --eval '%{py3_dist heh}'
python3dist(heh)

$ rpm -q python36-rpm-macros
python36-rpm-macros-3.6.8-38.module_el8.5.0+2569+5c5719bc.noarch
$ rpm --eval '%{py3_dist heh}'
python3dist(heh)

$ rpm -q python38-rpm-macros
python38-rpm-macros-3.8.12-1.module_el8.6.0+2778+cd494b30.noarch
$ rpm --eval '%{py3_dist heh}'
python3.8dist(heh)

$ rpm -q python39-rpm-macros
python39-rpm-macros-3.9.7-1.module_el8.6.0+2780+a40f65e1.noarch
$ rpm --eval '%{py3_dist heh}'
python3.9dist(heh)

The value for non-3 %python3_pkgversion is preserved as is:

$ rpm --define 'python3_pkgversion 4' --eval '%{py3_dist heh}'
python4dist(heh)

$ rpm --define 'python3_pkgversion 48' --eval '%{py3_dist heh}'
python48dist(heh)

Co-authored-by: @lbalhar

This looks good to me. My only suggestion would be to consider creating a separate macro that adds dots to %python3_pkgversion and use that in %py3_dist so this logic can be used by packagers and potentially in other backported macros (e.g. https://src.fedoraproject.org/rpms/python-rpm-macros/c/a8b26546eb699afe0dbfcef913a2aa7085fc5afb?branch=rawhide).

My concern wrt adding a macro is that it would be RHEL-only and would not exist on Fedora.
So if we add it, we should probably define it n Fedora first.

%python3_pkgversion_dot ?

So if we add it, we should probably define it n Fedora first.

That makes sense. Is the plan to just make the Fedora macro spit out %python3_pkgversion or actually copy over the dot logic even though it's not useful in Fedora? Either way, I'm happy to review or potentially submit a PR to Fedora's python-rpm-macros.

I would probably just define it as:

# For compatibility with RHEL 8, where pkgversion is e.g. 39 instead of 3.9
%python3_pkgversion_dot %python3_pkgversion

I've slept on it. I'd rather not pollute the macro-space with another thing like that. We can make the macro "private" and only encourage using it from other RHEL/EPEL 8 macro backports. Let's call it %_python3_pkgversion_dot instead.

I've slept on it. I'd rather not pollute the macro-space with another thing like that.

It's also worth noting that we already have %python3_version and %python3_version_nodots1 in python3-rpm-macros. This won't work for our usecase, as I don't think we can rely on %__python3 being available (or even set correctly) at SRPM buildtime. It also won't work if we decide to backport https://src.fedoraproject.org/rpms/python-rpm-macros/c/a8b26546eb699afe0dbfcef913a2aa7085fc5afb?branch=rawhide, which I'm thinking might be better and less fragile than what I proposed in https://src.fedoraproject.org/rpms/epel-rpm-macros/pull-request/44. However, I think already having a similar macro in Fedora is another reason to make this a RHEL-only private macro.

Let's call it %_python3_pkgversion_dot instead.

Another idea would be to name it %__py3_dist_version to make its purpose clearer.

Another idea would be to name it %__py3_dist_version to make its purpose clearer.

That would scope it to this particular macro entirely - I thought the idea of defining it as a macro was to be able to reuse it elsewhere... ?

1 new commit added

  • fixup! Make %py3_dist respect %python3_pkgversion
2 years ago

This looks good to me. I think the final macro name is better than the other proposed options.

rebased onto fae685b

2 years ago

Squashed. Merged to RHEL dist git.

Pull-Request has been closed by churchyard

2 years ago