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: CLOSED MIGRATED QA Contact: swm-qe
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: ---CC: torsava
Target Milestone: rcKeywords: MigratedToJIRA
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: 2023-09-21 17:35:59 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:

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

Comment 1 RHEL Program Management 2023-09-21 17:33:23 UTC
Issue migration from Bugzilla to Jira is in process at this time. This will be the last message in Jira copied from the Bugzilla bug.

Comment 2 RHEL Program Management 2023-09-21 17:35:59 UTC
This BZ has been automatically migrated to the issues.redhat.com Red Hat Issue Tracker. All future work related to this report will be managed there.

Due to differences in account names between systems, some fields were not replicated.  Be sure to add yourself to Jira issue's "Watchers" field to continue receiving updates and add others to the "Need Info From" field to continue requesting information.

To find the migrated issue, look in the "Links" section for a direct link to the new issue location. The issue key will have an icon of 2 footprints next to it, and begin with "RHEL-" followed by an integer.  You can also find this issue by visiting https://issues.redhat.com/issues/?jql= and searching the "Bugzilla Bug" field for this BZ's number, e.g. a search like:

"Bugzilla Bug" = 1234567

In the event you have trouble locating or viewing this issue, you can file an issue by sending mail to rh-issues. You can also visit https://access.redhat.com/articles/7032570 for general account information.