2001-07-18 15:39:56 -03:00
|
|
|
"""Provide access to Python's configuration information. The specific
|
|
|
|
configuration variables available depend heavily on the platform and
|
|
|
|
configuration. The values may be retrieved using
|
|
|
|
get_config_var(name), and the list of variables is available via
|
|
|
|
get_config_vars().keys(). Additional convenience functions are also
|
|
|
|
available.
|
1998-12-18 19:46:33 -04:00
|
|
|
|
|
|
|
Written by: Fred L. Drake, Jr.
|
|
|
|
Email: <fdrake@acm.org>
|
2010-01-23 05:23:15 -04:00
|
|
|
|
|
|
|
**This module has been moved out of Distutils and will be removed from
|
2010-02-02 18:55:00 -04:00
|
|
|
Python in the next version (3.3)**
|
1998-12-18 19:46:33 -04:00
|
|
|
"""
|
|
|
|
|
2000-06-02 21:44:30 -03:00
|
|
|
__revision__ = "$Id$"
|
1998-12-18 19:46:33 -04:00
|
|
|
|
1999-01-06 10:46:06 -04:00
|
|
|
import re
|
2010-01-23 05:23:15 -04:00
|
|
|
from warnings import warn
|
2000-03-09 11:54:52 -04:00
|
|
|
|
2010-01-23 05:23:15 -04:00
|
|
|
# importing sysconfig from Lib
|
|
|
|
# to avoid this module to shadow it
|
|
|
|
_sysconfig = __import__('sysconfig')
|
2001-08-02 17:03:12 -03:00
|
|
|
|
2010-01-26 17:21:54 -04:00
|
|
|
# names defined here to keep backward compatibility
|
|
|
|
# for APIs that were relocated
|
|
|
|
get_python_version = _sysconfig.get_python_version
|
|
|
|
get_config_h_filename = _sysconfig.get_config_h_filename
|
|
|
|
parse_config_h = _sysconfig.parse_config_h
|
|
|
|
get_config_vars = _sysconfig.get_config_vars
|
|
|
|
get_config_var = _sysconfig.get_config_var
|
|
|
|
from distutils.ccompiler import customize_compiler
|
|
|
|
|
2010-01-23 05:23:15 -04:00
|
|
|
_DEPRECATION_MSG = ("distutils.sysconfig.%s is deprecated. "
|
|
|
|
"Use the APIs provided by the sysconfig module instead")
|
|
|
|
|
|
|
|
def _get_project_base():
|
|
|
|
return _sysconfig._PROJECT_BASE
|
2002-11-13 21:43:00 -04:00
|
|
|
|
2010-01-23 05:23:15 -04:00
|
|
|
project_base = _get_project_base()
|
|
|
|
|
|
|
|
class _DeprecatedBool(int):
|
|
|
|
def __nonzero__(self):
|
|
|
|
warn(_DEPRECATION_MSG % 'get_python_version', DeprecationWarning)
|
|
|
|
return super(_DeprecatedBool, self).__nonzero__()
|
|
|
|
|
|
|
|
def _python_build():
|
|
|
|
return _DeprecatedBool(_sysconfig.is_python_build())
|
|
|
|
|
|
|
|
python_build = _python_build()
|
2002-11-13 21:43:00 -04:00
|
|
|
|
2000-04-09 22:17:49 -03:00
|
|
|
def get_python_inc(plat_specific=0, prefix=None):
|
2010-01-23 05:23:15 -04:00
|
|
|
"""This function is deprecated.
|
|
|
|
|
|
|
|
Return the directory containing installed Python header files.
|
2000-03-09 11:54:52 -04:00
|
|
|
|
|
|
|
If 'plat_specific' is false (the default), this is the path to the
|
|
|
|
non-platform-specific header files, i.e. Python.h and so on;
|
|
|
|
otherwise, this is the path to platform-specific header files
|
2001-07-26 10:41:06 -03:00
|
|
|
(namely pyconfig.h).
|
2000-03-09 11:54:52 -04:00
|
|
|
|
2000-04-09 22:17:49 -03:00
|
|
|
If 'prefix' is supplied, use it instead of sys.prefix or
|
|
|
|
sys.exec_prefix -- i.e., ignore 'plat_specific'.
|
2001-12-06 16:51:35 -04:00
|
|
|
"""
|
2010-01-23 05:23:15 -04:00
|
|
|
warn(_DEPRECATION_MSG % 'get_python_inc', DeprecationWarning)
|
|
|
|
get_path = _sysconfig.get_path
|
|
|
|
|
|
|
|
if prefix is not None:
|
|
|
|
vars = {'base': prefix}
|
|
|
|
return get_path('include', vars=vars)
|
|
|
|
|
|
|
|
if not plat_specific:
|
|
|
|
return get_path('include')
|
2000-03-08 23:16:05 -04:00
|
|
|
else:
|
2010-01-23 05:23:15 -04:00
|
|
|
return get_path('platinclude')
|
2000-03-08 23:16:05 -04:00
|
|
|
|
2010-01-23 05:23:15 -04:00
|
|
|
def get_python_lib(plat_specific=False, standard_lib=False, prefix=None):
|
|
|
|
"""This function is deprecated.
|
2000-03-08 23:16:05 -04:00
|
|
|
|
2010-01-23 05:23:15 -04:00
|
|
|
Return the directory containing the Python library (standard or
|
2000-03-09 11:54:52 -04:00
|
|
|
site additions).
|
|
|
|
|
|
|
|
If 'plat_specific' is true, return the directory containing
|
|
|
|
platform-specific modules, i.e. any module from a non-pure-Python
|
|
|
|
module distribution; otherwise, return the platform-shared library
|
|
|
|
directory. If 'standard_lib' is true, return the directory
|
|
|
|
containing standard Python library modules; otherwise, return the
|
|
|
|
directory for site-specific modules.
|
2000-03-08 23:16:05 -04:00
|
|
|
|
2000-04-09 22:17:49 -03:00
|
|
|
If 'prefix' is supplied, use it instead of sys.prefix or
|
|
|
|
sys.exec_prefix -- i.e., ignore 'plat_specific'.
|
2000-03-09 11:54:52 -04:00
|
|
|
"""
|
2010-01-23 05:23:15 -04:00
|
|
|
warn(_DEPRECATION_MSG % 'get_python_lib', DeprecationWarning)
|
|
|
|
vars = {}
|
|
|
|
get_path = _sysconfig.get_path
|
|
|
|
if prefix is not None:
|
|
|
|
if plat_specific:
|
|
|
|
vars['platbase'] = prefix
|
2000-03-08 23:16:05 -04:00
|
|
|
else:
|
2010-01-23 05:23:15 -04:00
|
|
|
vars['base'] = prefix
|
2000-03-08 23:16:05 -04:00
|
|
|
|
2010-01-23 05:23:15 -04:00
|
|
|
if standard_lib:
|
2000-08-01 22:49:40 -03:00
|
|
|
if plat_specific:
|
2010-01-23 05:23:15 -04:00
|
|
|
return get_path('platstdlib', vars=vars)
|
2002-01-31 14:56:00 -04:00
|
|
|
else:
|
2010-01-23 05:23:15 -04:00
|
|
|
return get_path('stdlib', vars=vars)
|
2000-03-08 23:16:05 -04:00
|
|
|
else:
|
2010-01-23 05:23:15 -04:00
|
|
|
if plat_specific:
|
|
|
|
return get_path('platlib', vars=vars)
|
2007-12-06 09:15:13 -04:00
|
|
|
else:
|
2010-01-23 05:23:15 -04:00
|
|
|
return get_path('purelib', vars=vars)
|
1998-12-18 19:46:33 -04:00
|
|
|
|
1999-01-06 10:46:06 -04:00
|
|
|
def get_makefile_filename():
|
2010-01-23 05:23:15 -04:00
|
|
|
"""This function is deprecated.
|
1998-12-18 19:46:33 -04:00
|
|
|
|
2010-01-23 05:23:15 -04:00
|
|
|
Return full pathname of installed Makefile from the Python build.
|
1999-01-06 12:28:34 -04:00
|
|
|
"""
|
2010-01-23 05:23:15 -04:00
|
|
|
warn(_DEPRECATION_MSG % 'get_makefile_filename', DeprecationWarning)
|
|
|
|
return _sysconfig._get_makefile_filename()
|
2000-09-16 21:53:02 -03:00
|
|
|
|
|
|
|
# Regexes needed for parsing Makefile (and similar syntaxes,
|
|
|
|
# like old-style Setup files).
|
|
|
|
_variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
|
|
|
|
_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
|
|
|
|
_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
|
|
|
|
|
2000-09-14 21:03:13 -03:00
|
|
|
def parse_makefile(fn, g=None):
|
2010-01-23 05:23:15 -04:00
|
|
|
"""This function is deprecated.
|
|
|
|
|
|
|
|
Parse a Makefile-style file.
|
2000-03-09 11:54:52 -04:00
|
|
|
|
|
|
|
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.
|
1999-01-06 12:28:34 -04:00
|
|
|
"""
|
2010-01-23 05:23:15 -04:00
|
|
|
warn(_DEPRECATION_MSG % 'parse_makefile', DeprecationWarning)
|
|
|
|
return _sysconfig._parse_makefile(fn, g)
|
1998-12-18 19:46:33 -04:00
|
|
|
|
2000-09-16 21:53:02 -03:00
|
|
|
def expand_makefile_vars(s, vars):
|
2010-01-23 05:23:15 -04:00
|
|
|
"""This function is deprecated.
|
|
|
|
|
|
|
|
Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
|
2000-09-16 21:53:02 -03:00
|
|
|
'string' according to 'vars' (a dictionary mapping variable names to
|
|
|
|
values). Variables not present in 'vars' are silently expanded to the
|
|
|
|
empty string. The variable values in 'vars' should not contain further
|
|
|
|
variable expansions; if 'vars' is the output of 'parse_makefile()',
|
|
|
|
you're fine. Returns a variable-expanded version of 's'.
|
|
|
|
"""
|
2010-01-23 05:23:15 -04:00
|
|
|
warn('this function will be removed in then next version of Python',
|
|
|
|
DeprecationWarning)
|
2000-09-16 21:53:02 -03:00
|
|
|
|
|
|
|
# This algorithm does multiple expansion, so if vars['foo'] contains
|
|
|
|
# "${bar}", it will expand ${foo} to ${bar}, and then expand
|
|
|
|
# ${bar}... and so forth. This is fine as long as 'vars' comes from
|
|
|
|
# 'parse_makefile()', which takes care of such expansions eagerly,
|
|
|
|
# according to make's variable expansion semantics.
|
|
|
|
|
|
|
|
while 1:
|
|
|
|
m = _findvar1_rx.search(s) or _findvar2_rx.search(s)
|
|
|
|
if m:
|
|
|
|
(beg, end) = m.span()
|
|
|
|
s = s[0:beg] + vars.get(m.group(1)) + s[end:]
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
return s
|