Skip to content

Commit 04346fd

Browse files
committed
Load install schemes from sysconfig
1 parent 8bbfeb3 commit 04346fd

File tree

3 files changed

+43
-38
lines changed

3 files changed

+43
-38
lines changed

Lib/distutils/command/install.py

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
Implements the Distutils 'install' command."""
44

55
import sys
6+
import sysconfig
67
import os
8+
import re
79

810
from distutils import log
911
from distutils.core import Command
@@ -20,33 +22,45 @@
2022

2123
HAS_USER_SITE = (USER_SITE is not None)
2224

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 installation scheme above,
27+
# 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 on single place.
34+
# This module is depracated anyway (PEP 632) so if anything
35+
# doesn't work for you, take a look at sysconfig.
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 different definition
62+
# that the one in sysconfig but because both depends on site module
63+
# the outcomes should be the same.
5064
if HAS_USER_SITE:
5165
INSTALL_SCHEMES['nt_user'] = {
5266
'purelib': '$usersite',
@@ -65,11 +79,6 @@
6579
'data' : '$userbase',
6680
}
6781

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-
7382

7483
class install(Command):
7584

Lib/sysconfig.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,6 @@ def is_python_build(check_home=False):
176176

177177
_PYTHON_BUILD = is_python_build(True)
178178

179-
if _PYTHON_BUILD:
180-
for scheme in ('posix_prefix', 'posix_home'):
181-
_INSTALL_SCHEMES[scheme]['include'] = '{srcdir}/Include'
182-
_INSTALL_SCHEMES[scheme]['platinclude'] = '{projectbase}/.'
183-
184-
185179
def _subst_vars(s, local_vars):
186180
try:
187181
return s.format(**local_vars)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Install schemes in :mod:`distutils.command.install` are now loaded from
2+
:mod:`sysconfig`.

0 commit comments

Comments
 (0)