]> granicus.if.org Git - python/commitdiff
Merged revisions 75704 via svnmerge from
authorTarek Ziadé <ziade.tarek@gmail.com>
Sun, 25 Oct 2009 23:16:51 +0000 (23:16 +0000)
committerTarek Ziadé <ziade.tarek@gmail.com>
Sun, 25 Oct 2009 23:16:51 +0000 (23:16 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r75704 | tarek.ziade | 2009-10-26 00:08:47 +0100 (Mon, 26 Oct 2009) | 17 lines

  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
Lib/distutils/command/install_lib.py
Lib/distutils/errors.py
Lib/distutils/tests/test_build_py.py
Lib/distutils/tests/test_install_lib.py
Lib/distutils/tests/test_util.py
Lib/distutils/util.py
Misc/NEWS

index 99d85be96c85f11d4b72ea90b87c78000428c8be..26002e4b3fbb3277fb7ee697ec2077aa05c26797 100644 (file)
@@ -5,6 +5,7 @@ Implements the Distutils 'build_py' command."""
 __revision__ = "$Id$"
 
 import sys, os
+import sys
 from glob import glob
 
 from distutils.core import Command
@@ -369,6 +370,10 @@ class build_py (Command):
                 self.build_module(module, module_file, package)
 
     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:
index 85fb3acd4e9add2304961588dbd6124fd43404db..6022d30f278e7484967659c1cc63afe317314b74 100644 (file)
@@ -6,6 +6,8 @@ Implements the Distutils 'install_lib' command
 __revision__ = "$Id$"
 
 import os
+import sys
+
 from distutils.core import Command
 from distutils.errors import DistutilsOptionError
 
@@ -115,6 +117,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,
index 963d83377c08f23ec39e05b43eacca0f5a329225..acecacccb5641e92f4fcef936e212fee0ec6d0ca 100644 (file)
@@ -74,6 +74,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):
index 8ad3bbc452699067ee50cd79c3138074414c81de..582f24634ab43a06fee09aeec9634b4f9dbf6b7f 100644 (file)
@@ -89,6 +89,22 @@ class BuildPyTestCase(support.TempdirManager,
             os.chdir(cwd)
             sys.stdout = sys.__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)
 
index b2185b8442e230df4c7978a73fc5896aff915c9d..99a6d9062727972757a07fe29e1c0cac10055b5f 100644 (file)
@@ -31,6 +31,8 @@ class InstallLibTestCase(support.TempdirManager,
         cmd.finalize_options()
         self.assertEquals(cmd.optimize, 2)
 
+    @unittest.skipUnless(not sys.dont_write_bytecode,
+                         'byte-compile not supported')
     def test_byte_compile(self):
         pkg_dir, dist = self.create_dist()
         cmd = install_lib(dist)
@@ -76,6 +78,21 @@ class InstallLibTestCase(support.TempdirManager,
         # get_input should return 2 elements
         self.assertEquals(len(cmd.get_inputs()), 2)
 
+    def test_dont_write_bytecode(self):
+        # makes sure byte_compile is not used
+        pkg_dir, dist = self.create_dist()
+        cmd = install_lib(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(InstallLibTestCase)
index 35f81a6b370854165bfa41b90c43826b70fe973c..dcc1a2069b5d71d689679bacecec33162ba3ac44 100644 (file)
@@ -1,16 +1,13 @@
 """Tests for distutils.util."""
-# not covered yet:
-#    - byte_compile
-#
 import os
 import sys
 import unittest
 from copy import copy
 
-from distutils.errors import DistutilsPlatformError
+from distutils.errors import DistutilsPlatformError, DistutilsByteCompileError
 from distutils.util import (get_platform, convert_path, change_root,
                             check_environ, split_quoted, strtobool,
-                            rfc822_escape)
+                            rfc822_escape, byte_compile)
 from distutils import util # used to patch _environ_checked
 from distutils.sysconfig import get_config_vars
 from distutils import sysconfig
@@ -258,6 +255,16 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
                   'header%(8s)s') % {'8s': '\n'+8*' '}
         self.assertEquals(res, wanted)
 
+    def test_dont_write_bytecode(self):
+        # makes sure byte_compile raise a DistutilsError
+        # if sys.dont_write_bytecode is True
+        old_dont_write_bytecode = sys.dont_write_bytecode
+        sys.dont_write_bytecode = True
+        try:
+            self.assertRaises(DistutilsByteCompileError, byte_compile, [])
+        finally:
+            sys.dont_write_bytecode = old_dont_write_bytecode
+
 def test_suite():
     return unittest.makeSuite(UtilTestCase)
 
index 5054d0c86769ec517023823d3e727a044dbdeede..4bc4c984136b7fd4da1bfad50445ef4382ea5b9f 100644 (file)
@@ -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
@@ -443,6 +444,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
index e6d09c6116cb8f19b64361d6d0bc04949ca0fc23..becd5b1c5a29211b7a9ee1302338f9ddcc07834b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -34,6 +34,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #7071: byte-compilation in Distutils is now done with respect to
+  sys.dont_write_bytecode.
+
 - Issue #7099: Decimal.is_normal now returns True for numbers with exponent
   larger than emax.