Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ec177c1

Browse files
committed
Packaging removal: also revert introduction of sysconfig.cfg.
We need a discussion to define what should be customized how; this new config file is premature. It was added to serve the needs of the resources system in install_data / packaging.database, so it can be removed alongside packaging for 3.3.
1 parent 853ef47 commit ec177c1

5 files changed

Lines changed: 114 additions & 201 deletions

File tree

Lib/sysconfig.cfg

Lines changed: 0 additions & 110 deletions
This file was deleted.

Lib/sysconfig.py

Lines changed: 97 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import os
44
import re
55
import sys
6-
import os
76
from os.path import pardir, realpath
8-
from configparser import RawConfigParser
97

108
__all__ = [
119
'get_config_h_filename',
@@ -21,46 +19,89 @@
2119
'parse_config_h',
2220
]
2321

24-
# let's read the configuration file
25-
# XXX _CONFIG_DIR will be set by the Makefile later
26-
_CONFIG_DIR = os.path.normpath(os.path.dirname(__file__))
27-
_CONFIG_FILE = os.path.join(_CONFIG_DIR, 'sysconfig.cfg')
28-
_SCHEMES = RawConfigParser(dict_type=dict) # Faster than OrderedDict
29-
_SCHEMES.read(_CONFIG_FILE)
30-
_VAR_REPL = re.compile(r'\{([^{]*?)\}')
31-
32-
33-
def _expand_globals(config):
34-
if config.has_section('globals'):
35-
globals = config.items('globals')
36-
else:
37-
globals = tuple()
38-
39-
sections = config.sections()
40-
for section in sections:
41-
if section == 'globals':
42-
continue
43-
for option, value in globals:
44-
if config.has_option(section, option):
45-
continue
46-
config.set(section, option, value)
47-
config.remove_section('globals')
48-
49-
# now expanding local variables defined in the cfg file
50-
#
51-
for section in config.sections():
52-
variables = dict(config.items(section))
53-
54-
def _replacer(matchobj):
55-
name = matchobj.group(1)
56-
if name in variables:
57-
return variables[name]
58-
return matchobj.group(0)
59-
60-
for option, value in config.items(section):
61-
config.set(section, option, _VAR_REPL.sub(_replacer, value))
62-
63-
_expand_globals(_SCHEMES)
22+
_INSTALL_SCHEMES = {
23+
'posix_prefix': {
24+
'stdlib': '{installed_base}/lib/python{py_version_short}',
25+
'platstdlib': '{platbase}/lib/python{py_version_short}',
26+
'purelib': '{base}/lib/python{py_version_short}/site-packages',
27+
'platlib': '{platbase}/lib/python{py_version_short}/site-packages',
28+
'include':
29+
'{installed_base}/include/python{py_version_short}{abiflags}',
30+
'platinclude':
31+
'{installed_platbase}/include/python{py_version_short}{abiflags}',
32+
'scripts': '{base}/bin',
33+
'data': '{base}',
34+
},
35+
'posix_home': {
36+
'stdlib': '{installed_base}/lib/python',
37+
'platstdlib': '{base}/lib/python',
38+
'purelib': '{base}/lib/python',
39+
'platlib': '{base}/lib/python',
40+
'include': '{installed_base}/include/python',
41+
'platinclude': '{installed_base}/include/python',
42+
'scripts': '{base}/bin',
43+
'data': '{base}',
44+
},
45+
'nt': {
46+
'stdlib': '{installed_base}/Lib',
47+
'platstdlib': '{base}/Lib',
48+
'purelib': '{base}/Lib/site-packages',
49+
'platlib': '{base}/Lib/site-packages',
50+
'include': '{installed_base}/Include',
51+
'platinclude': '{installed_base}/Include',
52+
'scripts': '{base}/Scripts',
53+
'data': '{base}',
54+
},
55+
'os2': {
56+
'stdlib': '{installed_base}/Lib',
57+
'platstdlib': '{base}/Lib',
58+
'purelib': '{base}/Lib/site-packages',
59+
'platlib': '{base}/Lib/site-packages',
60+
'include': '{installed_base}/Include',
61+
'platinclude': '{installed_base}/Include',
62+
'scripts': '{base}/Scripts',
63+
'data': '{base}',
64+
},
65+
'os2_home': {
66+
'stdlib': '{userbase}/lib/python{py_version_short}',
67+
'platstdlib': '{userbase}/lib/python{py_version_short}',
68+
'purelib': '{userbase}/lib/python{py_version_short}/site-packages',
69+
'platlib': '{userbase}/lib/python{py_version_short}/site-packages',
70+
'include': '{userbase}/include/python{py_version_short}',
71+
'scripts': '{userbase}/bin',
72+
'data': '{userbase}',
73+
},
74+
'nt_user': {
75+
'stdlib': '{userbase}/Python{py_version_nodot}',
76+
'platstdlib': '{userbase}/Python{py_version_nodot}',
77+
'purelib': '{userbase}/Python{py_version_nodot}/site-packages',
78+
'platlib': '{userbase}/Python{py_version_nodot}/site-packages',
79+
'include': '{userbase}/Python{py_version_nodot}/Include',
80+
'scripts': '{userbase}/Scripts',
81+
'data': '{userbase}',
82+
},
83+
'posix_user': {
84+
'stdlib': '{userbase}/lib/python{py_version_short}',
85+
'platstdlib': '{userbase}/lib/python{py_version_short}',
86+
'purelib': '{userbase}/lib/python{py_version_short}/site-packages',
87+
'platlib': '{userbase}/lib/python{py_version_short}/site-packages',
88+
'include': '{userbase}/include/python{py_version_short}',
89+
'scripts': '{userbase}/bin',
90+
'data': '{userbase}',
91+
},
92+
'osx_framework_user': {
93+
'stdlib': '{userbase}/lib/python',
94+
'platstdlib': '{userbase}/lib/python',
95+
'purelib': '{userbase}/lib/python/site-packages',
96+
'platlib': '{userbase}/lib/python/site-packages',
97+
'include': '{userbase}/include',
98+
'scripts': '{userbase}/bin',
99+
'data': '{userbase}',
100+
},
101+
}
102+
103+
_SCHEME_KEYS = ('stdlib', 'platstdlib', 'purelib', 'platlib', 'include',
104+
'scripts', 'data')
64105

65106
# FIXME don't rely on sys.version here, its format is an implementation detail
66107
# of CPython, use sys.version_info or sys.hexversion
@@ -118,25 +159,18 @@ def is_python_build(check_home=False):
118159

119160
if _PYTHON_BUILD:
120161
for scheme in ('posix_prefix', 'posix_home'):
121-
_SCHEMES.set(scheme, 'include', '{srcdir}/Include')
122-
_SCHEMES.set(scheme, 'platinclude', '{projectbase}/.')
123-
162+
_INSTALL_SCHEMES[scheme]['include'] = '{srcdir}/Include'
163+
_INSTALL_SCHEMES[scheme]['platinclude'] = '{projectbase}/.'
124164

125-
def _subst_vars(path, local_vars):
126-
"""In the string `path`, replace tokens like {some.thing} with the
127-
corresponding value from the map `local_vars`.
128-
129-
If there is no corresponding value, leave the token unchanged.
130-
"""
131-
def _replacer(matchobj):
132-
name = matchobj.group(1)
133-
if name in local_vars:
134-
return local_vars[name]
135-
elif name in os.environ:
136-
return os.environ[name]
137-
return matchobj.group(0)
138-
return _VAR_REPL.sub(_replacer, path)
139165

166+
def _subst_vars(s, local_vars):
167+
try:
168+
return s.format(**local_vars)
169+
except KeyError:
170+
try:
171+
return s.format(**os.environ)
172+
except KeyError as var:
173+
raise AttributeError('{%s}' % var)
140174

141175
def _extend_dict(target_dict, other_dict):
142176
target_keys = target_dict.keys()
@@ -152,22 +186,13 @@ def _expand_vars(scheme, vars):
152186
vars = {}
153187
_extend_dict(vars, get_config_vars())
154188

155-
for key, value in _SCHEMES.items(scheme):
189+
for key, value in _INSTALL_SCHEMES[scheme].items():
156190
if os.name in ('posix', 'nt'):
157191
value = os.path.expanduser(value)
158192
res[key] = os.path.normpath(_subst_vars(value, vars))
159193
return res
160194

161195

162-
def format_value(value, vars):
163-
def _replacer(matchobj):
164-
name = matchobj.group(1)
165-
if name in vars:
166-
return vars[name]
167-
return matchobj.group(0)
168-
return _VAR_REPL.sub(_replacer, value)
169-
170-
171196
def _get_default_scheme():
172197
if os.name == 'posix':
173198
# the default scheme for posix is posix_prefix
@@ -435,13 +460,12 @@ def get_config_h_filename():
435460

436461
def get_scheme_names():
437462
"""Return a tuple containing the schemes names."""
438-
return tuple(sorted(_SCHEMES.sections()))
463+
return tuple(sorted(_INSTALL_SCHEMES))
439464

440465

441466
def get_path_names():
442467
"""Return a tuple containing the paths names."""
443-
# xxx see if we want a static list
444-
return _SCHEMES.options('posix_prefix')
468+
return _SCHEME_KEYS
445469

446470

447471
def get_paths(scheme=_get_default_scheme(), vars=None, expand=True):
@@ -453,7 +477,7 @@ def get_paths(scheme=_get_default_scheme(), vars=None, expand=True):
453477
if expand:
454478
return _expand_vars(scheme, vars)
455479
else:
456-
return dict(_SCHEMES.items(scheme))
480+
return _INSTALL_SCHEMES[scheme]
457481

458482

459483
def get_path(name, scheme=_get_default_scheme(), vars=None, expand=True):

Lib/test/regrtest.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ def __init__(self, testname, verbose=0, quiet=False):
966966
'logging._handlers', 'logging._handlerList', 'sys.gettrace',
967967
'sys.warnoptions', 'threading._dangling',
968968
'multiprocessing.process._dangling',
969-
'sysconfig._CONFIG_VARS', 'sysconfig._SCHEMES',
969+
'sysconfig._CONFIG_VARS', 'sysconfig._INSTALL_SCHEMES',
970970
'support.TESTFN',
971971
)
972972

@@ -1113,15 +1113,13 @@ def restore_sysconfig__CONFIG_VARS(self, saved):
11131113
sysconfig._CONFIG_VARS.clear()
11141114
sysconfig._CONFIG_VARS.update(saved[2])
11151115

1116-
def get_sysconfig__SCHEMES(self):
1117-
# it's mildly evil to look at the internal attribute, but it's easier
1118-
# than copying a RawConfigParser object
1119-
return (id(sysconfig._SCHEMES), sysconfig._SCHEMES._sections,
1120-
sysconfig._SCHEMES._sections.copy())
1121-
def restore_sysconfig__SCHEMES(self, saved):
1122-
sysconfig._SCHEMES._sections = saved[1]
1123-
sysconfig._SCHEMES._sections.clear()
1124-
sysconfig._SCHEMES._sections.update(saved[2])
1116+
def get_sysconfig__INSTALL_SCHEMES(self):
1117+
return (id(sysconfig._INSTALL_SCHEMES), sysconfig._INSTALL_SCHEMES,
1118+
sysconfig._INSTALL_SCHEMES.copy())
1119+
def restore_sysconfig__INSTALL_SCHEMES(self, saved):
1120+
sysconfig._INSTALL_SCHEMES = saved[1]
1121+
sysconfig._INSTALL_SCHEMES.clear()
1122+
sysconfig._INSTALL_SCHEMES.update(saved[2])
11251123

11261124
def get_support_TESTFN(self):
11271125
if os.path.isfile(support.TESTFN):

0 commit comments

Comments
 (0)