summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2012-06-24 07:27:43 (GMT)
committerÉric Araujo <merwok@netwok.org>2012-06-24 07:27:43 (GMT)
commitec177c14d326a06204f0922bc61565b60589ba82 (patch)
treea4d0ed1a9eb3e468df71174829c5a4425bf0f9d5
parent853ef475228e6fb9683209b361878e8f610e3762 (diff)
downloadcpython-ec177c14d326a06204f0922bc61565b60589ba82.zip
cpython-ec177c14d326a06204f0922bc61565b60589ba82.tar.gz
cpython-ec177c14d326a06204f0922bc61565b60589ba82.tar.bz2
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.
-rw-r--r--Lib/sysconfig.cfg110
-rw-r--r--Lib/sysconfig.py170
-rwxr-xr-xLib/test/regrtest.py18
-rw-r--r--Lib/test/test_sysconfig.py15
-rw-r--r--Makefile.pre.in2
5 files changed, 114 insertions, 201 deletions
diff --git a/Lib/sysconfig.cfg b/Lib/sysconfig.cfg
deleted file mode 100644
index a8d62b9..0000000
--- a/Lib/sysconfig.cfg
+++ /dev/null
@@ -1,110 +0,0 @@
-[globals]
-# These are useful categories that can be referenced at run time.
-# Configuration files
-config = {confdir}/{distribution.name}
-# Non-writable data that is independent of architecture (images, many xml/text files)
-appdata = {datadir}/{distribution.name}
-# Non-writable data that is architecture-dependent (some binary data formats)
-appdata.arch = {libdir}/{distribution.name}
-# Data, written by the app/lib, that must be preserved (databases)
-appdata.persistent = {statedir}/lib/{distribution.name}
-# Data, written by the app/lib, that can be safely discarded (cache)
-appdata.disposable = {statedir}/cache/{distribution.name}
-# Help or documentation files
-help = {datadir}/{distribution.name}
-icon = {datadir}/pixmaps
-scripts = {base}/bin
-
-# Non-runtime files. These are valid categories for marking files for
-# install, but they should not be referenced by the app/lib at run time.
-# Help or documentation files
-doc = {datadir}/doc/{distribution.name}
-# GNU info documentation files
-info = {datadir}/info
-# man pages
-man = {datadir}/man
-
-[posix_prefix]
-# Configuration directories. Some of these come straight out of the
-# configure script. They are for implementing the other variables, not to
-# be used directly in [resource_locations].
-confdir = /etc
-datadir = /usr/share
-libdir = /usr/lib
-statedir = /var
-# User resource directory
-local = ~/.local/{distribution.name}
-
-stdlib = {installed_base}/lib/python{py_version_short}
-platstdlib = {platbase}/lib/python{py_version_short}
-purelib = {base}/lib/python{py_version_short}/site-packages
-platlib = {platbase}/lib/python{py_version_short}/site-packages
-include = {installed_base}/include/python{py_version_short}{abiflags}
-platinclude = {installed_platbase}/include/python{py_version_short}{abiflags}
-data = {base}
-
-[posix_home]
-stdlib = {installed_base}/lib/python
-platstdlib = {base}/lib/python
-purelib = {base}/lib/python
-platlib = {base}/lib/python
-include = {installed_base}/include/python
-platinclude = {installed_base}/include/python
-scripts = {base}/bin
-data = {base}
-
-[nt]
-stdlib = {installed_base}/Lib
-platstdlib = {base}/Lib
-purelib = {base}/Lib/site-packages
-platlib = {base}/Lib/site-packages
-include = {installed_base}/Include
-platinclude = {installed_base}/Include
-scripts = {base}/Scripts
-data = {base}
-
-[os2]
-stdlib = {installed_base}/Lib
-platstdlib = {base}/Lib
-purelib = {base}/Lib/site-packages
-platlib = {base}/Lib/site-packages
-include = {installed_base}/Include
-platinclude = {installed_base}/Include
-scripts = {base}/Scripts
-data = {base}
-
-[os2_home]
-stdlib = {userbase}/lib/python{py_version_short}
-platstdlib = {userbase}/lib/python{py_version_short}
-purelib = {userbase}/lib/python{py_version_short}/site-packages
-platlib = {userbase}/lib/python{py_version_short}/site-packages
-include = {userbase}/include/python{py_version_short}
-scripts = {userbase}/bin
-data = {userbase}
-
-[nt_user]
-stdlib = {userbase}/Python{py_version_nodot}
-platstdlib = {userbase}/Python{py_version_nodot}
-purelib = {userbase}/Python{py_version_nodot}/site-packages
-platlib = {userbase}/Python{py_version_nodot}/site-packages
-include = {userbase}/Python{py_version_nodot}/Include
-scripts = {userbase}/Scripts
-data = {userbase}
-
-[posix_user]
-stdlib = {userbase}/lib/python{py_version_short}
-platstdlib = {userbase}/lib/python{py_version_short}
-purelib = {userbase}/lib/python{py_version_short}/site-packages
-platlib = {userbase}/lib/python{py_version_short}/site-packages
-include = {userbase}/include/python{py_version_short}
-scripts = {userbase}/bin
-data = {userbase}
-
-[osx_framework_user]
-stdlib = {userbase}/lib/python
-platstdlib = {userbase}/lib/python
-purelib = {userbase}/lib/python/site-packages
-platlib = {userbase}/lib/python/site-packages
-include = {userbase}/include
-scripts = {userbase}/bin
-data = {userbase}
diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py
index 00bd0b9..2f5d9d0 100644
--- a/Lib/sysconfig.py
+++ b/Lib/sysconfig.py
@@ -3,9 +3,7 @@
import os
import re
import sys
-import os
from os.path import pardir, realpath
-from configparser import RawConfigParser
__all__ = [
'get_config_h_filename',
@@ -21,46 +19,89 @@ __all__ = [
'parse_config_h',
]
-# let's read the configuration file
-# XXX _CONFIG_DIR will be set by the Makefile later
-_CONFIG_DIR = os.path.normpath(os.path.dirname(__file__))
-_CONFIG_FILE = os.path.join(_CONFIG_DIR, 'sysconfig.cfg')
-_SCHEMES = RawConfigParser(dict_type=dict) # Faster than OrderedDict
-_SCHEMES.read(_CONFIG_FILE)
-_VAR_REPL = re.compile(r'\{([^{]*?)\}')
-
-
-def _expand_globals(config):
- if config.has_section('globals'):
- globals = config.items('globals')
- else:
- globals = tuple()
-
- sections = config.sections()
- for section in sections:
- if section == 'globals':
- continue
- for option, value in globals:
- if config.has_option(section, option):
- continue
- 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)
+_INSTALL_SCHEMES = {
+ 'posix_prefix': {
+ 'stdlib': '{installed_base}/lib/python{py_version_short}',
+ 'platstdlib': '{platbase}/lib/python{py_version_short}',
+ 'purelib': '{base}/lib/python{py_version_short}/site-packages',
+ 'platlib': '{platbase}/lib/python{py_version_short}/site-packages',
+ 'include':
+ '{installed_base}/include/python{py_version_short}{abiflags}',
+ 'platinclude':
+ '{installed_platbase}/include/python{py_version_short}{abiflags}',
+ 'scripts': '{base}/bin',
+ 'data': '{base}',
+ },
+ 'posix_home': {
+ 'stdlib': '{installed_base}/lib/python',
+ 'platstdlib': '{base}/lib/python',
+ 'purelib': '{base}/lib/python',
+ 'platlib': '{base}/lib/python',
+ 'include': '{installed_base}/include/python',
+ 'platinclude': '{installed_base}/include/python',
+ 'scripts': '{base}/bin',
+ 'data': '{base}',
+ },
+ 'nt': {
+ 'stdlib': '{installed_base}/Lib',
+ 'platstdlib': '{base}/Lib',
+ 'purelib': '{base}/Lib/site-packages',
+ 'platlib': '{base}/Lib/site-packages',
+ 'include': '{installed_base}/Include',
+ 'platinclude': '{installed_base}/Include',
+ 'scripts': '{base}/Scripts',
+ 'data': '{base}',
+ },
+ 'os2': {
+ 'stdlib': '{installed_base}/Lib',
+ 'platstdlib': '{base}/Lib',
+ 'purelib': '{base}/Lib/site-packages',
+ 'platlib': '{base}/Lib/site-packages',
+ 'include': '{installed_base}/Include',
+ 'platinclude': '{installed_base}/Include',
+ 'scripts': '{base}/Scripts',
+ 'data': '{base}',
+ },
+ 'os2_home': {
+ 'stdlib': '{userbase}/lib/python{py_version_short}',
+ 'platstdlib': '{userbase}/lib/python{py_version_short}',
+ 'purelib': '{userbase}/lib/python{py_version_short}/site-packages',
+ 'platlib': '{userbase}/lib/python{py_version_short}/site-packages',
+ 'include': '{userbase}/include/python{py_version_short}',
+ 'scripts': '{userbase}/bin',
+ 'data': '{userbase}',
+ },
+ 'nt_user': {
+ 'stdlib': '{userbase}/Python{py_version_nodot}',
+ 'platstdlib': '{userbase}/Python{py_version_nodot}',
+ 'purelib': '{userbase}/Python{py_version_nodot}/site-packages',
+ 'platlib': '{userbase}/Python{py_version_nodot}/site-packages',
+ 'include': '{userbase}/Python{py_version_nodot}/Include',
+ 'scripts': '{userbase}/Scripts',
+ 'data': '{userbase}',
+ },
+ 'posix_user': {
+ 'stdlib': '{userbase}/lib/python{py_version_short}',
+ 'platstdlib': '{userbase}/lib/python{py_version_short}',
+ 'purelib': '{userbase}/lib/python{py_version_short}/site-packages',
+ 'platlib': '{userbase}/lib/python{py_version_short}/site-packages',
+ 'include': '{userbase}/include/python{py_version_short}',
+ 'scripts': '{userbase}/bin',
+ 'data': '{userbase}',
+ },
+ 'osx_framework_user': {
+ 'stdlib': '{userbase}/lib/python',
+ 'platstdlib': '{userbase}/lib/python',
+ 'purelib': '{userbase}/lib/python/site-packages',
+ 'platlib': '{userbase}/lib/python/site-packages',
+ 'include': '{userbase}/include',
+ 'scripts': '{userbase}/bin',
+ 'data': '{userbase}',
+ },
+ }
+
+_SCHEME_KEYS = ('stdlib', 'platstdlib', 'purelib', 'platlib', 'include',
+ 'scripts', 'data')
# FIXME don't rely on sys.version here, its format is an implementation detail
# of CPython, use sys.version_info or sys.hexversion
@@ -118,25 +159,18 @@ _PYTHON_BUILD = is_python_build(True)
if _PYTHON_BUILD:
for scheme in ('posix_prefix', 'posix_home'):
- _SCHEMES.set(scheme, 'include', '{srcdir}/Include')
- _SCHEMES.set(scheme, 'platinclude', '{projectbase}/.')
-
+ _INSTALL_SCHEMES[scheme]['include'] = '{srcdir}/Include'
+ _INSTALL_SCHEMES[scheme]['platinclude'] = '{projectbase}/.'
-def _subst_vars(path, local_vars):
- """In the string `path`, replace tokens like {some.thing} with the
- corresponding value from the map `local_vars`.
-
- If there is no corresponding value, leave the token unchanged.
- """
- def _replacer(matchobj):
- name = matchobj.group(1)
- if name in local_vars:
- return local_vars[name]
- elif name in os.environ:
- return os.environ[name]
- return matchobj.group(0)
- return _VAR_REPL.sub(_replacer, path)
+def _subst_vars(s, local_vars):
+ try:
+ return s.format(**local_vars)
+ except KeyError:
+ try:
+ return s.format(**os.environ)
+ except KeyError as var:
+ raise AttributeError('{%s}' % var)
def _extend_dict(target_dict, other_dict):
target_keys = target_dict.keys()
@@ -152,22 +186,13 @@ def _expand_vars(scheme, vars):
vars = {}
_extend_dict(vars, get_config_vars())
- for key, value in _SCHEMES.items(scheme):
+ for key, value in _INSTALL_SCHEMES[scheme].items():
if os.name in ('posix', 'nt'):
value = os.path.expanduser(value)
res[key] = os.path.normpath(_subst_vars(value, vars))
return res
-def format_value(value, vars):
- def _replacer(matchobj):
- name = matchobj.group(1)
- if name in vars:
- return vars[name]
- return matchobj.group(0)
- return _VAR_REPL.sub(_replacer, value)
-
-
def _get_default_scheme():
if os.name == 'posix':
# the default scheme for posix is posix_prefix
@@ -435,13 +460,12 @@ def get_config_h_filename():
def get_scheme_names():
"""Return a tuple containing the schemes names."""
- return tuple(sorted(_SCHEMES.sections()))
+ return tuple(sorted(_INSTALL_SCHEMES))
def get_path_names():
"""Return a tuple containing the paths names."""
- # xxx see if we want a static list
- return _SCHEMES.options('posix_prefix')
+ return _SCHEME_KEYS
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):
if expand:
return _expand_vars(scheme, vars)
else:
- return dict(_SCHEMES.items(scheme))
+ return _INSTALL_SCHEMES[scheme]
def get_path(name, scheme=_get_default_scheme(), vars=None, expand=True):
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index f528e63..90931e7 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -966,7 +966,7 @@ class saved_test_environment:
'logging._handlers', 'logging._handlerList', 'sys.gettrace',
'sys.warnoptions', 'threading._dangling',
'multiprocessing.process._dangling',
- 'sysconfig._CONFIG_VARS', 'sysconfig._SCHEMES',
+ 'sysconfig._CONFIG_VARS', 'sysconfig._INSTALL_SCHEMES',
'support.TESTFN',
)
@@ -1113,15 +1113,13 @@ class saved_test_environment:
sysconfig._CONFIG_VARS.clear()
sysconfig._CONFIG_VARS.update(saved[2])
- def get_sysconfig__SCHEMES(self):
- # it's mildly evil to look at the internal attribute, but it's easier
- # than copying a RawConfigParser object
- return (id(sysconfig._SCHEMES), sysconfig._SCHEMES._sections,
- sysconfig._SCHEMES._sections.copy())
- def restore_sysconfig__SCHEMES(self, saved):
- sysconfig._SCHEMES._sections = saved[1]
- sysconfig._SCHEMES._sections.clear()
- sysconfig._SCHEMES._sections.update(saved[2])
+ def get_sysconfig__INSTALL_SCHEMES(self):
+ return (id(sysconfig._INSTALL_SCHEMES), sysconfig._INSTALL_SCHEMES,
+ sysconfig._INSTALL_SCHEMES.copy())
+ def restore_sysconfig__INSTALL_SCHEMES(self, saved):
+ sysconfig._INSTALL_SCHEMES = saved[1]
+ sysconfig._INSTALL_SCHEMES.clear()
+ sysconfig._INSTALL_SCHEMES.update(saved[2])
def get_support_TESTFN(self):
if os.path.isfile(support.TESTFN):
diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py
index e583793..3cb63ed 100644
--- a/Lib/test/test_sysconfig.py
+++ b/Lib/test/test_sysconfig.py
@@ -10,7 +10,7 @@ from test.support import (run_unittest, TESTFN, unlink,
import sysconfig
from sysconfig import (get_paths, get_platform, get_config_vars,
- get_path, get_path_names, _SCHEMES,
+ get_path, get_path_names, _INSTALL_SCHEMES,
_get_default_scheme, _expand_vars,
get_scheme_names, get_config_var, _main)
@@ -36,8 +36,7 @@ class TestSysConfig(unittest.TestCase):
self.join = os.path.join
self.isabs = os.path.isabs
self.splitdrive = os.path.splitdrive
- self._config_vars = sysconfig._CONFIG_VARS
- sysconfig._CONFIG_VARS = copy(sysconfig._CONFIG_VARS)
+ self._config_vars = sysconfig._CONFIG_VARS, copy(sysconfig._CONFIG_VARS)
self._added_envvars = []
self._changed_envvars = []
for var in ('MACOSX_DEPLOYMENT_TARGET', 'PATH'):
@@ -60,7 +59,9 @@ class TestSysConfig(unittest.TestCase):
os.path.join = self.join
os.path.isabs = self.isabs
os.path.splitdrive = self.splitdrive
- sysconfig._CONFIG_VARS = self._config_vars
+ sysconfig._CONFIG_VARS = self._config_vars[0]
+ sysconfig._CONFIG_VARS.clear()
+ sysconfig._CONFIG_VARS.update(self._config_vars[1])
for var, value in self._changed_envvars:
os.environ[var] = value
for var in self._added_envvars:
@@ -82,7 +83,7 @@ class TestSysConfig(unittest.TestCase):
shutil.rmtree(path)
def test_get_path_names(self):
- self.assertEqual(get_path_names(), _SCHEMES.options('posix_prefix'))
+ self.assertEqual(get_path_names(), sysconfig._SCHEME_KEYS)
def test_get_paths(self):
scheme = get_paths()
@@ -94,8 +95,8 @@ class TestSysConfig(unittest.TestCase):
def test_get_path(self):
# XXX make real tests here
- for scheme in _SCHEMES:
- for name in _SCHEMES[scheme]:
+ for scheme in _INSTALL_SCHEMES:
+ for name in _INSTALL_SCHEMES[scheme]:
res = get_path(name, scheme)
def test_get_config_vars(self):
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 682ed32..2156847 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -1031,7 +1031,7 @@ libinstall: build_all $(srcdir)/Lib/$(PLATDIR) $(srcdir)/Modules/xxmodule.c
else true; \
fi; \
done
- @for i in $(srcdir)/Lib/*.py $(srcdir)/Lib/*.cfg ; \
+ @for i in $(srcdir)/Lib/*.py ; \
do \
if test -x $$i; then \
$(INSTALL_SCRIPT) $$i $(DESTDIR)$(LIBDEST); \