Bug 2231359

Summary: rpm - brp-python-bytecompile: Python 3.11 scripts are not compiled in __os_install_post on RHEL 8
Product: Red Hat Enterprise Linux 8 Reporter: Tomas Orsava <torsava>
Component: rpmAssignee: Python Maintainers <python-maint>
Status: NEW --- QA Contact: swm-qe
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: ---CC: torsava
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 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:

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 ==================