Bug 2231359 - rpm - brp-python-bytecompile: Python 3.11 scripts are not compiled in __os_install_post on RHEL 8
Summary: rpm - brp-python-bytecompile: Python 3.11 scripts are not compiled in __os_in...
Keywords:
Status: NEW
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: rpm
Version: ---
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Python Maintainers
QA Contact: swm-qe
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-08-11 11:28 UTC by Tomas Orsava
Modified: 2023-08-11 12:09 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-165617 0 None None None 2023-08-11 11:29:54 UTC

Description Tomas Orsava 2023-08-11 11:28:51 UTC
The `%__os_install_post` macro is run after the %install section of each RPM build. It launches the `brp-python-bytecompile` script that is supposed to bytecompile all Python scripts that haven't been bytecompiled already.

The Python 3.11 stack was added to both RHEL 8 and 9. On RHEL 9 the brp-python-bytecompile script is newer and is prepared for Python 3.11, but on RHEL 8 it isn't. Thus Python 3.11 scripts that weren't bytecompiled as part of the %build or %install sections are left uncompiled.


Tested in Copr: https://copr.devel.redhat.com/coprs/torsava/python3.11-test-os-install-post-bytecompile/


Spec file changes to reproduce:

```
...
%install
mkdir -p %{buildroot}%{python3_sitelib}/directory/
echo "print()" > %{buildroot}%{python3_sitelib}/directory/hugo.py
...

%check
echo "============== Print .py files found =================="
find %{buildroot}%{python3_sitelib}/directory/ -name "*.py"
echo "============== Print .pyc files found =================="
find %{buildroot}%{python3_sitelib}/directory/ -name "*.py[co]"
echo "============== End of print =================="

# Count .py and .pyc files
PY=$(find %{buildroot}%{python3_sitelib}/directory/ -name "*.py" | wc -l)
PYC=$(find %{buildroot}%{python3_sitelib}/directory/ -name "*.py[co]" | wc -l)
test $PY -eq 1
test $(expr $PY \* 2) -eq $PYC
...
```

Output for .py files is the same on RHEL 8 & 9:

============== Print .py files found ==================
+ find /builddir/build/BUILDROOT/python3.11-wheel-0.38.4-3.el9.x86_64/usr/lib/python3.11/site-packages/directory/ -name '*.py'
/builddir/build/BUILDROOT/python3.11-wheel-0.38.4-3.el9.x86_64/usr/lib/python3.11/site-packages/directory/hugo.py


But for .pyc it's different:

RHEL 9:

+ echo '============== Print .pyc files found =================='
+ find /builddir/build/BUILDROOT/python3.11-wheel-0.38.4-3.el9.x86_64/usr/lib/python3.11/site-packages/directory/ -name '*.py[co]'
/builddir/build/BUILDROOT/python3.11-wheel-0.38.4-3.el9.x86_64/usr/lib/python3.11/site-packages/directory/__pycache__/hugo.cpython-311.opt-1.pyc
/builddir/build/BUILDROOT/python3.11-wheel-0.38.4-3.el9.x86_64/usr/lib/python3.11/site-packages/directory/__pycache__/hugo.cpython-311.pyc
============== End of print ==================

RHEL 8:

+ echo '============== Print .pyc files found =================='
+ find /builddir/build/BUILDROOT/python3.11-wheel-0.38.4-3.el8.x86_64/usr/lib/python3.11/site-packages/directory/ -name '*.py[co]'
============== End of print ==================


Note You need to log in before you can comment on or make changes to this bug.