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 |
| 10 | from distutils import sysconfig |
| 11 | from distutils.core import Command |
| 12 | |
| 13 | |
| 14 | class 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 Ward | 0f72695 | 1999-05-02 21:39:13 +0000 | [diff] [blame^] | 46 | # Flags for 'build_py' |
| 47 | ('compile-py', None, "compile .py to .pyc"), |
| 48 | ('optimize-py', None, "compile .py to .pyo (optimized)"), |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 49 | ] |
| 50 | |
| 51 | def set_default_options (self): |
| 52 | |
| 53 | self.build_base = None |
| 54 | self.build_lib = None |
| 55 | self.build_platlib = None |
| 56 | |
| 57 | # Don't define 'prefix' or 'exec_prefix' so we can know when the |
| 58 | # command is run whether the user supplied values |
| 59 | self.prefix = None |
| 60 | self.exec_prefix = None |
| 61 | |
| 62 | # These two, we can supply real values for! (because they're |
| 63 | # not directories, and don't have a confusing multitude of |
| 64 | # possible derivations) |
| 65 | #self.install_scheme = 'site' |
| 66 | self.doc_format = None |
| 67 | |
| 68 | # The actual installation directories are determined only at |
| 69 | # run-time, so the user can supply just prefix (and exec_prefix?) |
| 70 | # as a base for everything else |
| 71 | self.install_lib = None |
| 72 | self.install_platlib = None |
| 73 | self.install_site_lib = None |
| 74 | self.install_site_platlib = None |
| 75 | |
| 76 | self.install_man = None |
| 77 | self.install_html = None |
| 78 | self.install_info = None |
| 79 | |
Greg Ward | 0f72695 | 1999-05-02 21:39:13 +0000 | [diff] [blame^] | 80 | self.compile_py = 1 |
| 81 | self.optimize_py = 1 |
| 82 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 83 | |
| 84 | def set_final_options (self): |
| 85 | |
| 86 | # Figure out the build directories, ie. where to install from |
| 87 | self.set_peer_option ('build', 'basedir', self.build_base) |
| 88 | self.set_undefined_options ('build', |
| 89 | ('basedir', 'build_base'), |
| 90 | ('libdir', 'build_lib'), |
| 91 | ('platdir', 'build_platlib')) |
| 92 | |
| 93 | # Figure out actual installation directories; the basic principle |
| 94 | # is: if the user supplied nothing, then use the directories that |
| 95 | # Python was built and installed with (ie. the compiled-in prefix |
| 96 | # and exec_prefix, and the actual installation directories gleaned |
| 97 | # by sysconfig). If the user supplied a prefix (and possibly |
| 98 | # exec_prefix), then we generate our own installation directories, |
| 99 | # following any pattern gleaned from sysconfig's findings. If no |
| 100 | # such pattern can be gleaned, then we'll just make do and try to |
| 101 | # ape the behaviour of Python's configure script. |
| 102 | |
| 103 | if self.prefix is None: # user didn't override |
| 104 | self.prefix = sys.prefix |
| 105 | if self.exec_prefix is None: |
| 106 | self.exec_prefix = sys.exec_prefix |
| 107 | |
| 108 | if self.install_lib is None: |
| 109 | self.install_lib = \ |
| 110 | self.replace_sys_prefix ('LIBDEST', ('lib','python1.5')) |
| 111 | if self.install_platlib is None: |
| 112 | # XXX this should probably be DESTSHARED -- but why is there no |
| 113 | # equivalent to DESTSHARED for the "site-packages" dir"? |
| 114 | self.install_platlib = \ |
| 115 | self.replace_sys_prefix ('BINLIBDEST', ('lib','python1.5'), 1) |
| 116 | |
| 117 | if self.install_site_lib is None: |
| 118 | self.install_site_lib = \ |
| 119 | os.path.join (self.install_lib, 'site-packages') |
| 120 | if self.install_site_platlib is None: |
| 121 | # XXX ugh! this puts platform-specific files in with shared files, |
| 122 | # with no nice way to override it! (this might be a Python |
| 123 | # problem, though, not a Distutils problem...) |
| 124 | self.install_site_platlib = \ |
| 125 | os.path.join (self.install_lib, 'site-packages') |
| 126 | |
| 127 | #if self.install_scheme == 'site': |
| 128 | # install_lib = self.install_site_lib |
| 129 | # install_platlib = self.install_site_platlib |
| 130 | #elif self.install_scheme == 'system': |
| 131 | # install_lib = self.install_lib |
| 132 | # install_platlib = self.install_platlib |
| 133 | #else: |
| 134 | # # XXX new exception for this kind of misbehaviour? |
| 135 | # raise DistutilsArgError, \ |
| 136 | # "invalid install scheme '%s'" % self.install_scheme |
| 137 | |
| 138 | |
| 139 | # Punt on doc directories for now -- after all, we're punting on |
| 140 | # documentation completely! |
| 141 | |
| 142 | # set_final_options () |
| 143 | |
| 144 | |
| 145 | def replace_sys_prefix (self, config_attr, fallback_postfix, use_exec=0): |
| 146 | """Attempts to glean a simple pattern from an installation |
| 147 | directory available as a 'sysconfig' attribute: if the |
| 148 | directory name starts with the "system prefix" (the one |
| 149 | hard-coded in the Makefile and compiled into Python), |
| 150 | then replace it with the current installation prefix and |
| 151 | return the "relocated" installation directory.""" |
| 152 | |
| 153 | if use_exec: |
| 154 | sys_prefix = sys.exec_prefix |
| 155 | my_prefix = self.exec_prefix |
| 156 | else: |
| 157 | sys_prefix = sys.prefix |
| 158 | my_prefix = self.prefix |
| 159 | |
| 160 | val = getattr (sysconfig, config_attr) |
| 161 | if string.find (val, sys_prefix) == 0: |
| 162 | # If the sysconfig directory starts with the system prefix, |
| 163 | # then we can "relocate" it to the user-supplied prefix -- |
| 164 | # assuming, of course, it is different from the system prefix. |
| 165 | |
| 166 | if sys_prefix == my_prefix: |
| 167 | return val |
| 168 | else: |
| 169 | return my_prefix + val[len(sys_prefix):] |
| 170 | |
| 171 | else: |
| 172 | # Otherwise, just tack the "fallback postfix" onto the |
| 173 | # user-specified prefix. |
| 174 | |
| 175 | return apply (os.join, (my_prefix,) + fallback_postfix) |
| 176 | |
| 177 | # replace_sys_prefix () |
| 178 | |
| 179 | |
| 180 | def run (self): |
| 181 | |
| 182 | self.set_final_options () |
| 183 | |
| 184 | # Install modules in two steps: "platform-shared" files (ie. pure |
| 185 | # python modules) and platform-specific files (compiled C |
| 186 | # extensions). |
| 187 | |
| 188 | self.run_peer ('install_py') |
| 189 | |
| 190 | # don't have an 'install_ext' command just yet! |
| 191 | #self.run_peer ('install_ext')) |
| 192 | |
| 193 | # run () |
| 194 | |
| 195 | # class Install |