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
........
This commit is contained in:
Tarek Ziadé 2010-01-08 23:27:23 +00:00
parent 0b074575b7
commit f998341572
7 changed files with 67 additions and 0 deletions

View File

@ -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:

View File

@ -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,

View File

@ -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):

View File

@ -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.

View File

@ -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)

View 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
@ -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

View File

@ -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