Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 1 | """distutils.command.install |
| 2 | |
| 3 | Implements the Distutils 'install' command.""" |
| 4 | |
| 5 | # created 1999/03/13, Greg Ward |
| 6 | |
Greg Ward | 3ce77fd | 2000-03-02 01:49:45 +0000 | [diff] [blame] | 7 | __revision__ = "$Id$" |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 8 | |
| 9 | import sys, os, string |
Greg Ward | 865de83 | 1999-09-21 18:31:14 +0000 | [diff] [blame] | 10 | from types import * |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 11 | from distutils.core import Command |
Greg Ward | ff2d9b7 | 2000-04-26 02:38:01 +0000 | [diff] [blame] | 12 | from distutils import sysconfig |
Greg Ward | 6a647bb | 2000-04-27 01:56:38 +0000 | [diff] [blame] | 13 | from distutils.util import write_file, native_path, subst_vars, change_root |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame] | 14 | from distutils.errors import DistutilsOptionError |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 15 | |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 16 | INSTALL_SCHEMES = { |
| 17 | 'unix_prefix': { |
| 18 | 'purelib': '$base/lib/python$py_version_short/site-packages', |
| 19 | 'platlib': '$platbase/lib/python$py_version_short/site-packages', |
| 20 | 'scripts': '$base/bin', |
| 21 | 'data' : '$base/share', |
| 22 | }, |
| 23 | 'unix_home': { |
| 24 | 'purelib': '$base/lib/python', |
| 25 | 'platlib': '$base/lib/python', |
| 26 | 'scripts': '$base/bin', |
| 27 | 'data' : '$base/share', |
| 28 | }, |
| 29 | 'nt': { |
| 30 | 'purelib': '$base', |
| 31 | 'platlib': '$base', |
| 32 | 'scripts': '$base\\Scripts', |
| 33 | 'data' : '$base\\Data', |
| 34 | }, |
| 35 | 'mac': { |
| 36 | 'purelib': '$base:Lib', |
| 37 | 'platlib': '$base:Mac:PlugIns', |
| 38 | 'scripts': '$base:Scripts', |
| 39 | 'data' : '$base:Data', |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | |
Greg Ward | 1993f9a | 2000-02-18 00:13:53 +0000 | [diff] [blame] | 44 | class install (Command): |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 45 | |
Greg Ward | 37bc815 | 2000-01-30 18:34:15 +0000 | [diff] [blame] | 46 | description = "install everything from build directory" |
| 47 | |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 48 | user_options = [ |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 49 | # Select installation scheme and set base director(y|ies) |
| 50 | ('prefix=', None, |
| 51 | "installation prefix"), |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 52 | ('exec-prefix=', None, |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 53 | "(Unix only) prefix for platform-specific files"), |
| 54 | ('home=', None, |
| 55 | "(Unix only) home directory to install under"), |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 56 | |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 57 | # Or, just set the base director(y|ies) |
| 58 | ('install-base=', None, |
| 59 | "base installation directory (instead of --prefix or --home)"), |
| 60 | ('install-platbase=', None, |
| 61 | "base installation directory for platform-specific files " + |
| 62 | "(instead of --exec-prefix or --home)"), |
Greg Ward | 6a647bb | 2000-04-27 01:56:38 +0000 | [diff] [blame] | 63 | ('root=', None, |
| 64 | "install everything relative to this alternate root directory"), |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 65 | |
| 66 | # Or, explicitly set the installation scheme |
| 67 | ('install-purelib=', None, |
| 68 | "installation directory for pure Python module distributions"), |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame] | 69 | ('install-platlib=', None, |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 70 | "installation directory for non-pure module distributions"), |
| 71 | ('install-lib=', None, |
| 72 | "installation directory for all module distributions " + |
| 73 | "(overrides --install-purelib and --install-platlib)"), |
| 74 | |
| 75 | ('install-scripts=', None, |
| 76 | "installation directory for Python scripts"), |
| 77 | ('install-data=', None, |
| 78 | "installation directory for data files"), |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame] | 79 | |
Gregory P. Smith | 74ead8f | 2000-05-12 01:46:47 +0000 | [diff] [blame] | 80 | # For lazy debuggers who just want to test the install |
| 81 | # commands without rerunning "build" all the time |
| 82 | ('skip-build', None, |
| 83 | "skip rebuilding everything (for testing/debugging)"), |
| 84 | |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 85 | # Where to install documentation (eventually!) |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame] | 86 | #('doc-format=', None, "format of documentation to generate"), |
| 87 | #('install-man=', None, "directory for Unix man pages"), |
| 88 | #('install-html=', None, "directory for HTML documentation"), |
| 89 | #('install-info=', None, "directory for GNU info files"), |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 90 | ] |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 91 | |
Greg Ward | 9a33707 | 1999-06-08 02:04:36 +0000 | [diff] [blame] | 92 | |
Greg Ward | ee94c57 | 2000-03-29 02:15:57 +0000 | [diff] [blame] | 93 | # 'sub_commands': a list of commands this command might have to run |
| 94 | # to get its work done. Each command is represented as a tuple |
| 95 | # (func, command) where 'func' is a function to call that returns |
| 96 | # true if 'command' (the sub-command name, a string) needs to be |
| 97 | # run. If 'func' is None, assume that 'command' must always be run. |
Gregory P. Smith | b2e3bb3 | 2000-05-12 00:52:23 +0000 | [diff] [blame] | 98 | sub_commands = [(None, 'install_lib'), |
| 99 | (None, 'install_scripts'), |
| 100 | (None, 'install_data'), |
| 101 | ] |
Greg Ward | ee94c57 | 2000-03-29 02:15:57 +0000 | [diff] [blame] | 102 | |
| 103 | |
Greg Ward | e01149c | 2000-02-18 00:35:22 +0000 | [diff] [blame] | 104 | def initialize_options (self): |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 105 | |
Greg Ward | 790c110 | 2000-03-22 00:51:18 +0000 | [diff] [blame] | 106 | # High-level options: these select both an installation base |
| 107 | # and scheme. |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 108 | self.prefix = None |
| 109 | self.exec_prefix = None |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 110 | self.home = None |
| 111 | |
Greg Ward | 790c110 | 2000-03-22 00:51:18 +0000 | [diff] [blame] | 112 | # These select only the installation base; it's up to the user to |
| 113 | # specify the installation scheme (currently, that means supplying |
| 114 | # the --install-{platlib,purelib,scripts,data} options). |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 115 | self.install_base = None |
| 116 | self.install_platbase = None |
Greg Ward | 6a647bb | 2000-04-27 01:56:38 +0000 | [diff] [blame] | 117 | self.root = None |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 118 | |
Greg Ward | 790c110 | 2000-03-22 00:51:18 +0000 | [diff] [blame] | 119 | # These options are the actual installation directories; if not |
| 120 | # supplied by the user, they are filled in using the installation |
| 121 | # scheme implied by prefix/exec-prefix/home and the contents of |
| 122 | # that installation scheme. |
| 123 | self.install_purelib = None # for pure module distributions |
| 124 | self.install_platlib = None # non-pure (dists w/ extensions) |
| 125 | self.install_lib = None # set to either purelib or platlib |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 126 | self.install_scripts = None |
| 127 | self.install_data = None |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 128 | |
Greg Ward | 790c110 | 2000-03-22 00:51:18 +0000 | [diff] [blame] | 129 | # These two are for putting non-packagized distributions into their |
| 130 | # own directory and creating a .pth file if it makes sense. |
| 131 | # 'extra_path' comes from the setup file; 'install_path_file' is |
| 132 | # set only if we determine that it makes sense to install a path |
| 133 | # file. |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 134 | self.extra_path = None |
| 135 | self.install_path_file = 0 |
| 136 | |
Gregory P. Smith | 74ead8f | 2000-05-12 01:46:47 +0000 | [diff] [blame] | 137 | self.skip_build = 0 |
| 138 | |
Greg Ward | 066af10 | 2000-03-22 00:30:54 +0000 | [diff] [blame] | 139 | # These are only here as a conduit from the 'build' command to the |
| 140 | # 'install_*' commands that do the real work. ('build_base' isn't |
| 141 | # actually used anywhere, but it might be useful in future.) They |
| 142 | # are not user options, because if the user told the install |
| 143 | # command where the build directory is, that wouldn't affect the |
| 144 | # build command. |
| 145 | self.build_base = None |
| 146 | self.build_lib = None |
| 147 | |
Greg Ward | 790c110 | 2000-03-22 00:51:18 +0000 | [diff] [blame] | 148 | # Not defined yet because we don't know anything about |
| 149 | # documentation yet. |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 150 | #self.install_man = None |
| 151 | #self.install_html = None |
| 152 | #self.install_info = None |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 153 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 154 | |
Greg Ward | e01149c | 2000-02-18 00:35:22 +0000 | [diff] [blame] | 155 | def finalize_options (self): |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 156 | |
Greg Ward | 790c110 | 2000-03-22 00:51:18 +0000 | [diff] [blame] | 157 | # This method (and its pliant slaves, like 'finalize_unix()', |
| 158 | # 'finalize_other()', and 'select_scheme()') is where the default |
| 159 | # installation directories for modules, extension modules, and |
| 160 | # anything else we care to install from a Python module |
| 161 | # distribution. Thus, this code makes a pretty important policy |
| 162 | # statement about how third-party stuff is added to a Python |
| 163 | # installation! Note that the actual work of installation is done |
| 164 | # by the relatively simple 'install_*' commands; they just take |
| 165 | # their orders from the installation directory options determined |
| 166 | # here. |
Greg Ward | 9a33707 | 1999-06-08 02:04:36 +0000 | [diff] [blame] | 167 | |
Greg Ward | 790c110 | 2000-03-22 00:51:18 +0000 | [diff] [blame] | 168 | # Check for errors/inconsistencies in the options; first, stuff |
| 169 | # that's wrong on any platform. |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 170 | |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 171 | if ((self.prefix or self.exec_prefix or self.home) and |
| 172 | (self.install_base or self.install_platbase)): |
| 173 | raise DistutilsOptionError, \ |
| 174 | ("must supply either prefix/exec-prefix/home or " + |
| 175 | "install-base/install-platbase -- not both") |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame] | 176 | |
Greg Ward | 790c110 | 2000-03-22 00:51:18 +0000 | [diff] [blame] | 177 | # Next, stuff that's wrong (or dubious) only on certain platforms. |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame] | 178 | if os.name == 'posix': |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 179 | if self.home and (self.prefix or self.exec_prefix): |
Greg Ward | 865de83 | 1999-09-21 18:31:14 +0000 | [diff] [blame] | 180 | raise DistutilsOptionError, \ |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 181 | ("must supply either home or prefix/exec-prefix -- " + |
| 182 | "not both") |
Greg Ward | 865de83 | 1999-09-21 18:31:14 +0000 | [diff] [blame] | 183 | else: |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 184 | if self.exec_prefix: |
| 185 | self.warn ("exec-prefix option ignored on this platform") |
| 186 | self.exec_prefix = None |
| 187 | if self.home: |
| 188 | self.warn ("home option ignored on this platform") |
| 189 | self.home = None |
Greg Ward | 865de83 | 1999-09-21 18:31:14 +0000 | [diff] [blame] | 190 | |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 191 | # Now the interesting logic -- so interesting that we farm it out |
| 192 | # to other methods. The goal of these methods is to set the final |
| 193 | # values for the install_{lib,scripts,data,...} options, using as |
| 194 | # input a heady brew of prefix, exec_prefix, home, install_base, |
| 195 | # install_platbase, user-supplied versions of |
| 196 | # install_{purelib,platlib,lib,scripts,data,...}, and the |
| 197 | # INSTALL_SCHEME dictionary above. Phew! |
Greg Ward | 865de83 | 1999-09-21 18:31:14 +0000 | [diff] [blame] | 198 | |
Greg Ward | 6a647bb | 2000-04-27 01:56:38 +0000 | [diff] [blame] | 199 | self.dump_dirs ("pre-finalize_xxx") |
Greg Ward | ff2d9b7 | 2000-04-26 02:38:01 +0000 | [diff] [blame] | 200 | |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 201 | if os.name == 'posix': |
| 202 | self.finalize_unix () |
| 203 | else: |
| 204 | self.finalize_other () |
| 205 | |
Greg Ward | 6a647bb | 2000-04-27 01:56:38 +0000 | [diff] [blame] | 206 | self.dump_dirs ("post-finalize_xxx()") |
Greg Ward | ff2d9b7 | 2000-04-26 02:38:01 +0000 | [diff] [blame] | 207 | |
| 208 | # Expand configuration variables, tilde, etc. in self.install_base |
| 209 | # and self.install_platbase -- that way, we can use $base or |
| 210 | # $platbase in the other installation directories and not worry |
| 211 | # about needing recursive variable expansion (shudder). |
| 212 | |
| 213 | self.config_vars = {'py_version_short': sys.version[0:3], |
| 214 | 'sys_prefix': sysconfig.PREFIX, |
| 215 | 'sys_exec_prefix': sysconfig.EXEC_PREFIX, |
| 216 | } |
| 217 | self.expand_basedirs () |
| 218 | |
Greg Ward | 6a647bb | 2000-04-27 01:56:38 +0000 | [diff] [blame] | 219 | self.dump_dirs ("post-expand_basedirs()") |
Greg Ward | ff2d9b7 | 2000-04-26 02:38:01 +0000 | [diff] [blame] | 220 | |
| 221 | # Now define config vars for the base directories so we can expand |
| 222 | # everything else. |
| 223 | self.config_vars['base'] = self.install_base |
| 224 | self.config_vars['platbase'] = self.install_platbase |
| 225 | |
Greg Ward | 6a647bb | 2000-04-27 01:56:38 +0000 | [diff] [blame] | 226 | from pprint import pprint |
Greg Ward | ff2d9b7 | 2000-04-26 02:38:01 +0000 | [diff] [blame] | 227 | print "config vars:" |
| 228 | pprint (self.config_vars) |
| 229 | |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 230 | # Expand "~" and configuration variables in the installation |
| 231 | # directories. |
| 232 | self.expand_dirs () |
| 233 | |
Greg Ward | 6a647bb | 2000-04-27 01:56:38 +0000 | [diff] [blame] | 234 | self.dump_dirs ("post-expand_dirs()") |
Greg Ward | ff2d9b7 | 2000-04-26 02:38:01 +0000 | [diff] [blame] | 235 | |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 236 | # Pick the actual directory to install all modules to: either |
| 237 | # install_purelib or install_platlib, depending on whether this |
| 238 | # module distribution is pure or not. Of course, if the user |
| 239 | # already specified install_lib, use their selection. |
| 240 | if self.install_lib is None: |
| 241 | if self.distribution.ext_modules: # has extensions: non-pure |
| 242 | self.install_lib = self.install_platlib |
| 243 | else: |
| 244 | self.install_lib = self.install_purelib |
| 245 | |
| 246 | # Well, we're not actually fully completely finalized yet: we still |
| 247 | # have to deal with 'extra_path', which is the hack for allowing |
| 248 | # non-packagized module distributions (hello, Numerical Python!) to |
| 249 | # get their own directories. |
| 250 | self.handle_extra_path () |
| 251 | self.install_libbase = self.install_lib # needed for .pth file |
| 252 | self.install_lib = os.path.join (self.install_lib, self.extra_dirs) |
Greg Ward | 865de83 | 1999-09-21 18:31:14 +0000 | [diff] [blame] | 253 | |
Greg Ward | 6a647bb | 2000-04-27 01:56:38 +0000 | [diff] [blame] | 254 | # If a new root directory was supplied, make all the installation |
| 255 | # dirs relative to it. |
| 256 | if self.root is not None: |
| 257 | for name in ('lib', 'purelib', 'platlib', 'scripts', 'data'): |
| 258 | attr = "install_" + name |
| 259 | new_val = change_root (self.root, getattr (self, attr)) |
| 260 | setattr (self, attr, new_val) |
| 261 | |
| 262 | self.dump_dirs ("after prepending root") |
| 263 | |
Greg Ward | 790c110 | 2000-03-22 00:51:18 +0000 | [diff] [blame] | 264 | # Find out the build directories, ie. where to install from. |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame] | 265 | self.set_undefined_options ('build', |
| 266 | ('build_base', 'build_base'), |
Greg Ward | 066af10 | 2000-03-22 00:30:54 +0000 | [diff] [blame] | 267 | ('build_lib', 'build_lib')) |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 268 | |
| 269 | # Punt on doc directories for now -- after all, we're punting on |
| 270 | # documentation completely! |
| 271 | |
Greg Ward | e01149c | 2000-02-18 00:35:22 +0000 | [diff] [blame] | 272 | # finalize_options () |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 273 | |
| 274 | |
Greg Ward | 6a647bb | 2000-04-27 01:56:38 +0000 | [diff] [blame] | 275 | # hack for debugging output |
| 276 | def dump_dirs (self, msg): |
| 277 | from distutils.fancy_getopt import longopt_xlate |
| 278 | print msg + ":" |
| 279 | for opt in self.user_options: |
Gregory P. Smith | 74ead8f | 2000-05-12 01:46:47 +0000 | [diff] [blame] | 280 | opt_name = opt[0] |
| 281 | if opt_name[-1] == "=": |
| 282 | opt_name = opt_name[0:-1] |
| 283 | opt_name = string.translate (opt_name, longopt_xlate) |
Greg Ward | 6a647bb | 2000-04-27 01:56:38 +0000 | [diff] [blame] | 284 | val = getattr (self, opt_name) |
| 285 | print " %s: %s" % (opt_name, val) |
| 286 | |
| 287 | |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 288 | def finalize_unix (self): |
| 289 | |
| 290 | if self.install_base is not None or self.install_platbase is not None: |
| 291 | if ((self.install_lib is None and |
| 292 | self.install_purelib is None and |
| 293 | self.install_platlib is None) or |
| 294 | self.install_scripts is None or |
| 295 | self.install_data is None): |
| 296 | raise DistutilsOptionError, \ |
| 297 | "install-base or install-platbase supplied, but " + \ |
| 298 | "installation scheme is incomplete" |
| 299 | |
| 300 | return |
| 301 | |
| 302 | if self.home is not None: |
| 303 | self.install_base = self.install_platbase = self.home |
| 304 | self.select_scheme ("unix_home") |
| 305 | else: |
| 306 | if self.prefix is None: |
| 307 | if self.exec_prefix is not None: |
| 308 | raise DistutilsOptionError, \ |
| 309 | "must not supply exec-prefix without prefix" |
| 310 | |
| 311 | self.prefix = os.path.normpath (sys.prefix) |
| 312 | self.exec_prefix = os.path.normpath (sys.exec_prefix) |
| 313 | self.install_path_file = 1 |
| 314 | |
| 315 | else: |
| 316 | if self.exec_prefix is None: |
| 317 | self.exec_prefix = self.prefix |
| 318 | |
| 319 | |
| 320 | # XXX since we don't *know* that a user-supplied prefix really |
| 321 | # points to another Python installation, we can't be sure that |
| 322 | # writing a .pth file there will actually work -- so we don't |
| 323 | # try. That is, we only set 'install_path_file' if the user |
| 324 | # didn't supply prefix. There are certainly circumstances |
| 325 | # under which we *should* install a .pth file when the user |
| 326 | # supplies a prefix, namely when that prefix actually points to |
| 327 | # another Python installation. Hmmm. |
| 328 | |
| 329 | self.install_base = self.prefix |
| 330 | self.install_platbase = self.exec_prefix |
| 331 | self.select_scheme ("unix_prefix") |
| 332 | |
| 333 | # finalize_unix () |
| 334 | |
| 335 | |
| 336 | def finalize_other (self): # Windows and Mac OS for now |
| 337 | |
| 338 | if self.prefix is None: |
| 339 | self.prefix = os.path.normpath (sys.prefix) |
| 340 | self.install_path_file = 1 |
| 341 | |
| 342 | # XXX same caveat regarding 'install_path_file' as in |
| 343 | # 'finalize_unix()'. |
| 344 | |
| 345 | self.install_base = self.install_platbase = self.prefix |
| 346 | try: |
| 347 | self.select_scheme (os.name) |
| 348 | except KeyError: |
| 349 | raise DistutilsPlatformError, \ |
| 350 | "I don't know how to install stuff on '%s'" % os.name |
| 351 | |
| 352 | # finalize_other () |
| 353 | |
| 354 | |
| 355 | def select_scheme (self, name): |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 356 | # it's the caller's problem if they supply a bad name! |
| 357 | scheme = INSTALL_SCHEMES[name] |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 358 | for key in ('purelib', 'platlib', 'scripts', 'data'): |
Gregory P. Smith | 17f641c | 2000-05-12 01:54:50 +0000 | [diff] [blame] | 359 | attrname = 'install_' + key |
| 360 | if getattr(self, attrname) is None: |
| 361 | setattr(self, attrname, scheme[key]) |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 362 | |
| 363 | |
Greg Ward | ff2d9b7 | 2000-04-26 02:38:01 +0000 | [diff] [blame] | 364 | def _expand_attrs (self, attrs): |
| 365 | for attr in attrs: |
| 366 | val = getattr (self, attr) |
| 367 | if val is not None: |
| 368 | if os.name == 'posix': |
| 369 | val = os.path.expanduser (val) |
| 370 | val = subst_vars (val, self.config_vars) |
| 371 | setattr (self, attr, val) |
| 372 | |
| 373 | |
| 374 | def expand_basedirs (self): |
| 375 | self._expand_attrs (['install_base', |
Greg Ward | 6a647bb | 2000-04-27 01:56:38 +0000 | [diff] [blame] | 376 | 'install_platbase', |
| 377 | 'root']) |
Greg Ward | ff2d9b7 | 2000-04-26 02:38:01 +0000 | [diff] [blame] | 378 | |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 379 | def expand_dirs (self): |
Greg Ward | ff2d9b7 | 2000-04-26 02:38:01 +0000 | [diff] [blame] | 380 | self._expand_attrs (['install_purelib', |
| 381 | 'install_platlib', |
| 382 | 'install_lib', |
| 383 | 'install_scripts', |
| 384 | 'install_data',]) |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 385 | |
| 386 | |
| 387 | def handle_extra_path (self): |
| 388 | |
| 389 | if self.extra_path is None: |
| 390 | self.extra_path = self.distribution.extra_path |
| 391 | |
| 392 | if self.extra_path is not None: |
| 393 | if type (self.extra_path) is StringType: |
| 394 | self.extra_path = string.split (self.extra_path, ',') |
| 395 | |
| 396 | if len (self.extra_path) == 1: |
| 397 | path_file = extra_dirs = self.extra_path[0] |
| 398 | elif len (self.extra_path) == 2: |
| 399 | (path_file, extra_dirs) = self.extra_path |
| 400 | else: |
| 401 | raise DistutilsOptionError, \ |
| 402 | "'extra_path' option must be a list, tuple, or " + \ |
| 403 | "comma-separated string with 1 or 2 elements" |
| 404 | |
| 405 | # convert to local form in case Unix notation used (as it |
| 406 | # should be in setup scripts) |
| 407 | extra_dirs = native_path (extra_dirs) |
| 408 | |
| 409 | else: |
| 410 | path_file = None |
| 411 | extra_dirs = '' |
| 412 | |
| 413 | # XXX should we warn if path_file and not extra_dirs? (in which |
| 414 | # case the path file would be harmless but pointless) |
| 415 | self.path_file = path_file |
| 416 | self.extra_dirs = extra_dirs |
| 417 | |
| 418 | # handle_extra_path () |
| 419 | |
| 420 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 421 | def run (self): |
| 422 | |
Greg Ward | 9a33707 | 1999-06-08 02:04:36 +0000 | [diff] [blame] | 423 | # Obviously have to build before we can install |
Gregory P. Smith | 74ead8f | 2000-05-12 01:46:47 +0000 | [diff] [blame] | 424 | if not self.skip_build: |
| 425 | self.run_peer ('build') |
Greg Ward | 9a33707 | 1999-06-08 02:04:36 +0000 | [diff] [blame] | 426 | |
Greg Ward | ee94c57 | 2000-03-29 02:15:57 +0000 | [diff] [blame] | 427 | # Run all sub-commands: currently this just means install all |
| 428 | # Python modules using 'install_lib'. |
Greg Ward | ba38d12 | 2000-03-31 02:52:02 +0000 | [diff] [blame] | 429 | for (func, cmd_name) in self.sub_commands: |
Greg Ward | ee94c57 | 2000-03-29 02:15:57 +0000 | [diff] [blame] | 430 | if func is None or func(): |
Greg Ward | ba38d12 | 2000-03-31 02:52:02 +0000 | [diff] [blame] | 431 | self.run_peer (cmd_name) |
Greg Ward | 865de83 | 1999-09-21 18:31:14 +0000 | [diff] [blame] | 432 | |
| 433 | if self.path_file: |
| 434 | self.create_path_file () |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 435 | |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 436 | normalized_path = map (os.path.normpath, sys.path) |
| 437 | if (not (self.path_file and self.install_path_file) and |
| 438 | os.path.normpath (self.install_lib) not in normalized_path): |
| 439 | self.warn (("modules installed to '%s', which is not in " + |
| 440 | "Python's module search path (sys.path) -- " + |
| 441 | "you'll have to change the search path yourself") % |
| 442 | self.install_lib) |
| 443 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 444 | # run () |
| 445 | |
Greg Ward | 865de83 | 1999-09-21 18:31:14 +0000 | [diff] [blame] | 446 | |
Greg Ward | ee94c57 | 2000-03-29 02:15:57 +0000 | [diff] [blame] | 447 | def get_outputs (self): |
| 448 | # This command doesn't have any outputs of its own, so just |
| 449 | # get the outputs of all its sub-commands. |
| 450 | outputs = [] |
Greg Ward | ba38d12 | 2000-03-31 02:52:02 +0000 | [diff] [blame] | 451 | for (func, cmd_name) in self.sub_commands: |
Greg Ward | ee94c57 | 2000-03-29 02:15:57 +0000 | [diff] [blame] | 452 | if func is None or func(): |
Greg Ward | ba38d12 | 2000-03-31 02:52:02 +0000 | [diff] [blame] | 453 | cmd = self.find_peer (cmd_name) |
| 454 | outputs.extend (cmd.get_outputs()) |
Greg Ward | ee94c57 | 2000-03-29 02:15:57 +0000 | [diff] [blame] | 455 | |
| 456 | return outputs |
| 457 | |
| 458 | |
Greg Ward | ba38d12 | 2000-03-31 02:52:02 +0000 | [diff] [blame] | 459 | def get_inputs (self): |
| 460 | # XXX gee, this looks familiar ;-( |
| 461 | inputs = [] |
| 462 | for (func, cmd_name) in self.sub_commands: |
| 463 | if func is None or func(): |
| 464 | cmd = self.find_peer (cmd_name) |
| 465 | inputs.extend (cmd.get_inputs()) |
| 466 | |
| 467 | return inputs |
| 468 | |
| 469 | |
Greg Ward | 865de83 | 1999-09-21 18:31:14 +0000 | [diff] [blame] | 470 | def create_path_file (self): |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 471 | filename = os.path.join (self.install_libbase, |
| 472 | self.path_file + ".pth") |
| 473 | if self.install_path_file: |
| 474 | self.execute (write_file, |
| 475 | (filename, [self.extra_dirs]), |
| 476 | "creating %s" % filename) |
Greg Ward | 865de83 | 1999-09-21 18:31:14 +0000 | [diff] [blame] | 477 | else: |
Greg Ward | a233d86 | 2000-03-22 00:15:45 +0000 | [diff] [blame] | 478 | self.warn (("path file '%s' not created for alternate or custom " + |
| 479 | "installation (path files only work with standard " + |
| 480 | "installations)") % |
| 481 | filename) |
Greg Ward | 865de83 | 1999-09-21 18:31:14 +0000 | [diff] [blame] | 482 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 483 | # class Install |