1999-03-22 14:55:25 +00:00
|
|
|
"""distutils.command.install
|
|
|
|
|
|
|
|
Implements the Distutils 'install' command."""
|
|
|
|
|
|
|
|
# created 1999/03/13, Greg Ward
|
|
|
|
|
|
|
|
__rcsid__ = "$Id$"
|
|
|
|
|
|
|
|
import sys, os, string
|
1999-09-21 18:31:14 +00:00
|
|
|
from types import *
|
1999-03-22 14:55:25 +00:00
|
|
|
from distutils.core import Command
|
1999-09-21 18:31:14 +00:00
|
|
|
from distutils.util import write_file
|
2000-02-26 00:49:04 +00:00
|
|
|
from distutils.errors import DistutilsOptionError
|
1999-03-22 14:55:25 +00:00
|
|
|
|
2000-02-18 00:13:53 +00:00
|
|
|
class install (Command):
|
1999-03-22 14:55:25 +00:00
|
|
|
|
2000-01-30 18:34:15 +00:00
|
|
|
description = "install everything from build directory"
|
|
|
|
|
2000-02-18 00:25:39 +00:00
|
|
|
user_options = [
|
|
|
|
('prefix=', None, "installation prefix"),
|
|
|
|
('exec-prefix=', None,
|
|
|
|
"prefix for platform-specific files"),
|
|
|
|
|
|
|
|
# Installation directories: where to put modules and packages
|
|
|
|
('install-lib=', None,
|
|
|
|
"base Python library directory"),
|
|
|
|
('install-platlib=', None,
|
|
|
|
"platform-specific Python library directory"),
|
|
|
|
('install-path=', None,
|
|
|
|
"extra intervening directories to put below install-lib"),
|
|
|
|
|
2000-02-26 00:49:04 +00:00
|
|
|
# Build directories: where to find the files to install
|
|
|
|
('build-base=', None,
|
|
|
|
"base build directory"),
|
|
|
|
('build-lib=', None,
|
|
|
|
"build directory for pure Python modules"),
|
|
|
|
('build-platlib=', None,
|
|
|
|
"build directory for extension modules"),
|
|
|
|
|
2000-02-18 00:25:39 +00:00
|
|
|
# Where to install documentation (eventually!)
|
2000-02-26 00:49:04 +00:00
|
|
|
#('doc-format=', None, "format of documentation to generate"),
|
|
|
|
#('install-man=', None, "directory for Unix man pages"),
|
|
|
|
#('install-html=', None, "directory for HTML documentation"),
|
|
|
|
#('install-info=', None, "directory for GNU info files"),
|
2000-02-18 00:25:39 +00:00
|
|
|
|
|
|
|
# Flags for 'build_py'
|
2000-02-26 00:49:04 +00:00
|
|
|
#('compile-py', None, "compile .py to .pyc"),
|
|
|
|
#('optimize-py', None, "compile .py to .pyo (optimized)"),
|
2000-02-18 00:25:39 +00:00
|
|
|
]
|
1999-03-22 14:55:25 +00:00
|
|
|
|
1999-06-08 02:04:36 +00:00
|
|
|
|
2000-02-18 00:35:22 +00:00
|
|
|
def initialize_options (self):
|
1999-03-22 14:55:25 +00:00
|
|
|
|
|
|
|
# Don't define 'prefix' or 'exec_prefix' so we can know when the
|
|
|
|
# command is run whether the user supplied values
|
|
|
|
self.prefix = None
|
|
|
|
self.exec_prefix = None
|
|
|
|
|
|
|
|
# The actual installation directories are determined only at
|
|
|
|
# run-time, so the user can supply just prefix (and exec_prefix?)
|
|
|
|
# as a base for everything else
|
|
|
|
self.install_lib = None
|
|
|
|
self.install_platlib = None
|
1999-09-21 18:31:14 +00:00
|
|
|
self.install_path = None
|
1999-03-22 14:55:25 +00:00
|
|
|
|
2000-02-26 00:49:04 +00:00
|
|
|
self.build_base = None
|
|
|
|
self.build_lib = None
|
|
|
|
self.build_platlib = None
|
|
|
|
|
1999-03-22 14:55:25 +00:00
|
|
|
self.install_man = None
|
|
|
|
self.install_html = None
|
|
|
|
self.install_info = None
|
|
|
|
|
1999-05-02 21:39:13 +00:00
|
|
|
self.compile_py = 1
|
|
|
|
self.optimize_py = 1
|
|
|
|
|
1999-03-22 14:55:25 +00:00
|
|
|
|
2000-02-18 00:35:22 +00:00
|
|
|
def finalize_options (self):
|
1999-03-22 14:55:25 +00:00
|
|
|
|
1999-06-08 02:04:36 +00:00
|
|
|
# XXX this method is where the default installation directories
|
|
|
|
# for modules and extension modules are determined. (Someday,
|
|
|
|
# the default installation directories for scripts,
|
|
|
|
# documentation, and whatever else the Distutils can build and
|
|
|
|
# install will also be determined here.) Thus, this is a pretty
|
|
|
|
# important place to fiddle with for anyone interested in
|
|
|
|
# installation schemes for the Python library. Issues that
|
|
|
|
# are not yet resolved to my satisfaction:
|
|
|
|
# * how much platform dependence should be here, and
|
|
|
|
# how much can be pushed off to sysconfig (or, better, the
|
|
|
|
# Makefiles parsed by sysconfig)?
|
|
|
|
# * how independent of Python version should this be -- ie.
|
|
|
|
# should we have special cases to handle Python 1.5 and
|
|
|
|
# older, and then do it "the right way" for 1.6? Or should
|
|
|
|
# we install a site.py along with Distutils under pre-1.6
|
|
|
|
# Python to take care of the current deficiencies in
|
|
|
|
# Python's library installation scheme?
|
|
|
|
#
|
|
|
|
# Currently, this method has hacks to distinguish POSIX from
|
|
|
|
# non-POSIX systems (for installation of site-local modules),
|
|
|
|
# and assumes the Python 1.5 installation tree with no site.py
|
|
|
|
# to fix things.
|
|
|
|
|
1999-03-22 14:55:25 +00:00
|
|
|
# Figure out actual installation directories; the basic principle
|
2000-02-26 00:49:04 +00:00
|
|
|
# is: ...
|
|
|
|
|
|
|
|
sys_prefix = os.path.normpath (sys.prefix)
|
|
|
|
sys_exec_prefix = os.path.normpath (sys.exec_prefix)
|
|
|
|
|
|
|
|
if self.prefix is None:
|
|
|
|
if self.exec_prefix is not None:
|
|
|
|
raise DistutilsOptionError, \
|
|
|
|
"you may not supply exec_prefix without prefix"
|
|
|
|
self.prefix = sys_prefix
|
|
|
|
else:
|
|
|
|
# This is handy to guarantee that self.prefix is normalized --
|
|
|
|
# but it could be construed as rude to go normalizing a
|
|
|
|
# user-supplied path (they might like to see their "../" or
|
|
|
|
# symlinks in the installation feedback).
|
|
|
|
self.prefix = os.path.normpath (self.prefix)
|
|
|
|
|
1999-03-22 14:55:25 +00:00
|
|
|
if self.exec_prefix is None:
|
2000-02-26 00:49:04 +00:00
|
|
|
if self.prefix == sys_prefix:
|
|
|
|
self.exec_prefix = sys_exec_prefix
|
|
|
|
else:
|
|
|
|
self.exec_prefix = self.prefix
|
|
|
|
else:
|
|
|
|
# Same as above about handy versus rude to normalize user's
|
|
|
|
# exec_prefix.
|
|
|
|
self.exec_prefix = os.path.normpath (self.exec_prefix)
|
|
|
|
|
|
|
|
if self.distribution.ext_modules: # any extensions to install?
|
|
|
|
effective_prefix = self.exec_prefix
|
|
|
|
else:
|
|
|
|
effective_prefix = self.prefix
|
|
|
|
|
1999-09-21 18:31:14 +00:00
|
|
|
if os.name == 'posix':
|
2000-02-26 00:49:04 +00:00
|
|
|
if self.install_lib is None:
|
|
|
|
if self.prefix == sys_prefix:
|
|
|
|
self.install_lib = \
|
|
|
|
os.path.join (effective_prefix,
|
|
|
|
"lib",
|
|
|
|
"python" + sys.version[:3],
|
|
|
|
"site-packages")
|
|
|
|
else:
|
|
|
|
self.install_lib = \
|
|
|
|
os.path.join (effective_prefix,
|
|
|
|
"lib",
|
|
|
|
"python") # + sys.version[:3] ???
|
|
|
|
# end if self.install_lib ...
|
|
|
|
|
|
|
|
if self.install_platlib is None:
|
|
|
|
if self.exec_prefix == sys_exec_prefix:
|
|
|
|
self.install_platlib = \
|
|
|
|
os.path.join (effective_prefix,
|
|
|
|
"lib",
|
|
|
|
"python" + sys.version[:3],
|
|
|
|
"site-packages")
|
|
|
|
else:
|
|
|
|
self.install_platlib = \
|
|
|
|
os.path.join (effective_prefix,
|
|
|
|
"lib",
|
|
|
|
"python") # + sys.version[:3] ???
|
|
|
|
# end if self.install_platlib ...
|
|
|
|
|
1999-09-21 18:31:14 +00:00
|
|
|
else:
|
2000-02-26 00:49:04 +00:00
|
|
|
raise DistutilsPlatformError, \
|
|
|
|
"duh, I'm clueless (for now) about installing on %s" % os.name
|
|
|
|
|
|
|
|
# end if/else on os.name
|
|
|
|
|
|
|
|
|
|
|
|
# 'path_file' and 'extra_dirs' are how we handle distributions that
|
|
|
|
# want to be installed to their own directory, but aren't
|
1999-09-21 18:31:14 +00:00
|
|
|
# package-ized yet. 'extra_dirs' is just a directory under
|
2000-02-26 00:49:04 +00:00
|
|
|
# 'install_lib' or 'install_platlib' where top-level modules will
|
|
|
|
# actually be installed; 'path_file' is the basename of a .pth file
|
|
|
|
# to drop in 'install_lib' or 'install_platlib' (depending on the
|
|
|
|
# distribution). Very often they will be the same, which is why we
|
|
|
|
# allow them to be supplied as a string or 1-tuple as well as a
|
|
|
|
# 2-element comma-separated string or a 2-tuple.
|
|
|
|
|
|
|
|
# XXX this will drop a .pth file in install_{lib,platlib} even if
|
|
|
|
# they're not one of the site-packages directories: this is wrong!
|
|
|
|
# we need to suppress path_file in those cases, and warn if
|
|
|
|
# "install_lib/extra_dirs" is not in sys.path.
|
|
|
|
|
1999-09-21 18:31:14 +00:00
|
|
|
if self.install_path is None:
|
|
|
|
self.install_path = self.distribution.install_path
|
|
|
|
|
|
|
|
if self.install_path is not None:
|
|
|
|
if type (self.install_path) is StringType:
|
|
|
|
self.install_path = string.split (self.install_path, ',')
|
|
|
|
|
|
|
|
if len (self.install_path) == 1:
|
|
|
|
path_file = extra_dirs = self.install_path[0]
|
|
|
|
elif len (self.install_path) == 2:
|
|
|
|
(path_file, extra_dirs) = self.install_path
|
1999-06-08 02:04:36 +00:00
|
|
|
else:
|
1999-09-21 18:31:14 +00:00
|
|
|
raise DistutilsOptionError, \
|
|
|
|
"'install_path' option must be a list, tuple, or " + \
|
|
|
|
"comma-separated string with 1 or 2 elements"
|
|
|
|
|
|
|
|
# install path has slashes in it -- might need to convert to
|
|
|
|
# local form
|
|
|
|
if string.find (extra_dirs, '/') and os.name != "posix":
|
|
|
|
extra_dirs = string.split (extra_dirs, '/')
|
|
|
|
extra_dirs = apply (os.path.join, extra_dirs)
|
|
|
|
else:
|
|
|
|
path_file = None
|
|
|
|
extra_dirs = ''
|
|
|
|
|
|
|
|
# XXX should we warn if path_file and not extra_dirs (in which case
|
|
|
|
# the path file would be harmless but pointless)
|
|
|
|
self.path_file = path_file
|
|
|
|
self.extra_dirs = extra_dirs
|
|
|
|
|
|
|
|
|
2000-02-26 00:49:04 +00:00
|
|
|
# Figure out the build directories, ie. where to install from
|
|
|
|
self.set_peer_option ('build', 'build_base', self.build_base)
|
|
|
|
self.set_undefined_options ('build',
|
|
|
|
('build_base', 'build_base'),
|
|
|
|
('build_lib', 'build_lib'),
|
|
|
|
('build_platlib', 'build_platlib'))
|
1999-03-22 14:55:25 +00:00
|
|
|
|
|
|
|
# Punt on doc directories for now -- after all, we're punting on
|
|
|
|
# documentation completely!
|
|
|
|
|
2000-02-18 00:35:22 +00:00
|
|
|
# finalize_options ()
|
1999-03-22 14:55:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
def run (self):
|
|
|
|
|
1999-06-08 02:04:36 +00:00
|
|
|
# Obviously have to build before we can install
|
|
|
|
self.run_peer ('build')
|
|
|
|
|
1999-03-22 14:55:25 +00:00
|
|
|
# Install modules in two steps: "platform-shared" files (ie. pure
|
2000-02-26 00:49:04 +00:00
|
|
|
# Python modules) and platform-specific files (compiled C
|
1999-09-13 13:57:26 +00:00
|
|
|
# extensions). Note that 'install_py' is smart enough to install
|
|
|
|
# pure Python modules in the "platlib" directory if we built any
|
|
|
|
# extensions.
|
1999-09-21 18:31:14 +00:00
|
|
|
if self.distribution.packages or self.distribution.py_modules:
|
|
|
|
self.run_peer ('install_py')
|
|
|
|
if self.distribution.ext_modules:
|
|
|
|
self.run_peer ('install_ext')
|
|
|
|
|
|
|
|
if self.path_file:
|
|
|
|
self.create_path_file ()
|
1999-03-22 14:55:25 +00:00
|
|
|
|
|
|
|
# run ()
|
|
|
|
|
1999-09-21 18:31:14 +00:00
|
|
|
|
|
|
|
def create_path_file (self):
|
|
|
|
|
|
|
|
if self.distribution.ext_modules:
|
|
|
|
base = self.platbase
|
|
|
|
else:
|
|
|
|
base = self.base
|
|
|
|
|
|
|
|
filename = os.path.join (base, self.path_file + ".pth")
|
|
|
|
self.execute (write_file,
|
|
|
|
(filename, [self.extra_dirs]),
|
|
|
|
"creating %s" % filename)
|
|
|
|
|
|
|
|
|
1999-03-22 14:55:25 +00:00
|
|
|
# class Install
|