Index: Misc/NEWS =================================================================== --- Misc/NEWS (révision 69881) +++ Misc/NEWS (copie de travail) @@ -165,6 +165,10 @@ Library ------- + +- Issue #1533164: distutils.command.bdist_rpm now calls the install + command with -O1 by default, and has a new option for that. + - Issue #5287: Add exception handling around findCaller() call to help out IronPython. Index: Lib/distutils/tests/test_bdist_rpm.py =================================================================== --- Lib/distutils/tests/test_bdist_rpm.py (révision 0) +++ Lib/distutils/tests/test_bdist_rpm.py (révision 0) @@ -0,0 +1,107 @@ +"""Tests for distutils.command.bdist_rpm.""" + +import unittest +import sys +import os +import tempfile +import shutil + +from distutils.core import Distribution +from distutils.command.bdist_rpm import bdist_rpm +from distutils.tests import support +from distutils.spawn import find_executable +from distutils import spawn +from distutils.errors import DistutilsExecError + +SETUP_PY = """\ +from distutils.core import setup +import foo + +setup(name='foo', version='0.1', py_modules=['foo'], + url='xxx', author='xxx', author_email='xxx') + +""" + +def _quiet(func): + def __quiet(*args, **kw): + cmd = args[0] + if cmd[0] in ('rpm', 'rpmbuild'): + cmd.insert(1, '--quiet') + args = [cmd] + list(args[1:]) + return func(*args, **kw) + return __quiet + +class BuildRpmTestCase(support.TempdirManager, + support.LoggingSilencer, + unittest.TestCase): + + def setUp(self): + support.TempdirManager.setUp(self) + support.LoggingSilencer.setUp(self) + self.old_location = os.getcwd() + self.old_sys_argv = sys.argv[:] + # making sure the rpmbuild and rpm commands + # are called with --quiet + spawn.spawn = _quiet(spawn.spawn) + + def tearDown(self): + os.chdir(self.old_location) + sys.argv = self.old_sys_argv[:] + support.LoggingSilencer.tearDown(self) + support.TempdirManager.tearDown(self) + + def test_no_optimize_flag(self): + + # http://bugs.python.org/issue1533164 + # this test will run only if the rpm command is found + if (find_executable('rpm') is None or + find_executable('rpmbuild') is None): + return + + # let's create a package that brakes bdist_rpm + tmp_dir = self.mkdtemp() + pkg_dir = os.path.join(tmp_dir, 'foo') + os.mkdir(pkg_dir) + self.write_file((pkg_dir, 'setup.py'), SETUP_PY) + self.write_file((pkg_dir, 'foo.py'), '#') + self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py') + self.write_file((pkg_dir, 'README'), '') + + dist = Distribution({'name': 'foo', 'version': '0.1', + 'py_modules': ['foo'], + 'url': 'xxx', 'author': 'xxx', + 'author_email': 'xxx'}) + dist.script_name = 'setup.py' + os.chdir(pkg_dir) + + sys.argv = ['setup.py'] + cmd = bdist_rpm(dist) + cmd.fix_python = True + + # running with force-optimize = 1 + cmd.ensure_finalized() + cmd.run() + + dist_created = os.listdir(os.path.join(pkg_dir, 'dist')) + self.assert_('foo-0.1-1.noarch.rpm' in dist_created) + os.remove(os.path.join(pkg_dir, 'dist', 'foo-0.1-1.noarch.rpm')) + + # running with force-optimize = 0 + cmd.force_optimize = 0 + try: + # XXX How to prevent the spawned + # rpmbuild command to display errors ? + # this can be a problem for buildbots + cmd.ensure_finalized() + cmd.run() + except DistutilsExecError: + # happens under Fedora/RedHat + return + dist_created = os.listdir(os.path.join(pkg_dir, 'dist')) + self.assert_('foo-0.1-1.noarch.rpm' in dist_created) + +def test_suite(): + return unittest.makeSuite(BuildRpmTestCase) + +if __name__ == '__main__': + test_support.run_unittest(test_suite()) Modification de propriétés sur Lib/distutils/tests/test_bdist_rpm.py ___________________________________________________________________ Nom : svn:keywords + Id Nom : svn:eol-style + native Index: Lib/distutils/command/bdist_rpm.py =================================================================== --- Lib/distutils/command/bdist_rpm.py (révision 69881) +++ Lib/distutils/command/bdist_rpm.py (copie de travail) @@ -123,10 +123,16 @@ # Allow a packager to explicitly force an architecture ('force-arch=', None, "Force an architecture onto the RPM build process"), + + # Forces the -O1 option when calling the install command, + # so the rpm builds under SELinux environments + ('force-optimize', 'o', + "don't clean up RPM build directory"), + ] boolean_options = ['keep-temp', 'use-rpm-opt-flags', 'rpm3-mode', - 'no-autoreq'] + 'no-autoreq', 'force-optimize'] negative_opt = {'no-keep-temp': 'keep-temp', 'no-rpm-opt-flags': 'use-rpm-opt-flags', @@ -176,6 +182,7 @@ self.no_autoreq = 0 self.force_arch = None + self.force_optimize = 1 # initialize_options() @@ -357,7 +364,6 @@ # The source rpm is named after the first entry in the spec file if source_rpm is None: source_rpm = l[0] - status = out.close() if status: raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd)) @@ -485,14 +491,20 @@ # XXX this is kind of misleading: user-supplied options are files # that we open and interpolate into the spec file, but the defaults # are just text that we drop in as-is. Hmmm. + + # forcing -O1 if force-optimize is 1 + if self.force_optimize: + install_cmd = ("%s install -O1 --root=$RPM_BUILD_ROOT " + "--record=INSTALLED_FILES") % def_setup_call + else: + install_cmd = ("%s install --root=$RPM_BUILD_ROOT " + "--record=INSTALLED_FILES") % def_setup_call + script_options = [ ('prep', 'prep_script', "%setup -n %{name}-%{unmangled_version}"), ('build', 'build_script', def_build), - ('install', 'install_script', - ("%s install " - "--root=$RPM_BUILD_ROOT " - "--record=INSTALLED_FILES") % def_setup_call), + ('install', 'install_script', install_cmd), ('clean', 'clean_script', "rm -rf $RPM_BUILD_ROOT"), ('verifyscript', 'verify_script', None), ('pre', 'pre_install', None),