+++ /dev/null
-"""distutils.command.install\r
-\r
-Implements the Distutils 'install' command."""\r
-\r
-from distutils import log\r
-\r
-# This module should be kept compatible with Python 2.1.\r
-\r
-__revision__ = "$Id$"\r
-\r
-import sys, os, string\r
-from types import *\r
-from distutils.core import Command\r
-from distutils.debug import DEBUG\r
-from distutils.sysconfig import get_config_vars\r
-from distutils.errors import DistutilsPlatformError\r
-from distutils.file_util import write_file\r
-from distutils.util import convert_path, subst_vars, change_root\r
-from distutils.util import get_platform\r
-from distutils.errors import DistutilsOptionError\r
-from site import USER_BASE\r
-from site import USER_SITE\r
-\r
-\r
-if sys.version < "2.2":\r
- WINDOWS_SCHEME = {\r
- 'purelib': '$base',\r
- 'platlib': '$base',\r
- 'headers': '$base/Include/$dist_name',\r
- 'scripts': '$base/Scripts',\r
- 'data' : '$base',\r
- }\r
-else:\r
- WINDOWS_SCHEME = {\r
- 'purelib': '$base/Lib/site-packages',\r
- 'platlib': '$base/Lib/site-packages',\r
- 'headers': '$base/Include/$dist_name',\r
- 'scripts': '$base/Scripts',\r
- 'data' : '$base',\r
- }\r
-\r
-INSTALL_SCHEMES = {\r
- 'unix_prefix': {\r
- 'purelib': '$base/lib/python$py_version_short/site-packages',\r
- 'platlib': '$platbase/lib/python$py_version_short/site-packages',\r
- 'headers': '$base/include/python$py_version_short/$dist_name',\r
- 'scripts': '$base/bin',\r
- 'data' : '$base',\r
- },\r
- 'unix_home': {\r
- 'purelib': '$base/lib/python',\r
- 'platlib': '$base/lib/python',\r
- 'headers': '$base/include/python/$dist_name',\r
- 'scripts': '$base/bin',\r
- 'data' : '$base',\r
- },\r
- 'unix_user': {\r
- 'purelib': '$usersite',\r
- 'platlib': '$usersite',\r
- 'headers': '$userbase/include/python$py_version_short/$dist_name',\r
- 'scripts': '$userbase/bin',\r
- 'data' : '$userbase',\r
- },\r
- 'nt': WINDOWS_SCHEME,\r
- 'nt_user': {\r
- 'purelib': '$usersite',\r
- 'platlib': '$usersite',\r
- 'headers': '$userbase/Python$py_version_nodot/Include/$dist_name',\r
- 'scripts': '$userbase/Scripts',\r
- 'data' : '$userbase',\r
- },\r
- 'os2': {\r
- 'purelib': '$base/Lib/site-packages',\r
- 'platlib': '$base/Lib/site-packages',\r
- 'headers': '$base/Include/$dist_name',\r
- 'scripts': '$base/Scripts',\r
- 'data' : '$base',\r
- },\r
- 'os2_home': {\r
- 'purelib': '$usersite',\r
- 'platlib': '$usersite',\r
- 'headers': '$userbase/include/python$py_version_short/$dist_name',\r
- 'scripts': '$userbase/bin',\r
- 'data' : '$userbase',\r
- },\r
- }\r
-\r
-# The keys to an installation scheme; if any new types of files are to be\r
-# installed, be sure to add an entry to every installation scheme above,\r
-# and to SCHEME_KEYS here.\r
-SCHEME_KEYS = ('purelib', 'platlib', 'headers', 'scripts', 'data')\r
-\r
-\r
-class install (Command):\r
-\r
- description = "install everything from build directory"\r
-\r
- user_options = [\r
- # Select installation scheme and set base director(y|ies)\r
- ('prefix=', None,\r
- "installation prefix"),\r
- ('exec-prefix=', None,\r
- "(Unix only) prefix for platform-specific files"),\r
- ('home=', None,\r
- "(Unix only) home directory to install under"),\r
- ('user', None,\r
- "install in user site-package '%s'" % USER_SITE),\r
-\r
- # Or, just set the base director(y|ies)\r
- ('install-base=', None,\r
- "base installation directory (instead of --prefix or --home)"),\r
- ('install-platbase=', None,\r
- "base installation directory for platform-specific files " +\r
- "(instead of --exec-prefix or --home)"),\r
- ('root=', None,\r
- "install everything relative to this alternate root directory"),\r
-\r
- # Or, explicitly set the installation scheme\r
- ('install-purelib=', None,\r
- "installation directory for pure Python module distributions"),\r
- ('install-platlib=', None,\r
- "installation directory for non-pure module distributions"),\r
- ('install-lib=', None,\r
- "installation directory for all module distributions " +\r
- "(overrides --install-purelib and --install-platlib)"),\r
-\r
- ('install-headers=', None,\r
- "installation directory for C/C++ headers"),\r
- ('install-scripts=', None,\r
- "installation directory for Python scripts"),\r
- ('install-data=', None,\r
- "installation directory for data files"),\r
-\r
- # Byte-compilation options -- see install_lib.py for details, as\r
- # these are duplicated from there (but only install_lib does\r
- # anything with them).\r
- ('compile', 'c', "compile .py to .pyc [default]"),\r
- ('no-compile', None, "don't compile .py files"),\r
- ('optimize=', 'O',\r
- "also compile with optimization: -O1 for \"python -O\", "\r
- "-O2 for \"python -OO\", and -O0 to disable [default: -O0]"),\r
-\r
- # Miscellaneous control options\r
- ('force', 'f',\r
- "force installation (overwrite any existing files)"),\r
- ('skip-build', None,\r
- "skip rebuilding everything (for testing/debugging)"),\r
-\r
- # Where to install documentation (eventually!)\r
- #('doc-format=', None, "format of documentation to generate"),\r
- #('install-man=', None, "directory for Unix man pages"),\r
- #('install-html=', None, "directory for HTML documentation"),\r
- #('install-info=', None, "directory for GNU info files"),\r
-\r
- ('record=', None,\r
- "filename in which to record list of installed files"),\r
- ]\r
-\r
- boolean_options = ['compile', 'force', 'skip-build', 'user']\r
- negative_opt = {'no-compile' : 'compile'}\r
-\r
-\r
- def initialize_options (self):\r
-\r
- # High-level options: these select both an installation base\r
- # and scheme.\r
- self.prefix = None\r
- self.exec_prefix = None\r
- self.home = None\r
- self.user = 0\r
-\r
- # These select only the installation base; it's up to the user to\r
- # specify the installation scheme (currently, that means supplying\r
- # the --install-{platlib,purelib,scripts,data} options).\r
- self.install_base = None\r
- self.install_platbase = None\r
- self.root = None\r
-\r
- # These options are the actual installation directories; if not\r
- # supplied by the user, they are filled in using the installation\r
- # scheme implied by prefix/exec-prefix/home and the contents of\r
- # that installation scheme.\r
- self.install_purelib = None # for pure module distributions\r
- self.install_platlib = None # non-pure (dists w/ extensions)\r
- self.install_headers = None # for C/C++ headers\r
- self.install_lib = None # set to either purelib or platlib\r
- self.install_scripts = None\r
- self.install_data = None\r
- self.install_userbase = USER_BASE\r
- self.install_usersite = USER_SITE\r
-\r
- self.compile = None\r
- self.optimize = None\r
-\r
- # These two are for putting non-packagized distributions into their\r
- # own directory and creating a .pth file if it makes sense.\r
- # 'extra_path' comes from the setup file; 'install_path_file' can\r
- # be turned off if it makes no sense to install a .pth file. (But\r
- # better to install it uselessly than to guess wrong and not\r
- # install it when it's necessary and would be used!) Currently,\r
- # 'install_path_file' is always true unless some outsider meddles\r
- # with it.\r
- self.extra_path = None\r
- self.install_path_file = 1\r
-\r
- # 'force' forces installation, even if target files are not\r
- # out-of-date. 'skip_build' skips running the "build" command,\r
- # handy if you know it's not necessary. 'warn_dir' (which is *not*\r
- # a user option, it's just there so the bdist_* commands can turn\r
- # it off) determines whether we warn about installing to a\r
- # directory not in sys.path.\r
- self.force = 0\r
- self.skip_build = 0\r
- self.warn_dir = 1\r
-\r
- # These are only here as a conduit from the 'build' command to the\r
- # 'install_*' commands that do the real work. ('build_base' isn't\r
- # actually used anywhere, but it might be useful in future.) They\r
- # are not user options, because if the user told the install\r
- # command where the build directory is, that wouldn't affect the\r
- # build command.\r
- self.build_base = None\r
- self.build_lib = None\r
-\r
- # Not defined yet because we don't know anything about\r
- # documentation yet.\r
- #self.install_man = None\r
- #self.install_html = None\r
- #self.install_info = None\r
-\r
- self.record = None\r
-\r
-\r
- # -- Option finalizing methods -------------------------------------\r
- # (This is rather more involved than for most commands,\r
- # because this is where the policy for installing third-\r
- # party Python modules on various platforms given a wide\r
- # array of user input is decided. Yes, it's quite complex!)\r
-\r
- def finalize_options (self):\r
-\r
- # This method (and its pliant slaves, like 'finalize_unix()',\r
- # 'finalize_other()', and 'select_scheme()') is where the default\r
- # installation directories for modules, extension modules, and\r
- # anything else we care to install from a Python module\r
- # distribution. Thus, this code makes a pretty important policy\r
- # statement about how third-party stuff is added to a Python\r
- # installation! Note that the actual work of installation is done\r
- # by the relatively simple 'install_*' commands; they just take\r
- # their orders from the installation directory options determined\r
- # here.\r
-\r
- # Check for errors/inconsistencies in the options; first, stuff\r
- # that's wrong on any platform.\r
-\r
- if ((self.prefix or self.exec_prefix or self.home) and\r
- (self.install_base or self.install_platbase)):\r
- raise DistutilsOptionError, \\r
- ("must supply either prefix/exec-prefix/home or " +\r
- "install-base/install-platbase -- not both")\r
-\r
- if self.home and (self.prefix or self.exec_prefix):\r
- raise DistutilsOptionError, \\r
- "must supply either home or prefix/exec-prefix -- not both"\r
-\r
- if self.user and (self.prefix or self.exec_prefix or self.home or\r
- self.install_base or self.install_platbase):\r
- raise DistutilsOptionError("can't combine user with with prefix/"\r
- "exec_prefix/home or install_(plat)base")\r
-\r
- # Next, stuff that's wrong (or dubious) only on certain platforms.\r
- if os.name != "posix":\r
- if self.exec_prefix:\r
- self.warn("exec-prefix option ignored on this platform")\r
- self.exec_prefix = None\r
-\r
- # Now the interesting logic -- so interesting that we farm it out\r
- # to other methods. The goal of these methods is to set the final\r
- # values for the install_{lib,scripts,data,...} options, using as\r
- # input a heady brew of prefix, exec_prefix, home, install_base,\r
- # install_platbase, user-supplied versions of\r
- # install_{purelib,platlib,lib,scripts,data,...}, and the\r
- # INSTALL_SCHEME dictionary above. Phew!\r
-\r
- self.dump_dirs("pre-finalize_{unix,other}")\r
-\r
- if os.name == 'posix':\r
- self.finalize_unix()\r
- else:\r
- self.finalize_other()\r
-\r
- self.dump_dirs("post-finalize_{unix,other}()")\r
-\r
- # Expand configuration variables, tilde, etc. in self.install_base\r
- # and self.install_platbase -- that way, we can use $base or\r
- # $platbase in the other installation directories and not worry\r
- # about needing recursive variable expansion (shudder).\r
-\r
- py_version = (string.split(sys.version))[0]\r
- (prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix')\r
- self.config_vars = {'dist_name': self.distribution.get_name(),\r
- 'dist_version': self.distribution.get_version(),\r
- 'dist_fullname': self.distribution.get_fullname(),\r
- 'py_version': py_version,\r
- 'py_version_short': py_version[0:3],\r
- 'py_version_nodot': py_version[0] + py_version[2],\r
- 'sys_prefix': prefix,\r
- 'prefix': prefix,\r
- 'sys_exec_prefix': exec_prefix,\r
- 'exec_prefix': exec_prefix,\r
- 'userbase': self.install_userbase,\r
- 'usersite': self.install_usersite,\r
- }\r
- self.expand_basedirs()\r
-\r
- self.dump_dirs("post-expand_basedirs()")\r
-\r
- # Now define config vars for the base directories so we can expand\r
- # everything else.\r
- self.config_vars['base'] = self.install_base\r
- self.config_vars['platbase'] = self.install_platbase\r
-\r
- if DEBUG:\r
- from pprint import pprint\r
- print "config vars:"\r
- pprint(self.config_vars)\r
-\r
- # Expand "~" and configuration variables in the installation\r
- # directories.\r
- self.expand_dirs()\r
-\r
- self.dump_dirs("post-expand_dirs()")\r
-\r
- # Create directories in the home dir:\r
- if self.user:\r
- self.create_home_path()\r
-\r
- # Pick the actual directory to install all modules to: either\r
- # install_purelib or install_platlib, depending on whether this\r
- # module distribution is pure or not. Of course, if the user\r
- # already specified install_lib, use their selection.\r
- if self.install_lib is None:\r
- if self.distribution.ext_modules: # has extensions: non-pure\r
- self.install_lib = self.install_platlib\r
- else:\r
- self.install_lib = self.install_purelib\r
-\r
-\r
- # Convert directories from Unix /-separated syntax to the local\r
- # convention.\r
- self.convert_paths('lib', 'purelib', 'platlib',\r
- 'scripts', 'data', 'headers',\r
- 'userbase', 'usersite')\r
-\r
- # Well, we're not actually fully completely finalized yet: we still\r
- # have to deal with 'extra_path', which is the hack for allowing\r
- # non-packagized module distributions (hello, Numerical Python!) to\r
- # get their own directories.\r
- self.handle_extra_path()\r
- self.install_libbase = self.install_lib # needed for .pth file\r
- self.install_lib = os.path.join(self.install_lib, self.extra_dirs)\r
-\r
- # If a new root directory was supplied, make all the installation\r
- # dirs relative to it.\r
- if self.root is not None:\r
- self.change_roots('libbase', 'lib', 'purelib', 'platlib',\r
- 'scripts', 'data', 'headers')\r
-\r
- self.dump_dirs("after prepending root")\r
-\r
- # Find out the build directories, ie. where to install from.\r
- self.set_undefined_options('build',\r
- ('build_base', 'build_base'),\r
- ('build_lib', 'build_lib'))\r
-\r
- # Punt on doc directories for now -- after all, we're punting on\r
- # documentation completely!\r
-\r
- # finalize_options ()\r
-\r
-\r
- def dump_dirs (self, msg):\r
- if DEBUG:\r
- from distutils.fancy_getopt import longopt_xlate\r
- print msg + ":"\r
- for opt in self.user_options:\r
- opt_name = opt[0]\r
- if opt_name[-1] == "=":\r
- opt_name = opt_name[0:-1]\r
- if opt_name in self.negative_opt:\r
- opt_name = string.translate(self.negative_opt[opt_name],\r
- longopt_xlate)\r
- val = not getattr(self, opt_name)\r
- else:\r
- opt_name = string.translate(opt_name, longopt_xlate)\r
- val = getattr(self, opt_name)\r
- print " %s: %s" % (opt_name, val)\r
-\r
-\r
- def finalize_unix (self):\r
-\r
- if self.install_base is not None or self.install_platbase is not None:\r
- if ((self.install_lib is None and\r
- self.install_purelib is None and\r
- self.install_platlib is None) or\r
- self.install_headers is None or\r
- self.install_scripts is None or\r
- self.install_data is None):\r
- raise DistutilsOptionError, \\r
- ("install-base or install-platbase supplied, but "\r
- "installation scheme is incomplete")\r
- return\r
-\r
- if self.user:\r
- if self.install_userbase is None:\r
- raise DistutilsPlatformError(\r
- "User base directory is not specified")\r
- self.install_base = self.install_platbase = self.install_userbase\r
- self.select_scheme("unix_user")\r
- elif self.home is not None:\r
- self.install_base = self.install_platbase = self.home\r
- self.select_scheme("unix_home")\r
- else:\r
- if self.prefix is None:\r
- if self.exec_prefix is not None:\r
- raise DistutilsOptionError, \\r
- "must not supply exec-prefix without prefix"\r
-\r
- self.prefix = os.path.normpath(sys.prefix)\r
- self.exec_prefix = os.path.normpath(sys.exec_prefix)\r
-\r
- else:\r
- if self.exec_prefix is None:\r
- self.exec_prefix = self.prefix\r
-\r
- self.install_base = self.prefix\r
- self.install_platbase = self.exec_prefix\r
- self.select_scheme("unix_prefix")\r
-\r
- # finalize_unix ()\r
-\r
-\r
- def finalize_other (self): # Windows and Mac OS for now\r
-\r
- if self.user:\r
- if self.install_userbase is None:\r
- raise DistutilsPlatformError(\r
- "User base directory is not specified")\r
- self.install_base = self.install_platbase = self.install_userbase\r
- self.select_scheme(os.name + "_user")\r
- elif self.home is not None:\r
- self.install_base = self.install_platbase = self.home\r
- self.select_scheme("unix_home")\r
- else:\r
- if self.prefix is None:\r
- self.prefix = os.path.normpath(sys.prefix)\r
-\r
- self.install_base = self.install_platbase = self.prefix\r
- try:\r
- self.select_scheme(os.name)\r
- except KeyError:\r
- raise DistutilsPlatformError, \\r
- "I don't know how to install stuff on '%s'" % os.name\r
-\r
- # finalize_other ()\r
-\r
-\r
- def select_scheme (self, name):\r
- # it's the caller's problem if they supply a bad name!\r
- scheme = INSTALL_SCHEMES[name]\r
- for key in SCHEME_KEYS:\r
- attrname = 'install_' + key\r
- if getattr(self, attrname) is None:\r
- setattr(self, attrname, scheme[key])\r
-\r
-\r
- def _expand_attrs (self, attrs):\r
- for attr in attrs:\r
- val = getattr(self, attr)\r
- if val is not None:\r
- if os.name == 'posix' or os.name == 'nt':\r
- val = os.path.expanduser(val)\r
- val = subst_vars(val, self.config_vars)\r
- setattr(self, attr, val)\r
-\r
-\r
- def expand_basedirs (self):\r
- self._expand_attrs(['install_base',\r
- 'install_platbase',\r
- 'root'])\r
-\r
- def expand_dirs (self):\r
- self._expand_attrs(['install_purelib',\r
- 'install_platlib',\r
- 'install_lib',\r
- 'install_headers',\r
- 'install_scripts',\r
- 'install_data',])\r
-\r
-\r
- def convert_paths (self, *names):\r
- for name in names:\r
- attr = "install_" + name\r
- setattr(self, attr, convert_path(getattr(self, attr)))\r
-\r
-\r
- def handle_extra_path (self):\r
-\r
- if self.extra_path is None:\r
- self.extra_path = self.distribution.extra_path\r
-\r
- if self.extra_path is not None:\r
- if type(self.extra_path) is StringType:\r
- self.extra_path = string.split(self.extra_path, ',')\r
-\r
- if len(self.extra_path) == 1:\r
- path_file = extra_dirs = self.extra_path[0]\r
- elif len(self.extra_path) == 2:\r
- (path_file, extra_dirs) = self.extra_path\r
- else:\r
- raise DistutilsOptionError, \\r
- ("'extra_path' option must be a list, tuple, or "\r
- "comma-separated string with 1 or 2 elements")\r
-\r
- # convert to local form in case Unix notation used (as it\r
- # should be in setup scripts)\r
- extra_dirs = convert_path(extra_dirs)\r
-\r
- else:\r
- path_file = None\r
- extra_dirs = ''\r
-\r
- # XXX should we warn if path_file and not extra_dirs? (in which\r
- # case the path file would be harmless but pointless)\r
- self.path_file = path_file\r
- self.extra_dirs = extra_dirs\r
-\r
- # handle_extra_path ()\r
-\r
-\r
- def change_roots (self, *names):\r
- for name in names:\r
- attr = "install_" + name\r
- setattr(self, attr, change_root(self.root, getattr(self, attr)))\r
-\r
- def create_home_path(self):\r
- """Create directories under ~\r
- """\r
- if not self.user:\r
- return\r
- home = convert_path(os.path.expanduser("~"))\r
- for name, path in self.config_vars.iteritems():\r
- if path.startswith(home) and not os.path.isdir(path):\r
- self.debug_print("os.makedirs('%s', 0700)" % path)\r
- os.makedirs(path, 0700)\r
-\r
- # -- Command execution methods -------------------------------------\r
-\r
- def run (self):\r
-\r
- # Obviously have to build before we can install\r
- if not self.skip_build:\r
- self.run_command('build')\r
- # If we built for any other platform, we can't install.\r
- build_plat = self.distribution.get_command_obj('build').plat_name\r
- # check warn_dir - it is a clue that the 'install' is happening\r
- # internally, and not to sys.path, so we don't check the platform\r
- # matches what we are running.\r
- if self.warn_dir and build_plat != get_platform():\r
- raise DistutilsPlatformError("Can't install when "\r
- "cross-compiling")\r
-\r
- # Run all sub-commands (at least those that need to be run)\r
- for cmd_name in self.get_sub_commands():\r
- self.run_command(cmd_name)\r
-\r
- if self.path_file:\r
- self.create_path_file()\r
-\r
- # write list of installed files, if requested.\r
- if self.record:\r
- outputs = self.get_outputs()\r
- if self.root: # strip any package prefix\r
- root_len = len(self.root)\r
- for counter in xrange(len(outputs)):\r
- outputs[counter] = outputs[counter][root_len:]\r
- self.execute(write_file,\r
- (self.record, outputs),\r
- "writing list of installed files to '%s'" %\r
- self.record)\r
-\r
- sys_path = map(os.path.normpath, sys.path)\r
- sys_path = map(os.path.normcase, sys_path)\r
- install_lib = os.path.normcase(os.path.normpath(self.install_lib))\r
- if (self.warn_dir and\r
- not (self.path_file and self.install_path_file) and\r
- install_lib not in sys_path):\r
- log.debug(("modules installed to '%s', which is not in "\r
- "Python's module search path (sys.path) -- "\r
- "you'll have to change the search path yourself"),\r
- self.install_lib)\r
-\r
- # run ()\r
-\r
- def create_path_file (self):\r
- filename = os.path.join(self.install_libbase,\r
- self.path_file + ".pth")\r
- if self.install_path_file:\r
- self.execute(write_file,\r
- (filename, [self.extra_dirs]),\r
- "creating %s" % filename)\r
- else:\r
- self.warn("path file '%s' not created" % filename)\r
-\r
-\r
- # -- Reporting methods ---------------------------------------------\r
-\r
- def get_outputs (self):\r
- # Assemble the outputs of all the sub-commands.\r
- outputs = []\r
- for cmd_name in self.get_sub_commands():\r
- cmd = self.get_finalized_command(cmd_name)\r
- # Add the contents of cmd.get_outputs(), ensuring\r
- # that outputs doesn't contain duplicate entries\r
- for filename in cmd.get_outputs():\r
- if filename not in outputs:\r
- outputs.append(filename)\r
-\r
- if self.path_file and self.install_path_file:\r
- outputs.append(os.path.join(self.install_libbase,\r
- self.path_file + ".pth"))\r
-\r
- return outputs\r
-\r
- def get_inputs (self):\r
- # XXX gee, this looks familiar ;-(\r
- inputs = []\r
- for cmd_name in self.get_sub_commands():\r
- cmd = self.get_finalized_command(cmd_name)\r
- inputs.extend(cmd.get_inputs())\r
-\r
- return inputs\r
-\r
-\r
- # -- Predicates for sub-command list -------------------------------\r
-\r
- def has_lib (self):\r
- """Return true if the current distribution has any Python\r
- modules to install."""\r
- return (self.distribution.has_pure_modules() or\r
- self.distribution.has_ext_modules())\r
-\r
- def has_headers (self):\r
- return self.distribution.has_headers()\r
-\r
- def has_scripts (self):\r
- return self.distribution.has_scripts()\r
-\r
- def has_data (self):\r
- return self.distribution.has_data_files()\r
-\r
-\r
- # 'sub_commands': a list of commands this command might have to run to\r
- # get its work done. See cmd.py for more info.\r
- sub_commands = [('install_lib', has_lib),\r
- ('install_headers', has_headers),\r
- ('install_scripts', has_scripts),\r
- ('install_data', has_data),\r
- ('install_egg_info', lambda self:True),\r
- ]\r
-\r
-# class install\r