bpo-41282: (PEP 632) Load install schemes from sysconfig (GH-24549) · python/cpython@341e8a9 (original) (raw)
`@@ -3,7 +3,9 @@
`
3
3
`Implements the Distutils 'install' command."""
`
4
4
``
5
5
`import sys
`
``
6
`+
import sysconfig
`
6
7
`import os
`
``
8
`+
import re
`
7
9
``
8
10
`from distutils import log
`
9
11
`from distutils.core import Command
`
`@@ -20,33 +22,45 @@
`
20
22
``
21
23
`HAS_USER_SITE = (USER_SITE is not None)
`
22
24
``
23
``
`-
WINDOWS_SCHEME = {
`
24
``
`-
'purelib': '$base/Lib/site-packages',
`
25
``
`-
'platlib': '$base/Lib/site-packages',
`
26
``
`-
'headers': '$base/Include/$dist_name',
`
27
``
`-
'scripts': '$base/Scripts',
`
28
``
`-
'data' : '$base',
`
29
``
`-
}
`
30
``
-
31
``
`-
INSTALL_SCHEMES = {
`
32
``
`-
'unix_prefix': {
`
33
``
`-
'purelib': '$base/lib/python$py_version_short/site-packages',
`
34
``
`-
'platlib': '$platbase/$platlibdir/python$py_version_short/site-packages',
`
35
``
`-
'headers': '$base/include/python$py_version_short$abiflags/$dist_name',
`
36
``
`-
'scripts': '$base/bin',
`
37
``
`-
'data' : '$base',
`
38
``
`-
},
`
39
``
`-
'unix_home': {
`
40
``
`-
'purelib': '$base/lib/python',
`
41
``
`-
'platlib': '$base/$platlibdir/python',
`
42
``
`-
'headers': '$base/include/python/$dist_name',
`
43
``
`-
'scripts': '$base/bin',
`
44
``
`-
'data' : '$base',
`
45
``
`-
},
`
46
``
`-
'nt': WINDOWS_SCHEME,
`
47
``
`-
}
`
48
``
-
49
``
`-
user site schemes
`
``
25
`+
The keys to an installation scheme; if any new types of files are to be
`
``
26
`+
installed, be sure to add an entry to every scheme in
`
``
27
`+
sysconfig._INSTALL_SCHEMES, and to SCHEME_KEYS here.
`
``
28
`+
SCHEME_KEYS = ('purelib', 'platlib', 'headers', 'scripts', 'data')
`
``
29
+
``
30
`+
The following code provides backward-compatible INSTALL_SCHEMES
`
``
31
`+
while making the sysconfig module the single point of truth.
`
``
32
`+
This makes it easier for OS distributions where they need to
`
``
33
`+
alter locations for packages installations in a single place.
`
``
34
`+
Note that this module is depracated (PEP 632); all consumers
`
``
35
`+
of this information should switch to using sysconfig directly.
`
``
36
`+
INSTALL_SCHEMES = {"unix_prefix": {}, "unix_home": {}, "nt": {}}
`
``
37
+
``
38
`+
Copy from sysconfig._INSTALL_SCHEMES
`
``
39
`+
for key in SCHEME_KEYS:
`
``
40
`+
sys_key = key
`
``
41
`+
if key == "headers":
`
``
42
`+
sys_key = "include"
`
``
43
`+
INSTALL_SCHEMES["unix_prefix"][key] = sysconfig._INSTALL_SCHEMES["posix_prefix"][sys_key]
`
``
44
`+
INSTALL_SCHEMES["unix_home"][key] = sysconfig._INSTALL_SCHEMES["posix_home"][sys_key]
`
``
45
`+
INSTALL_SCHEMES["nt"][key] = sysconfig._INSTALL_SCHEMES["nt"][sys_key]
`
``
46
+
``
47
`+
Transformation to different template format
`
``
48
`+
for main_key in INSTALL_SCHEMES:
`
``
49
`+
for key, value in INSTALL_SCHEMES[main_key].items():
`
``
50
`+
Change all ocurences of {variable} to $variable
`
``
51
`+
value = re.sub(r"{(.+?)}", r"$\g<1>", value)
`
``
52
`+
value = value.replace("$installed_base", "$base")
`
``
53
`+
value = value.replace("$py_version_nodot_plat", "$py_version_nodot")
`
``
54
`+
if key == "headers":
`
``
55
`+
value += "/$dist_name"
`
``
56
`+
if sys.version_info >= (3, 9) and key == "platlib":
`
``
57
`+
platlibdir is available since 3.9: bpo-1294959
`
``
58
`+
value = value.replace("/lib/", "/$platlibdir/")
`
``
59
`+
INSTALL_SCHEMES[main_key][key] = value
`
``
60
+
``
61
`+
The following part of INSTALL_SCHEMES has a different definition
`
``
62
`+
than the one in sysconfig, but because both depend on the site module,
`
``
63
`+
the outcomes should be the same.
`
50
64
`if HAS_USER_SITE:
`
51
65
`INSTALL_SCHEMES['nt_user'] = {
`
52
66
`'purelib': '$usersite',
`
`@@ -65,11 +79,6 @@
`
65
79
`'data' : '$userbase',
`
66
80
` }
`
67
81
``
68
``
`-
The keys to an installation scheme; if any new types of files are to be
`
69
``
`-
installed, be sure to add an entry to every installation scheme above,
`
70
``
`-
and to SCHEME_KEYS here.
`
71
``
`-
SCHEME_KEYS = ('purelib', 'platlib', 'headers', 'scripts', 'data')
`
72
``
-
73
82
``
74
83
`class install(Command):
`
75
84
``