You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

680 lines
27 KiB

Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r62194 | jeffrey.yasskin | 2008-04-07 01:04:28 +0200 (Mon, 07 Apr 2008) | 7 lines Add enough debugging information to diagnose failures where the HandlerBException is ignored, and fix one such problem, where it was thrown during the __del__ method of the previous Popen object. We may want to find a better way of printing verbose information so it's not spammy when the test passes. ........ r62197 | mark.hammond | 2008-04-07 03:53:39 +0200 (Mon, 07 Apr 2008) | 2 lines Issue #2513: enable 64bit cross compilation on windows. ........ r62198 | mark.hammond | 2008-04-07 03:59:40 +0200 (Mon, 07 Apr 2008) | 2 lines correct heading underline for new "Cross-compiling on Windows" section ........ r62204 | gregory.p.smith | 2008-04-07 08:33:21 +0200 (Mon, 07 Apr 2008) | 4 lines Use the new PyFile_IncUseCount & PyFile_DecUseCount calls appropriatly within the standard library. These modules use PyFile_AsFile and later release the GIL while operating on the previously returned FILE*. ........ r62205 | mark.summerfield | 2008-04-07 09:39:23 +0200 (Mon, 07 Apr 2008) | 4 lines changed "2500 components" to "several thousand" since the number keeps growning:-) ........ r62214 | georg.brandl | 2008-04-07 20:51:59 +0200 (Mon, 07 Apr 2008) | 2 lines #2525: update timezone info examples in the docs. ........ r62219 | andrew.kuchling | 2008-04-08 01:57:07 +0200 (Tue, 08 Apr 2008) | 1 line Write PEP 3127 section; add items ........ r62220 | andrew.kuchling | 2008-04-08 01:57:21 +0200 (Tue, 08 Apr 2008) | 1 line Typo fix ........ r62221 | andrew.kuchling | 2008-04-08 03:33:10 +0200 (Tue, 08 Apr 2008) | 1 line Typographical fix: 32bit -> 32-bit, 64bit -> 64-bit ........ r62227 | andrew.kuchling | 2008-04-08 23:22:53 +0200 (Tue, 08 Apr 2008) | 1 line Add items ........ r62229 | amaury.forgeotdarc | 2008-04-08 23:27:42 +0200 (Tue, 08 Apr 2008) | 7 lines Issue2564: Prevent a hang in "import test.autotest", which runs the entire test suite as a side-effect of importing the module. - in test_capi, a thread tried to import other modules - re.compile() imported sre_parse again on every call. ........ r62230 | amaury.forgeotdarc | 2008-04-08 23:51:57 +0200 (Tue, 08 Apr 2008) | 2 lines Prevent an error when inspect.isabstract() is called with something else than a new-style class. ........ r62231 | amaury.forgeotdarc | 2008-04-09 00:07:05 +0200 (Wed, 09 Apr 2008) | 8 lines Issue 2408: remove the _types module It was only used as a helper in types.py to access types (GetSetDescriptorType and MemberDescriptorType), when they can easily be obtained with python code. These expressions even work with Jython. I don't know what the future of the types module is; (cf. discussion in http://bugs.python.org/issue1605 ) at least this change makes it simpler. ........ r62233 | amaury.forgeotdarc | 2008-04-09 01:10:07 +0200 (Wed, 09 Apr 2008) | 2 lines Add a NEWS entry for previous checkin ........ r62234 | trent.nelson | 2008-04-09 01:47:30 +0200 (Wed, 09 Apr 2008) | 37 lines - Issue #2550: The approach used by client/server code for obtaining ports to listen on in network-oriented tests has been refined in an effort to facilitate running multiple instances of the entire regression test suite in parallel without issue. test_support.bind_port() has been fixed such that it will always return a unique port -- which wasn't always the case with the previous implementation, especially if socket options had been set that affected address reuse (i.e. SO_REUSEADDR, SO_REUSEPORT). The new implementation of bind_port() will actually raise an exception if it is passed an AF_INET/SOCK_STREAM socket with either the SO_REUSEADDR or SO_REUSEPORT socket option set. Furthermore, if available, bind_port() will set the SO_EXCLUSIVEADDRUSE option on the socket it's been passed. This currently only applies to Windows. This option prevents any other sockets from binding to the host/port we've bound to, thus removing the possibility of the 'non-deterministic' behaviour, as Microsoft puts it, that occurs when a second SOCK_STREAM socket binds and accepts to a host/port that's already been bound by another socket. The optional preferred port parameter to bind_port() has been removed. Under no circumstances should tests be hard coding ports! test_support.find_unused_port() has also been introduced, which will pass a temporary socket object to bind_port() in order to obtain an unused port. The temporary socket object is then closed and deleted, and the port is returned. This method should only be used for obtaining an unused port in order to pass to an external program (i.e. the -accept [port] argument to openssl's s_server mode) or as a parameter to a server-oriented class that doesn't give you direct access to the underlying socket used. Finally, test_support.HOST has been introduced, which should be used for the host argument of any relevant socket calls (i.e. bind and connect). The following tests were updated to following the new conventions: test_socket, test_smtplib, test_asyncore, test_ssl, test_httplib, test_poplib, test_ftplib, test_telnetlib, test_socketserver, test_asynchat and test_socket_ssl. It is now possible for multiple instances of the regression test suite to run in parallel without issue. ........ r62235 | gregory.p.smith | 2008-04-09 02:25:17 +0200 (Wed, 09 Apr 2008) | 3 lines Fix zlib crash from zlib.decompressobj().flush(val) when val was not positive. It tried to allocate negative or zero memory. That fails. ........ r62237 | trent.nelson | 2008-04-09 02:34:53 +0200 (Wed, 09 Apr 2008) | 1 line Fix typo with regards to self.PORT shadowing class variables with the same name. ........ r62238 | andrew.kuchling | 2008-04-09 03:08:32 +0200 (Wed, 09 Apr 2008) | 1 line Add items ........ r62239 | jerry.seutter | 2008-04-09 07:07:58 +0200 (Wed, 09 Apr 2008) | 1 line Changed test so it no longer runs as a side effect of importing. ........
18 years ago
Merged revisions 55007-55179 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ........ r55077 | guido.van.rossum | 2007-05-02 11:54:37 -0700 (Wed, 02 May 2007) | 2 lines Use the new print syntax, at least. ........ r55142 | fred.drake | 2007-05-04 21:27:30 -0700 (Fri, 04 May 2007) | 1 line remove old cruftiness ........ r55143 | fred.drake | 2007-05-04 21:52:16 -0700 (Fri, 04 May 2007) | 1 line make this work with the new Python ........ r55162 | neal.norwitz | 2007-05-06 22:29:18 -0700 (Sun, 06 May 2007) | 1 line Get asdl code gen working with Python 2.3. Should continue to work with 3.0 ........ r55164 | neal.norwitz | 2007-05-07 00:00:38 -0700 (Mon, 07 May 2007) | 1 line Verify checkins to p3yk (sic) branch go to 3000 list. ........ r55166 | neal.norwitz | 2007-05-07 00:12:35 -0700 (Mon, 07 May 2007) | 1 line Fix this test so it runs again by importing warnings_test properly. ........ r55167 | neal.norwitz | 2007-05-07 01:03:22 -0700 (Mon, 07 May 2007) | 8 lines So long xrange. range() now supports values that are outside -sys.maxint to sys.maxint. floats raise a TypeError. This has been sitting for a long time. It probably has some problems and needs cleanup. Objects/rangeobject.c now uses 4-space indents since it is almost completely new. ........ r55171 | guido.van.rossum | 2007-05-07 10:21:26 -0700 (Mon, 07 May 2007) | 4 lines Fix two tests that were previously depending on significant spaces at the end of a line (and before that on Python 2.x print behavior that has no exact equivalent in 3.0). ........
19 years ago
26 years ago
  1. """distutils.command.install
  2. Implements the Distutils 'install' command."""
  3. import sys
  4. import os
  5. from distutils import log
  6. from distutils.core import Command
  7. from distutils.debug import DEBUG
  8. from distutils.sysconfig import get_config_vars
  9. from distutils.errors import DistutilsPlatformError
  10. from distutils.file_util import write_file
  11. from distutils.util import convert_path, subst_vars, change_root
  12. from distutils.util import get_platform
  13. from distutils.errors import DistutilsOptionError
  14. # this keeps compatibility from 2.3 to 2.5
  15. if sys.version < "2.6":
  16. USER_BASE = None
  17. USER_SITE = None
  18. HAS_USER_SITE = False
  19. else:
  20. from site import USER_BASE
  21. from site import USER_SITE
  22. HAS_USER_SITE = True
  23. if sys.version < "2.2":
  24. WINDOWS_SCHEME = {
  25. 'purelib': '$base',
  26. 'platlib': '$base',
  27. 'headers': '$base/Include/$dist_name',
  28. 'scripts': '$base/Scripts',
  29. 'data' : '$base',
  30. }
  31. else:
  32. WINDOWS_SCHEME = {
  33. 'purelib': '$base/Lib/site-packages',
  34. 'platlib': '$base/Lib/site-packages',
  35. 'headers': '$base/Include/$dist_name',
  36. 'scripts': '$base/Scripts',
  37. 'data' : '$base',
  38. }
  39. INSTALL_SCHEMES = {
  40. 'unix_prefix': {
  41. 'purelib': '$base/lib/python$py_version_short/site-packages',
  42. 'platlib': '$platbase/lib/python$py_version_short/site-packages',
  43. 'headers': '$base/include/python$py_version_short$abiflags/$dist_name',
  44. 'scripts': '$base/bin',
  45. 'data' : '$base',
  46. },
  47. 'unix_home': {
  48. 'purelib': '$base/lib/python',
  49. 'platlib': '$base/lib/python',
  50. 'headers': '$base/include/python/$dist_name',
  51. 'scripts': '$base/bin',
  52. 'data' : '$base',
  53. },
  54. 'nt': WINDOWS_SCHEME,
  55. 'os2': {
  56. 'purelib': '$base/Lib/site-packages',
  57. 'platlib': '$base/Lib/site-packages',
  58. 'headers': '$base/Include/$dist_name',
  59. 'scripts': '$base/Scripts',
  60. 'data' : '$base',
  61. },
  62. }
  63. # user site schemes
  64. if HAS_USER_SITE:
  65. INSTALL_SCHEMES['nt_user'] = {
  66. 'purelib': '$usersite',
  67. 'platlib': '$usersite',
  68. 'headers': '$userbase/Python$py_version_nodot/Include/$dist_name',
  69. 'scripts': '$userbase/Scripts',
  70. 'data' : '$userbase',
  71. }
  72. INSTALL_SCHEMES['unix_user'] = {
  73. 'purelib': '$usersite',
  74. 'platlib': '$usersite',
  75. 'headers':
  76. '$userbase/include/python$py_version_short$abiflags/$dist_name',
  77. 'scripts': '$userbase/bin',
  78. 'data' : '$userbase',
  79. }
  80. INSTALL_SCHEMES['os2_home'] = {
  81. 'purelib': '$usersite',
  82. 'platlib': '$usersite',
  83. 'headers': '$userbase/include/python$py_version_short/$dist_name',
  84. 'scripts': '$userbase/bin',
  85. 'data' : '$userbase',
  86. }
  87. # The keys to an installation scheme; if any new types of files are to be
  88. # installed, be sure to add an entry to every installation scheme above,
  89. # and to SCHEME_KEYS here.
  90. SCHEME_KEYS = ('purelib', 'platlib', 'headers', 'scripts', 'data')
  91. class install(Command):
  92. description = "install everything from build directory"
  93. user_options = [
  94. # Select installation scheme and set base director(y|ies)
  95. ('prefix=', None,
  96. "installation prefix"),
  97. ('exec-prefix=', None,
  98. "(Unix only) prefix for platform-specific files"),
  99. ('home=', None,
  100. "(Unix only) home directory to install under"),
  101. # Or, just set the base director(y|ies)
  102. ('install-base=', None,
  103. "base installation directory (instead of --prefix or --home)"),
  104. ('install-platbase=', None,
  105. "base installation directory for platform-specific files " +
  106. "(instead of --exec-prefix or --home)"),
  107. ('root=', None,
  108. "install everything relative to this alternate root directory"),
  109. # Or, explicitly set the installation scheme
  110. ('install-purelib=', None,
  111. "installation directory for pure Python module distributions"),
  112. ('install-platlib=', None,
  113. "installation directory for non-pure module distributions"),
  114. ('install-lib=', None,
  115. "installation directory for all module distributions " +
  116. "(overrides --install-purelib and --install-platlib)"),
  117. ('install-headers=', None,
  118. "installation directory for C/C++ headers"),
  119. ('install-scripts=', None,
  120. "installation directory for Python scripts"),
  121. ('install-data=', None,
  122. "installation directory for data files"),
  123. # Byte-compilation options -- see install_lib.py for details, as
  124. # these are duplicated from there (but only install_lib does
  125. # anything with them).
  126. ('compile', 'c', "compile .py to .pyc [default]"),
  127. ('no-compile', None, "don't compile .py files"),
  128. ('optimize=', 'O',
  129. "also compile with optimization: -O1 for \"python -O\", "
  130. "-O2 for \"python -OO\", and -O0 to disable [default: -O0]"),
  131. # Miscellaneous control options
  132. ('force', 'f',
  133. "force installation (overwrite any existing files)"),
  134. ('skip-build', None,
  135. "skip rebuilding everything (for testing/debugging)"),
  136. # Where to install documentation (eventually!)
  137. #('doc-format=', None, "format of documentation to generate"),
  138. #('install-man=', None, "directory for Unix man pages"),
  139. #('install-html=', None, "directory for HTML documentation"),
  140. #('install-info=', None, "directory for GNU info files"),
  141. ('record=', None,
  142. "filename in which to record list of installed files"),
  143. ]
  144. boolean_options = ['compile', 'force', 'skip-build']
  145. if HAS_USER_SITE:
  146. user_options.append(('user', None,
  147. "install in user site-package '%s'" % USER_SITE))
  148. boolean_options.append('user')
  149. negative_opt = {'no-compile' : 'compile'}
  150. def initialize_options(self):
  151. """Initializes options."""
  152. # High-level options: these select both an installation base
  153. # and scheme.
  154. self.prefix = None
  155. self.exec_prefix = None
  156. self.home = None
  157. self.user = 0
  158. # These select only the installation base; it's up to the user to
  159. # specify the installation scheme (currently, that means supplying
  160. # the --install-{platlib,purelib,scripts,data} options).
  161. self.install_base = None
  162. self.install_platbase = None
  163. self.root = None
  164. # These options are the actual installation directories; if not
  165. # supplied by the user, they are filled in using the installation
  166. # scheme implied by prefix/exec-prefix/home and the contents of
  167. # that installation scheme.
  168. self.install_purelib = None # for pure module distributions
  169. self.install_platlib = None # non-pure (dists w/ extensions)
  170. self.install_headers = None # for C/C++ headers
  171. self.install_lib = None # set to either purelib or platlib
  172. self.install_scripts = None
  173. self.install_data = None
  174. self.install_userbase = USER_BASE
  175. self.install_usersite = USER_SITE
  176. self.compile = None
  177. self.optimize = None
  178. # These two are for putting non-packagized distributions into their
  179. # own directory and creating a .pth file if it makes sense.
  180. # 'extra_path' comes from the setup file; 'install_path_file' can
  181. # be turned off if it makes no sense to install a .pth file. (But
  182. # better to install it uselessly than to guess wrong and not
  183. # install it when it's necessary and would be used!) Currently,
  184. # 'install_path_file' is always true unless some outsider meddles
  185. # with it.
  186. self.extra_path = None
  187. self.install_path_file = 1
  188. # 'force' forces installation, even if target files are not
  189. # out-of-date. 'skip_build' skips running the "build" command,
  190. # handy if you know it's not necessary. 'warn_dir' (which is *not*
  191. # a user option, it's just there so the bdist_* commands can turn
  192. # it off) determines whether we warn about installing to a
  193. # directory not in sys.path.
  194. self.force = 0
  195. self.skip_build = 0
  196. self.warn_dir = 1
  197. # These are only here as a conduit from the 'build' command to the
  198. # 'install_*' commands that do the real work. ('build_base' isn't
  199. # actually used anywhere, but it might be useful in future.) They
  200. # are not user options, because if the user told the install
  201. # command where the build directory is, that wouldn't affect the
  202. # build command.
  203. self.build_base = None
  204. self.build_lib = None
  205. # Not defined yet because we don't know anything about
  206. # documentation yet.
  207. #self.install_man = None
  208. #self.install_html = None
  209. #self.install_info = None
  210. self.record = None
  211. # -- Option finalizing methods -------------------------------------
  212. # (This is rather more involved than for most commands,
  213. # because this is where the policy for installing third-
  214. # party Python modules on various platforms given a wide
  215. # array of user input is decided. Yes, it's quite complex!)
  216. def finalize_options(self):
  217. """Finalizes options."""
  218. # This method (and its pliant slaves, like 'finalize_unix()',
  219. # 'finalize_other()', and 'select_scheme()') is where the default
  220. # installation directories for modules, extension modules, and
  221. # anything else we care to install from a Python module
  222. # distribution. Thus, this code makes a pretty important policy
  223. # statement about how third-party stuff is added to a Python
  224. # installation! Note that the actual work of installation is done
  225. # by the relatively simple 'install_*' commands; they just take
  226. # their orders from the installation directory options determined
  227. # here.
  228. # Check for errors/inconsistencies in the options; first, stuff
  229. # that's wrong on any platform.
  230. if ((self.prefix or self.exec_prefix or self.home) and
  231. (self.install_base or self.install_platbase)):
  232. raise DistutilsOptionError(
  233. "must supply either prefix/exec-prefix/home or " +
  234. "install-base/install-platbase -- not both")
  235. if self.home and (self.prefix or self.exec_prefix):
  236. raise DistutilsOptionError(
  237. "must supply either home or prefix/exec-prefix -- not both")
  238. if self.user and (self.prefix or self.exec_prefix or self.home or
  239. self.install_base or self.install_platbase):
  240. raise DistutilsOptionError("can't combine user with with prefix/"
  241. "exec_prefix/home or install_(plat)base")
  242. # Next, stuff that's wrong (or dubious) only on certain platforms.
  243. if os.name != "posix":
  244. if self.exec_prefix:
  245. self.warn("exec-prefix option ignored on this platform")
  246. self.exec_prefix = None
  247. # Now the interesting logic -- so interesting that we farm it out
  248. # to other methods. The goal of these methods is to set the final
  249. # values for the install_{lib,scripts,data,...} options, using as
  250. # input a heady brew of prefix, exec_prefix, home, install_base,
  251. # install_platbase, user-supplied versions of
  252. # install_{purelib,platlib,lib,scripts,data,...}, and the
  253. # INSTALL_SCHEME dictionary above. Phew!
  254. self.dump_dirs("pre-finalize_{unix,other}")
  255. if os.name == 'posix':
  256. self.finalize_unix()
  257. else:
  258. self.finalize_other()
  259. self.dump_dirs("post-finalize_{unix,other}()")
  260. # Expand configuration variables, tilde, etc. in self.install_base
  261. # and self.install_platbase -- that way, we can use $base or
  262. # $platbase in the other installation directories and not worry
  263. # about needing recursive variable expansion (shudder).
  264. py_version = sys.version.split()[0]
  265. (prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix')
  266. try:
  267. abiflags = sys.abiflags
  268. except AttributeError:
  269. # sys.abiflags may not be defined on all platforms.
  270. abiflags = ''
  271. self.config_vars = {'dist_name': self.distribution.get_name(),
  272. 'dist_version': self.distribution.get_version(),
  273. 'dist_fullname': self.distribution.get_fullname(),
  274. 'py_version': py_version,
  275. 'py_version_short': py_version[0:3],
  276. 'py_version_nodot': py_version[0] + py_version[2],
  277. 'sys_prefix': prefix,
  278. 'prefix': prefix,
  279. 'sys_exec_prefix': exec_prefix,
  280. 'exec_prefix': exec_prefix,
  281. 'abiflags': abiflags,
  282. }
  283. if HAS_USER_SITE:
  284. self.config_vars['userbase'] = self.install_userbase
  285. self.config_vars['usersite'] = self.install_usersite
  286. self.expand_basedirs()
  287. self.dump_dirs("post-expand_basedirs()")
  288. # Now define config vars for the base directories so we can expand
  289. # everything else.
  290. self.config_vars['base'] = self.install_base
  291. self.config_vars['platbase'] = self.install_platbase
  292. if DEBUG:
  293. from pprint import pprint
  294. print("config vars:")
  295. pprint(self.config_vars)
  296. # Expand "~" and configuration variables in the installation
  297. # directories.
  298. self.expand_dirs()
  299. self.dump_dirs("post-expand_dirs()")
  300. # Create directories in the home dir:
  301. if self.user:
  302. self.create_home_path()
  303. # Pick the actual directory to install all modules to: either
  304. # install_purelib or install_platlib, depending on whether this
  305. # module distribution is pure or not. Of course, if the user
  306. # already specified install_lib, use their selection.
  307. if self.install_lib is None:
  308. if self.distribution.ext_modules: # has extensions: non-pure
  309. self.install_lib = self.install_platlib
  310. else:
  311. self.install_lib = self.install_purelib
  312. # Convert directories from Unix /-separated syntax to the local
  313. # convention.
  314. self.convert_paths('lib', 'purelib', 'platlib',
  315. 'scripts', 'data', 'headers',
  316. 'userbase', 'usersite')
  317. # Well, we're not actually fully completely finalized yet: we still
  318. # have to deal with 'extra_path', which is the hack for allowing
  319. # non-packagized module distributions (hello, Numerical Python!) to
  320. # get their own directories.
  321. self.handle_extra_path()
  322. self.install_libbase = self.install_lib # needed for .pth file
  323. self.install_lib = os.path.join(self.install_lib, self.extra_dirs)
  324. # If a new root directory was supplied, make all the installation
  325. # dirs relative to it.
  326. if self.root is not None:
  327. self.change_roots('libbase', 'lib', 'purelib', 'platlib',
  328. 'scripts', 'data', 'headers')
  329. self.dump_dirs("after prepending root")
  330. # Find out the build directories, ie. where to install from.
  331. self.set_undefined_options('build',
  332. ('build_base', 'build_base'),
  333. ('build_lib', 'build_lib'))
  334. # Punt on doc directories for now -- after all, we're punting on
  335. # documentation completely!
  336. def dump_dirs(self, msg):
  337. """Dumps the list of user options."""
  338. if not DEBUG:
  339. return
  340. from distutils.fancy_getopt import longopt_xlate
  341. log.debug(msg + ":")
  342. for opt in self.user_options:
  343. opt_name = opt[0]
  344. if opt_name[-1] == "=":
  345. opt_name = opt_name[0:-1]
  346. if opt_name in self.negative_opt:
  347. opt_name = self.negative_opt[opt_name]
  348. opt_name = opt_name.translate(longopt_xlate)
  349. val = not getattr(self, opt_name)
  350. else:
  351. opt_name = opt_name.translate(longopt_xlate)
  352. val = getattr(self, opt_name)
  353. log.debug(" %s: %s" % (opt_name, val))
  354. def finalize_unix(self):
  355. """Finalizes options for posix platforms."""
  356. if self.install_base is not None or self.install_platbase is not None:
  357. if ((self.install_lib is None and
  358. self.install_purelib is None and
  359. self.install_platlib is None) or
  360. self.install_headers is None or
  361. self.install_scripts is None or
  362. self.install_data is None):
  363. raise DistutilsOptionError(
  364. "install-base or install-platbase supplied, but "
  365. "installation scheme is incomplete")
  366. return
  367. if self.user:
  368. if self.install_userbase is None:
  369. raise DistutilsPlatformError(
  370. "User base directory is not specified")
  371. self.install_base = self.install_platbase = self.install_userbase
  372. self.select_scheme("unix_user")
  373. elif self.home is not None:
  374. self.install_base = self.install_platbase = self.home
  375. self.select_scheme("unix_home")
  376. else:
  377. if self.prefix is None:
  378. if self.exec_prefix is not None:
  379. raise DistutilsOptionError(
  380. "must not supply exec-prefix without prefix")
  381. self.prefix = os.path.normpath(sys.prefix)
  382. self.exec_prefix = os.path.normpath(sys.exec_prefix)
  383. else:
  384. if self.exec_prefix is None:
  385. self.exec_prefix = self.prefix
  386. self.install_base = self.prefix
  387. self.install_platbase = self.exec_prefix
  388. self.select_scheme("unix_prefix")
  389. def finalize_other(self):
  390. """Finalizes options for non-posix platforms"""
  391. if self.user:
  392. if self.install_userbase is None:
  393. raise DistutilsPlatformError(
  394. "User base directory is not specified")
  395. self.install_base = self.install_platbase = self.install_userbase
  396. self.select_scheme(os.name + "_user")
  397. elif self.home is not None:
  398. self.install_base = self.install_platbase = self.home
  399. self.select_scheme("unix_home")
  400. else:
  401. if self.prefix is None:
  402. self.prefix = os.path.normpath(sys.prefix)
  403. self.install_base = self.install_platbase = self.prefix
  404. try:
  405. self.select_scheme(os.name)
  406. except KeyError:
  407. raise DistutilsPlatformError(
  408. "I don't know how to install stuff on '%s'" % os.name)
  409. def select_scheme(self, name):
  410. """Sets the install directories by applying the install schemes."""
  411. # it's the caller's problem if they supply a bad name!
  412. scheme = INSTALL_SCHEMES[name]
  413. for key in SCHEME_KEYS:
  414. attrname = 'install_' + key
  415. if getattr(self, attrname) is None:
  416. setattr(self, attrname, scheme[key])
  417. def _expand_attrs(self, attrs):
  418. for attr in attrs:
  419. val = getattr(self, attr)
  420. if val is not None:
  421. if os.name == 'posix' or os.name == 'nt':
  422. val = os.path.expanduser(val)
  423. val = subst_vars(val, self.config_vars)
  424. setattr(self, attr, val)
  425. def expand_basedirs(self):
  426. """Calls `os.path.expanduser` on install_base, install_platbase and
  427. root."""
  428. self._expand_attrs(['install_base', 'install_platbase', 'root'])
  429. def expand_dirs(self):
  430. """Calls `os.path.expanduser` on install dirs."""
  431. self._expand_attrs(['install_purelib', 'install_platlib',
  432. 'install_lib', 'install_headers',
  433. 'install_scripts', 'install_data',])
  434. def convert_paths(self, *names):
  435. """Call `convert_path` over `names`."""
  436. for name in names:
  437. attr = "install_" + name
  438. setattr(self, attr, convert_path(getattr(self, attr)))
  439. def handle_extra_path(self):
  440. """Set `path_file` and `extra_dirs` using `extra_path`."""
  441. if self.extra_path is None:
  442. self.extra_path = self.distribution.extra_path
  443. if self.extra_path is not None:
  444. if isinstance(self.extra_path, str):
  445. self.extra_path = self.extra_path.split(',')
  446. if len(self.extra_path) == 1:
  447. path_file = extra_dirs = self.extra_path[0]
  448. elif len(self.extra_path) == 2:
  449. path_file, extra_dirs = self.extra_path
  450. else:
  451. raise DistutilsOptionError(
  452. "'extra_path' option must be a list, tuple, or "
  453. "comma-separated string with 1 or 2 elements")
  454. # convert to local form in case Unix notation used (as it
  455. # should be in setup scripts)
  456. extra_dirs = convert_path(extra_dirs)
  457. else:
  458. path_file = None
  459. extra_dirs = ''
  460. # XXX should we warn if path_file and not extra_dirs? (in which
  461. # case the path file would be harmless but pointless)
  462. self.path_file = path_file
  463. self.extra_dirs = extra_dirs
  464. def change_roots(self, *names):
  465. """Change the install direcories pointed by name using root."""
  466. for name in names:
  467. attr = "install_" + name
  468. setattr(self, attr, change_root(self.root, getattr(self, attr)))
  469. def create_home_path(self):
  470. """Create directories under ~."""
  471. if not self.user:
  472. return
  473. home = convert_path(os.path.expanduser("~"))
  474. for name, path in self.config_vars.items():
  475. if path.startswith(home) and not os.path.isdir(path):
  476. self.debug_print("os.makedirs('%s', 0o700)" % path)
  477. os.makedirs(path, 0o700)
  478. # -- Command execution methods -------------------------------------
  479. def run(self):
  480. """Runs the command."""
  481. # Obviously have to build before we can install
  482. if not self.skip_build:
  483. self.run_command('build')
  484. # If we built for any other platform, we can't install.
  485. build_plat = self.distribution.get_command_obj('build').plat_name
  486. # check warn_dir - it is a clue that the 'install' is happening
  487. # internally, and not to sys.path, so we don't check the platform
  488. # matches what we are running.
  489. if self.warn_dir and build_plat != get_platform():
  490. raise DistutilsPlatformError("Can't install when "
  491. "cross-compiling")
  492. # Run all sub-commands (at least those that need to be run)
  493. for cmd_name in self.get_sub_commands():
  494. self.run_command(cmd_name)
  495. if self.path_file:
  496. self.create_path_file()
  497. # write list of installed files, if requested.
  498. if self.record:
  499. outputs = self.get_outputs()
  500. if self.root: # strip any package prefix
  501. root_len = len(self.root)
  502. for counter in range(len(outputs)):
  503. outputs[counter] = outputs[counter][root_len:]
  504. self.execute(write_file,
  505. (self.record, outputs),
  506. "writing list of installed files to '%s'" %
  507. self.record)
  508. sys_path = map(os.path.normpath, sys.path)
  509. sys_path = map(os.path.normcase, sys_path)
  510. install_lib = os.path.normcase(os.path.normpath(self.install_lib))
  511. if (self.warn_dir and
  512. not (self.path_file and self.install_path_file) and
  513. install_lib not in sys_path):
  514. log.debug(("modules installed to '%s', which is not in "
  515. "Python's module search path (sys.path) -- "
  516. "you'll have to change the search path yourself"),
  517. self.install_lib)
  518. def create_path_file(self):
  519. """Creates the .pth file"""
  520. filename = os.path.join(self.install_libbase,
  521. self.path_file + ".pth")
  522. if self.install_path_file:
  523. self.execute(write_file,
  524. (filename, [self.extra_dirs]),
  525. "creating %s" % filename)
  526. else:
  527. self.warn("path file '%s' not created" % filename)
  528. # -- Reporting methods ---------------------------------------------
  529. def get_outputs(self):
  530. """Assembles the outputs of all the sub-commands."""
  531. outputs = []
  532. for cmd_name in self.get_sub_commands():
  533. cmd = self.get_finalized_command(cmd_name)
  534. # Add the contents of cmd.get_outputs(), ensuring
  535. # that outputs doesn't contain duplicate entries
  536. for filename in cmd.get_outputs():
  537. if filename not in outputs:
  538. outputs.append(filename)
  539. if self.path_file and self.install_path_file:
  540. outputs.append(os.path.join(self.install_libbase,
  541. self.path_file + ".pth"))
  542. return outputs
  543. def get_inputs(self):
  544. """Returns the inputs of all the sub-commands"""
  545. # XXX gee, this looks familiar ;-(
  546. inputs = []
  547. for cmd_name in self.get_sub_commands():
  548. cmd = self.get_finalized_command(cmd_name)
  549. inputs.extend(cmd.get_inputs())
  550. return inputs
  551. # -- Predicates for sub-command list -------------------------------
  552. def has_lib(self):
  553. """Returns true if the current distribution has any Python
  554. modules to install."""
  555. return (self.distribution.has_pure_modules() or
  556. self.distribution.has_ext_modules())
  557. def has_headers(self):
  558. """Returns true if the current distribution has any headers to
  559. install."""
  560. return self.distribution.has_headers()
  561. def has_scripts(self):
  562. """Returns true if the current distribution has any scripts to.
  563. install."""
  564. return self.distribution.has_scripts()
  565. def has_data(self):
  566. """Returns true if the current distribution has any data to.
  567. install."""
  568. return self.distribution.has_data_files()
  569. # 'sub_commands': a list of commands this command might have to run to
  570. # get its work done. See cmd.py for more info.
  571. sub_commands = [('install_lib', has_lib),
  572. ('install_headers', has_headers),
  573. ('install_scripts', has_scripts),
  574. ('install_data', has_data),
  575. ('install_egg_info', lambda self:True),
  576. ]