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