blob: 54b81879a566e3a91c51d0919b697de4144eb9cd [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...)
168 self.install_site_platlib = \
169 os.path.join (self.install_lib, 'site-packages')
170 else:
171 self.install_site_platlib = self.exec_prefix
Greg Ward13ae1c81999-03-22 14:55:25 +0000172
173 #if self.install_scheme == 'site':
174 # install_lib = self.install_site_lib
175 # install_platlib = self.install_site_platlib
176 #elif self.install_scheme == 'system':
177 # install_lib = self.install_lib
178 # install_platlib = self.install_platlib
179 #else:
180 # # XXX new exception for this kind of misbehaviour?
181 # raise DistutilsArgError, \
182 # "invalid install scheme '%s'" % self.install_scheme
183
184
185 # Punt on doc directories for now -- after all, we're punting on
186 # documentation completely!
187
188 # set_final_options ()
189
190
191 def replace_sys_prefix (self, config_attr, fallback_postfix, use_exec=0):
192 """Attempts to glean a simple pattern from an installation
193 directory available as a 'sysconfig' attribute: if the
194 directory name starts with the "system prefix" (the one
195 hard-coded in the Makefile and compiled into Python),
196 then replace it with the current installation prefix and
197 return the "relocated" installation directory."""
198
199 if use_exec:
200 sys_prefix = sys.exec_prefix
201 my_prefix = self.exec_prefix
202 else:
203 sys_prefix = sys.prefix
204 my_prefix = self.prefix
205
206 val = getattr (sysconfig, config_attr)
207 if string.find (val, sys_prefix) == 0:
208 # If the sysconfig directory starts with the system prefix,
209 # then we can "relocate" it to the user-supplied prefix --
210 # assuming, of course, it is different from the system prefix.
211
212 if sys_prefix == my_prefix:
213 return val
214 else:
215 return my_prefix + val[len(sys_prefix):]
216
217 else:
218 # Otherwise, just tack the "fallback postfix" onto the
219 # user-specified prefix.
220
221 return apply (os.join, (my_prefix,) + fallback_postfix)
222
223 # replace_sys_prefix ()
224
225
226 def run (self):
227
228 self.set_final_options ()
229
Greg Ward9a337071999-06-08 02:04:36 +0000230 # Obviously have to build before we can install
231 self.run_peer ('build')
232
Greg Ward13ae1c81999-03-22 14:55:25 +0000233 # Install modules in two steps: "platform-shared" files (ie. pure
234 # python modules) and platform-specific files (compiled C
235 # extensions).
236
237 self.run_peer ('install_py')
238
239 # don't have an 'install_ext' command just yet!
240 #self.run_peer ('install_ext'))
241
242 # run ()
243
244# class Install