Uploaded image for project: 'RHEL'
  1. RHEL
  2. RHEL-6423

rpm - brp-python-bytecompile: Python 3.11 scripts are not compiled in __os_install_post on RHEL 8

    • Icon: Bug Bug
    • Resolution: Done-Errata
    • Icon: Undefined Undefined
    • rhel-8.10
    • rhel-8.9.0
    • rpm
    • rpm-4.14.3-27.el8
    • None
    • None
    • rhel-sst-cs-software-management
    • ssg_core_services
    • 10
    • 12
    • None
    • QE ack, Dev ack
    • False
    • Hide

      None

      Show
      None
    • No
    • None
    • Release Note Not Required
    • None

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

              lbalhar@redhat.com Lumir Balhar
              torsava@redhat.com Tomas Orsava
              Martin Banas Martin Banas
              Votes:
              0 Vote for this issue
              Watchers:
              11 Start watching this issue

                Created:
                Updated:
                Resolved: