summaryrefslogtreecommitdiff
path: root/src/distutils2
diff options
context:
space:
mode:
authorTarek Ziad? <tarek@ziade.org>2010-02-23 18:47:55 -0500
committerTarek Ziad? <tarek@ziade.org>2010-02-23 18:47:55 -0500
commit82811e474340b745a7ce7ed330f9e67cf116e519 (patch)
tree4fb03213fd54386ab64dcf7a1f6b6a77d680a58a /src/distutils2
parent1f413234732ac3790ad4195ce30752cd12409f7f (diff)
parent244050bad90f4444400c8d2557a0f3566135a801 (diff)
downloaddisutils2-82811e474340b745a7ce7ed330f9e67cf116e519.tar.gz
merge dance
Diffstat (limited to 'src/distutils2')
-rw-r--r--src/distutils2/_backport/sysconfig.py30
-rw-r--r--src/distutils2/_backport/tests/test_sysconfig.py19
2 files changed, 38 insertions, 11 deletions
diff --git a/src/distutils2/_backport/sysconfig.py b/src/distutils2/_backport/sysconfig.py
index 00ef5cc..f72ef5c 100644
--- a/src/distutils2/_backport/sysconfig.py
+++ b/src/distutils2/_backport/sysconfig.py
@@ -16,20 +16,33 @@ _CONFIG_DIR = os.path.normpath(os.path.dirname(__file__))
_CONFIG_FILE = os.path.join(_CONFIG_DIR, 'sysconfig.cfg')
_SCHEMES = ConfigParser()
_SCHEMES.read(_CONFIG_FILE)
+_VAR_REPL = re.compile(r'\{(.*?)\}')
-def _expand_globals():
- globals = _SCHEMES.items('globals')
- sections = _SCHEMES.sections()
+def _expand_globals(config):
+ globals = config.items('globals')
+ sections = config.sections()
for section in sections:
if section == 'globals':
continue
for option, value in globals:
- if _SCHEMES.has_option(section, option):
+ if config.has_option(section, option):
continue
- _SCHEMES.set(section, option, value)
- _SCHEMES.remove_section('globals')
-
-_expand_globals()
+ config.set(section, option, value)
+ config.remove_section('globals')
+
+ # now expanding local variables defined in the cfg file
+ #
+ for section in config.sections():
+ variables = dict(config.items(section))
+ def _replacer(matchobj):
+ name = matchobj.group(1)
+ if name in variables:
+ return variables[name]
+ return matchobj.group(0)
+ for option, value in config.items(section):
+ config.set(section, option, _VAR_REPL.sub(_replacer, value))
+
+_expand_globals(_SCHEMES)
_PY_VERSION = sys.version.split()[0]
_PY_VERSION_SHORT = sys.version[:3]
@@ -60,7 +73,6 @@ if _PYTHON_BUILD:
_SCHEMES.set(scheme, 'include', '{projectbase}/Include')
_SCHEMES.set(scheme, 'platinclude', '{srcdir}')
-_VAR_REPL = re.compile(r'\{(.*?)\}')
def _subst_vars(path, local_vars):
# simple curly-braces replacement
diff --git a/src/distutils2/_backport/tests/test_sysconfig.py b/src/distutils2/_backport/tests/test_sysconfig.py
index 1961991..5bc98cf 100644
--- a/src/distutils2/_backport/tests/test_sysconfig.py
+++ b/src/distutils2/_backport/tests/test_sysconfig.py
@@ -9,14 +9,16 @@ import sys
import os
import shutil
from copy import copy, deepcopy
+from ConfigParser import ConfigParser
from test.test_support import run_unittest, TESTFN
import distutils2._backport.sysconfig
-from distutils2._backport.sysconfig import (get_paths, get_platform, get_config_vars,
+from distutils2._backport.sysconfig import (get_paths, get_platform,
+ get_config_vars, _expand_globals,
get_path, get_path_names,
_get_default_scheme, _expand_vars,
- get_scheme_names)
+ get_scheme_names, _CONFIG_FILE)
class TestSysConfig(unittest2.TestCase):
@@ -229,6 +231,19 @@ class TestSysConfig(unittest2.TestCase):
'posix_prefix', 'posix_user')
self.assertEquals(get_scheme_names(), wanted)
+ def test_expand_globals(self):
+
+ config = ConfigParser()
+ config.add_section('globals')
+ config.set('globals', 'foo', 'ok')
+ config.add_section('posix')
+ config.set('posix', 'config', '/etc')
+ config.set('posix', 'more', '{config}/ok')
+
+ _expand_globals(config)
+
+ self.assertEquals(config.get('posix', 'foo'), 'ok')
+ self.assertEquals(config.get('posix', 'more'), '/etc/ok')
def test_suite():
return unittest2.makeSuite(TestSysConfig)