Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b837192

Browse files
committed
Issue #14443: ensure that brp-python-bytecompile is invoked with the correct
python executable The __os_install_macro defines some post-processing activities during an rpm build; one of the scripts it calls is brp-python-bytecompile, which can take an argument: the python executable with which to byte-compile .py files in the package payload. In some older versions of rpm (e.g. in RHEL 6), this invocation doesn't pass in an argument, and brp-python-bytecompile defaults to using /usr/bin/python, which can lead to the .py files being byte-compiled for the wrong version of python. This has been fixed in later versions of rpm by passing in %{__python} as an argument to brp-python-bytecompile. Workaround this by detecting if __os_install_post has a 0-argument invocation of brp-python-bytecompile, and if so generating an equivalent macro that has the argument, and explicitly provide the new definition within the specfile.
1 parent 72a80e8 commit b837192

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

Lib/distutils/command/bdist_rpm.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Implements the Distutils 'bdist_rpm' command (create RPM source and binary
44
distributions)."""
55

6-
import sys, os
6+
import subprocess, sys, os
77
from distutils.core import Command
88
from distutils.debug import DEBUG
99
from distutils.util import get_platform
@@ -406,6 +406,21 @@ def _make_spec_file(self):
406406
'Summary: ' + self.distribution.get_description(),
407407
]
408408

409+
# Workaround for #14443 which affects some RPM based systems such as
410+
# RHEL6 (and probably derivatives)
411+
vendor_hook = subprocess.getoutput('rpm --eval %{__os_install_post}')
412+
# Generate a potential replacement value for __os_install_post (whilst
413+
# normalizing the whitespace to simplify the test for whether the
414+
# invocation of brp-python-bytecompile passes in __python):
415+
vendor_hook = '\n'.join([' %s \\' % line.strip()
416+
for line in vendor_hook.splitlines()])
417+
problem = "brp-python-bytecompile \\\n"
418+
fixed = "brp-python-bytecompile %{__python} \\\n"
419+
fixed_hook = vendor_hook.replace(problem, fixed)
420+
if fixed_hook != vendor_hook:
421+
spec_file.append('# Workaround for http://bugs.python.org/issue14443')
422+
spec_file.append('%define __os_install_post ' + fixed_hook + '\n')
423+
409424
# put locale summaries into spec file
410425
# XXX not supported for now (hard to put a dictionary
411426
# in a config file -- arg!)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,9 @@ Library
11381138
- Issue #12451: xml.dom.pulldom: parse() now opens files in binary mode instead
11391139
of the text mode (using the locale encoding) to avoid encoding issues.
11401140

1141+
- Issue #14443: Ensure that .py files are byte-compiled with the correct Python
1142+
executable within bdist_rpm even on older versions of RPM
1143+
11411144
Extension Modules
11421145
-----------------
11431146

0 commit comments

Comments
 (0)