summaryrefslogtreecommitdiffstats
path: root/Lib/packaging/util.py
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2011-11-03 04:08:28 (GMT)
committerÉric Araujo <merwok@netwok.org>2011-11-03 04:08:28 (GMT)
commit880801501b778d93079afc11672dba86e60eab94 (patch)
tree32bad2da11ff3f125f67e46d93c308f18c311eab /Lib/packaging/util.py
parentdfd232898d4ae64a4c176ed492eec5e1ab209ef8 (diff)
downloadcpython-880801501b778d93079afc11672dba86e60eab94.zip
cpython-880801501b778d93079afc11672dba86e60eab94.tar.gz
cpython-880801501b778d93079afc11672dba86e60eab94.tar.bz2
Improve byte-compilation in packaging to be independent of -O or -B.
The code I fixed to comply with PEP 3147 still had one bug: When run under python -O, some paths for pyc files would be pyo, because I called imp.cache_from_source without explicit debug_override argument in some places, and under -O that would return .pyo (this is well explained in the imp docs). Now all code (util.byte_compile, build_py, install_lib) can create .pyo files according to options given by users, without interference from the calling Python’s own optimize mode. On a related topic, I also removed the code that prevented byte compilation under python -B. The rationale is that packaging gives control over the creation of pyc files to the user with its own explicit option, and the behavior should not be changed if the calling Python happens to run with -B for whatever reason. I will argue that this is a bug fix and ask to be allowed to backport this change to distutils. Finally, I moved one nugget of information about the --compile and --optimize options from the source into the doc. It clears up a misunderstanding that I (and maybe other people) had.
Diffstat (limited to 'Lib/packaging/util.py')
-rw-r--r--Lib/packaging/util.py20
1 files changed, 8 insertions, 12 deletions
diff --git a/Lib/packaging/util.py b/Lib/packaging/util.py
index 8dd715f..e76e3c3 100644
--- a/Lib/packaging/util.py
+++ b/Lib/packaging/util.py
@@ -20,8 +20,8 @@ from configparser import RawConfigParser
from packaging import logger
from packaging.errors import (PackagingPlatformError, PackagingFileError,
- PackagingByteCompileError, PackagingExecError,
- InstallationException, PackagingInternalError)
+ PackagingExecError, InstallationException,
+ PackagingInternalError)
__all__ = [
# file dependencies
@@ -325,12 +325,10 @@ def byte_compile(py_files, optimize=0, force=False, prefix=None,
the source for details). The 'direct' flag is used by the script
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
- # FIXME this should not raise an error
- if sys.dont_write_bytecode:
- raise PackagingByteCompileError('byte-compiling is disabled.')
+ This function is independent from the running Python's -O or -B options;
+ it is fully controlled by the parameters passed in.
+ """
# 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
@@ -417,12 +415,10 @@ byte_compile(files, optimize=%r, force=%r,
# Terminology from the py_compile module:
# cfile - byte-compiled file
# dfile - purported source filename (same as 'file' by default)
- if optimize >= 0:
- cfile = imp.cache_from_source(file,
- debug_override=not optimize)
- else:
- cfile = imp.cache_from_source(file)
+ debug_override = not optimize
+ cfile = imp.cache_from_source(file, debug_override)
dfile = file
+
if prefix:
if file[:len(prefix)] != prefix:
raise ValueError("invalid prefix: filename %r doesn't "