Debian Codegraph @

lib-python/3/distutils/command/install.py

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