[Python-checkins] r75704 - in python/branches/py3k: 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

tarek.ziade python-checkins at python.org
Mon Oct 26 00:08:47 CET 2009


Author: tarek.ziade
Date: Mon Oct 26 00:08:47 2009
New Revision: 75704
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 (2009年10月24日) | 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 (2009年10月24日) | 1 line
 
 fixed finally state in distutils.test_util
........
 r75671 | tarek.ziade | 2009年10月24日 17:51:30 +0200 (2009年10月24日) | 1 line
 
 fixed warning and error message
........
Modified:
 python/branches/py3k/ (props changed)
 python/branches/py3k/Lib/distutils/command/build_py.py
 python/branches/py3k/Lib/distutils/command/install_lib.py
 python/branches/py3k/Lib/distutils/errors.py
 python/branches/py3k/Lib/distutils/tests/test_build_py.py
 python/branches/py3k/Lib/distutils/tests/test_install_lib.py
 python/branches/py3k/Lib/distutils/tests/test_util.py
 python/branches/py3k/Lib/distutils/util.py
 python/branches/py3k/Misc/NEWS
Modified: python/branches/py3k/Lib/distutils/command/build_py.py
==============================================================================
--- python/branches/py3k/Lib/distutils/command/build_py.py	(original)
+++ python/branches/py3k/Lib/distutils/command/build_py.py	Mon Oct 26 00:08:47 2009
@@ -5,6 +5,7 @@
 __revision__ = "$Id$"
 
 import os
+import sys
 from glob import glob
 
 from distutils.core import Command
@@ -369,6 +370,10 @@
 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:
Modified: python/branches/py3k/Lib/distutils/command/install_lib.py
==============================================================================
--- python/branches/py3k/Lib/distutils/command/install_lib.py	(original)
+++ python/branches/py3k/Lib/distutils/command/install_lib.py	Mon Oct 26 00:08:47 2009
@@ -6,6 +6,8 @@
 __revision__ = "$Id$"
 
 import os
+import sys
+
 from distutils.core import Command
 from distutils.errors import DistutilsOptionError
 
@@ -115,6 +117,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/py3k/Lib/distutils/errors.py
==============================================================================
--- python/branches/py3k/Lib/distutils/errors.py	(original)
+++ python/branches/py3k/Lib/distutils/errors.py	Mon Oct 26 00:08:47 2009
@@ -74,6 +74,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/py3k/Lib/distutils/tests/test_build_py.py
==============================================================================
--- python/branches/py3k/Lib/distutils/tests/test_build_py.py	(original)
+++ python/branches/py3k/Lib/distutils/tests/test_build_py.py	Mon Oct 26 00:08:47 2009
@@ -89,6 +89,22 @@
 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)
 
Modified: python/branches/py3k/Lib/distutils/tests/test_install_lib.py
==============================================================================
--- python/branches/py3k/Lib/distutils/tests/test_install_lib.py	(original)
+++ python/branches/py3k/Lib/distutils/tests/test_install_lib.py	Mon Oct 26 00:08:47 2009
@@ -31,6 +31,8 @@
 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 @@
 # 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)
Modified: python/branches/py3k/Lib/distutils/tests/test_util.py
==============================================================================
--- python/branches/py3k/Lib/distutils/tests/test_util.py	(original)
+++ python/branches/py3k/Lib/distutils/tests/test_util.py	Mon Oct 26 00:08:47 2009
@@ -1,7 +1,4 @@
 """Tests for distutils.util."""
-# not covered yet:
-# - byte_compile
-#
 import os
 import sys
 import unittest
@@ -9,11 +6,12 @@
 from io import BytesIO
 import subprocess
 
-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, get_compiler_versions,
- _find_exe_version, _MAC_OS_X_LD_VERSION)
+ _find_exe_version, _MAC_OS_X_LD_VERSION,
+ byte_compile)
 from distutils import util
 from distutils.sysconfig import get_config_vars
 from distutils import sysconfig
@@ -349,6 +347,16 @@
 res = get_compiler_versions()
 self.assertEquals(res[2], None)
 
+ 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)
 
Modified: python/branches/py3k/Lib/distutils/util.py
==============================================================================
--- python/branches/py3k/Lib/distutils/util.py	(original)
+++ python/branches/py3k/Lib/distutils/util.py	Mon Oct 26 00:08:47 2009
@@ -13,6 +13,7 @@
 from distutils.spawn import spawn, find_executable
 from distutils import log
 from distutils.version import LooseVersion
+from distutils.errors import DistutilsByteCompileError
 
 def get_platform():
 """Return a string that identifies the current platform.
@@ -444,6 +445,10 @@
 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
 # approach: choose direct mode *only* if the current interpreter is
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Mon Oct 26 00:08:47 2009
@@ -1152,6 +1152,9 @@
 Library
 -------
 
+- Issue #7071: byte-compilation in Distutils is now done with respect to
+ sys.dont_write_bytecode.
+
 - Issue #7066: archive_util.make_archive now restores the cwd if an error is 
 raised. Initial patch by Ezio Melotti.
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /