From f9983415722d1beafc1845c17be2d851637b5397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tarek=20Ziad=C3=A9?= Date: Fri, 8 Jan 2010 23:27:23 +0000 Subject: Merged revisions 75669-75671 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75669 | tarek.ziade | 2009-10-24 17:10:37 +0200 (Sat, 24 Oct 2009) | 1 line Issue #7071: byte-compilation in Distutils now looks at sys.dont_write_bytecode ........ r75670 | tarek.ziade | 2009-10-24 17:19:03 +0200 (Sat, 24 Oct 2009) | 1 line fixed finally state in distutils.test_util ........ r75671 | tarek.ziade | 2009-10-24 17:51:30 +0200 (Sat, 24 Oct 2009) | 1 line fixed warning and error message ........ --- Lib/distutils/command/build_py.py | 5 +++++ Lib/distutils/command/install_lib.py | 6 ++++++ Lib/distutils/errors.py | 2 ++ Lib/distutils/tests/support.py | 31 +++++++++++++++++++++++++++++++ Lib/distutils/tests/test_build_py.py | 16 ++++++++++++++++ Lib/distutils/util.py | 4 ++++ Misc/NEWS | 3 +++ 7 files changed, 67 insertions(+) diff --git a/Lib/distutils/command/build_py.py b/Lib/distutils/command/build_py.py index 3bf1267..708ef0f 100644 --- a/Lib/distutils/command/build_py.py +++ b/Lib/distutils/command/build_py.py @@ -8,6 +8,7 @@ __revision__ = "$Id$" import string, os from types import * +import sys from glob import glob from distutils.core import Command @@ -418,6 +419,10 @@ class build_py (Command): def byte_compile (self, files): + if sys.dont_write_bytecode: + self.warn('byte-compiling is disabled, skipping.') + return + from distutils.util import byte_compile prefix = self.build_lib if prefix[-1] != os.sep: diff --git a/Lib/distutils/command/install_lib.py b/Lib/distutils/command/install_lib.py index 4ea61d7..7e0c708 100644 --- a/Lib/distutils/command/install_lib.py +++ b/Lib/distutils/command/install_lib.py @@ -4,6 +4,8 @@ __revision__ = "$Id$" import os from types import IntType +import sys + from distutils.core import Command from distutils.errors import DistutilsOptionError @@ -122,6 +124,10 @@ class install_lib (Command): return outfiles def byte_compile (self, files): + if sys.dont_write_bytecode: + self.warn('byte-compiling is disabled, skipping.') + return + from distutils.util import byte_compile # Get the "--root" directory supplied to the "install" command, diff --git a/Lib/distutils/errors.py b/Lib/distutils/errors.py index e72221b..9d1756b 100644 --- a/Lib/distutils/errors.py +++ b/Lib/distutils/errors.py @@ -76,6 +76,8 @@ class DistutilsInternalError (DistutilsError): class DistutilsTemplateError (DistutilsError): """Syntax error in a file list template.""" +class DistutilsByteCompileError(DistutilsError): + """Byte compile error.""" # Exception classes used by the CCompiler implementation classes class CCompilerError (Exception): diff --git a/Lib/distutils/tests/support.py b/Lib/distutils/tests/support.py index 9d373e9..2a03765 100644 --- a/Lib/distutils/tests/support.py +++ b/Lib/distutils/tests/support.py @@ -3,19 +3,50 @@ import os import shutil import tempfile +from distutils.log import DEBUG, INFO, WARN, ERROR, FATAL from distutils import log from distutils.dist import Distribution +from distutils.cmd import Command class LoggingSilencer(object): def setUp(self): super(LoggingSilencer, self).setUp() self.threshold = log.set_threshold(log.FATAL) + # catching warnings + # when log will be replaced by logging + # we won't need such monkey-patch anymore + self._old_log = log.Log._log + log.Log._log = self._log + self.logs = [] + self._old_warn = Command.warn + Command.warn = self._warn def tearDown(self): log.set_threshold(self.threshold) + log.Log._log = self._old_log + Command.warn = self._old_warn super(LoggingSilencer, self).tearDown() + def _warn(self, msg): + self.logs.append(('', msg, '')) + + def _log(self, level, msg, args): + if level not in (DEBUG, INFO, WARN, ERROR, FATAL): + raise ValueError('%s wrong log level' % str(level)) + self.logs.append((level, msg, args)) + + def get_logs(self, *levels): + def _format(msg, args): + if len(args) == 0: + return msg + return msg % args + return [_format(msg, args) for level, msg, args + in self.logs if level in levels] + + def clear_logs(self): + self.logs = [] + class TempdirManager(object): """Mix-in class that handles temporary directories for test cases. diff --git a/Lib/distutils/tests/test_build_py.py b/Lib/distutils/tests/test_build_py.py index 4b04547..4a054f2 100644 --- a/Lib/distutils/tests/test_build_py.py +++ b/Lib/distutils/tests/test_build_py.py @@ -90,6 +90,22 @@ class BuildPyTestCase(support.TempdirManager, os.chdir(cwd) sys.stdout = old_stdout + def test_dont_write_bytecode(self): + # makes sure byte_compile is not used + pkg_dir, dist = self.create_dist() + cmd = build_py(dist) + cmd.compile = 1 + cmd.optimize = 1 + + old_dont_write_bytecode = sys.dont_write_bytecode + sys.dont_write_bytecode = True + try: + cmd.byte_compile([]) + finally: + sys.dont_write_bytecode = old_dont_write_bytecode + + self.assertTrue('byte-compiling is disabled' in self.logs[0][1]) + def test_suite(): return unittest.makeSuite(BuildPyTestCase) diff --git a/Lib/distutils/util.py b/Lib/distutils/util.py index d314961..36ac721 100644 --- a/Lib/distutils/util.py +++ b/Lib/distutils/util.py @@ -11,6 +11,7 @@ from distutils.errors import DistutilsPlatformError from distutils.dep_util import newer from distutils.spawn import spawn from distutils import log +from distutils.errors import DistutilsByteCompileError def get_platform (): """Return a string that identifies the current platform. This is used @@ -457,6 +458,9 @@ def byte_compile (py_files, generated in indirect mode; unless you know what you're doing, leave it set to None. """ + # nothing is done if sys.dont_write_bytecode is True + if sys.dont_write_bytecode: + raise DistutilsByteCompileError('byte-compiling is disabled.') # First, if the caller didn't force us into direct or indirect mode, # figure out which mode we should be in. We take a conservative diff --git a/Misc/NEWS b/Misc/NEWS index 00082bc..14dd963 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -48,6 +48,9 @@ Core and Builtins Library ------- +- Issue #7071: byte-compilation in Distutils is now done with respect to + sys.dont_write_bytecode. + - Issue #7092: Remove py3k warning when importing cPickle. 2to3 handles renaming of `cPickle` to `pickle`. The warning was annoying since there's no alternative to cPickle if you care about performance. Patch by Florent -- cgit v0.12