Skip to content

Commit bd79768

Browse files
author
Tarek Ziadé
committed
Merged revisions 77919,77921-77922 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r77919 | tarek.ziade | 2010-02-02 23:50:23 +0100 (Tue, 02 Feb 2010) | 1 line module reorganization + missing doctests ........ r77921 | tarek.ziade | 2010-02-02 23:54:28 +0100 (Tue, 02 Feb 2010) | 1 line sysconfig.get_scheme_names now returns a sorted tuple ........ r77922 | tarek.ziade | 2010-02-02 23:55:00 +0100 (Tue, 02 Feb 2010) | 1 line fixed a typo on distutils.sysconfig. thanks arfever ........
1 parent f06917e commit bd79768

File tree

3 files changed

+54
-40
lines changed

3 files changed

+54
-40
lines changed

Lib/distutils/sysconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Email: <fdrake@acm.org>
1010
1111
**This module has been moved out of Distutils and will be removed from
12-
Python in the next version (3.2)**
12+
Python in the next version (3.3)**
1313
"""
1414

1515
__revision__ = "$Id$"

Lib/sysconfig.py

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -239,49 +239,12 @@ def _parse_makefile(filename, vars=None):
239239
vars.update(done)
240240
return vars
241241

242-
def parse_config_h(fp, vars=None):
243-
"""Parse a config.h-style file.
244-
245-
A dictionary containing name/value pairs is returned. If an
246-
optional dictionary is passed in as the second argument, it is
247-
used instead of a new dictionary.
248-
"""
249-
import re
250-
if vars is None:
251-
vars = {}
252-
define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
253-
undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
254-
255-
while True:
256-
line = fp.readline()
257-
if not line:
258-
break
259-
m = define_rx.match(line)
260-
if m:
261-
n, v = m.group(1, 2)
262-
try: v = int(v)
263-
except ValueError: pass
264-
vars[n] = v
265-
else:
266-
m = undef_rx.match(line)
267-
if m:
268-
vars[m.group(1)] = 0
269-
return vars
270242

271243
def _get_makefile_filename():
272244
if _PYTHON_BUILD:
273245
return os.path.join(_PROJECT_BASE, "Makefile")
274246
return os.path.join(get_path('stdlib'), "config", "Makefile")
275247

276-
def get_config_h_filename():
277-
if _PYTHON_BUILD:
278-
if os.name == "nt":
279-
inc_dir = os.path.join(_PROJECT_BASE, "PC")
280-
else:
281-
inc_dir = _PROJECT_BASE
282-
else:
283-
inc_dir = get_path('platinclude')
284-
return os.path.join(inc_dir, 'pyconfig.h')
285248

286249
def _init_posix(vars):
287250
"""Initialize the module as appropriate for POSIX systems."""
@@ -339,10 +302,55 @@ def _init_non_posix(vars):
339302
# public APIs
340303
#
341304

305+
306+
def parse_config_h(fp, vars=None):
307+
"""Parse a config.h-style file.
308+
309+
A dictionary containing name/value pairs is returned. If an
310+
optional dictionary is passed in as the second argument, it is
311+
used instead of a new dictionary.
312+
"""
313+
import re
314+
if vars is None:
315+
vars = {}
316+
define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
317+
undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
318+
319+
while True:
320+
line = fp.readline()
321+
if not line:
322+
break
323+
m = define_rx.match(line)
324+
if m:
325+
n, v = m.group(1, 2)
326+
try: v = int(v)
327+
except ValueError: pass
328+
vars[n] = v
329+
else:
330+
m = undef_rx.match(line)
331+
if m:
332+
vars[m.group(1)] = 0
333+
return vars
334+
335+
def get_config_h_filename():
336+
"""Returns the path of pyconfig.h."""
337+
if _PYTHON_BUILD:
338+
if os.name == "nt":
339+
inc_dir = os.path.join(_PROJECT_BASE, "PC")
340+
else:
341+
inc_dir = _PROJECT_BASE
342+
else:
343+
inc_dir = get_path('platinclude')
344+
return os.path.join(inc_dir, 'pyconfig.h')
345+
342346
def get_scheme_names():
343-
return _INSTALL_SCHEMES.keys()
347+
"""Returns a tuple containing the schemes names."""
348+
schemes = list(_INSTALL_SCHEMES.keys())
349+
schemes.sort()
350+
return tuple(schemes)
344351

345352
def get_path_names():
353+
"""Returns a tuple containing the paths names."""
346354
return _SCHEME_KEYS
347355

348356
def get_paths(scheme=_get_default_scheme(), vars=None, expand=True):

Lib/test/test_sysconfig.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
import sysconfig
1616
from sysconfig import (get_paths, get_platform, get_config_vars,
1717
get_path, get_path_names, _INSTALL_SCHEMES,
18-
_get_default_scheme, _expand_vars)
18+
_get_default_scheme, _expand_vars,
19+
get_scheme_names)
1920

2021
class TestSysConfig(unittest.TestCase):
2122

@@ -232,6 +233,11 @@ def test_get_config_h_filename(self):
232233
config_h = sysconfig.get_config_h_filename()
233234
self.assertTrue(os.path.isfile(config_h), config_h)
234235

236+
def test_get_scheme_names(self):
237+
wanted = ('nt', 'nt_user', 'os2', 'os2_home', 'posix_home',
238+
'posix_prefix', 'posix_user')
239+
self.assertEquals(get_scheme_names(), wanted)
240+
235241

236242
def test_main():
237243
run_unittest(TestSysConfig)

0 commit comments

Comments
 (0)