[Python-checkins] r77376 - in python/branches/release26-maint: Lib/distutils/command/build_py.py Lib/distutils/command/install_lib.py Lib/distutils/errors.py Lib/distutils/tests/support.py Lib/distutils/tests/test_build_py.py Lib/distutils/util.py Misc/NEWS

tarek.ziade python-checkins at python.org
Sat Jan 9 00:27:23 CET 2010


Author: tarek.ziade
Date: Sat Jan  9 00:27:23 2010
New Revision: 77376

Log:
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
........


Modified:
   python/branches/release26-maint/   (props changed)
   python/branches/release26-maint/Lib/distutils/command/build_py.py
   python/branches/release26-maint/Lib/distutils/command/install_lib.py
   python/branches/release26-maint/Lib/distutils/errors.py
   python/branches/release26-maint/Lib/distutils/tests/support.py
   python/branches/release26-maint/Lib/distutils/tests/test_build_py.py
   python/branches/release26-maint/Lib/distutils/util.py
   python/branches/release26-maint/Misc/NEWS

Modified: python/branches/release26-maint/Lib/distutils/command/build_py.py
==============================================================================
--- python/branches/release26-maint/Lib/distutils/command/build_py.py	(original)
+++ python/branches/release26-maint/Lib/distutils/command/build_py.py	Sat Jan  9 00:27:23 2010
@@ -8,6 +8,7 @@
 
 import string, os
 from types import *
+import sys
 from glob import glob
 
 from distutils.core import Command
@@ -418,6 +419,10 @@
 
 
     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:

Modified: python/branches/release26-maint/Lib/distutils/command/install_lib.py
==============================================================================
--- python/branches/release26-maint/Lib/distutils/command/install_lib.py	(original)
+++ python/branches/release26-maint/Lib/distutils/command/install_lib.py	Sat Jan  9 00:27:23 2010
@@ -4,6 +4,8 @@
 
 import os
 from types import IntType
+import sys
+
 from distutils.core import Command
 from distutils.errors import DistutilsOptionError
 
@@ -122,6 +124,10 @@
         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,

Modified: python/branches/release26-maint/Lib/distutils/errors.py
==============================================================================
--- python/branches/release26-maint/Lib/distutils/errors.py	(original)
+++ python/branches/release26-maint/Lib/distutils/errors.py	Sat Jan  9 00:27:23 2010
@@ -76,6 +76,8 @@
 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):

Modified: python/branches/release26-maint/Lib/distutils/tests/support.py
==============================================================================
--- python/branches/release26-maint/Lib/distutils/tests/support.py	(original)
+++ python/branches/release26-maint/Lib/distutils/tests/support.py	Sat Jan  9 00:27:23 2010
@@ -3,19 +3,50 @@
 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.

Modified: python/branches/release26-maint/Lib/distutils/tests/test_build_py.py
==============================================================================
--- python/branches/release26-maint/Lib/distutils/tests/test_build_py.py	(original)
+++ python/branches/release26-maint/Lib/distutils/tests/test_build_py.py	Sat Jan  9 00:27:23 2010
@@ -90,6 +90,22 @@
             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)
 

Modified: python/branches/release26-maint/Lib/distutils/util.py
==============================================================================
--- python/branches/release26-maint/Lib/distutils/util.py	(original)
+++ python/branches/release26-maint/Lib/distutils/util.py	Sat Jan  9 00:27:23 2010
@@ -11,6 +11,7 @@
 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 @@
     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

Modified: python/branches/release26-maint/Misc/NEWS
==============================================================================
--- python/branches/release26-maint/Misc/NEWS	(original)
+++ python/branches/release26-maint/Misc/NEWS	Sat Jan  9 00:27:23 2010
@@ -48,6 +48,9 @@
 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


More information about the Python-checkins mailing list