blob: 7fb46a74bb9c72f08a70065f8e9d1046015069a0 [file] [log] [blame]
Greg Ward13ae1c81999-03-22 14:55:25 +00001"""distutils.command.install
2
3Implements the Distutils 'install' command."""
4
Jeremy Hyltondc8412e2002-06-04 21:20:08 +00005from distutils import log
6
Andrew M. Kuchlingd448f662002-11-19 13:12:28 +00007# This module should be kept compatible with Python 1.5.2.
8
Greg Ward3ce77fd2000-03-02 01:49:45 +00009__revision__ = "$Id$"
Greg Ward13ae1c81999-03-22 14:55:25 +000010
11import sys, os, string
Greg Ward865de831999-09-21 18:31:14 +000012from types import *
Jeremy Hyltonfcd73532002-09-11 16:31:53 +000013from distutils.core import Command
14from distutils.debug import DEBUG
Greg Ward9bd3e9b2000-09-15 01:20:10 +000015from distutils.sysconfig import get_config_vars
Andrew M. Kuchling665f2482001-08-10 18:59:59 +000016from distutils.errors import DistutilsPlatformError
Greg Wardab3a0f32000-08-05 01:31:54 +000017from distutils.file_util import write_file
18from distutils.util import convert_path, subst_vars, change_root
Greg Ward4f08e4f2000-02-26 00:49:04 +000019from distutils.errors import DistutilsOptionError
Gregory P. Smith8cb67612000-05-13 01:58:19 +000020from glob import glob
Greg Ward13ae1c81999-03-22 14:55:25 +000021
Greg Wardf17efb92001-08-23 20:53:27 +000022if sys.version < "2.2":
23 WINDOWS_SCHEME = {
24 'purelib': '$base',
25 'platlib': '$base',
26 'headers': '$base/Include/$dist_name',
27 'scripts': '$base/Scripts',
28 'data' : '$base',
29 }
30else:
31 WINDOWS_SCHEME = {
32 'purelib': '$base/Lib/site-packages',
33 'platlib': '$base/Lib/site-packages',
34 'headers': '$base/Include/$dist_name',
35 'scripts': '$base/Scripts',
36 'data' : '$base',
37 }
38
Greg Warda233d862000-03-22 00:15:45 +000039INSTALL_SCHEMES = {
40 'unix_prefix': {
41 'purelib': '$base/lib/python$py_version_short/site-packages',
42 'platlib': '$platbase/lib/python$py_version_short/site-packages',
Greg Wardc5662322000-06-17 01:34:45 +000043 'headers': '$base/include/python$py_version_short/$dist_name',
Greg Warda233d862000-03-22 00:15:45 +000044 'scripts': '$base/bin',
Greg Wardfa2f4b62000-06-24 17:22:39 +000045 'data' : '$base',
Greg Warda233d862000-03-22 00:15:45 +000046 },
47 'unix_home': {
48 'purelib': '$base/lib/python',
49 'platlib': '$base/lib/python',
Greg Wardcae5a1f2000-05-27 01:33:12 +000050 'headers': '$base/include/python/$dist_name',
Greg Warda233d862000-03-22 00:15:45 +000051 'scripts': '$base/bin',
Greg Wardfa2f4b62000-06-24 17:22:39 +000052 'data' : '$base',
Greg Warda233d862000-03-22 00:15:45 +000053 },
Greg Wardf17efb92001-08-23 20:53:27 +000054 'nt': WINDOWS_SCHEME,
Greg Warda233d862000-03-22 00:15:45 +000055 'mac': {
Greg Ward379a02f2000-09-22 01:31:08 +000056 'purelib': '$base/Lib/site-packages',
57 'platlib': '$base/Lib/site-packages',
58 'headers': '$base/Include/$dist_name',
59 'scripts': '$base/Scripts',
Greg Wardfa2f4b62000-06-24 17:22:39 +000060 'data' : '$base',
Marc-André Lemburg2544f512002-01-31 18:56:00 +000061 },
62 'os2': {
63 'purelib': '$base/Lib/site-packages',
64 'platlib': '$base/Lib/site-packages',
65 'headers': '$base/Include/$dist_name',
66 'scripts': '$base/Scripts',
67 'data' : '$base',
Greg Warda233d862000-03-22 00:15:45 +000068 }
69 }
70
Greg Ward379a02f2000-09-22 01:31:08 +000071# The keys to an installation scheme; if any new types of files are to be
72# installed, be sure to add an entry to every installation scheme above,
73# and to SCHEME_KEYS here.
74SCHEME_KEYS = ('purelib', 'platlib', 'headers', 'scripts', 'data')
75
Greg Warda233d862000-03-22 00:15:45 +000076
Greg Ward1993f9a2000-02-18 00:13:53 +000077class install (Command):
Greg Ward13ae1c81999-03-22 14:55:25 +000078
Greg Ward37bc8152000-01-30 18:34:15 +000079 description = "install everything from build directory"
80
Greg Wardbbeceea2000-02-18 00:25:39 +000081 user_options = [
Greg Warda233d862000-03-22 00:15:45 +000082 # Select installation scheme and set base director(y|ies)
83 ('prefix=', None,
84 "installation prefix"),
Greg Wardbbeceea2000-02-18 00:25:39 +000085 ('exec-prefix=', None,
Greg Warda233d862000-03-22 00:15:45 +000086 "(Unix only) prefix for platform-specific files"),
87 ('home=', None,
88 "(Unix only) home directory to install under"),
Greg Ward13ae1c81999-03-22 14:55:25 +000089
Greg Warda233d862000-03-22 00:15:45 +000090 # Or, just set the base director(y|ies)
91 ('install-base=', None,
92 "base installation directory (instead of --prefix or --home)"),
93 ('install-platbase=', None,
94 "base installation directory for platform-specific files " +
95 "(instead of --exec-prefix or --home)"),
Greg Ward6a647bb2000-04-27 01:56:38 +000096 ('root=', None,
97 "install everything relative to this alternate root directory"),
Greg Warda233d862000-03-22 00:15:45 +000098
99 # Or, explicitly set the installation scheme
100 ('install-purelib=', None,
101 "installation directory for pure Python module distributions"),
Greg Ward4f08e4f2000-02-26 00:49:04 +0000102 ('install-platlib=', None,
Greg Warda233d862000-03-22 00:15:45 +0000103 "installation directory for non-pure module distributions"),
104 ('install-lib=', None,
105 "installation directory for all module distributions " +
106 "(overrides --install-purelib and --install-platlib)"),
107
Greg Wardcae5a1f2000-05-27 01:33:12 +0000108 ('install-headers=', None,
109 "installation directory for C/C++ headers"),
Greg Warda233d862000-03-22 00:15:45 +0000110 ('install-scripts=', None,
111 "installation directory for Python scripts"),
112 ('install-data=', None,
113 "installation directory for data files"),
Greg Ward4f08e4f2000-02-26 00:49:04 +0000114
Greg Ward81610222000-10-02 02:16:04 +0000115 # Byte-compilation options -- see install_lib.py for details, as
116 # these are duplicated from there (but only install_lib does
117 # anything with them).
118 ('compile', 'c', "compile .py to .pyc [default]"),
119 ('no-compile', None, "don't compile .py files"),
120 ('optimize=', 'O',
121 "also compile with optimization: -O1 for \"python -O\", "
122 "-O2 for \"python -OO\", and -O0 to disable [default: -O0]"),
Fred Drake21d45352001-12-06 21:01:19 +0000123
Greg Ward3a0310a2000-09-13 01:02:25 +0000124 # Miscellaneous control options
125 ('force', 'f',
126 "force installation (overwrite any existing files)"),
Gregory P. Smith74ead8f2000-05-12 01:46:47 +0000127 ('skip-build', None,
128 "skip rebuilding everything (for testing/debugging)"),
Anthony Baxter05f842b2004-03-22 22:22:05 +0000129 ('skip-checkdep', None,
130 "skip checking dependencies (use at own risk)"),
Gregory P. Smith74ead8f2000-05-12 01:46:47 +0000131
Greg Wardbbeceea2000-02-18 00:25:39 +0000132 # Where to install documentation (eventually!)
Greg Ward4f08e4f2000-02-26 00:49:04 +0000133 #('doc-format=', None, "format of documentation to generate"),
134 #('install-man=', None, "directory for Unix man pages"),
135 #('install-html=', None, "directory for HTML documentation"),
136 #('install-info=', None, "directory for GNU info files"),
Greg Ward13ae1c81999-03-22 14:55:25 +0000137
Gregory P. Smith0ec8ef12000-05-13 02:16:45 +0000138 ('record=', None,
139 "filename in which to record list of installed files"),
Gregory P. Smith8cb67612000-05-13 01:58:19 +0000140 ]
Greg Ward9a337071999-06-08 02:04:36 +0000141
Andrew M. Kuchling3f1822b2002-03-21 23:46:54 +0000142 boolean_options = ['compile', 'force', 'skip-build']
Greg Warda9d37832000-10-03 03:31:52 +0000143 negative_opt = {'no-compile' : 'compile'}
Greg Ward99b032e2000-09-25 01:41:15 +0000144
Greg Wardee94c572000-03-29 02:15:57 +0000145
Greg Warde01149c2000-02-18 00:35:22 +0000146 def initialize_options (self):
Greg Ward13ae1c81999-03-22 14:55:25 +0000147
Greg Ward790c1102000-03-22 00:51:18 +0000148 # High-level options: these select both an installation base
149 # and scheme.
Greg Ward13ae1c81999-03-22 14:55:25 +0000150 self.prefix = None
151 self.exec_prefix = None
Greg Warda233d862000-03-22 00:15:45 +0000152 self.home = None
153
Greg Ward790c1102000-03-22 00:51:18 +0000154 # These select only the installation base; it's up to the user to
155 # specify the installation scheme (currently, that means supplying
156 # the --install-{platlib,purelib,scripts,data} options).
Greg Warda233d862000-03-22 00:15:45 +0000157 self.install_base = None
158 self.install_platbase = None
Greg Ward6a647bb2000-04-27 01:56:38 +0000159 self.root = None
Greg Ward13ae1c81999-03-22 14:55:25 +0000160
Greg Ward790c1102000-03-22 00:51:18 +0000161 # These options are the actual installation directories; if not
162 # supplied by the user, they are filled in using the installation
163 # scheme implied by prefix/exec-prefix/home and the contents of
164 # that installation scheme.
165 self.install_purelib = None # for pure module distributions
166 self.install_platlib = None # non-pure (dists w/ extensions)
Greg Wardcae5a1f2000-05-27 01:33:12 +0000167 self.install_headers = None # for C/C++ headers
Greg Ward790c1102000-03-22 00:51:18 +0000168 self.install_lib = None # set to either purelib or platlib
Greg Warda233d862000-03-22 00:15:45 +0000169 self.install_scripts = None
170 self.install_data = None
Greg Ward13ae1c81999-03-22 14:55:25 +0000171
Andrew M. Kuchlingb26ca9d2002-03-22 15:35:17 +0000172 self.compile = None
Greg Ward81610222000-10-02 02:16:04 +0000173 self.optimize = None
174
Greg Ward790c1102000-03-22 00:51:18 +0000175 # These two are for putting non-packagized distributions into their
176 # own directory and creating a .pth file if it makes sense.
Greg Ward379a02f2000-09-22 01:31:08 +0000177 # 'extra_path' comes from the setup file; 'install_path_file' can
178 # be turned off if it makes no sense to install a .pth file. (But
179 # better to install it uselessly than to guess wrong and not
180 # install it when it's necessary and would be used!) Currently,
181 # 'install_path_file' is always true unless some outsider meddles
182 # with it.
Greg Warda233d862000-03-22 00:15:45 +0000183 self.extra_path = None
Greg Ward379a02f2000-09-22 01:31:08 +0000184 self.install_path_file = 1
Greg Warda233d862000-03-22 00:15:45 +0000185
Greg Ward379a02f2000-09-22 01:31:08 +0000186 # 'force' forces installation, even if target files are not
187 # out-of-date. 'skip_build' skips running the "build" command,
Anthony Baxter05f842b2004-03-22 22:22:05 +0000188 # handy if you know it's not necessary. 'skip_checkdep' skips
189 # the 'checkdep' command, if you are sure you can work around the
190 # dependency failure in another way. 'warn_dir' (which is *not*
Greg Ward379a02f2000-09-22 01:31:08 +0000191 # a user option, it's just there so the bdist_* commands can turn
192 # it off) determines whether we warn about installing to a
193 # directory not in sys.path.
Greg Ward3a0310a2000-09-13 01:02:25 +0000194 self.force = 0
Gregory P. Smith74ead8f2000-05-12 01:46:47 +0000195 self.skip_build = 0
Anthony Baxter05f842b2004-03-22 22:22:05 +0000196 self.skip_checkdep = 0
Greg Ward379a02f2000-09-22 01:31:08 +0000197 self.warn_dir = 1
Gregory P. Smith74ead8f2000-05-12 01:46:47 +0000198
Greg Ward066af102000-03-22 00:30:54 +0000199 # These are only here as a conduit from the 'build' command to the
200 # 'install_*' commands that do the real work. ('build_base' isn't
201 # actually used anywhere, but it might be useful in future.) They
202 # are not user options, because if the user told the install
203 # command where the build directory is, that wouldn't affect the
204 # build command.
205 self.build_base = None
206 self.build_lib = None
207
Greg Ward790c1102000-03-22 00:51:18 +0000208 # Not defined yet because we don't know anything about
209 # documentation yet.
Greg Warda233d862000-03-22 00:15:45 +0000210 #self.install_man = None
211 #self.install_html = None
212 #self.install_info = None
Greg Ward13ae1c81999-03-22 14:55:25 +0000213
Gregory P. Smith8cb67612000-05-13 01:58:19 +0000214 self.record = None
Greg Ward13ae1c81999-03-22 14:55:25 +0000215
Greg Ward70b1fd12000-09-30 17:05:37 +0000216
217 # -- Option finalizing methods -------------------------------------
218 # (This is rather more involved than for most commands,
219 # because this is where the policy for installing third-
220 # party Python modules on various platforms given a wide
221 # array of user input is decided. Yes, it's quite complex!)
222
Greg Warde01149c2000-02-18 00:35:22 +0000223 def finalize_options (self):
Greg Ward13ae1c81999-03-22 14:55:25 +0000224
Greg Ward790c1102000-03-22 00:51:18 +0000225 # This method (and its pliant slaves, like 'finalize_unix()',
226 # 'finalize_other()', and 'select_scheme()') is where the default
227 # installation directories for modules, extension modules, and
228 # anything else we care to install from a Python module
229 # distribution. Thus, this code makes a pretty important policy
230 # statement about how third-party stuff is added to a Python
231 # installation! Note that the actual work of installation is done
232 # by the relatively simple 'install_*' commands; they just take
233 # their orders from the installation directory options determined
234 # here.
Greg Ward9a337071999-06-08 02:04:36 +0000235
Greg Ward790c1102000-03-22 00:51:18 +0000236 # Check for errors/inconsistencies in the options; first, stuff
237 # that's wrong on any platform.
Greg Ward13ae1c81999-03-22 14:55:25 +0000238
Greg Warda233d862000-03-22 00:15:45 +0000239 if ((self.prefix or self.exec_prefix or self.home) and
240 (self.install_base or self.install_platbase)):
241 raise DistutilsOptionError, \
242 ("must supply either prefix/exec-prefix/home or " +
243 "install-base/install-platbase -- not both")
Greg Ward4f08e4f2000-02-26 00:49:04 +0000244
Greg Ward790c1102000-03-22 00:51:18 +0000245 # Next, stuff that's wrong (or dubious) only on certain platforms.
Greg Ward4f08e4f2000-02-26 00:49:04 +0000246 if os.name == 'posix':
Greg Warda233d862000-03-22 00:15:45 +0000247 if self.home and (self.prefix or self.exec_prefix):
Greg Ward865de831999-09-21 18:31:14 +0000248 raise DistutilsOptionError, \
Greg Warda233d862000-03-22 00:15:45 +0000249 ("must supply either home or prefix/exec-prefix -- " +
250 "not both")
Greg Ward865de831999-09-21 18:31:14 +0000251 else:
Greg Warda233d862000-03-22 00:15:45 +0000252 if self.exec_prefix:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000253 self.warn("exec-prefix option ignored on this platform")
Greg Warda233d862000-03-22 00:15:45 +0000254 self.exec_prefix = None
255 if self.home:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000256 self.warn("home option ignored on this platform")
Greg Warda233d862000-03-22 00:15:45 +0000257 self.home = None
Greg Ward865de831999-09-21 18:31:14 +0000258
Greg Warda233d862000-03-22 00:15:45 +0000259 # Now the interesting logic -- so interesting that we farm it out
260 # to other methods. The goal of these methods is to set the final
261 # values for the install_{lib,scripts,data,...} options, using as
262 # input a heady brew of prefix, exec_prefix, home, install_base,
263 # install_platbase, user-supplied versions of
264 # install_{purelib,platlib,lib,scripts,data,...}, and the
265 # INSTALL_SCHEME dictionary above. Phew!
Greg Ward865de831999-09-21 18:31:14 +0000266
Greg Wardcb1f4c42000-09-30 18:27:54 +0000267 self.dump_dirs("pre-finalize_{unix,other}")
Greg Wardff2d9b72000-04-26 02:38:01 +0000268
Greg Warda233d862000-03-22 00:15:45 +0000269 if os.name == 'posix':
Greg Wardcb1f4c42000-09-30 18:27:54 +0000270 self.finalize_unix()
Greg Warda233d862000-03-22 00:15:45 +0000271 else:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000272 self.finalize_other()
Greg Warda233d862000-03-22 00:15:45 +0000273
Greg Wardcb1f4c42000-09-30 18:27:54 +0000274 self.dump_dirs("post-finalize_{unix,other}()")
Greg Wardff2d9b72000-04-26 02:38:01 +0000275
276 # Expand configuration variables, tilde, etc. in self.install_base
277 # and self.install_platbase -- that way, we can use $base or
278 # $platbase in the other installation directories and not worry
279 # about needing recursive variable expansion (shudder).
280
Greg Wardcae5a1f2000-05-27 01:33:12 +0000281 py_version = (string.split(sys.version))[0]
Greg Warde918b6f2000-09-16 01:59:06 +0000282 (prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix')
Greg Wardcae5a1f2000-05-27 01:33:12 +0000283 self.config_vars = {'dist_name': self.distribution.get_name(),
284 'dist_version': self.distribution.get_version(),
285 'dist_fullname': self.distribution.get_fullname(),
286 'py_version': py_version,
287 'py_version_short': py_version[0:3],
Greg Ward9bd3e9b2000-09-15 01:20:10 +0000288 'sys_prefix': prefix,
289 'prefix': prefix,
290 'sys_exec_prefix': exec_prefix,
291 'exec_prefix': exec_prefix,
Greg Wardff2d9b72000-04-26 02:38:01 +0000292 }
Greg Wardcb1f4c42000-09-30 18:27:54 +0000293 self.expand_basedirs()
Greg Wardff2d9b72000-04-26 02:38:01 +0000294
Greg Wardcb1f4c42000-09-30 18:27:54 +0000295 self.dump_dirs("post-expand_basedirs()")
Greg Wardff2d9b72000-04-26 02:38:01 +0000296
297 # Now define config vars for the base directories so we can expand
298 # everything else.
299 self.config_vars['base'] = self.install_base
300 self.config_vars['platbase'] = self.install_platbase
301
Greg Wardfbb04c42000-05-28 23:47:31 +0000302 if DEBUG:
303 from pprint import pprint
304 print "config vars:"
Greg Wardcb1f4c42000-09-30 18:27:54 +0000305 pprint(self.config_vars)
Greg Wardff2d9b72000-04-26 02:38:01 +0000306
Greg Warda233d862000-03-22 00:15:45 +0000307 # Expand "~" and configuration variables in the installation
308 # directories.
Greg Wardcb1f4c42000-09-30 18:27:54 +0000309 self.expand_dirs()
Greg Warda233d862000-03-22 00:15:45 +0000310
Greg Wardcb1f4c42000-09-30 18:27:54 +0000311 self.dump_dirs("post-expand_dirs()")
Greg Wardff2d9b72000-04-26 02:38:01 +0000312
Greg Warda233d862000-03-22 00:15:45 +0000313 # Pick the actual directory to install all modules to: either
314 # install_purelib or install_platlib, depending on whether this
315 # module distribution is pure or not. Of course, if the user
316 # already specified install_lib, use their selection.
317 if self.install_lib is None:
318 if self.distribution.ext_modules: # has extensions: non-pure
319 self.install_lib = self.install_platlib
320 else:
321 self.install_lib = self.install_purelib
Fred Drake21d45352001-12-06 21:01:19 +0000322
Greg Ward379a02f2000-09-22 01:31:08 +0000323
324 # Convert directories from Unix /-separated syntax to the local
325 # convention.
326 self.convert_paths('lib', 'purelib', 'platlib',
327 'scripts', 'data', 'headers')
328
Greg Warda233d862000-03-22 00:15:45 +0000329 # Well, we're not actually fully completely finalized yet: we still
330 # have to deal with 'extra_path', which is the hack for allowing
331 # non-packagized module distributions (hello, Numerical Python!) to
332 # get their own directories.
Greg Wardcb1f4c42000-09-30 18:27:54 +0000333 self.handle_extra_path()
Greg Warda233d862000-03-22 00:15:45 +0000334 self.install_libbase = self.install_lib # needed for .pth file
Greg Wardcb1f4c42000-09-30 18:27:54 +0000335 self.install_lib = os.path.join(self.install_lib, self.extra_dirs)
Greg Ward865de831999-09-21 18:31:14 +0000336
Greg Ward6a647bb2000-04-27 01:56:38 +0000337 # If a new root directory was supplied, make all the installation
338 # dirs relative to it.
339 if self.root is not None:
Greg Ward379a02f2000-09-22 01:31:08 +0000340 self.change_roots('libbase', 'lib', 'purelib', 'platlib',
341 'scripts', 'data', 'headers')
Greg Ward6a647bb2000-04-27 01:56:38 +0000342
Greg Wardcb1f4c42000-09-30 18:27:54 +0000343 self.dump_dirs("after prepending root")
Greg Ward6a647bb2000-04-27 01:56:38 +0000344
Greg Ward790c1102000-03-22 00:51:18 +0000345 # Find out the build directories, ie. where to install from.
Greg Wardcb1f4c42000-09-30 18:27:54 +0000346 self.set_undefined_options('build',
347 ('build_base', 'build_base'),
348 ('build_lib', 'build_lib'))
Greg Ward13ae1c81999-03-22 14:55:25 +0000349
350 # Punt on doc directories for now -- after all, we're punting on
351 # documentation completely!
352
Greg Warde01149c2000-02-18 00:35:22 +0000353 # finalize_options ()
Greg Ward13ae1c81999-03-22 14:55:25 +0000354
355
Greg Ward6a647bb2000-04-27 01:56:38 +0000356 def dump_dirs (self, msg):
Greg Wardfbb04c42000-05-28 23:47:31 +0000357 if DEBUG:
358 from distutils.fancy_getopt import longopt_xlate
359 print msg + ":"
360 for opt in self.user_options:
361 opt_name = opt[0]
362 if opt_name[-1] == "=":
363 opt_name = opt_name[0:-1]
Greg Wardcb1f4c42000-09-30 18:27:54 +0000364 opt_name = string.translate(opt_name, longopt_xlate)
365 val = getattr(self, opt_name)
Greg Wardfbb04c42000-05-28 23:47:31 +0000366 print " %s: %s" % (opt_name, val)
Greg Ward6a647bb2000-04-27 01:56:38 +0000367
368
Greg Warda233d862000-03-22 00:15:45 +0000369 def finalize_unix (self):
Fred Drake21d45352001-12-06 21:01:19 +0000370
Greg Warda233d862000-03-22 00:15:45 +0000371 if self.install_base is not None or self.install_platbase is not None:
372 if ((self.install_lib is None and
373 self.install_purelib is None and
374 self.install_platlib is None) or
Greg Wardcae5a1f2000-05-27 01:33:12 +0000375 self.install_headers is None or
Greg Warda233d862000-03-22 00:15:45 +0000376 self.install_scripts is None or
377 self.install_data is None):
378 raise DistutilsOptionError, \
Jeremy Hyltondc8412e2002-06-04 21:20:08 +0000379 ("install-base or install-platbase supplied, but "
380 "installation scheme is incomplete")
Greg Warda233d862000-03-22 00:15:45 +0000381 return
382
383 if self.home is not None:
384 self.install_base = self.install_platbase = self.home
Greg Wardcb1f4c42000-09-30 18:27:54 +0000385 self.select_scheme("unix_home")
Greg Warda233d862000-03-22 00:15:45 +0000386 else:
387 if self.prefix is None:
388 if self.exec_prefix is not None:
389 raise DistutilsOptionError, \
390 "must not supply exec-prefix without prefix"
391
Greg Wardcb1f4c42000-09-30 18:27:54 +0000392 self.prefix = os.path.normpath(sys.prefix)
393 self.exec_prefix = os.path.normpath(sys.exec_prefix)
Greg Warda233d862000-03-22 00:15:45 +0000394
395 else:
396 if self.exec_prefix is None:
397 self.exec_prefix = self.prefix
398
Greg Warda233d862000-03-22 00:15:45 +0000399 self.install_base = self.prefix
400 self.install_platbase = self.exec_prefix
Greg Wardcb1f4c42000-09-30 18:27:54 +0000401 self.select_scheme("unix_prefix")
Greg Warda233d862000-03-22 00:15:45 +0000402
403 # finalize_unix ()
404
405
406 def finalize_other (self): # Windows and Mac OS for now
407
408 if self.prefix is None:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000409 self.prefix = os.path.normpath(sys.prefix)
Greg Warda233d862000-03-22 00:15:45 +0000410
411 self.install_base = self.install_platbase = self.prefix
412 try:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000413 self.select_scheme(os.name)
Greg Warda233d862000-03-22 00:15:45 +0000414 except KeyError:
415 raise DistutilsPlatformError, \
416 "I don't know how to install stuff on '%s'" % os.name
417
418 # finalize_other ()
419
420
421 def select_scheme (self, name):
Greg Warda233d862000-03-22 00:15:45 +0000422 # it's the caller's problem if they supply a bad name!
423 scheme = INSTALL_SCHEMES[name]
Greg Ward379a02f2000-09-22 01:31:08 +0000424 for key in SCHEME_KEYS:
Gregory P. Smith17f641c2000-05-12 01:54:50 +0000425 attrname = 'install_' + key
426 if getattr(self, attrname) is None:
427 setattr(self, attrname, scheme[key])
Greg Warda233d862000-03-22 00:15:45 +0000428
429
Greg Wardff2d9b72000-04-26 02:38:01 +0000430 def _expand_attrs (self, attrs):
431 for attr in attrs:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000432 val = getattr(self, attr)
Greg Wardff2d9b72000-04-26 02:38:01 +0000433 if val is not None:
434 if os.name == 'posix':
Greg Wardcb1f4c42000-09-30 18:27:54 +0000435 val = os.path.expanduser(val)
436 val = subst_vars(val, self.config_vars)
437 setattr(self, attr, val)
Greg Wardff2d9b72000-04-26 02:38:01 +0000438
439
440 def expand_basedirs (self):
Greg Wardcb1f4c42000-09-30 18:27:54 +0000441 self._expand_attrs(['install_base',
442 'install_platbase',
Fred Drake21d45352001-12-06 21:01:19 +0000443 'root'])
Greg Wardff2d9b72000-04-26 02:38:01 +0000444
Greg Warda233d862000-03-22 00:15:45 +0000445 def expand_dirs (self):
Greg Wardcb1f4c42000-09-30 18:27:54 +0000446 self._expand_attrs(['install_purelib',
447 'install_platlib',
448 'install_lib',
449 'install_headers',
450 'install_scripts',
451 'install_data',])
Greg Warda233d862000-03-22 00:15:45 +0000452
453
Greg Ward379a02f2000-09-22 01:31:08 +0000454 def convert_paths (self, *names):
455 for name in names:
456 attr = "install_" + name
457 setattr(self, attr, convert_path(getattr(self, attr)))
458
459
Greg Warda233d862000-03-22 00:15:45 +0000460 def handle_extra_path (self):
461
462 if self.extra_path is None:
463 self.extra_path = self.distribution.extra_path
464
465 if self.extra_path is not None:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000466 if type(self.extra_path) is StringType:
467 self.extra_path = string.split(self.extra_path, ',')
Greg Warda233d862000-03-22 00:15:45 +0000468
Greg Wardcb1f4c42000-09-30 18:27:54 +0000469 if len(self.extra_path) == 1:
Greg Warda233d862000-03-22 00:15:45 +0000470 path_file = extra_dirs = self.extra_path[0]
Greg Wardcb1f4c42000-09-30 18:27:54 +0000471 elif len(self.extra_path) == 2:
Greg Warda233d862000-03-22 00:15:45 +0000472 (path_file, extra_dirs) = self.extra_path
473 else:
474 raise DistutilsOptionError, \
Jeremy Hyltondc8412e2002-06-04 21:20:08 +0000475 ("'extra_path' option must be a list, tuple, or "
476 "comma-separated string with 1 or 2 elements")
Greg Warda233d862000-03-22 00:15:45 +0000477
478 # convert to local form in case Unix notation used (as it
479 # should be in setup scripts)
Greg Wardcb1f4c42000-09-30 18:27:54 +0000480 extra_dirs = convert_path(extra_dirs)
Greg Warda233d862000-03-22 00:15:45 +0000481
482 else:
483 path_file = None
484 extra_dirs = ''
485
486 # XXX should we warn if path_file and not extra_dirs? (in which
487 # case the path file would be harmless but pointless)
488 self.path_file = path_file
489 self.extra_dirs = extra_dirs
490
491 # handle_extra_path ()
492
493
Greg Ward379a02f2000-09-22 01:31:08 +0000494 def change_roots (self, *names):
495 for name in names:
496 attr = "install_" + name
497 setattr(self, attr, change_root(self.root, getattr(self, attr)))
498
499
Greg Ward70b1fd12000-09-30 17:05:37 +0000500 # -- Command execution methods -------------------------------------
501
Greg Ward13ae1c81999-03-22 14:55:25 +0000502 def run (self):
503
Greg Ward9a337071999-06-08 02:04:36 +0000504 # Obviously have to build before we can install
Gregory P. Smith74ead8f2000-05-12 01:46:47 +0000505 if not self.skip_build:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000506 self.run_command('build')
Greg Ward9a337071999-06-08 02:04:36 +0000507
Anthony Baxter05f842b2004-03-22 22:22:05 +0000508 # We check dependencies before we install
509 # For now, this is disabled. Before 2.4 is released, this will
510 # be turned on.
511 #if not self.skip_checkdep:
512 # self.run_command('checkdep')
513
Greg Warda4adafd2000-05-20 15:17:09 +0000514 # Run all sub-commands (at least those that need to be run)
515 for cmd_name in self.get_sub_commands():
Greg Wardcb1f4c42000-09-30 18:27:54 +0000516 self.run_command(cmd_name)
Greg Ward865de831999-09-21 18:31:14 +0000517
518 if self.path_file:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000519 self.create_path_file()
Greg Ward13ae1c81999-03-22 14:55:25 +0000520
Gregory P. Smith8cb67612000-05-13 01:58:19 +0000521 # write list of installed files, if requested.
522 if self.record:
523 outputs = self.get_outputs()
Gregory P. Smith7e855ef2000-05-13 02:13:53 +0000524 if self.root: # strip any package prefix
Gregory P. Smith8cb67612000-05-13 01:58:19 +0000525 root_len = len(self.root)
Greg Wardcb1f4c42000-09-30 18:27:54 +0000526 for counter in xrange(len(outputs)):
Gregory P. Smith8cb67612000-05-13 01:58:19 +0000527 outputs[counter] = outputs[counter][root_len:]
528 self.execute(write_file,
Gregory P. Smith0ec8ef12000-05-13 02:16:45 +0000529 (self.record, outputs),
530 "writing list of installed files to '%s'" %
531 self.record)
Gregory P. Smithf9ebf982000-05-13 02:01:22 +0000532
Greg Ward0b4dafc2000-10-14 03:47:07 +0000533 sys_path = map(os.path.normpath, sys.path)
Greg Wardfa9ff762000-10-14 04:06:40 +0000534 sys_path = map(os.path.normcase, sys_path)
Greg Ward0b4dafc2000-10-14 03:47:07 +0000535 install_lib = os.path.normcase(os.path.normpath(self.install_lib))
Greg Ward379a02f2000-09-22 01:31:08 +0000536 if (self.warn_dir and
537 not (self.path_file and self.install_path_file) and
Greg Ward0b4dafc2000-10-14 03:47:07 +0000538 install_lib not in sys_path):
Jeremy Hyltondc8412e2002-06-04 21:20:08 +0000539 log.debug(("modules installed to '%s', which is not in "
540 "Python's module search path (sys.path) -- "
541 "you'll have to change the search path yourself"),
542 self.install_lib)
Gregory P. Smith8cb67612000-05-13 01:58:19 +0000543
Greg Ward13ae1c81999-03-22 14:55:25 +0000544 # run ()
545
Greg Ward70b1fd12000-09-30 17:05:37 +0000546 def create_path_file (self):
Greg Wardcb1f4c42000-09-30 18:27:54 +0000547 filename = os.path.join(self.install_libbase,
548 self.path_file + ".pth")
Greg Ward70b1fd12000-09-30 17:05:37 +0000549 if self.install_path_file:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000550 self.execute(write_file,
551 (filename, [self.extra_dirs]),
552 "creating %s" % filename)
Greg Ward70b1fd12000-09-30 17:05:37 +0000553 else:
554 self.warn("path file '%s' not created" % filename)
555
556
557 # -- Reporting methods ---------------------------------------------
558
559 def get_outputs (self):
Andrew M. Kuchlinga8ea5ba2001-09-04 20:06:43 +0000560 # Assemble the outputs of all the sub-commands.
Greg Ward70b1fd12000-09-30 17:05:37 +0000561 outputs = []
562 for cmd_name in self.get_sub_commands():
Greg Wardcb1f4c42000-09-30 18:27:54 +0000563 cmd = self.get_finalized_command(cmd_name)
Andrew M. Kuchling97102972001-01-16 16:16:03 +0000564 # Add the contents of cmd.get_outputs(), ensuring
565 # that outputs doesn't contain duplicate entries
566 for filename in cmd.get_outputs():
567 if filename not in outputs:
568 outputs.append(filename)
Greg Ward70b1fd12000-09-30 17:05:37 +0000569
Andrew M. Kuchlinga8ea5ba2001-09-04 20:06:43 +0000570 if self.path_file and self.install_path_file:
571 outputs.append(os.path.join(self.install_libbase,
572 self.path_file + ".pth"))
Fred Drake21d45352001-12-06 21:01:19 +0000573
Greg Ward70b1fd12000-09-30 17:05:37 +0000574 return outputs
575
576 def get_inputs (self):
577 # XXX gee, this looks familiar ;-(
578 inputs = []
579 for cmd_name in self.get_sub_commands():
Greg Wardcb1f4c42000-09-30 18:27:54 +0000580 cmd = self.get_finalized_command(cmd_name)
581 inputs.extend(cmd.get_inputs())
Greg Ward70b1fd12000-09-30 17:05:37 +0000582
583 return inputs
584
Greg Ward865de831999-09-21 18:31:14 +0000585
Greg Wardfadefed2000-09-16 15:06:57 +0000586 # -- Predicates for sub-command list -------------------------------
587
Greg Warda4adafd2000-05-20 15:17:09 +0000588 def has_lib (self):
589 """Return true if the current distribution has any Python
590 modules to install."""
591 return (self.distribution.has_pure_modules() or
592 self.distribution.has_ext_modules())
593
Greg Wardcae5a1f2000-05-27 01:33:12 +0000594 def has_headers (self):
595 return self.distribution.has_headers()
596
Greg Warda4adafd2000-05-20 15:17:09 +0000597 def has_scripts (self):
598 return self.distribution.has_scripts()
599
600 def has_data (self):
601 return self.distribution.has_data_files()
602
603
Greg Wardfadefed2000-09-16 15:06:57 +0000604 # 'sub_commands': a list of commands this command might have to run to
605 # get its work done. See cmd.py for more info.
606 sub_commands = [('install_lib', has_lib),
607 ('install_headers', has_headers),
608 ('install_scripts', has_scripts),
609 ('install_data', has_data),
610 ]
611
Greg Wardfcd974e2000-05-25 01:10:04 +0000612# class install