Bug 2169780

Summary: python3_version macros doesn't support python 3.11
Product: Red Hat Enterprise Linux 8 Reporter: Dimitri Savineau <dsavinea>
Component: python-rpm-macrosAssignee: Python Maintainers <python-maint>
Status: CLOSED ERRATA QA Contact: Lukáš Zachar <lzachar>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 8.8CC: lmiksik, maxwell, orion, python-maint, torsava
Target Milestone: rcKeywords: Triaged
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: python-rpm-macros-3-45.el8 Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of:
: 2172909 (view as bug list) Environment:
Last Closed: 2023-05-16 08:35:40 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2137139, 2172909    

Description Dimitri Savineau 2023-02-14 16:49:32 UTC
Description of problem:

The %python3_version macros don't support python 3.11 (ie: they only support one digit for the python minor version)

Version-Release number of selected component (if applicable):

# python3.11 -V
Python 3.11.1
# rpm -q python3.11
python3.11-3.11.1-4.el8.x86_64
# rpm -q python3-rpm-macros
python3-rpm-macros-3-44.el8.noarch

How reproducible:
100%

Steps to Reproduce:
1. Set %global __python3 /usr/bin/python3.11
2. Try to use anything that use the %python3_version macro like %py3_shebang_fix

Actual results:

+ '[' -f /usr/bin/pathfix3.1.py ']'
+ pathfix=/usr/bin/pathfix.py
+ '[' -z '' ']'
+ shebang_flags=-k
+ /usr/bin/pathfix.py -pni /usr/bin/python3.11 -k test/lib/ansible_test
/var/tmp/rpm-tmp.0UpaOA: line 88: /usr/bin/pathfix.py: No such file or directory


Expected results:


+ '[' -f /usr/bin/pathfix3.11.py ']'
+ pathfix=/usr/bin/pathfix3.11.py
+ '[' -z '' ']'
+ shebang_flags=-k
+ /usr/bin/pathfix3.11.py -pni /usr/bin/python3.11 -k test/lib/ansible_test

Additional info:

%py3_shebang_fix macro is based on the %python3_version macro but the latest only supports one digit for the python minor version (%python3_version_nodots is also affected by this)

The current macro definition from the python3-rpm-macros package is the following:

%python3_version %(%{__python3} -Ic "import sys; sys.stdout.write(sys.version[:3])")
%python3_version_nodots %(%{__python3} -Ic "import sys; sys.stdout.write(sys.version[:3].replace('.',''))")


# /usr/bin/python3.11 -Ic "import sys; sys.stdout.write(sys.version[:3])"
3.1
# /usr/bin/python3.11 -Ic "import sys; sys.stdout.write(sys.version[:3].replace('.',''))"
31

Those macros on RHEL 9 aren't affected by the same issue due to a different implementation:

%python3_version %(RPM_BUILD_ROOT= %{__python3} -Ic "import sys; sys.stdout.write('{0.major}.{0.minor}'.format(sys.version_info))")
%python3_version_nodots %(RPM_BUILD_ROOT= %{__python3} -Ic "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))")

Note that as a workaround, one can just override the macro with the following:

%global python3_version 3.11

Comment 1 Miro Hrončok 2023-02-14 17:08:12 UTC
Thanks for the report.

The idea is that for Python 3.11 you use python3.11-rpm-macros on RHEL 8, because the original macros are too old. https://git.centos.org/rpms/python3.11/blob/c8s/f/SOURCES/macros.python3.11#_12

But on the other hand, fixing the %python3_version macro in python3-rpm-macros (and python-rpm-macros) is certainly possible and I suspect we will have a hard time explaining the concept of python3.11-rpm-macros to users who get bit by this if we don't fix it.

Comment 2 Dimitri Savineau 2023-02-14 17:26:40 UTC
> The idea is that for Python 3.11 you use python3.11-rpm-macros on RHEL 8

That was my initial plan by using

%global python3_pkgversion 3.11

BuildRequires: python%{python3_pkgversion}-rpm-macros

And I was not able to find any python3.11-rpm-macros package available.

But looks like I didn't look closely as that package is built as part of the python3.11 package so let me retest this.

So if this is working correctly then we can close this BZ unless you really want to fix this for python3-rpm-macros

Comment 3 Dimitri Savineau 2023-02-14 17:36:11 UTC
Ok I confirm that using the correct python3.11-rpm-macros fix my issue.

I'll let you decide if this needs to be fixed for python3-rpm-macros or not and close this BZ accordaly

Comment 6 Miro Hrončok 2023-02-22 14:26:15 UTC
$ rpm -qa | grep python | grep macros
python-rpm-macros-3-44.el8.noarch
python-srpm-macros-3-44.el8.noarch
python3-rpm-macros-3-44.el8.noarch

$ rpm --define '__python3 /usr/bin/python3.11' --eval '%python3_version'
3.1

$ rpm --define '__python3 /usr/bin/python3.11' --eval '%python3_version_nodots'
31

$ rpm --define '__python3 /usr/bin/python3.11' --eval '%py3_shebang_fix'
\
  if [ -f /usr/bin/pathfix3.1.py ]; then
    pathfix=/usr/bin/pathfix3.1.py
  else
    # unversioned pathfix.py provided by platform-python-devel
    pathfix=/usr/bin/pathfix.py
  fi
  if [ -z "s" ]; then
    shebang_flags="-k"
  else
    shebang_flags="-kas"
  fi
  $pathfix -pni /usr/bin/python3.11 $shebang_flags


===========================================================================

$ rpm -qa | grep python | grep macros
python-rpm-macros-3-45.el8.noarch
python-srpm-macros-3-45.el8.noarch
python3-rpm-macros-3-45.el8.noarch

$ rpm --define '__python3 /usr/bin/python3.11' --eval '%python3_version'
3.11

$ rpm --define '__python3 /usr/bin/python3.11' --eval '%python3_version_nodots'
311

$ rpm --define '__python3 /usr/bin/python3.11' --eval '%py3_shebang_fix'
\
  if [ -f /usr/bin/pathfix3.11.py ]; then
    pathfix=/usr/bin/pathfix3.11.py
  else
    # unversioned pathfix.py provided by platform-python-devel
    pathfix=/usr/bin/pathfix.py
  fi
  if [ -z "s" ]; then
    shebang_flags="-k"
  else
    shebang_flags="-kas"
  fi
  $pathfix -pni /usr/bin/python3.11 $shebang_flags

Comment 7 Miro Hrončok 2023-02-22 14:29:36 UTC
Regression check, this still works as expected:

$ rpm --eval '%python3_version'
3.6

$ rpm --eval '%python3_version_nodots'
36

Comment 14 Miro Hrončok 2023-03-29 17:39:54 UTC
The updated package is missing from CentOS 8 Stream:

$ repoquery -q --repo=RHEL8.9-AppStream python3-rpm-macros
python3-rpm-macros-0:3-45.el8.noarch

$ repoquery -q --repo=c8s-appstream python3-rpm-macros
python3-rpm-macros-0:3-41.el8.noarch
python3-rpm-macros-0:3-42.el8.noarch
python3-rpm-macros-0:3-43.el8.noarch

Comment 15 Miro Hrončok 2023-03-29 17:43:14 UTC
(In reply to Miro Hrončok from comment #14)
> The updated package is missing from CentOS 8 Stream:
> 
> $ repoquery -q --repo=RHEL8.9-AppStream python3-rpm-macros
> python3-rpm-macros-0:3-45.el8.noarch
> 
> $ repoquery -q --repo=c8s-appstream python3-rpm-macros
> python3-rpm-macros-0:3-41.el8.noarch
> python3-rpm-macros-0:3-42.el8.noarch
> python3-rpm-macros-0:3-43.el8.noarch

I reported this in https://issues.redhat.com/browse/CS-1523

Comment 16 Maxwell G 2023-04-03 16:24:05 UTC
It seems python-rpm-macros-3-45.el8 was not built at all in CentOS Stream Koji [1]. The last build is python-rpm-macros-3-44.el8. Are the maintainers able to submit a build?

[1] https://kojihub.stream.centos.org/koji/packageinfo?packageID=1891

Comment 17 Miro Hrončok 2023-04-03 16:32:21 UTC
I don't really know. I can submit the build but it will not reach the compose until it's built and gated into RHEL, which will likely fail. I'd better ask in the CS jira ticket.

Comment 18 Miro Hrončok 2023-04-03 16:33:53 UTC
Ah, bstinson is actually building it, as it seems from https://kojihub.stream.centos.org/koji/packageinfo?packageID=1891

Comment 21 errata-xmlrpc 2023-05-16 08:35:40 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (python-rpm-macros bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:2820