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 | |
| 7 | __rcsid__ = "$Id$" |
| 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 | 865de83 | 1999-09-21 18:31:14 +0000 | [diff] [blame] | 12 | from distutils.util import write_file |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame^] | 13 | from distutils.errors import DistutilsOptionError |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 14 | |
Greg Ward | 1993f9a | 2000-02-18 00:13:53 +0000 | [diff] [blame] | 15 | class install (Command): |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 16 | |
Greg Ward | 37bc815 | 2000-01-30 18:34:15 +0000 | [diff] [blame] | 17 | description = "install everything from build directory" |
| 18 | |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 19 | user_options = [ |
| 20 | ('prefix=', None, "installation prefix"), |
| 21 | ('exec-prefix=', None, |
| 22 | "prefix for platform-specific files"), |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 23 | |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame^] | 24 | # Installation directories: where to put modules and packages |
| 25 | ('install-lib=', None, |
| 26 | "base Python library directory"), |
| 27 | ('install-platlib=', None, |
| 28 | "platform-specific Python library directory"), |
| 29 | ('install-path=', None, |
| 30 | "extra intervening directories to put below install-lib"), |
| 31 | |
| 32 | # Build directories: where to find the files to install |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 33 | ('build-base=', None, |
| 34 | "base build directory"), |
| 35 | ('build-lib=', None, |
| 36 | "build directory for pure Python modules"), |
| 37 | ('build-platlib=', None, |
| 38 | "build directory for extension modules"), |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 39 | |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 40 | # Where to install documentation (eventually!) |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame^] | 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"), |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 45 | |
| 46 | # Flags for 'build_py' |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame^] | 47 | #('compile-py', None, "compile .py to .pyc"), |
| 48 | #('optimize-py', None, "compile .py to .pyo (optimized)"), |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 49 | ] |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 50 | |
Greg Ward | 9a33707 | 1999-06-08 02:04:36 +0000 | [diff] [blame] | 51 | |
Greg Ward | e01149c | 2000-02-18 00:35:22 +0000 | [diff] [blame] | 52 | def initialize_options (self): |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 53 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 54 | # Don't define 'prefix' or 'exec_prefix' so we can know when the |
| 55 | # command is run whether the user supplied values |
| 56 | self.prefix = None |
| 57 | self.exec_prefix = None |
| 58 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 59 | # The actual installation directories are determined only at |
| 60 | # run-time, so the user can supply just prefix (and exec_prefix?) |
| 61 | # as a base for everything else |
| 62 | self.install_lib = None |
| 63 | self.install_platlib = None |
Greg Ward | 865de83 | 1999-09-21 18:31:14 +0000 | [diff] [blame] | 64 | self.install_path = None |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 65 | |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame^] | 66 | self.build_base = None |
| 67 | self.build_lib = None |
| 68 | self.build_platlib = None |
| 69 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 70 | self.install_man = None |
| 71 | self.install_html = None |
| 72 | self.install_info = None |
| 73 | |
Greg Ward | 0f72695 | 1999-05-02 21:39:13 +0000 | [diff] [blame] | 74 | self.compile_py = 1 |
| 75 | self.optimize_py = 1 |
| 76 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 77 | |
Greg Ward | e01149c | 2000-02-18 00:35:22 +0000 | [diff] [blame] | 78 | def finalize_options (self): |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 79 | |
Greg Ward | 9a33707 | 1999-06-08 02:04:36 +0000 | [diff] [blame] | 80 | # XXX this method is where the default installation directories |
| 81 | # for modules and extension modules are determined. (Someday, |
| 82 | # the default installation directories for scripts, |
| 83 | # documentation, and whatever else the Distutils can build and |
| 84 | # install will also be determined here.) Thus, this is a pretty |
| 85 | # important place to fiddle with for anyone interested in |
| 86 | # installation schemes for the Python library. Issues that |
| 87 | # are not yet resolved to my satisfaction: |
| 88 | # * how much platform dependence should be here, and |
| 89 | # how much can be pushed off to sysconfig (or, better, the |
| 90 | # Makefiles parsed by sysconfig)? |
| 91 | # * how independent of Python version should this be -- ie. |
| 92 | # should we have special cases to handle Python 1.5 and |
| 93 | # older, and then do it "the right way" for 1.6? Or should |
| 94 | # we install a site.py along with Distutils under pre-1.6 |
| 95 | # Python to take care of the current deficiencies in |
| 96 | # Python's library installation scheme? |
| 97 | # |
| 98 | # Currently, this method has hacks to distinguish POSIX from |
| 99 | # non-POSIX systems (for installation of site-local modules), |
| 100 | # and assumes the Python 1.5 installation tree with no site.py |
| 101 | # to fix things. |
| 102 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 103 | # Figure out actual installation directories; the basic principle |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame^] | 104 | # is: ... |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 105 | |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame^] | 106 | sys_prefix = os.path.normpath (sys.prefix) |
| 107 | sys_exec_prefix = os.path.normpath (sys.exec_prefix) |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 108 | |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame^] | 109 | if self.prefix is None: |
| 110 | if self.exec_prefix is not None: |
| 111 | raise DistutilsOptionError, \ |
| 112 | "you may not supply exec_prefix without prefix" |
| 113 | self.prefix = sys_prefix |
Greg Ward | 865de83 | 1999-09-21 18:31:14 +0000 | [diff] [blame] | 114 | else: |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame^] | 115 | # This is handy to guarantee that self.prefix is normalized -- |
| 116 | # but it could be construed as rude to go normalizing a |
| 117 | # user-supplied path (they might like to see their "../" or |
| 118 | # symlinks in the installation feedback). |
| 119 | self.prefix = os.path.normpath (self.prefix) |
| 120 | |
| 121 | if self.exec_prefix is None: |
| 122 | if self.prefix == sys_prefix: |
| 123 | self.exec_prefix = sys_exec_prefix |
| 124 | else: |
| 125 | self.exec_prefix = self.prefix |
| 126 | else: |
| 127 | # Same as above about handy versus rude to normalize user's |
| 128 | # exec_prefix. |
| 129 | self.exec_prefix = os.path.normpath (self.exec_prefix) |
| 130 | |
| 131 | if self.distribution.ext_modules: # any extensions to install? |
| 132 | effective_prefix = self.exec_prefix |
| 133 | else: |
| 134 | effective_prefix = self.prefix |
| 135 | |
| 136 | if os.name == 'posix': |
| 137 | if self.install_lib is None: |
| 138 | if self.prefix == sys_prefix: |
| 139 | self.install_lib = \ |
| 140 | os.path.join (effective_prefix, |
| 141 | "lib", |
| 142 | "python" + sys.version[:3], |
| 143 | "site-packages") |
| 144 | else: |
| 145 | self.install_lib = \ |
| 146 | os.path.join (effective_prefix, |
| 147 | "lib", |
| 148 | "python") # + sys.version[:3] ??? |
| 149 | # end if self.install_lib ... |
| 150 | |
| 151 | if self.install_platlib is None: |
| 152 | if self.exec_prefix == sys_exec_prefix: |
| 153 | self.install_platlib = \ |
| 154 | os.path.join (effective_prefix, |
| 155 | "lib", |
| 156 | "python" + sys.version[:3], |
| 157 | "site-packages") |
| 158 | else: |
| 159 | self.install_platlib = \ |
| 160 | os.path.join (effective_prefix, |
| 161 | "lib", |
| 162 | "python") # + sys.version[:3] ??? |
| 163 | # end if self.install_platlib ... |
| 164 | |
| 165 | else: |
| 166 | raise DistutilsPlatformError, \ |
| 167 | "duh, I'm clueless (for now) about installing on %s" % os.name |
| 168 | |
| 169 | # end if/else on os.name |
| 170 | |
| 171 | |
| 172 | # 'path_file' and 'extra_dirs' are how we handle distributions that |
| 173 | # want to be installed to their own directory, but aren't |
Greg Ward | 865de83 | 1999-09-21 18:31:14 +0000 | [diff] [blame] | 174 | # package-ized yet. 'extra_dirs' is just a directory under |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame^] | 175 | # 'install_lib' or 'install_platlib' where top-level modules will |
| 176 | # actually be installed; 'path_file' is the basename of a .pth file |
| 177 | # to drop in 'install_lib' or 'install_platlib' (depending on the |
| 178 | # distribution). Very often they will be the same, which is why we |
| 179 | # allow them to be supplied as a string or 1-tuple as well as a |
| 180 | # 2-element comma-separated string or a 2-tuple. |
| 181 | |
| 182 | # XXX this will drop a .pth file in install_{lib,platlib} even if |
| 183 | # they're not one of the site-packages directories: this is wrong! |
| 184 | # we need to suppress path_file in those cases, and warn if |
| 185 | # "install_lib/extra_dirs" is not in sys.path. |
| 186 | |
Greg Ward | 865de83 | 1999-09-21 18:31:14 +0000 | [diff] [blame] | 187 | if self.install_path is None: |
| 188 | self.install_path = self.distribution.install_path |
| 189 | |
| 190 | if self.install_path is not None: |
| 191 | if type (self.install_path) is StringType: |
| 192 | self.install_path = string.split (self.install_path, ',') |
| 193 | |
| 194 | if len (self.install_path) == 1: |
| 195 | path_file = extra_dirs = self.install_path[0] |
| 196 | elif len (self.install_path) == 2: |
| 197 | (path_file, extra_dirs) = self.install_path |
Greg Ward | 9a33707 | 1999-06-08 02:04:36 +0000 | [diff] [blame] | 198 | else: |
Greg Ward | 865de83 | 1999-09-21 18:31:14 +0000 | [diff] [blame] | 199 | raise DistutilsOptionError, \ |
| 200 | "'install_path' option must be a list, tuple, or " + \ |
| 201 | "comma-separated string with 1 or 2 elements" |
| 202 | |
| 203 | # install path has slashes in it -- might need to convert to |
| 204 | # local form |
| 205 | if string.find (extra_dirs, '/') and os.name != "posix": |
| 206 | extra_dirs = string.split (extra_dirs, '/') |
| 207 | extra_dirs = apply (os.path.join, extra_dirs) |
| 208 | else: |
| 209 | path_file = None |
| 210 | extra_dirs = '' |
| 211 | |
| 212 | # XXX should we warn if path_file and not extra_dirs (in which case |
| 213 | # the path file would be harmless but pointless) |
| 214 | self.path_file = path_file |
| 215 | self.extra_dirs = extra_dirs |
| 216 | |
| 217 | |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame^] | 218 | # Figure out the build directories, ie. where to install from |
| 219 | self.set_peer_option ('build', 'build_base', self.build_base) |
| 220 | self.set_undefined_options ('build', |
| 221 | ('build_base', 'build_base'), |
| 222 | ('build_lib', 'build_lib'), |
| 223 | ('build_platlib', 'build_platlib')) |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 224 | |
| 225 | # Punt on doc directories for now -- after all, we're punting on |
| 226 | # documentation completely! |
| 227 | |
Greg Ward | e01149c | 2000-02-18 00:35:22 +0000 | [diff] [blame] | 228 | # finalize_options () |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 229 | |
| 230 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 231 | def run (self): |
| 232 | |
Greg Ward | 9a33707 | 1999-06-08 02:04:36 +0000 | [diff] [blame] | 233 | # Obviously have to build before we can install |
| 234 | self.run_peer ('build') |
| 235 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 236 | # Install modules in two steps: "platform-shared" files (ie. pure |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame^] | 237 | # Python modules) and platform-specific files (compiled C |
Greg Ward | c9c011c | 1999-09-13 13:57:26 +0000 | [diff] [blame] | 238 | # extensions). Note that 'install_py' is smart enough to install |
| 239 | # pure Python modules in the "platlib" directory if we built any |
| 240 | # extensions. |
Greg Ward | 865de83 | 1999-09-21 18:31:14 +0000 | [diff] [blame] | 241 | if self.distribution.packages or self.distribution.py_modules: |
| 242 | self.run_peer ('install_py') |
| 243 | if self.distribution.ext_modules: |
| 244 | self.run_peer ('install_ext') |
| 245 | |
| 246 | if self.path_file: |
| 247 | self.create_path_file () |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 248 | |
| 249 | # run () |
| 250 | |
Greg Ward | 865de83 | 1999-09-21 18:31:14 +0000 | [diff] [blame] | 251 | |
| 252 | def create_path_file (self): |
| 253 | |
| 254 | if self.distribution.ext_modules: |
| 255 | base = self.platbase |
| 256 | else: |
| 257 | base = self.base |
| 258 | |
| 259 | filename = os.path.join (base, self.path_file + ".pth") |
| 260 | self.execute (write_file, |
| 261 | (filename, [self.extra_dirs]), |
| 262 | "creating %s" % filename) |
| 263 | |
| 264 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 265 | # class Install |