install.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. """distutils.command.install
  2. Implements the Distutils 'install' command."""
  3. import sys
  4. import os
  5. import contextlib
  6. import sysconfig
  7. import itertools
  8. from distutils import log
  9. from distutils.core import Command
  10. from distutils.debug import DEBUG
  11. from distutils.sysconfig import get_config_vars
  12. from distutils.errors import DistutilsPlatformError
  13. from distutils.file_util import write_file
  14. from distutils.util import convert_path, subst_vars, change_root
  15. from distutils.util import get_platform
  16. from distutils.errors import DistutilsOptionError
  17. from site import USER_BASE
  18. from site import USER_SITE
  19. HAS_USER_SITE = True
  20. WINDOWS_SCHEME = {
  21. 'purelib': '{base}/Lib/site-packages',
  22. 'platlib': '{base}/Lib/site-packages',
  23. 'headers': '{base}/Include/{dist_name}',
  24. 'scripts': '{base}/Scripts',
  25. 'data' : '{base}',
  26. }
  27. INSTALL_SCHEMES = {
  28. 'posix_prefix': {
  29. 'purelib': '{base}/lib/{implementation_lower}{py_version_short}/site-packages',
  30. 'platlib': '{platbase}/{platlibdir}/{implementation_lower}{py_version_short}/site-packages',
  31. 'headers': '{base}/include/{implementation_lower}{py_version_short}{abiflags}/{dist_name}',
  32. 'scripts': '{base}/bin',
  33. 'data' : '{base}',
  34. },
  35. 'posix_home': {
  36. 'purelib': '{base}/lib/{implementation_lower}',
  37. 'platlib': '{base}/{platlibdir}/{implementation_lower}',
  38. 'headers': '{base}/include/{implementation_lower}/{dist_name}',
  39. 'scripts': '{base}/bin',
  40. 'data' : '{base}',
  41. },
  42. 'nt': WINDOWS_SCHEME,
  43. 'pypy': {
  44. 'purelib': '{base}/site-packages',
  45. 'platlib': '{base}/site-packages',
  46. 'headers': '{base}/include/{dist_name}',
  47. 'scripts': '{base}/bin',
  48. 'data' : '{base}',
  49. },
  50. 'pypy_nt': {
  51. 'purelib': '{base}/site-packages',
  52. 'platlib': '{base}/site-packages',
  53. 'headers': '{base}/include/{dist_name}',
  54. 'scripts': '{base}/Scripts',
  55. 'data' : '{base}',
  56. },
  57. }
  58. # user site schemes
  59. if HAS_USER_SITE:
  60. INSTALL_SCHEMES['nt_user'] = {
  61. 'purelib': '{usersite}',
  62. 'platlib': '{usersite}',
  63. 'headers': '{userbase}/{implementation}{py_version_nodot}/Include/{dist_name}',
  64. 'scripts': '{userbase}/{implementation}{py_version_nodot}/Scripts',
  65. 'data' : '{userbase}',
  66. }
  67. INSTALL_SCHEMES['posix_user'] = {
  68. 'purelib': '{usersite}',
  69. 'platlib': '{usersite}',
  70. 'headers':
  71. '{userbase}/include/{implementation_lower}{py_version_short}{abiflags}/{dist_name}',
  72. 'scripts': '{userbase}/bin',
  73. 'data' : '{userbase}',
  74. }
  75. # The keys to an installation scheme; if any new types of files are to be
  76. # installed, be sure to add an entry to every installation scheme above,
  77. # and to SCHEME_KEYS here.
  78. SCHEME_KEYS = ('purelib', 'platlib', 'headers', 'scripts', 'data')
  79. def _load_sysconfig_schemes():
  80. with contextlib.suppress(AttributeError):
  81. return {
  82. scheme: sysconfig.get_paths(scheme, expand=False)
  83. for scheme in sysconfig.get_scheme_names()
  84. }
  85. def _load_schemes():
  86. """
  87. Extend default schemes with schemes from sysconfig.
  88. """
  89. sysconfig_schemes = _load_sysconfig_schemes() or {}
  90. return {
  91. scheme: {
  92. **INSTALL_SCHEMES.get(scheme, {}),
  93. **sysconfig_schemes.get(scheme, {}),
  94. }
  95. for scheme in set(itertools.chain(INSTALL_SCHEMES, sysconfig_schemes))
  96. }
  97. def _get_implementation():
  98. if hasattr(sys, 'pypy_version_info'):
  99. return 'PyPy'
  100. else:
  101. return 'Python'
  102. class install(Command):
  103. description = "install everything from build directory"
  104. user_options = [
  105. # Select installation scheme and set base director(y|ies)
  106. ('prefix=', None,
  107. "installation prefix"),
  108. ('exec-prefix=', None,
  109. "(Unix only) prefix for platform-specific files"),
  110. ('home=', None,
  111. "(Unix only) home directory to install under"),
  112. # Or, just set the base director(y|ies)
  113. ('install-base=', None,
  114. "base installation directory (instead of --prefix or --home)"),
  115. ('install-platbase=', None,
  116. "base installation directory for platform-specific files " +
  117. "(instead of --exec-prefix or --home)"),
  118. ('root=', None,
  119. "install everything relative to this alternate root directory"),
  120. # Or, explicitly set the installation scheme
  121. ('install-purelib=', None,
  122. "installation directory for pure Python module distributions"),
  123. ('install-platlib=', None,
  124. "installation directory for non-pure module distributions"),
  125. ('install-lib=', None,
  126. "installation directory for all module distributions " +
  127. "(overrides --install-purelib and --install-platlib)"),
  128. ('install-headers=', None,
  129. "installation directory for C/C++ headers"),
  130. ('install-scripts=', None,
  131. "installation directory for Python scripts"),
  132. ('install-data=', None,
  133. "installation directory for data files"),
  134. # Byte-compilation options -- see install_lib.py for details, as
  135. # these are duplicated from there (but only install_lib does
  136. # anything with them).
  137. ('compile', 'c', "compile .py to .pyc [default]"),
  138. ('no-compile', None, "don't compile .py files"),
  139. ('optimize=', 'O',
  140. "also compile with optimization: -O1 for \"python -O\", "
  141. "-O2 for \"python -OO\", and -O0 to disable [default: -O0]"),
  142. # Miscellaneous control options
  143. ('force', 'f',
  144. "force installation (overwrite any existing files)"),
  145. ('skip-build', None,
  146. "skip rebuilding everything (for testing/debugging)"),
  147. # Where to install documentation (eventually!)
  148. #('doc-format=', None, "format of documentation to generate"),
  149. #('install-man=', None, "directory for Unix man pages"),
  150. #('install-html=', None, "directory for HTML documentation"),
  151. #('install-info=', None, "directory for GNU info files"),
  152. ('record=', None,
  153. "filename in which to record list of installed files"),
  154. ]
  155. boolean_options = ['compile', 'force', 'skip-build']
  156. if HAS_USER_SITE:
  157. user_options.append(('user', None,
  158. "install in user site-package '%s'" % USER_SITE))
  159. boolean_options.append('user')
  160. negative_opt = {'no-compile' : 'compile'}
  161. def initialize_options(self):
  162. """Initializes options."""
  163. # High-level options: these select both an installation base
  164. # and scheme.
  165. self.prefix = None
  166. self.exec_prefix = None
  167. self.home = None
  168. self.user = 0
  169. # These select only the installation base; it's up to the user to
  170. # specify the installation scheme (currently, that means supplying
  171. # the --install-{platlib,purelib,scripts,data} options).
  172. self.install_base = None
  173. self.install_platbase = None
  174. self.root = None
  175. # These options are the actual installation directories; if not
  176. # supplied by the user, they are filled in using the installation
  177. # scheme implied by prefix/exec-prefix/home and the contents of
  178. # that installation scheme.
  179. self.install_purelib = None # for pure module distributions
  180. self.install_platlib = None # non-pure (dists w/ extensions)
  181. self.install_headers = None # for C/C++ headers
  182. self.install_lib = None # set to either purelib or platlib
  183. self.install_scripts = None
  184. self.install_data = None
  185. self.install_userbase = USER_BASE
  186. self.install_usersite = USER_SITE
  187. self.compile = None
  188. self.optimize = None
  189. # Deprecated
  190. # These two are for putting non-packagized distributions into their
  191. # own directory and creating a .pth file if it makes sense.
  192. # 'extra_path' comes from the setup file; 'install_path_file' can
  193. # be turned off if it makes no sense to install a .pth file. (But
  194. # better to install it uselessly than to guess wrong and not
  195. # install it when it's necessary and would be used!) Currently,
  196. # 'install_path_file' is always true unless some outsider meddles
  197. # with it.
  198. self.extra_path = None
  199. self.install_path_file = 1
  200. # 'force' forces installation, even if target files are not
  201. # out-of-date. 'skip_build' skips running the "build" command,
  202. # handy if you know it's not necessary. 'warn_dir' (which is *not*
  203. # a user option, it's just there so the bdist_* commands can turn
  204. # it off) determines whether we warn about installing to a
  205. # directory not in sys.path.
  206. self.force = 0
  207. self.skip_build = 0
  208. self.warn_dir = 1
  209. # These are only here as a conduit from the 'build' command to the
  210. # 'install_*' commands that do the real work. ('build_base' isn't
  211. # actually used anywhere, but it might be useful in future.) They
  212. # are not user options, because if the user told the install
  213. # command where the build directory is, that wouldn't affect the
  214. # build command.
  215. self.build_base = None
  216. self.build_lib = None
  217. # Not defined yet because we don't know anything about
  218. # documentation yet.
  219. #self.install_man = None
  220. #self.install_html = None
  221. #self.install_info = None
  222. self.record = None
  223. # -- Option finalizing methods -------------------------------------
  224. # (This is rather more involved than for most commands,
  225. # because this is where the policy for installing third-
  226. # party Python modules on various platforms given a wide
  227. # array of user input is decided. Yes, it's quite complex!)
  228. def finalize_options(self):
  229. """Finalizes options."""
  230. # This method (and its helpers, like 'finalize_unix()',
  231. # 'finalize_other()', and 'select_scheme()') is where the default
  232. # installation directories for modules, extension modules, and
  233. # anything else we care to install from a Python module
  234. # distribution. Thus, this code makes a pretty important policy
  235. # statement about how third-party stuff is added to a Python
  236. # installation! Note that the actual work of installation is done
  237. # by the relatively simple 'install_*' commands; they just take
  238. # their orders from the installation directory options determined
  239. # here.
  240. # Check for errors/inconsistencies in the options; first, stuff
  241. # that's wrong on any platform.
  242. if ((self.prefix or self.exec_prefix or self.home) and
  243. (self.install_base or self.install_platbase)):
  244. raise DistutilsOptionError(
  245. "must supply either prefix/exec-prefix/home or " +
  246. "install-base/install-platbase -- not both")
  247. if self.home and (self.prefix or self.exec_prefix):
  248. raise DistutilsOptionError(
  249. "must supply either home or prefix/exec-prefix -- not both")
  250. if self.user and (self.prefix or self.exec_prefix or self.home or
  251. self.install_base or self.install_platbase):
  252. raise DistutilsOptionError("can't combine user with prefix, "
  253. "exec_prefix/home, or install_(plat)base")
  254. # Next, stuff that's wrong (or dubious) only on certain platforms.
  255. if os.name != "posix":
  256. if self.exec_prefix:
  257. self.warn("exec-prefix option ignored on this platform")
  258. self.exec_prefix = None
  259. # Now the interesting logic -- so interesting that we farm it out
  260. # to other methods. The goal of these methods is to set the final
  261. # values for the install_{lib,scripts,data,...} options, using as
  262. # input a heady brew of prefix, exec_prefix, home, install_base,
  263. # install_platbase, user-supplied versions of
  264. # install_{purelib,platlib,lib,scripts,data,...}, and the
  265. # install schemes. Phew!
  266. self.dump_dirs("pre-finalize_{unix,other}")
  267. if os.name == 'posix':
  268. self.finalize_unix()
  269. else:
  270. self.finalize_other()
  271. self.dump_dirs("post-finalize_{unix,other}()")
  272. # Expand configuration variables, tilde, etc. in self.install_base
  273. # and self.install_platbase -- that way, we can use $base or
  274. # $platbase in the other installation directories and not worry
  275. # about needing recursive variable expansion (shudder).
  276. py_version = sys.version.split()[0]
  277. (prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix')
  278. try:
  279. abiflags = sys.abiflags
  280. except AttributeError:
  281. # sys.abiflags may not be defined on all platforms.
  282. abiflags = ''
  283. self.config_vars = {'dist_name': self.distribution.get_name(),
  284. 'dist_version': self.distribution.get_version(),
  285. 'dist_fullname': self.distribution.get_fullname(),
  286. 'py_version': py_version,
  287. 'py_version_short': '%d.%d' % sys.version_info[:2],
  288. 'py_version_nodot': '%d%d' % sys.version_info[:2],
  289. 'sys_prefix': prefix,
  290. 'prefix': prefix,
  291. 'sys_exec_prefix': exec_prefix,
  292. 'exec_prefix': exec_prefix,
  293. 'abiflags': abiflags,
  294. 'platlibdir': getattr(sys, 'platlibdir', 'lib'),
  295. 'implementation_lower': _get_implementation().lower(),
  296. 'implementation': _get_implementation(),
  297. }
  298. if HAS_USER_SITE:
  299. self.config_vars['userbase'] = self.install_userbase
  300. self.config_vars['usersite'] = self.install_usersite
  301. self.expand_basedirs()
  302. self.dump_dirs("post-expand_basedirs()")
  303. # Now define config vars for the base directories so we can expand
  304. # everything else.
  305. self.config_vars['base'] = self.install_base
  306. self.config_vars['platbase'] = self.install_platbase
  307. self.config_vars['installed_base'] = (
  308. sysconfig.get_config_vars()['installed_base'])
  309. if DEBUG:
  310. from pprint import pprint
  311. print("config vars:")
  312. pprint(self.config_vars)
  313. # Expand "~" and configuration variables in the installation
  314. # directories.
  315. self.expand_dirs()
  316. self.dump_dirs("post-expand_dirs()")
  317. # Create directories in the home dir:
  318. if self.user:
  319. self.create_home_path()
  320. # Pick the actual directory to install all modules to: either
  321. # install_purelib or install_platlib, depending on whether this
  322. # module distribution is pure or not. Of course, if the user
  323. # already specified install_lib, use their selection.
  324. if self.install_lib is None:
  325. if self.distribution.has_ext_modules(): # has extensions: non-pure
  326. self.install_lib = self.install_platlib
  327. else:
  328. self.install_lib = self.install_purelib
  329. # Convert directories from Unix /-separated syntax to the local
  330. # convention.
  331. self.convert_paths('lib', 'purelib', 'platlib',
  332. 'scripts', 'data', 'headers',
  333. 'userbase', 'usersite')
  334. # Deprecated
  335. # Well, we're not actually fully completely finalized yet: we still
  336. # have to deal with 'extra_path', which is the hack for allowing
  337. # non-packagized module distributions (hello, Numerical Python!) to
  338. # get their own directories.
  339. self.handle_extra_path()
  340. self.install_libbase = self.install_lib # needed for .pth file
  341. self.install_lib = os.path.join(self.install_lib, self.extra_dirs)
  342. # If a new root directory was supplied, make all the installation
  343. # dirs relative to it.
  344. if self.root is not None:
  345. self.change_roots('libbase', 'lib', 'purelib', 'platlib',
  346. 'scripts', 'data', 'headers')
  347. self.dump_dirs("after prepending root")
  348. # Find out the build directories, ie. where to install from.
  349. self.set_undefined_options('build',
  350. ('build_base', 'build_base'),
  351. ('build_lib', 'build_lib'))
  352. # Punt on doc directories for now -- after all, we're punting on
  353. # documentation completely!
  354. def dump_dirs(self, msg):
  355. """Dumps the list of user options."""
  356. if not DEBUG:
  357. return
  358. from distutils.fancy_getopt import longopt_xlate
  359. log.debug(msg + ":")
  360. for opt in self.user_options:
  361. opt_name = opt[0]
  362. if opt_name[-1] == "=":
  363. opt_name = opt_name[0:-1]
  364. if opt_name in self.negative_opt:
  365. opt_name = self.negative_opt[opt_name]
  366. opt_name = opt_name.translate(longopt_xlate)
  367. val = not getattr(self, opt_name)
  368. else:
  369. opt_name = opt_name.translate(longopt_xlate)
  370. val = getattr(self, opt_name)
  371. log.debug(" %s: %s", opt_name, val)
  372. def finalize_unix(self):
  373. """Finalizes options for posix platforms."""
  374. if self.install_base is not None or self.install_platbase is not None:
  375. if ((self.install_lib is None and
  376. self.install_purelib is None and
  377. self.install_platlib is None) or
  378. self.install_headers is None or
  379. self.install_scripts is None or
  380. self.install_data is None):
  381. raise DistutilsOptionError(
  382. "install-base or install-platbase supplied, but "
  383. "installation scheme is incomplete")
  384. return
  385. if self.user:
  386. if self.install_userbase is None:
  387. raise DistutilsPlatformError(
  388. "User base directory is not specified")
  389. self.install_base = self.install_platbase = self.install_userbase
  390. self.select_scheme("posix_user")
  391. elif self.home is not None:
  392. self.install_base = self.install_platbase = self.home
  393. self.select_scheme("posix_home")
  394. else:
  395. if self.prefix is None:
  396. if self.exec_prefix is not None:
  397. raise DistutilsOptionError(
  398. "must not supply exec-prefix without prefix")
  399. # Allow Fedora to add components to the prefix
  400. _prefix_addition = getattr(sysconfig, '_prefix_addition', "")
  401. self.prefix = (
  402. os.path.normpath(sys.prefix) + _prefix_addition)
  403. self.exec_prefix = (
  404. os.path.normpath(sys.exec_prefix) + _prefix_addition)
  405. else:
  406. if self.exec_prefix is None:
  407. self.exec_prefix = self.prefix
  408. self.install_base = self.prefix
  409. self.install_platbase = self.exec_prefix
  410. self.select_scheme("posix_prefix")
  411. def finalize_other(self):
  412. """Finalizes options for non-posix platforms"""
  413. if self.user:
  414. if self.install_userbase is None:
  415. raise DistutilsPlatformError(
  416. "User base directory is not specified")
  417. self.install_base = self.install_platbase = self.install_userbase
  418. self.select_scheme(os.name + "_user")
  419. elif self.home is not None:
  420. self.install_base = self.install_platbase = self.home
  421. self.select_scheme("posix_home")
  422. else:
  423. if self.prefix is None:
  424. self.prefix = os.path.normpath(sys.prefix)
  425. self.install_base = self.install_platbase = self.prefix
  426. try:
  427. self.select_scheme(os.name)
  428. except KeyError:
  429. raise DistutilsPlatformError(
  430. "I don't know how to install stuff on '%s'" % os.name)
  431. def select_scheme(self, name):
  432. """Sets the install directories by applying the install schemes."""
  433. # it's the caller's problem if they supply a bad name!
  434. if (hasattr(sys, 'pypy_version_info') and
  435. sys.version_info < (3, 8) and
  436. not name.endswith(('_user', '_home'))):
  437. if os.name == 'nt':
  438. name = 'pypy_nt'
  439. else:
  440. name = 'pypy'
  441. scheme = _load_schemes()[name]
  442. for key in SCHEME_KEYS:
  443. attrname = 'install_' + key
  444. if getattr(self, attrname) is None:
  445. setattr(self, attrname, scheme[key])
  446. def _expand_attrs(self, attrs):
  447. for attr in attrs:
  448. val = getattr(self, attr)
  449. if val is not None:
  450. if os.name == 'posix' or os.name == 'nt':
  451. val = os.path.expanduser(val)
  452. val = subst_vars(val, self.config_vars)
  453. setattr(self, attr, val)
  454. def expand_basedirs(self):
  455. """Calls `os.path.expanduser` on install_base, install_platbase and
  456. root."""
  457. self._expand_attrs(['install_base', 'install_platbase', 'root'])
  458. def expand_dirs(self):
  459. """Calls `os.path.expanduser` on install dirs."""
  460. self._expand_attrs(['install_purelib', 'install_platlib',
  461. 'install_lib', 'install_headers',
  462. 'install_scripts', 'install_data',])
  463. def convert_paths(self, *names):
  464. """Call `convert_path` over `names`."""
  465. for name in names:
  466. attr = "install_" + name
  467. setattr(self, attr, convert_path(getattr(self, attr)))
  468. def handle_extra_path(self):
  469. """Set `path_file` and `extra_dirs` using `extra_path`."""
  470. if self.extra_path is None:
  471. self.extra_path = self.distribution.extra_path
  472. if self.extra_path is not None:
  473. log.warn(
  474. "Distribution option extra_path is deprecated. "
  475. "See issue27919 for details."
  476. )
  477. if isinstance(self.extra_path, str):
  478. self.extra_path = self.extra_path.split(',')
  479. if len(self.extra_path) == 1:
  480. path_file = extra_dirs = self.extra_path[0]
  481. elif len(self.extra_path) == 2:
  482. path_file, extra_dirs = self.extra_path
  483. else:
  484. raise DistutilsOptionError(
  485. "'extra_path' option must be a list, tuple, or "
  486. "comma-separated string with 1 or 2 elements")
  487. # convert to local form in case Unix notation used (as it
  488. # should be in setup scripts)
  489. extra_dirs = convert_path(extra_dirs)
  490. else:
  491. path_file = None
  492. extra_dirs = ''
  493. # XXX should we warn if path_file and not extra_dirs? (in which
  494. # case the path file would be harmless but pointless)
  495. self.path_file = path_file
  496. self.extra_dirs = extra_dirs
  497. def change_roots(self, *names):
  498. """Change the install directories pointed by name using root."""
  499. for name in names:
  500. attr = "install_" + name
  501. setattr(self, attr, change_root(self.root, getattr(self, attr)))
  502. def create_home_path(self):
  503. """Create directories under ~."""
  504. if not self.user:
  505. return
  506. home = convert_path(os.path.expanduser("~"))
  507. for name, path in self.config_vars.items():
  508. if path.startswith(home) and not os.path.isdir(path):
  509. self.debug_print("os.makedirs('%s', 0o700)" % path)
  510. os.makedirs(path, 0o700)
  511. # -- Command execution methods -------------------------------------
  512. def run(self):
  513. """Runs the command."""
  514. # Obviously have to build before we can install
  515. if not self.skip_build:
  516. self.run_command('build')
  517. # If we built for any other platform, we can't install.
  518. build_plat = self.distribution.get_command_obj('build').plat_name
  519. # check warn_dir - it is a clue that the 'install' is happening
  520. # internally, and not to sys.path, so we don't check the platform
  521. # matches what we are running.
  522. if self.warn_dir and build_plat != get_platform():
  523. raise DistutilsPlatformError("Can't install when "
  524. "cross-compiling")
  525. # Run all sub-commands (at least those that need to be run)
  526. for cmd_name in self.get_sub_commands():
  527. self.run_command(cmd_name)
  528. if self.path_file:
  529. self.create_path_file()
  530. # write list of installed files, if requested.
  531. if self.record:
  532. outputs = self.get_outputs()
  533. if self.root: # strip any package prefix
  534. root_len = len(self.root)
  535. for counter in range(len(outputs)):
  536. outputs[counter] = outputs[counter][root_len:]
  537. self.execute(write_file,
  538. (self.record, outputs),
  539. "writing list of installed files to '%s'" %
  540. self.record)
  541. sys_path = map(os.path.normpath, sys.path)
  542. sys_path = map(os.path.normcase, sys_path)
  543. install_lib = os.path.normcase(os.path.normpath(self.install_lib))
  544. if (self.warn_dir and
  545. not (self.path_file and self.install_path_file) and
  546. install_lib not in sys_path):
  547. log.debug(("modules installed to '%s', which is not in "
  548. "Python's module search path (sys.path) -- "
  549. "you'll have to change the search path yourself"),
  550. self.install_lib)
  551. def create_path_file(self):
  552. """Creates the .pth file"""
  553. filename = os.path.join(self.install_libbase,
  554. self.path_file + ".pth")
  555. if self.install_path_file:
  556. self.execute(write_file,
  557. (filename, [self.extra_dirs]),
  558. "creating %s" % filename)
  559. else:
  560. self.warn("path file '%s' not created" % filename)
  561. # -- Reporting methods ---------------------------------------------
  562. def get_outputs(self):
  563. """Assembles the outputs of all the sub-commands."""
  564. outputs = []
  565. for cmd_name in self.get_sub_commands():
  566. cmd = self.get_finalized_command(cmd_name)
  567. # Add the contents of cmd.get_outputs(), ensuring
  568. # that outputs doesn't contain duplicate entries
  569. for filename in cmd.get_outputs():
  570. if filename not in outputs:
  571. outputs.append(filename)
  572. if self.path_file and self.install_path_file:
  573. outputs.append(os.path.join(self.install_libbase,
  574. self.path_file + ".pth"))
  575. return outputs
  576. def get_inputs(self):
  577. """Returns the inputs of all the sub-commands"""
  578. # XXX gee, this looks familiar ;-(
  579. inputs = []
  580. for cmd_name in self.get_sub_commands():
  581. cmd = self.get_finalized_command(cmd_name)
  582. inputs.extend(cmd.get_inputs())
  583. return inputs
  584. # -- Predicates for sub-command list -------------------------------
  585. def has_lib(self):
  586. """Returns true if the current distribution has any Python
  587. modules to install."""
  588. return (self.distribution.has_pure_modules() or
  589. self.distribution.has_ext_modules())
  590. def has_headers(self):
  591. """Returns true if the current distribution has any headers to
  592. install."""
  593. return self.distribution.has_headers()
  594. def has_scripts(self):
  595. """Returns true if the current distribution has any scripts to.
  596. install."""
  597. return self.distribution.has_scripts()
  598. def has_data(self):
  599. """Returns true if the current distribution has any data to.
  600. install."""
  601. return self.distribution.has_data_files()
  602. # 'sub_commands': a list of commands this command might have to run to
  603. # get its work done. See cmd.py for more info.
  604. sub_commands = [('install_lib', has_lib),
  605. ('install_headers', has_headers),
  606. ('install_scripts', has_scripts),
  607. ('install_data', has_data),
  608. ('install_egg_info', lambda self:True),
  609. ]