aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/distutils/command/install.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/distutils/command/install.py')
-rw-r--r--Lib/distutils/command/install.py272
1 files changed, 140 insertions, 132 deletions
diff --git a/Lib/distutils/command/install.py b/Lib/distutils/command/install.py
index f1f3bd5c6f5..0161898f49a 100644
--- a/Lib/distutils/command/install.py
+++ b/Lib/distutils/command/install.py
@@ -2,14 +2,10 @@
Implements the Distutils 'install' command."""
-from distutils import log
-
-# This module should be kept compatible with Python 2.1.
+import sys
+import os
-__revision__ = "$Id$"
-
-import sys, os, string
-from types import *
+from distutils import log
from distutils.core import Command
from distutils.debug import DEBUG
from distutils.sysconfig import get_config_vars
@@ -18,9 +14,16 @@ from distutils.file_util import write_file
from distutils.util import convert_path, subst_vars, change_root
from distutils.util import get_platform
from distutils.errors import DistutilsOptionError
-from site import USER_BASE
-from site import USER_SITE
+# this keeps compatibility from 2.3 to 2.5
+if sys.version < "2.6":
+ USER_BASE = None
+ USER_SITE = None
+ HAS_USER_SITE = False
+else:
+ from site import USER_BASE
+ from site import USER_SITE
+ HAS_USER_SITE = True
if sys.version < "2.2":
WINDOWS_SCHEME = {
@@ -43,7 +46,7 @@ INSTALL_SCHEMES = {
'unix_prefix': {
'purelib': '$base/lib/python$py_version_short/site-packages',
'platlib': '$platbase/lib/python$py_version_short/site-packages',
- 'headers': '$base/include/python$py_version_short/$dist_name',
+ 'headers': '$base/include/python$py_version_short$abiflags/$dist_name',
'scripts': '$base/bin',
'data' : '$base',
},
@@ -54,21 +57,7 @@ INSTALL_SCHEMES = {
'scripts': '$base/bin',
'data' : '$base',
},
- 'unix_user': {
- 'purelib': '$usersite',
- 'platlib': '$usersite',
- 'headers': '$userbase/include/python$py_version_short/$dist_name',
- 'scripts': '$userbase/bin',
- 'data' : '$userbase',
- },
'nt': WINDOWS_SCHEME,
- 'nt_user': {
- 'purelib': '$usersite',
- 'platlib': '$usersite',
- 'headers': '$userbase/Python$py_version_nodot/Include/$dist_name',
- 'scripts': '$userbase/Scripts',
- 'data' : '$userbase',
- },
'os2': {
'purelib': '$base/Lib/site-packages',
'platlib': '$base/Lib/site-packages',
@@ -76,14 +65,34 @@ INSTALL_SCHEMES = {
'scripts': '$base/Scripts',
'data' : '$base',
},
- 'os2_home': {
+ }
+
+# user site schemes
+if HAS_USER_SITE:
+ INSTALL_SCHEMES['nt_user'] = {
+ 'purelib': '$usersite',
+ 'platlib': '$usersite',
+ 'headers': '$userbase/Python$py_version_nodot/Include/$dist_name',
+ 'scripts': '$userbase/Scripts',
+ 'data' : '$userbase',
+ }
+
+ INSTALL_SCHEMES['unix_user'] = {
+ 'purelib': '$usersite',
+ 'platlib': '$usersite',
+ 'headers':
+ '$userbase/include/python$py_version_short$abiflags/$dist_name',
+ 'scripts': '$userbase/bin',
+ 'data' : '$userbase',
+ }
+
+ INSTALL_SCHEMES['os2_home'] = {
'purelib': '$usersite',
'platlib': '$usersite',
'headers': '$userbase/include/python$py_version_short/$dist_name',
'scripts': '$userbase/bin',
'data' : '$userbase',
- },
- }
+ }
# The keys to an installation scheme; if any new types of files are to be
# installed, be sure to add an entry to every installation scheme above,
@@ -91,7 +100,7 @@ INSTALL_SCHEMES = {
SCHEME_KEYS = ('purelib', 'platlib', 'headers', 'scripts', 'data')
-class install (Command):
+class install(Command):
description = "install everything from build directory"
@@ -103,8 +112,6 @@ class install (Command):
"(Unix only) prefix for platform-specific files"),
('home=', None,
"(Unix only) home directory to install under"),
- ('user', None,
- "install in user site-package '%s'" % USER_SITE),
# Or, just set the base director(y|ies)
('install-base=', None,
@@ -156,12 +163,18 @@ class install (Command):
"filename in which to record list of installed files"),
]
- boolean_options = ['compile', 'force', 'skip-build', 'user']
- negative_opt = {'no-compile' : 'compile'}
+ boolean_options = ['compile', 'force', 'skip-build']
+ if HAS_USER_SITE:
+ user_options.append(('user', None,
+ "install in user site-package '%s'" % USER_SITE))
+ boolean_options.append('user')
+
+ negative_opt = {'no-compile' : 'compile'}
- def initialize_options (self):
+ def initialize_options(self):
+ """Initializes options."""
# High-level options: these select both an installation base
# and scheme.
self.prefix = None
@@ -237,8 +250,8 @@ 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):
+ """Finalizes options."""
# This method (and its pliant slaves, like 'finalize_unix()',
# 'finalize_other()', and 'select_scheme()') is where the default
# installation directories for modules, extension modules, and
@@ -255,13 +268,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")
if self.user and (self.prefix or self.exec_prefix or self.home or
self.install_base or self.install_platbase):
@@ -296,8 +309,13 @@ class install (Command):
# $platbase in the other installation directories and not worry
# about needing recursive variable expansion (shudder).
- py_version = (string.split(sys.version))[0]
+ py_version = sys.version.split()[0]
(prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix')
+ try:
+ abiflags = sys.abiflags
+ except AttributeError:
+ # sys.abiflags may not be defined on all platforms.
+ abiflags = ''
self.config_vars = {'dist_name': self.distribution.get_name(),
'dist_version': self.distribution.get_version(),
'dist_fullname': self.distribution.get_fullname(),
@@ -308,9 +326,13 @@ class install (Command):
'prefix': prefix,
'sys_exec_prefix': exec_prefix,
'exec_prefix': exec_prefix,
- 'userbase': self.install_userbase,
- 'usersite': self.install_usersite,
+ 'abiflags': abiflags,
}
+
+ if HAS_USER_SITE:
+ self.config_vars['userbase'] = self.install_userbase
+ self.config_vars['usersite'] = self.install_usersite
+
self.expand_basedirs()
self.dump_dirs("post-expand_basedirs()")
@@ -322,7 +344,7 @@ class install (Command):
if DEBUG:
from pprint import pprint
- print "config vars:"
+ print("config vars:")
pprint(self.config_vars)
# Expand "~" and configuration variables in the installation
@@ -376,29 +398,27 @@ class install (Command):
# Punt on doc directories for now -- after all, we're punting on
# documentation completely!
- # finalize_options ()
-
-
- def dump_dirs (self, msg):
- if DEBUG:
- from distutils.fancy_getopt import longopt_xlate
- print msg + ":"
- for opt in self.user_options:
- opt_name = opt[0]
- if opt_name[-1] == "=":
- opt_name = opt_name[0:-1]
- if opt_name in self.negative_opt:
- opt_name = string.translate(self.negative_opt[opt_name],
- longopt_xlate)
- val = not getattr(self, opt_name)
- else:
- opt_name = string.translate(opt_name, longopt_xlate)
- val = getattr(self, opt_name)
- print " %s: %s" % (opt_name, val)
-
-
- def finalize_unix (self):
+ def dump_dirs(self, msg):
+ """Dumps the list of user options."""
+ if not DEBUG:
+ return
+ from distutils.fancy_getopt import longopt_xlate
+ log.debug(msg + ":")
+ for opt in self.user_options:
+ opt_name = opt[0]
+ if opt_name[-1] == "=":
+ opt_name = opt_name[0:-1]
+ if opt_name in self.negative_opt:
+ opt_name = self.negative_opt[opt_name]
+ opt_name = opt_name.translate(longopt_xlate)
+ val = not getattr(self, opt_name)
+ else:
+ opt_name = opt_name.translate(longopt_xlate)
+ val = getattr(self, opt_name)
+ log.debug(" %s: %s" % (opt_name, val))
+ def finalize_unix(self):
+ """Finalizes options for posix platforms."""
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
@@ -406,8 +426,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
@@ -423,8 +443,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)
@@ -437,11 +457,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):
+ """Finalizes options for non-posix platforms"""
if self.user:
if self.install_userbase is None:
raise DistutilsPlatformError(
@@ -459,13 +476,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):
+ """Sets the install directories by applying the install schemes."""
# it's the caller's problem if they supply a bad name!
scheme = INSTALL_SCHEMES[name]
for key in SCHEME_KEYS:
@@ -473,8 +488,7 @@ class install (Command):
if getattr(self, attrname) is None:
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:
@@ -483,49 +497,44 @@ class install (Command):
val = subst_vars(val, self.config_vars)
setattr(self, attr, val)
+ def expand_basedirs(self):
+ """Calls `os.path.expanduser` on install_base, install_platbase and
+ root."""
+ self._expand_attrs(['install_base', 'install_platbase', 'root'])
- def expand_basedirs (self):
- self._expand_attrs(['install_base',
- 'install_platbase',
- 'root'])
-
- def expand_dirs (self):
- self._expand_attrs(['install_purelib',
- 'install_platlib',
- 'install_lib',
- 'install_headers',
- 'install_scripts',
- 'install_data',])
+ def expand_dirs(self):
+ """Calls `os.path.expanduser` on install dirs."""
+ self._expand_attrs(['install_purelib', 'install_platlib',
+ 'install_lib', 'install_headers',
+ 'install_scripts', 'install_data',])
-
- def convert_paths (self, *names):
+ def convert_paths(self, *names):
+ """Call `convert_path` over `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):
+ """Set `path_file` and `extra_dirs` using `extra_path`."""
if self.extra_path is None:
self.extra_path = self.distribution.extra_path
if self.extra_path is not None:
- if type(self.extra_path) is StringType:
- self.extra_path = string.split(self.extra_path, ',')
+ if isinstance(self.extra_path, str):
+ self.extra_path = self.extra_path.split(',')
if len(self.extra_path) == 1:
path_file = extra_dirs = self.extra_path[0]
elif len(self.extra_path) == 2:
- (path_file, extra_dirs) = self.extra_path
+ 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
# should be in setup scripts)
extra_dirs = convert_path(extra_dirs)
-
else:
path_file = None
extra_dirs = ''
@@ -535,29 +544,26 @@ 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):
+ """Change the install direcories pointed by name using root."""
for name in names:
attr = "install_" + name
setattr(self, attr, change_root(self.root, getattr(self, attr)))
def create_home_path(self):
- """Create directories under ~
- """
+ """Create directories under ~."""
if not self.user:
return
home = convert_path(os.path.expanduser("~"))
- for name, path in self.config_vars.iteritems():
+ for name, path in self.config_vars.items():
if path.startswith(home) and not os.path.isdir(path):
- self.debug_print("os.makedirs('%s', 0700)" % path)
- os.makedirs(path, 0700)
+ self.debug_print("os.makedirs('%s', 0o700)" % path)
+ os.makedirs(path, 0o700)
# -- Command execution methods -------------------------------------
- def run (self):
-
+ def run(self):
+ """Runs the command."""
# Obviously have to build before we can install
if not self.skip_build:
self.run_command('build')
@@ -582,7 +588,7 @@ class install (Command):
outputs = self.get_outputs()
if self.root: # strip any package prefix
root_len = len(self.root)
- for counter in xrange(len(outputs)):
+ for counter in range(len(outputs)):
outputs[counter] = outputs[counter][root_len:]
self.execute(write_file,
(self.record, outputs),
@@ -600,9 +606,8 @@ 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):
+ """Creates the .pth file"""
filename = os.path.join(self.install_libbase,
self.path_file + ".pth")
if self.install_path_file:
@@ -615,8 +620,8 @@ class install (Command):
# -- Reporting methods ---------------------------------------------
- def get_outputs (self):
- # Assemble the outputs of all the sub-commands.
+ def get_outputs(self):
+ """Assembles the outputs of all the sub-commands."""
outputs = []
for cmd_name in self.get_sub_commands():
cmd = self.get_finalized_command(cmd_name)
@@ -632,7 +637,8 @@ class install (Command):
return outputs
- def get_inputs (self):
+ def get_inputs(self):
+ """Returns the inputs of all the sub-commands"""
# XXX gee, this looks familiar ;-(
inputs = []
for cmd_name in self.get_sub_commands():
@@ -641,25 +647,29 @@ class install (Command):
return inputs
-
# -- Predicates for sub-command list -------------------------------
- def has_lib (self):
- """Return true if the current distribution has any Python
+ def has_lib(self):
+ """Returns 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):
+ """Returns true if the current distribution has any headers to
+ install."""
return self.distribution.has_headers()
- def has_scripts (self):
+ def has_scripts(self):
+ """Returns true if the current distribution has any scripts to.
+ install."""
return self.distribution.has_scripts()
- def has_data (self):
+ def has_data(self):
+ """Returns true if the current distribution has any data to.
+ install."""
return self.distribution.has_data_files()
-
# 'sub_commands': a list of commands this command might have to run to
# get its work done. See cmd.py for more info.
sub_commands = [('install_lib', has_lib),
@@ -668,5 +678,3 @@ class install (Command):
('install_data', has_data),
('install_egg_info', lambda self:True),
]
-
-# class install