General cleanup, raise normalization in Lib/distutils.

This commit is contained in:
Collin Winter 2007-08-30 03:52:21 +00:00
parent a73bfee73d
commit 5b7e9d76f3
47 changed files with 963 additions and 1640 deletions

View file

@ -4,12 +4,9 @@ Implements the Distutils 'install' command."""
from distutils import log
# This module should be kept compatible with Python 2.1.
__revision__ = "$Id$"
import sys, os
from types import *
from distutils.core import Command
from distutils.debug import DEBUG
from distutils.sysconfig import get_config_vars
@ -141,7 +138,7 @@ class install (Command):
negative_opt = {'no-compile' : 'compile'}
def initialize_options (self):
def initialize_options(self):
# High-level options: these select both an installation base
# and scheme.
@ -215,7 +212,7 @@ class install (Command):
# party Python modules on various platforms given a wide
# array of user input is decided. Yes, it's quite complex!)
def finalize_options (self):
def finalize_options(self):
# This method (and its pliant slaves, like 'finalize_unix()',
# 'finalize_other()', and 'select_scheme()') is where the default
@ -233,13 +230,13 @@ class install (Command):
if ((self.prefix or self.exec_prefix or self.home) and
(self.install_base or self.install_platbase)):
raise DistutilsOptionError, \
("must supply either prefix/exec-prefix/home or " +
raise DistutilsOptionError(
"must supply either prefix/exec-prefix/home or " +
"install-base/install-platbase -- not both")
if self.home and (self.prefix or self.exec_prefix):
raise DistutilsOptionError, \
"must supply either home or prefix/exec-prefix -- not both"
raise DistutilsOptionError(
"must supply either home or prefix/exec-prefix -- not both")
# Next, stuff that's wrong (or dubious) only on certain platforms.
if os.name != "posix":
@ -341,10 +338,8 @@ class install (Command):
# Punt on doc directories for now -- after all, we're punting on
# documentation completely!
# finalize_options ()
def dump_dirs (self, msg):
def dump_dirs(self, msg):
if DEBUG:
from distutils.fancy_getopt import longopt_xlate
print(msg + ":")
@ -362,8 +357,7 @@ class install (Command):
print(" %s: %s" % (opt_name, val))
def finalize_unix (self):
def finalize_unix(self):
if self.install_base is not None or self.install_platbase is not None:
if ((self.install_lib is None and
self.install_purelib is None and
@ -371,8 +365,8 @@ class install (Command):
self.install_headers is None or
self.install_scripts is None or
self.install_data is None):
raise DistutilsOptionError, \
("install-base or install-platbase supplied, but "
raise DistutilsOptionError(
"install-base or install-platbase supplied, but "
"installation scheme is incomplete")
return
@ -382,8 +376,8 @@ class install (Command):
else:
if self.prefix is None:
if self.exec_prefix is not None:
raise DistutilsOptionError, \
"must not supply exec-prefix without prefix"
raise DistutilsOptionError(
"must not supply exec-prefix without prefix")
self.prefix = os.path.normpath(sys.prefix)
self.exec_prefix = os.path.normpath(sys.exec_prefix)
@ -396,11 +390,8 @@ class install (Command):
self.install_platbase = self.exec_prefix
self.select_scheme("unix_prefix")
# finalize_unix ()
def finalize_other (self): # Windows and Mac OS for now
def finalize_other(self): # Windows and Mac OS for now
if self.home is not None:
self.install_base = self.install_platbase = self.home
self.select_scheme("unix_home")
@ -412,13 +403,11 @@ class install (Command):
try:
self.select_scheme(os.name)
except KeyError:
raise DistutilsPlatformError, \
"I don't know how to install stuff on '%s'" % os.name
# finalize_other ()
raise DistutilsPlatformError(
"I don't know how to install stuff on '%s'" % os.name)
def select_scheme (self, name):
def select_scheme(self, name):
# it's the caller's problem if they supply a bad name!
scheme = INSTALL_SCHEMES[name]
for key in SCHEME_KEYS:
@ -427,7 +416,7 @@ class install (Command):
setattr(self, attrname, scheme[key])
def _expand_attrs (self, attrs):
def _expand_attrs(self, attrs):
for attr in attrs:
val = getattr(self, attr)
if val is not None:
@ -437,12 +426,12 @@ class install (Command):
setattr(self, attr, val)
def expand_basedirs (self):
def expand_basedirs(self):
self._expand_attrs(['install_base',
'install_platbase',
'root'])
def expand_dirs (self):
def expand_dirs(self):
self._expand_attrs(['install_purelib',
'install_platlib',
'install_lib',
@ -451,14 +440,12 @@ class install (Command):
'install_data',])
def convert_paths (self, *names):
def convert_paths(self, *names):
for name in names:
attr = "install_" + name
setattr(self, attr, convert_path(getattr(self, attr)))
def handle_extra_path (self):
def handle_extra_path(self):
if self.extra_path is None:
self.extra_path = self.distribution.extra_path
@ -471,8 +458,8 @@ class install (Command):
elif len(self.extra_path) == 2:
(path_file, extra_dirs) = self.extra_path
else:
raise DistutilsOptionError, \
("'extra_path' option must be a list, tuple, or "
raise DistutilsOptionError(
"'extra_path' option must be a list, tuple, or "
"comma-separated string with 1 or 2 elements")
# convert to local form in case Unix notation used (as it
@ -488,10 +475,7 @@ class install (Command):
self.path_file = path_file
self.extra_dirs = extra_dirs
# handle_extra_path ()
def change_roots (self, *names):
def change_roots(self, *names):
for name in names:
attr = "install_" + name
setattr(self, attr, change_root(self.root, getattr(self, attr)))
@ -499,8 +483,7 @@ class install (Command):
# -- Command execution methods -------------------------------------
def run (self):
def run(self):
# Obviously have to build before we can install
if not self.skip_build:
self.run_command('build')
@ -535,9 +518,7 @@ class install (Command):
"you'll have to change the search path yourself"),
self.install_lib)
# run ()
def create_path_file (self):
def create_path_file(self):
filename = os.path.join(self.install_libbase,
self.path_file + ".pth")
if self.install_path_file:
@ -550,7 +531,7 @@ class install (Command):
# -- Reporting methods ---------------------------------------------
def get_outputs (self):
def get_outputs(self):
# Assemble the outputs of all the sub-commands.
outputs = []
for cmd_name in self.get_sub_commands():
@ -567,7 +548,7 @@ class install (Command):
return outputs
def get_inputs (self):
def get_inputs(self):
# XXX gee, this looks familiar ;-(
inputs = []
for cmd_name in self.get_sub_commands():
@ -579,19 +560,19 @@ class install (Command):
# -- Predicates for sub-command list -------------------------------
def has_lib (self):
def has_lib(self):
"""Return true if the current distribution has any Python
modules to install."""
return (self.distribution.has_pure_modules() or
self.distribution.has_ext_modules())
def has_headers (self):
def has_headers(self):
return self.distribution.has_headers()
def has_scripts (self):
def has_scripts(self):
return self.distribution.has_scripts()
def has_data (self):
def has_data(self):
return self.distribution.has_data_files()
@ -603,5 +584,3 @@ class install (Command):
('install_data', has_data),
('install_egg_info', lambda self:True),
]
# class install