mirror of
https://github.com/python/cpython.git
synced 2025-11-03 11:23:31 +00:00
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 ........
This commit is contained in:
parent
f06917ee6f
commit
bd797687bd
3 changed files with 54 additions and 40 deletions
|
|
@ -9,7 +9,7 @@ Written by: Fred L. Drake, Jr.
|
||||||
Email: <fdrake@acm.org>
|
Email: <fdrake@acm.org>
|
||||||
|
|
||||||
**This module has been moved out of Distutils and will be removed from
|
**This module has been moved out of Distutils and will be removed from
|
||||||
Python in the next version (3.2)**
|
Python in the next version (3.3)**
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__revision__ = "$Id$"
|
__revision__ = "$Id$"
|
||||||
|
|
|
||||||
|
|
@ -239,49 +239,12 @@ def _parse_makefile(filename, vars=None):
|
||||||
vars.update(done)
|
vars.update(done)
|
||||||
return vars
|
return vars
|
||||||
|
|
||||||
def parse_config_h(fp, vars=None):
|
|
||||||
"""Parse a config.h-style file.
|
|
||||||
|
|
||||||
A dictionary containing name/value pairs is returned. If an
|
|
||||||
optional dictionary is passed in as the second argument, it is
|
|
||||||
used instead of a new dictionary.
|
|
||||||
"""
|
|
||||||
import re
|
|
||||||
if vars is None:
|
|
||||||
vars = {}
|
|
||||||
define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
|
|
||||||
undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
|
|
||||||
|
|
||||||
while True:
|
|
||||||
line = fp.readline()
|
|
||||||
if not line:
|
|
||||||
break
|
|
||||||
m = define_rx.match(line)
|
|
||||||
if m:
|
|
||||||
n, v = m.group(1, 2)
|
|
||||||
try: v = int(v)
|
|
||||||
except ValueError: pass
|
|
||||||
vars[n] = v
|
|
||||||
else:
|
|
||||||
m = undef_rx.match(line)
|
|
||||||
if m:
|
|
||||||
vars[m.group(1)] = 0
|
|
||||||
return vars
|
|
||||||
|
|
||||||
def _get_makefile_filename():
|
def _get_makefile_filename():
|
||||||
if _PYTHON_BUILD:
|
if _PYTHON_BUILD:
|
||||||
return os.path.join(_PROJECT_BASE, "Makefile")
|
return os.path.join(_PROJECT_BASE, "Makefile")
|
||||||
return os.path.join(get_path('stdlib'), "config", "Makefile")
|
return os.path.join(get_path('stdlib'), "config", "Makefile")
|
||||||
|
|
||||||
def get_config_h_filename():
|
|
||||||
if _PYTHON_BUILD:
|
|
||||||
if os.name == "nt":
|
|
||||||
inc_dir = os.path.join(_PROJECT_BASE, "PC")
|
|
||||||
else:
|
|
||||||
inc_dir = _PROJECT_BASE
|
|
||||||
else:
|
|
||||||
inc_dir = get_path('platinclude')
|
|
||||||
return os.path.join(inc_dir, 'pyconfig.h')
|
|
||||||
|
|
||||||
def _init_posix(vars):
|
def _init_posix(vars):
|
||||||
"""Initialize the module as appropriate for POSIX systems."""
|
"""Initialize the module as appropriate for POSIX systems."""
|
||||||
|
|
@ -339,10 +302,55 @@ def _init_non_posix(vars):
|
||||||
# public APIs
|
# public APIs
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
|
def parse_config_h(fp, vars=None):
|
||||||
|
"""Parse a config.h-style file.
|
||||||
|
|
||||||
|
A dictionary containing name/value pairs is returned. If an
|
||||||
|
optional dictionary is passed in as the second argument, it is
|
||||||
|
used instead of a new dictionary.
|
||||||
|
"""
|
||||||
|
import re
|
||||||
|
if vars is None:
|
||||||
|
vars = {}
|
||||||
|
define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
|
||||||
|
undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
line = fp.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
m = define_rx.match(line)
|
||||||
|
if m:
|
||||||
|
n, v = m.group(1, 2)
|
||||||
|
try: v = int(v)
|
||||||
|
except ValueError: pass
|
||||||
|
vars[n] = v
|
||||||
|
else:
|
||||||
|
m = undef_rx.match(line)
|
||||||
|
if m:
|
||||||
|
vars[m.group(1)] = 0
|
||||||
|
return vars
|
||||||
|
|
||||||
|
def get_config_h_filename():
|
||||||
|
"""Returns the path of pyconfig.h."""
|
||||||
|
if _PYTHON_BUILD:
|
||||||
|
if os.name == "nt":
|
||||||
|
inc_dir = os.path.join(_PROJECT_BASE, "PC")
|
||||||
|
else:
|
||||||
|
inc_dir = _PROJECT_BASE
|
||||||
|
else:
|
||||||
|
inc_dir = get_path('platinclude')
|
||||||
|
return os.path.join(inc_dir, 'pyconfig.h')
|
||||||
|
|
||||||
def get_scheme_names():
|
def get_scheme_names():
|
||||||
return _INSTALL_SCHEMES.keys()
|
"""Returns a tuple containing the schemes names."""
|
||||||
|
schemes = list(_INSTALL_SCHEMES.keys())
|
||||||
|
schemes.sort()
|
||||||
|
return tuple(schemes)
|
||||||
|
|
||||||
def get_path_names():
|
def get_path_names():
|
||||||
|
"""Returns a tuple containing the paths names."""
|
||||||
return _SCHEME_KEYS
|
return _SCHEME_KEYS
|
||||||
|
|
||||||
def get_paths(scheme=_get_default_scheme(), vars=None, expand=True):
|
def get_paths(scheme=_get_default_scheme(), vars=None, expand=True):
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ from test.support import run_unittest, TESTFN
|
||||||
import sysconfig
|
import sysconfig
|
||||||
from sysconfig import (get_paths, get_platform, get_config_vars,
|
from sysconfig import (get_paths, get_platform, get_config_vars,
|
||||||
get_path, get_path_names, _INSTALL_SCHEMES,
|
get_path, get_path_names, _INSTALL_SCHEMES,
|
||||||
_get_default_scheme, _expand_vars)
|
_get_default_scheme, _expand_vars,
|
||||||
|
get_scheme_names)
|
||||||
|
|
||||||
class TestSysConfig(unittest.TestCase):
|
class TestSysConfig(unittest.TestCase):
|
||||||
|
|
||||||
|
|
@ -232,6 +233,11 @@ class TestSysConfig(unittest.TestCase):
|
||||||
config_h = sysconfig.get_config_h_filename()
|
config_h = sysconfig.get_config_h_filename()
|
||||||
self.assertTrue(os.path.isfile(config_h), config_h)
|
self.assertTrue(os.path.isfile(config_h), config_h)
|
||||||
|
|
||||||
|
def test_get_scheme_names(self):
|
||||||
|
wanted = ('nt', 'nt_user', 'os2', 'os2_home', 'posix_home',
|
||||||
|
'posix_prefix', 'posix_user')
|
||||||
|
self.assertEquals(get_scheme_names(), wanted)
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
run_unittest(TestSysConfig)
|
run_unittest(TestSysConfig)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue