4
4
5
5
import sys
6
6
import os
7
+ import contextlib
8
+ import sysconfig
9
+ import itertools
7
10
8
11
from distutils import log
9
12
from distutils .core import Command
20
23
HAS_USER_SITE = True
21
24
22
25
WINDOWS_SCHEME = {
23
- 'purelib' : '$ base/Lib/site-packages' ,
24
- 'platlib' : '$ base/Lib/site-packages' ,
25
- 'headers' : '$ base/Include/$ dist_name' ,
26
- 'scripts' : '$ base/Scripts' ,
27
- 'data' : '$ base' ,
26
+ 'purelib' : '{ base} /Lib/site-packages' ,
27
+ 'platlib' : '{ base} /Lib/site-packages' ,
28
+ 'headers' : '{ base} /Include/{ dist_name} ' ,
29
+ 'scripts' : '{ base} /Scripts' ,
30
+ 'data' : '{ base} ' ,
28
31
}
29
32
30
33
INSTALL_SCHEMES = {
31
- 'unix_prefix ' : {
32
- 'purelib' : '$ base/lib/$ implementation_lower$ py_version_short/site-packages' ,
33
- 'platlib' : '$ platbase/$ platlibdir/$ implementation_lower$ py_version_short/site-packages' ,
34
- 'headers' : '$ base/include/$ implementation_lower$ py_version_short$ abiflags/$ dist_name' ,
35
- 'scripts' : '$ base/bin' ,
36
- 'data' : '$ base' ,
34
+ 'posix_prefix ' : {
35
+ 'purelib' : '{ base} /lib/{ implementation_lower}{ py_version_short} /site-packages' ,
36
+ 'platlib' : '{ platbase}/{ platlibdir}/{ implementation_lower}{ py_version_short} /site-packages' ,
37
+ 'headers' : '{ base} /include/{ implementation_lower}{ py_version_short}{ abiflags}/{ dist_name} ' ,
38
+ 'scripts' : '{ base} /bin' ,
39
+ 'data' : '{ base} ' ,
37
40
},
38
- 'unix_home ' : {
39
- 'purelib' : '$ base/lib/$ implementation_lower' ,
40
- 'platlib' : '$ base/$ platlibdir/$ implementation_lower' ,
41
- 'headers' : '$ base/include/$ implementation_lower/$ dist_name' ,
42
- 'scripts' : '$ base/bin' ,
43
- 'data' : '$ base' ,
41
+ 'posix_home ' : {
42
+ 'purelib' : '{ base} /lib/{ implementation_lower} ' ,
43
+ 'platlib' : '{ base}/{ platlibdir}/{ implementation_lower} ' ,
44
+ 'headers' : '{ base} /include/{ implementation_lower}/{ dist_name} ' ,
45
+ 'scripts' : '{ base} /bin' ,
46
+ 'data' : '{ base} ' ,
44
47
},
45
48
'nt' : WINDOWS_SCHEME ,
46
49
'pypy' : {
47
- 'purelib' : '$ base/site-packages' ,
48
- 'platlib' : '$ base/site-packages' ,
49
- 'headers' : '$ base/include/$ dist_name' ,
50
- 'scripts' : '$ base/bin' ,
51
- 'data' : '$ base' ,
50
+ 'purelib' : '{ base} /site-packages' ,
51
+ 'platlib' : '{ base} /site-packages' ,
52
+ 'headers' : '{ base} /include/{ dist_name} ' ,
53
+ 'scripts' : '{ base} /bin' ,
54
+ 'data' : '{ base} ' ,
52
55
},
53
56
'pypy_nt' : {
54
- 'purelib' : '$ base/site-packages' ,
55
- 'platlib' : '$ base/site-packages' ,
56
- 'headers' : '$ base/include/$ dist_name' ,
57
- 'scripts' : '$ base/Scripts' ,
58
- 'data' : '$ base' ,
57
+ 'purelib' : '{ base} /site-packages' ,
58
+ 'platlib' : '{ base} /site-packages' ,
59
+ 'headers' : '{ base} /include/{ dist_name} ' ,
60
+ 'scripts' : '{ base} /Scripts' ,
61
+ 'data' : '{ base} ' ,
59
62
},
60
63
}
61
64
62
65
# user site schemes
63
66
if HAS_USER_SITE :
64
67
INSTALL_SCHEMES ['nt_user' ] = {
65
- 'purelib' : '$ usersite' ,
66
- 'platlib' : '$ usersite' ,
67
- 'headers' : '$ userbase/$ implementation$ py_version_nodot/Include/$ dist_name' ,
68
- 'scripts' : '$ userbase/$ implementation$ py_version_nodot/Scripts' ,
69
- 'data' : '$ userbase' ,
68
+ 'purelib' : '{ usersite} ' ,
69
+ 'platlib' : '{ usersite} ' ,
70
+ 'headers' : '{ userbase}/{ implementation}{ py_version_nodot} /Include/{ dist_name} ' ,
71
+ 'scripts' : '{ userbase}/{ implementation}{ py_version_nodot} /Scripts' ,
72
+ 'data' : '{ userbase} ' ,
70
73
}
71
74
72
- INSTALL_SCHEMES ['unix_user ' ] = {
73
- 'purelib' : '$ usersite' ,
74
- 'platlib' : '$ usersite' ,
75
+ INSTALL_SCHEMES ['posix_user ' ] = {
76
+ 'purelib' : '{ usersite} ' ,
77
+ 'platlib' : '{ usersite} ' ,
75
78
'headers' :
76
- '$ userbase/include/$ implementation_lower$ py_version_short$ abiflags/$ dist_name' ,
77
- 'scripts' : '$ userbase/bin' ,
78
- 'data' : '$ userbase' ,
79
+ '{ userbase} /include/{ implementation_lower}{ py_version_short}{ abiflags}/{ dist_name} ' ,
80
+ 'scripts' : '{ userbase} /bin' ,
81
+ 'data' : '{ userbase} ' ,
79
82
}
80
83
81
84
# The keys to an installation scheme; if any new types of files are to be
82
85
# installed, be sure to add an entry to every installation scheme above,
83
86
# and to SCHEME_KEYS here.
84
87
SCHEME_KEYS = ('purelib' , 'platlib' , 'headers' , 'scripts' , 'data' )
85
88
89
+
90
+ def _load_sysconfig_schemes ():
91
+ with contextlib .suppress (AttributeError ):
92
+ return {
93
+ scheme : sysconfig .get_paths (scheme , expand = False )
94
+ for scheme in sysconfig .get_scheme_names ()
95
+ }
96
+
97
+
98
+ def _load_schemes ():
99
+ """
100
+ Extend default schemes with schemes from sysconfig.
101
+ """
102
+
103
+ sysconfig_schemes = _load_sysconfig_schemes () or {}
104
+
105
+ return {
106
+ scheme : {
107
+ ** INSTALL_SCHEMES .get (scheme , {}),
108
+ ** sysconfig_schemes .get (scheme , {}),
109
+ }
110
+ for scheme in set (itertools .chain (INSTALL_SCHEMES , sysconfig_schemes ))
111
+ }
112
+
113
+
86
114
def _get_implementation ():
87
115
if hasattr (sys , 'pypy_version_info' ):
88
116
return 'PyPy'
@@ -284,7 +312,7 @@ def finalize_options(self):
284
312
# input a heady brew of prefix, exec_prefix, home, install_base,
285
313
# install_platbase, user-supplied versions of
286
314
# install_{purelib,platlib,lib,scripts,data,...}, and the
287
- # INSTALL_SCHEME dictionary above . Phew!
315
+ # install schemes . Phew!
288
316
289
317
self .dump_dirs ("pre-finalize_{unix,other}" )
290
318
@@ -335,6 +363,8 @@ def finalize_options(self):
335
363
# everything else.
336
364
self .config_vars ['base' ] = self .install_base
337
365
self .config_vars ['platbase' ] = self .install_platbase
366
+ self .config_vars ['installed_base' ] = (
367
+ sysconfig .get_config_vars ()['installed_base' ])
338
368
339
369
if DEBUG :
340
370
from pprint import pprint
@@ -431,10 +461,10 @@ def finalize_unix(self):
431
461
raise DistutilsPlatformError (
432
462
"User base directory is not specified" )
433
463
self .install_base = self .install_platbase = self .install_userbase
434
- self .select_scheme ("unix_user " )
464
+ self .select_scheme ("posix_user " )
435
465
elif self .home is not None :
436
466
self .install_base = self .install_platbase = self .home
437
- self .select_scheme ("unix_home " )
467
+ self .select_scheme ("posix_home " )
438
468
else :
439
469
if self .prefix is None :
440
470
if self .exec_prefix is not None :
@@ -450,7 +480,7 @@ def finalize_unix(self):
450
480
451
481
self .install_base = self .prefix
452
482
self .install_platbase = self .exec_prefix
453
- self .select_scheme ("unix_prefix " )
483
+ self .select_scheme ("posix_prefix " )
454
484
455
485
def finalize_other (self ):
456
486
"""Finalizes options for non-posix platforms"""
@@ -462,7 +492,7 @@ def finalize_other(self):
462
492
self .select_scheme (os .name + "_user" )
463
493
elif self .home is not None :
464
494
self .install_base = self .install_platbase = self .home
465
- self .select_scheme ("unix_home " )
495
+ self .select_scheme ("posix_home " )
466
496
else :
467
497
if self .prefix is None :
468
498
self .prefix = os .path .normpath (sys .prefix )
@@ -484,7 +514,7 @@ def select_scheme(self, name):
484
514
name = 'pypy_nt'
485
515
else :
486
516
name = 'pypy'
487
- scheme = INSTALL_SCHEMES [name ]
517
+ scheme = _load_schemes () [name ]
488
518
for key in SCHEME_KEYS :
489
519
attrname = 'install_' + key
490
520
if getattr (self , attrname ) is None :
0 commit comments