blob: cf45004f0758f355238365be944edddda1af1e23 [file] [log] [blame]
Greg Ward13ae1c81999-03-22 14:55:25 +00001"""distutils.command.install
2
3Implements the Distutils 'install' command."""
4
5# created 1999/03/13, Greg Ward
6
7__rcsid__ = "$Id$"
8
9import sys, os, string
10from distutils import sysconfig
11from distutils.core import Command
12
13
14class Install (Command):
15
16 options = [('prefix=', None, "installation prefix"),
17 ('execprefix=', None,
18 "prefix for platform-specific files"),
19
20 # Build directories: where to install from
21 ('build-base=', None,
22 "base build directory"),
23 ('build-lib=', None,
24 "build directory for non-platform-specific library files"),
25 ('build-platlib=', None,
26 "build directory for platform-specific library files"),
27
28 # Installation directories: where to put modules and packages
29 ('install-lib=', None,
30 "base Python library directory"),
31 ('install-platlib=', None,
32 "platform-specific Python library directory"),
33 ('install-site-lib=', None,
34 "directory for site-specific packages and modules"),
35 ('install-site-platlib=', None,
36 "platform-specific site directory"),
37 ('install-scheme=', None,
38 "install to 'system' or 'site' library directory?"),
39
40 # Where to install documentation (eventually!)
41 ('doc-format=', None, "format of documentation to generate"),
42 ('install-man=', None, "directory for Unix man pages"),
43 ('install-html=', None, "directory for HTML documentation"),
44 ('install-info=', None, "directory for GNU info files"),
45
Greg Ward0f726951999-05-02 21:39:13 +000046 # Flags for 'build_py'
47 ('compile-py', None, "compile .py to .pyc"),
48 ('optimize-py', None, "compile .py to .pyo (optimized)"),
Greg Ward13ae1c81999-03-22 14:55:25 +000049 ]
50
Greg Ward9a337071999-06-08 02:04:36 +000051
Greg Ward13ae1c81999-03-22 14:55:25 +000052 def set_default_options (self):
53
54 self.build_base = None
55 self.build_lib = None
56 self.build_platlib = None
57
58 # Don't define 'prefix' or 'exec_prefix' so we can know when the
59 # command is run whether the user supplied values
60 self.prefix = None
61 self.exec_prefix = None
62
63 # These two, we can supply real values for! (because they're
64 # not directories, and don't have a confusing multitude of
65 # possible derivations)
66 #self.install_scheme = 'site'
67 self.doc_format = None
68
69 # The actual installation directories are determined only at
70 # run-time, so the user can supply just prefix (and exec_prefix?)
71 # as a base for everything else
72 self.install_lib = None
73 self.install_platlib = None
74 self.install_site_lib = None
75 self.install_site_platlib = None
76
77 self.install_man = None
78 self.install_html = None
79 self.install_info = None
80
Greg Ward0f726951999-05-02 21:39:13 +000081 self.compile_py = 1
82 self.optimize_py = 1
83
Greg Ward13ae1c81999-03-22 14:55:25 +000084
85 def set_final_options (self):
86
Greg Ward9a337071999-06-08 02:04:36 +000087 # XXX this method is where the default installation directories
88 # for modules and extension modules are determined. (Someday,
89 # the default installation directories for scripts,
90 # documentation, and whatever else the Distutils can build and
91 # install will also be determined here.) Thus, this is a pretty
92 # important place to fiddle with for anyone interested in
93 # installation schemes for the Python library. Issues that
94 # are not yet resolved to my satisfaction:
95 # * how much platform dependence should be here, and
96 # how much can be pushed off to sysconfig (or, better, the
97 # Makefiles parsed by sysconfig)?
98 # * how independent of Python version should this be -- ie.
99 # should we have special cases to handle Python 1.5 and
100 # older, and then do it "the right way" for 1.6? Or should
101 # we install a site.py along with Distutils under pre-1.6
102 # Python to take care of the current deficiencies in
103 # Python's library installation scheme?
104 #
105 # Currently, this method has hacks to distinguish POSIX from
106 # non-POSIX systems (for installation of site-local modules),
107 # and assumes the Python 1.5 installation tree with no site.py
108 # to fix things.
109
Greg Ward13ae1c81999-03-22 14:55:25 +0000110 # Figure out the build directories, ie. where to install from
111 self.set_peer_option ('build', 'basedir', self.build_base)
112 self.set_undefined_options ('build',
113 ('basedir', 'build_base'),
114 ('libdir', 'build_lib'),
115 ('platdir', 'build_platlib'))
116
117 # Figure out actual installation directories; the basic principle
118 # is: if the user supplied nothing, then use the directories that
119 # Python was built and installed with (ie. the compiled-in prefix
120 # and exec_prefix, and the actual installation directories gleaned
121 # by sysconfig). If the user supplied a prefix (and possibly
122 # exec_prefix), then we generate our own installation directories,
123 # following any pattern gleaned from sysconfig's findings. If no
124 # such pattern can be gleaned, then we'll just make do and try to
125 # ape the behaviour of Python's configure script.
126
127 if self.prefix is None: # user didn't override
128 self.prefix = sys.prefix
129 if self.exec_prefix is None:
130 self.exec_prefix = sys.exec_prefix
131
132 if self.install_lib is None:
133 self.install_lib = \
134 self.replace_sys_prefix ('LIBDEST', ('lib','python1.5'))
135 if self.install_platlib is None:
136 # XXX this should probably be DESTSHARED -- but why is there no
137 # equivalent to DESTSHARED for the "site-packages" dir"?
138 self.install_platlib = \
139 self.replace_sys_prefix ('BINLIBDEST', ('lib','python1.5'), 1)
140
Greg Ward9a337071999-06-08 02:04:36 +0000141
142 # Here is where we decide where to install most library files:
143 # on POSIX systems, they go to 'site-packages' under the
144 # install_lib (determined above -- typically
145 # /usr/local/lib/python1.x). Unfortunately, both
146 # platform-independent (.py*) and platform-specific (.so) files
147 # go to this directory, since there is no site-packages under
148 # $exec_prefix in the usual way that Python builds sys.path. On
149 # non-POSIX systems, the situation is even worse: everything
150 # gets dumped right into $exec_prefix, not even a lib
151 # subdirectory! But apparently that's what needs to be done to
152 # make it work under Python 1.5 -- hope we can get this fixed
153 # for 1.6!
154
Greg Ward13ae1c81999-03-22 14:55:25 +0000155 if self.install_site_lib is None:
Greg Ward9a337071999-06-08 02:04:36 +0000156 if os.name == 'posix':
157 self.install_site_lib = \
158 os.path.join (self.install_lib, 'site-packages')
159 else:
160 self.install_site_lib = self.exec_prefix
161
Greg Ward13ae1c81999-03-22 14:55:25 +0000162 if self.install_site_platlib is None:
Greg Ward9a337071999-06-08 02:04:36 +0000163 if os.name == 'posix':
164 # XXX ugh! this puts platform-specific files in with
165 # shared files, with no nice way to override it! (this
166 # might be a Python problem, though, not a Distutils
167 # problem...)
Greg Wardba3f1081999-07-10 02:02:31 +0000168
169 # NO: the way to fix this is
170 # * any platform-dependent files in distribution?
171 # yes: install under exec-prefix
172 # no: install under prefix
173 # ...which will require a pretty major rethink of all
174 # this. Damn.
175
Greg Ward9a337071999-06-08 02:04:36 +0000176 self.install_site_platlib = \
177 os.path.join (self.install_lib, 'site-packages')
178 else:
179 self.install_site_platlib = self.exec_prefix
Greg Ward13ae1c81999-03-22 14:55:25 +0000180
181 #if self.install_scheme == 'site':
182 # install_lib = self.install_site_lib
183 # install_platlib = self.install_site_platlib
184 #elif self.install_scheme == 'system':
185 # install_lib = self.install_lib
186 # install_platlib = self.install_platlib
187 #else:
188 # # XXX new exception for this kind of misbehaviour?
189 # raise DistutilsArgError, \
190 # "invalid install scheme '%s'" % self.install_scheme
191
192
193 # Punt on doc directories for now -- after all, we're punting on
194 # documentation completely!
195
196 # set_final_options ()
197
198
199 def replace_sys_prefix (self, config_attr, fallback_postfix, use_exec=0):
200 """Attempts to glean a simple pattern from an installation
201 directory available as a 'sysconfig' attribute: if the
202 directory name starts with the "system prefix" (the one
203 hard-coded in the Makefile and compiled into Python),
204 then replace it with the current installation prefix and
205 return the "relocated" installation directory."""
206
207 if use_exec:
208 sys_prefix = sys.exec_prefix
209 my_prefix = self.exec_prefix
210 else:
211 sys_prefix = sys.prefix
212 my_prefix = self.prefix
213
214 val = getattr (sysconfig, config_attr)
215 if string.find (val, sys_prefix) == 0:
216 # If the sysconfig directory starts with the system prefix,
217 # then we can "relocate" it to the user-supplied prefix --
218 # assuming, of course, it is different from the system prefix.
219
220 if sys_prefix == my_prefix:
221 return val
222 else:
223 return my_prefix + val[len(sys_prefix):]
224
225 else:
226 # Otherwise, just tack the "fallback postfix" onto the
227 # user-specified prefix.
228
Greg Ward1016af91999-08-19 20:02:10 +0000229 return apply (os.path.join, (my_prefix,) + fallback_postfix)
Greg Ward13ae1c81999-03-22 14:55:25 +0000230
231 # replace_sys_prefix ()
232
233
234 def run (self):
235
236 self.set_final_options ()
237
Greg Ward9a337071999-06-08 02:04:36 +0000238 # Obviously have to build before we can install
239 self.run_peer ('build')
240
Greg Ward13ae1c81999-03-22 14:55:25 +0000241 # Install modules in two steps: "platform-shared" files (ie. pure
242 # python modules) and platform-specific files (compiled C
243 # extensions).
244
245 self.run_peer ('install_py')
246
247 # don't have an 'install_ext' command just yet!
248 #self.run_peer ('install_ext'))
249
250 # run ()
251
252# class Install