| 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 |
|
| 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 |
|
| 37 |
|
| 38 |
|
| 39 |
SCHEME_KEYS = ('purelib', 'platlib', 'headers', 'scripts', 'data') |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
INSTALL_SCHEMES = {"unix_prefix": {}, "unix_home": {}, "nt": {}} |
| 48 |
|
| 49 |
|
| 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 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
sys_key = 'include' |
| 63 |
INSTALL_SCHEMES[distutils_scheme_name][key] = sys_scheme[sys_key] |
| 64 |
|
| 65 |
|
| 66 |
for main_key in INSTALL_SCHEMES: |
| 67 |
for key, value in INSTALL_SCHEMES[main_key].items(): |
| 68 |
|
| 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 |
|
| 76 |
value = value.replace("/lib/", "/$platlibdir/") |
| 77 |
INSTALL_SCHEMES[main_key][key] = value |
| 78 |
|
| •79 |
|
| 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 |
|
| 104 |
|
| 105 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 164 |
|
| 165 |
|
| 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 |
|
| 173 |
('force', 'f', |
| 174 |
"force installation (overwrite any existing files)"), |
| 175 |
('skip-build', None, |
| 176 |
"skip rebuilding everything (for testing/debugging)"), |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 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 |
|
| 204 |
|
| 205 |
self.prefix = None |
| 206 |
self.exec_prefix = None |
| 207 |
self.home = None |
| 208 |
self.user = 0 |
| •209 |
self.prefix_option = None |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
self.install_base = None |
| 215 |
self.install_platbase = None |
| 216 |
self.root = None |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
self.install_purelib = None |
| 223 |
self.install_platlib = None |
| 224 |
self.install_headers = None |
| 225 |
self.install_lib = None |
| 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 |
|
| 233 |
self.install_layout = None |
| 234 |
|
| 235 |
self.compile = None |
| 236 |
self.optimize = None |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
self.extra_path = None |
| 248 |
self.install_path_file = 1 |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
self.force = 0 |
| 257 |
self.skip_build = 0 |
| 258 |
self.warn_dir = 1 |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
self.build_base = None |
| 267 |
self.build_lib = None |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
self.record = None |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
def finalize_options(self): |
| 285 |
"""Finalizes options.""" |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 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 |
|
| 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 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 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 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 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 |
|
| 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 |
|
| 378 |
|
| 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 |
|
| 388 |
|
| 389 |
self.expand_dirs() |
| 390 |
|
| 391 |
self.dump_dirs("post-expand_dirs()") |
| 392 |
|
| 393 |
|
| 394 |
if self.user: |
| 395 |
self.create_home_path() |
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
if self.install_lib is None: |
| 402 |
if self.distribution.ext_modules: |
| 403 |
self.install_lib = self.install_platlib |
| 404 |
else: |
| 405 |
self.install_lib = self.install_purelib |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
self.convert_paths('lib', 'purelib', 'platlib', |
| 411 |
'scripts', 'data', 'headers') |
| 412 |
if HAS_USER_SITE: |
| 413 |
self.convert_paths('userbase', 'usersite') |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
self.handle_extra_path() |
| 421 |
self.install_libbase = self.install_lib |
| 422 |
self.install_lib = os.path.join(self.install_lib, self.extra_dirs) |
| 423 |
|
| 424 |
|
| 425 |
|
| 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 |
|
| 433 |
self.set_undefined_options('build', |
| 434 |
('build_base', 'build_base'), |
| 435 |
('build_lib', 'build_lib')) |
| 436 |
|
| 437 |
|
| 438 |
|
| 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 |
|
| 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 |
|
| 597 |
|
| 598 |
extra_dirs = convert_path(extra_dirs) |
| 599 |
else: |
| 600 |
path_file = None |
| 601 |
extra_dirs = '' |
| 602 |
|
| 603 |
|
| 604 |
|
| 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 |
|
| 625 |
|
| 626 |
def run(self): |
| 627 |
"""Runs the command.""" |
| 628 |
|
| 629 |
if not self.skip_build: |
| 630 |
self.run_command('build') |
| 631 |
|
| 632 |
build_plat = self.distribution.get_command_obj('build').plat_name |
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
if self.warn_dir and build_plat != get_platform(): |
| 637 |
raise DistutilsPlatformError("Can't install when " |
| 638 |
"cross-compiling") |
| 639 |
|
| 640 |
|
| 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 |
|
| 648 |
if self.record: |
| 649 |
outputs = self.get_outputs() |
| 650 |
if self.root: |
| 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 |
|
| 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 |
|
| 690 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 735 |
|
| 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 |
] |