diff options
| author | ?ric Araujo <merwok@netwok.org> | 2011-11-12 07:33:45 +0100 |
|---|---|---|
| committer | ?ric Araujo <merwok@netwok.org> | 2011-11-12 07:33:45 +0100 |
| commit | ed71facf9298a2d12dc631f86e4ecdd33a117380 (patch) | |
| tree | e31993c8b5ca3878fc6142db3fb2fea458806827 /distutils2/command/install_lib.py | |
| parent | c00356888d4cce280d33dd86c7349bc9279a430d (diff) | |
| parent | e65890db19e3b798752544632abd303625c4a7f7 (diff) | |
| download | disutils2-ed71facf9298a2d12dc631f86e4ecdd33a117380.tar.gz | |
Ye olde merge.
I broke test_mixin2to3 somehow; distutils2-default is okay and packaging too,
so I don?t see an obvious reason right now, I?ll investigate later.
Diffstat (limited to 'distutils2/command/install_lib.py')
| -rw-r--r-- | distutils2/command/install_lib.py | 72 |
1 files changed, 19 insertions, 53 deletions
diff --git a/distutils2/command/install_lib.py b/distutils2/command/install_lib.py index ea53eab..8ee1fd5 100644 --- a/distutils2/command/install_lib.py +++ b/distutils2/command/install_lib.py @@ -1,34 +1,26 @@ """Install all modules (extensions and pure Python).""" import os -import sys -import logging from distutils2 import logger +from distutils2.compat import cache_from_source from distutils2.command.cmd import Command from distutils2.errors import PackagingOptionError # Extension for Python source files. +# XXX dead code? most of the codebase checks for literal '.py' if hasattr(os, 'extsep'): PYTHON_SOURCE_EXTENSION = os.extsep + "py" else: PYTHON_SOURCE_EXTENSION = ".py" + class install_lib(Command): description = "install all modules (extensions and pure Python)" - # The byte-compilation options are a tad confusing. Here are the - # possible scenarios: - # 1) no compilation at all (--no-compile --no-optimize) - # 2) compile .pyc only (--compile --no-optimize; default) - # 3) compile .pyc and "level 1" .pyo (--compile --optimize) - # 4) compile "level 1" .pyo only (--no-compile --optimize) - # 5) compile .pyc and "level 2" .pyo (--compile --optimize-more) - # 6) compile "level 2" .pyo only (--no-compile --optimize-more) - # - # The UI for this is two option, 'compile' and 'optimize'. + # 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 @@ -36,7 +28,7 @@ class install_lib(Command): user_options = [ ('install-dir=', 'd', "directory to install to"), - ('build-dir=','b', "build directory (where to install from)"), + ('build-dir=', 'b', "build directory (where to install from)"), ('force', 'f', "force installation (overwrite existing files)"), ('compile', 'c', "compile .py to .pyc [default]"), ('no-compile', None, "don't compile .py files"), @@ -47,7 +39,8 @@ class install_lib(Command): ] boolean_options = ['force', 'compile', 'skip-build'] - negative_opt = {'no-compile' : 'compile'} + + negative_opt = {'no-compile': 'compile'} def initialize_options(self): # let the 'install_dist' command dictate our installation directory @@ -65,7 +58,8 @@ class install_lib(Command): self.set_undefined_options('install_dist', ('build_lib', 'build_dir'), ('install_lib', 'install_dir'), - 'force', 'compile', 'optimize', 'skip_build') + 'force', 'compile', 'optimize', + 'skip_build') if self.compile is None: self.compile = True @@ -89,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()') @@ -113,38 +112,6 @@ class install_lib(Command): return return outfiles - def byte_compile(self, files): - if sys.dont_write_bytecode: - # XXX do we want this? because a Python runs without bytecode - # doesn't mean that the *dists should not contain bytecode - #--or does it? - logger.warning('%s: byte-compiling is disabled, skipping.', - self.get_command_name()) - return - - from distutils2.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, - 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): @@ -172,13 +139,12 @@ class install_lib(Command): if ext != PYTHON_SOURCE_EXTENSION: continue if self.compile: - bytecode_files.append(py_file + "c") - if self.optimize > 0: - bytecode_files.append(py_file + "o") + bytecode_files.append(cache_from_source(py_file, True)) + if self.optimize: + bytecode_files.append(cache_from_source(py_file, False)) return bytecode_files - # -- External interface -------------------------------------------- # (called by outsiders) |
