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