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)
This commit is contained in:
Éric Araujo 2011-11-14 18:10:19 +01:00
parent d5d4406c8e
commit f8361623f0
6 changed files with 57 additions and 78 deletions

View file

@ -18,7 +18,7 @@ class build_py(Command, Mixin2to3):
description = "build pure Python modules (copy to build directory)"
# The options for controlling byte compilations are two independent sets;
# The options for controlling byte compilation are two independent sets;
# more info in install_lib or the reST docs
user_options = [
@ -113,7 +113,8 @@ class build_py(Command, Mixin2to3):
self.run_2to3(self._updated_files, self._doctests_2to3,
self.use_2to3_fixers)
self.byte_compile(self.get_outputs(include_bytecode=False))
self.byte_compile(self.get_outputs(include_bytecode=False),
prefix=self.build_lib)
# -- Top-level worker functions ------------------------------------
@ -335,11 +336,9 @@ class build_py(Command, Mixin2to3):
outputs.append(filename)
if include_bytecode:
if self.compile:
outputs.append(imp.cache_from_source(filename,
debug_override=True))
if self.optimize > 0:
outputs.append(imp.cache_from_source(filename,
debug_override=False))
outputs.append(imp.cache_from_source(filename, True))
if self.optimize:
outputs.append(imp.cache_from_source(filename, False))
outputs += [
os.path.join(build_dir, filename)
@ -391,19 +390,3 @@ class build_py(Command, Mixin2to3):
for package_, module, module_file in modules:
assert package == package_
self.build_module(module, module_file, package)
def byte_compile(self, files):
from packaging.util import byte_compile # FIXME use compileall
prefix = self.build_lib
if prefix[-1] != os.sep:
prefix = prefix + os.sep
# XXX this code is essentially the same as the 'byte_compile()
# method of the "install_lib" command, except for the determination
# of the 'prefix' string. Hmmm.
if self.compile:
byte_compile(files, optimize=0,
force=self.force, prefix=prefix, dry_run=self.dry_run)
if self.optimize > 0:
byte_compile(files, optimize=self.optimize,
force=self.force, prefix=prefix, dry_run=self.dry_run)