import string, os
from types import *
+import sys
from glob import glob
from distutils.core import 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:
import os
from types import IntType
+import sys
+
from distutils.core import Command
from distutils.errors import DistutilsOptionError
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,
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):
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.
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)
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
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
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