summaryrefslogtreecommitdiffstats
path: root/Lib/packaging/command/install_lib.py
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2011-11-14 17:10:19 (GMT)
committerÉric Araujo <merwok@netwok.org>2011-11-14 17:10:19 (GMT)
commitf8361623f0e5ab6c6337afcccdb442f285590869 (patch)
tree91b0d49055dc1046f4b570cc034473feab770205 /Lib/packaging/command/install_lib.py
parentd5d4406c8ebbbdf8a8961fc119be22b15a1c40ad (diff)
downloadcpython-f8361623f0e5ab6c6337afcccdb442f285590869.zip
cpython-f8361623f0e5ab6c6337afcccdb442f285590869.tar.gz
cpython-f8361623f0e5ab6c6337afcccdb442f285590869.tar.bz2
Clean up byte-compilation code in packaging (#11254 followup).
- Don't use keyword arguments for debug_override; I find it more readable to have a comment explaining that True makes pyc and False pyo than to write out the non-obvious (when you haven’t read the doc) argument name - Move duplicate code from build_py and install_lib into cmd - Remove obsolete verbose argument of util.byte_compile - Remove obsolete passing of -O/-OO to the Python process spawned by util.byte_compile (I’ll remove the whole spawning later, after I write more tests to check the contents of pyc and pyo files; now that byte_compile does not depend on the value of __debug__ in the calling Python, we can call py_compile or compileall directly)
Diffstat (limited to 'Lib/packaging/command/install_lib.py')
-rw-r--r--Lib/packaging/command/install_lib.py42
1 files changed, 11 insertions, 31 deletions
diff --git a/Lib/packaging/command/install_lib.py b/Lib/packaging/command/install_lib.py
index f6c785f..ffc5d45 100644
--- a/Lib/packaging/command/install_lib.py
+++ b/Lib/packaging/command/install_lib.py
@@ -2,7 +2,6 @@
import os
import imp
-import logging
from packaging import logger
from packaging.command.cmd import Command
@@ -21,7 +20,7 @@ class install_lib(Command):
description = "install all modules (extensions and pure Python)"
- # The options for controlling byte compilations are two independent sets:
+ # The options for controlling byte compilation are two independent sets:
# 'compile' is strictly boolean, and only decides whether to
# generate .pyc files. 'optimize' is three-way (0, 1, or 2), and
# decides both whether to generate .pyo files and what level of
@@ -84,9 +83,14 @@ class install_lib(Command):
# having a build directory!)
outfiles = self.install()
- # (Optionally) compile .py to .pyc
+ # (Optionally) compile .py to .pyc and/or .pyo
if outfiles is not None and self.distribution.has_pure_modules():
- self.byte_compile(outfiles)
+ # XXX comment from distutils: "This [prefix stripping] is far from
+ # complete, but it should at least generate usable bytecode in RPM
+ # distributions." -> need to find exact requirements for
+ # byte-compiled files and fix it
+ install_root = self.get_finalized_command('install_dist').root
+ self.byte_compile(outfiles, prefix=install_root)
# -- Top-level worker functions ------------------------------------
# (called from 'run()')
@@ -108,28 +112,6 @@ class install_lib(Command):
return
return outfiles
- def byte_compile(self, files):
- from packaging.util import byte_compile # FIXME use compileall
-
- # Get the "--root" directory supplied to the "install_dist" command,
- # and use it as a prefix to strip off the purported filename
- # encoded in bytecode files. This is far from complete, but it
- # should at least generate usable bytecode in RPM distributions.
- install_root = self.get_finalized_command('install_dist').root
-
- # Temporary kludge until we remove the verbose arguments and use
- # logging everywhere
- verbose = logger.getEffectiveLevel() >= logging.DEBUG
-
- if self.compile:
- byte_compile(files, optimize=0,
- force=self.force, prefix=install_root,
- verbose=verbose, dry_run=self.dry_run)
- if self.optimize > 0:
- byte_compile(files, optimize=self.optimize,
- force=self.force, prefix=install_root,
- verbose=verbose, dry_run=self.dry_run)
-
# -- Utility methods -----------------------------------------------
def _mutate_outputs(self, has_any, build_cmd, cmd_option, output_dir):
@@ -157,11 +139,9 @@ class install_lib(Command):
if ext != PYTHON_SOURCE_EXTENSION:
continue
if self.compile:
- bytecode_files.append(imp.cache_from_source(
- py_file, debug_override=True))
- if self.optimize > 0:
- bytecode_files.append(imp.cache_from_source(
- py_file, debug_override=False))
+ bytecode_files.append(imp.cache_from_source(py_file, True))
+ if self.optimize:
+ bytecode_files.append(imp.cache_from_source(py_file, False))
return bytecode_files