mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Merged revisions 77704,77752 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r77704 | tarek.ziade | 2010-01-23 10:23:15 +0100 (Sat, 23 Jan 2010) | 1 line taking sysconfig out of distutils ........ r77752 | tarek.ziade | 2010-01-26 00:19:56 +0100 (Tue, 26 Jan 2010) | 1 line switched the call order so this call works without suffering from issue #7774 ........
This commit is contained in:
parent
82b8398583
commit
edacea30e4
35 changed files with 1193 additions and 926 deletions
|
@ -7,6 +7,9 @@ available.
|
|||
|
||||
Written by: Fred L. Drake, Jr.
|
||||
Email: <fdrake@acm.org>
|
||||
|
||||
**This module has been moved out of Distutils and will be removed from
|
||||
Python in the next version (3.2)**
|
||||
"""
|
||||
|
||||
__revision__ = "$Id$"
|
||||
|
@ -14,51 +17,36 @@ __revision__ = "$Id$"
|
|||
import io
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from warnings import warn
|
||||
|
||||
from .errors import DistutilsPlatformError
|
||||
from distutils.errors import DistutilsPlatformError
|
||||
|
||||
# These are needed in a couple of spots, so just compute them once.
|
||||
PREFIX = os.path.normpath(sys.prefix)
|
||||
EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
|
||||
# importing sysconfig from Lib
|
||||
# to avoid this module to shadow it
|
||||
_sysconfig = __import__('sysconfig')
|
||||
|
||||
# Path to the base directory of the project. On Windows the binary may
|
||||
# live in project/PCBuild9. If we're dealing with an x64 Windows build,
|
||||
# it'll live in project/PCbuild/amd64.
|
||||
project_base = os.path.dirname(os.path.abspath(sys.executable))
|
||||
if os.name == "nt" and "pcbuild" in project_base[-8:].lower():
|
||||
project_base = os.path.abspath(os.path.join(project_base, os.path.pardir))
|
||||
# PC/VS7.1
|
||||
if os.name == "nt" and "\\pc\\v" in project_base[-10:].lower():
|
||||
project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
|
||||
os.path.pardir))
|
||||
# PC/AMD64
|
||||
if os.name == "nt" and "\\pcbuild\\amd64" in project_base[-14:].lower():
|
||||
project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
|
||||
os.path.pardir))
|
||||
_DEPRECATION_MSG = ("distutils.sysconfig.%s is deprecated. "
|
||||
"Use the APIs provided by the sysconfig module instead")
|
||||
|
||||
def _get_project_base():
|
||||
return _sysconfig._PROJECT_BASE
|
||||
|
||||
project_base = _get_project_base()
|
||||
|
||||
class _DeprecatedBool(int):
|
||||
def __nonzero__(self):
|
||||
warn(_DEPRECATION_MSG % 'get_python_version', DeprecationWarning)
|
||||
return super(_DeprecatedBool, self).__nonzero__()
|
||||
|
||||
# python_build: (Boolean) if true, we're either building Python or
|
||||
# building an extension with an un-installed Python, so we use
|
||||
# different (hard-wired) directories.
|
||||
# Setup.local is available for Makefile builds including VPATH builds,
|
||||
# Setup.dist is available on Windows
|
||||
def _python_build():
|
||||
for fn in ("Setup.dist", "Setup.local"):
|
||||
if os.path.isfile(os.path.join(project_base, "Modules", fn)):
|
||||
return True
|
||||
return False
|
||||
return _DeprecatedBool(_sysconfig.is_python_build())
|
||||
|
||||
python_build = _python_build()
|
||||
|
||||
def get_python_version():
|
||||
"""Return a string containing the major and minor Python version,
|
||||
leaving off the patchlevel. Sample return values could be '1.5'
|
||||
or '2.2'.
|
||||
"""
|
||||
return sys.version[:3]
|
||||
|
||||
|
||||
def get_python_inc(plat_specific=0, prefix=None):
|
||||
"""Return the directory containing installed Python header files.
|
||||
"""This function is deprecated.
|
||||
|
||||
Return the directory containing installed Python header files.
|
||||
|
||||
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;
|
||||
|
@ -68,39 +56,22 @@ def get_python_inc(plat_specific=0, prefix=None):
|
|||
If 'prefix' is supplied, use it instead of sys.prefix or
|
||||
sys.exec_prefix -- i.e., ignore 'plat_specific'.
|
||||
"""
|
||||
if prefix is None:
|
||||
prefix = plat_specific and EXEC_PREFIX or PREFIX
|
||||
if os.name == "posix":
|
||||
if python_build:
|
||||
# Assume the executable is in the build directory. The
|
||||
# pyconfig.h file should be in the same directory. Since
|
||||
# the build directory may not be the source directory, we
|
||||
# must use "srcdir" from the makefile to find the "Include"
|
||||
# directory.
|
||||
base = os.path.dirname(os.path.abspath(sys.executable))
|
||||
if plat_specific:
|
||||
return base
|
||||
else:
|
||||
incdir = os.path.join(get_config_var('srcdir'), 'Include')
|
||||
return os.path.normpath(incdir)
|
||||
return os.path.join(prefix, "include", "python" + get_python_version())
|
||||
elif os.name == "nt":
|
||||
return os.path.join(prefix, "include")
|
||||
elif os.name == "mac":
|
||||
if plat_specific:
|
||||
return os.path.join(prefix, "Mac", "Include")
|
||||
else:
|
||||
return os.path.join(prefix, "Include")
|
||||
elif os.name == "os2":
|
||||
return os.path.join(prefix, "Include")
|
||||
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')
|
||||
else:
|
||||
raise DistutilsPlatformError(
|
||||
"I don't know where Python installs its C header files "
|
||||
"on platform '%s'" % os.name)
|
||||
return get_path('platinclude')
|
||||
|
||||
def get_python_lib(plat_specific=False, standard_lib=False, prefix=None):
|
||||
"""This function is deprecated.
|
||||
|
||||
def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
|
||||
"""Return the directory containing the Python library (standard or
|
||||
Return the directory containing the Python library (standard or
|
||||
site additions).
|
||||
|
||||
If 'plat_specific' is true, return the directory containing
|
||||
|
@ -113,149 +84,33 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
|
|||
If 'prefix' is supplied, use it instead of sys.prefix or
|
||||
sys.exec_prefix -- i.e., ignore 'plat_specific'.
|
||||
"""
|
||||
if prefix is None:
|
||||
prefix = plat_specific and EXEC_PREFIX or PREFIX
|
||||
|
||||
if os.name == "posix":
|
||||
libpython = os.path.join(prefix,
|
||||
"lib", "python" + get_python_version())
|
||||
if standard_lib:
|
||||
return libpython
|
||||
else:
|
||||
return os.path.join(libpython, "site-packages")
|
||||
elif os.name == "nt":
|
||||
if standard_lib:
|
||||
return os.path.join(prefix, "Lib")
|
||||
else:
|
||||
if get_python_version() < "2.2":
|
||||
return prefix
|
||||
else:
|
||||
return os.path.join(prefix, "Lib", "site-packages")
|
||||
elif os.name == "mac":
|
||||
warn(_DEPRECATION_MSG % 'get_python_lib', DeprecationWarning)
|
||||
vars = {}
|
||||
get_path = _sysconfig.get_path
|
||||
if prefix is not None:
|
||||
if plat_specific:
|
||||
if standard_lib:
|
||||
return os.path.join(prefix, "Lib", "lib-dynload")
|
||||
else:
|
||||
return os.path.join(prefix, "Lib", "site-packages")
|
||||
vars['platbase'] = prefix
|
||||
else:
|
||||
if standard_lib:
|
||||
return os.path.join(prefix, "Lib")
|
||||
else:
|
||||
return os.path.join(prefix, "Lib", "site-packages")
|
||||
elif os.name == "os2":
|
||||
if standard_lib:
|
||||
return os.path.join(prefix, "Lib")
|
||||
vars['base'] = prefix
|
||||
if standard_lib:
|
||||
if plat_specific:
|
||||
return get_path('platstdlib', vars=vars)
|
||||
else:
|
||||
return os.path.join(prefix, "Lib", "site-packages")
|
||||
return get_path('stdlib', vars=vars)
|
||||
else:
|
||||
raise DistutilsPlatformError(
|
||||
"I don't know where Python installs its library "
|
||||
"on platform '%s'" % os.name)
|
||||
|
||||
|
||||
def customize_compiler(compiler):
|
||||
"""Do any platform-specific customization of a CCompiler instance.
|
||||
|
||||
Mainly needed on Unix, so we can plug in the information that
|
||||
varies across Unices and is stored in Python's Makefile.
|
||||
"""
|
||||
if compiler.compiler_type == "unix":
|
||||
(cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \
|
||||
get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
|
||||
'CCSHARED', 'LDSHARED', 'SO', 'AR', 'ARFLAGS')
|
||||
|
||||
if 'CC' in os.environ:
|
||||
cc = os.environ['CC']
|
||||
if 'CXX' in os.environ:
|
||||
cxx = os.environ['CXX']
|
||||
if 'LDSHARED' in os.environ:
|
||||
ldshared = os.environ['LDSHARED']
|
||||
if 'CPP' in os.environ:
|
||||
cpp = os.environ['CPP']
|
||||
if plat_specific:
|
||||
return get_path('platlib', vars=vars)
|
||||
else:
|
||||
cpp = cc + " -E" # not always
|
||||
if 'LDFLAGS' in os.environ:
|
||||
ldshared = ldshared + ' ' + os.environ['LDFLAGS']
|
||||
if 'CFLAGS' in os.environ:
|
||||
cflags = opt + ' ' + os.environ['CFLAGS']
|
||||
ldshared = ldshared + ' ' + os.environ['CFLAGS']
|
||||
if 'CPPFLAGS' in os.environ:
|
||||
cpp = cpp + ' ' + os.environ['CPPFLAGS']
|
||||
cflags = cflags + ' ' + os.environ['CPPFLAGS']
|
||||
ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
|
||||
if 'AR' in os.environ:
|
||||
ar = os.environ['AR']
|
||||
if 'ARFLAGS' in os.environ:
|
||||
archiver = ar + ' ' + os.environ['ARFLAGS']
|
||||
else:
|
||||
archiver = ar + ' ' + ar_flags
|
||||
|
||||
cc_cmd = cc + ' ' + cflags
|
||||
compiler.set_executables(
|
||||
preprocessor=cpp,
|
||||
compiler=cc_cmd,
|
||||
compiler_so=cc_cmd + ' ' + ccshared,
|
||||
compiler_cxx=cxx,
|
||||
linker_so=ldshared,
|
||||
linker_exe=cc,
|
||||
archiver=archiver)
|
||||
|
||||
compiler.shared_lib_extension = so_ext
|
||||
|
||||
|
||||
def get_config_h_filename():
|
||||
"""Return full pathname of installed pyconfig.h file."""
|
||||
if python_build:
|
||||
if os.name == "nt":
|
||||
inc_dir = os.path.join(project_base, "PC")
|
||||
else:
|
||||
inc_dir = project_base
|
||||
else:
|
||||
inc_dir = get_python_inc(plat_specific=1)
|
||||
if get_python_version() < '2.2':
|
||||
config_h = 'config.h'
|
||||
else:
|
||||
# The name of the config.h file changed in 2.2
|
||||
config_h = 'pyconfig.h'
|
||||
return os.path.join(inc_dir, config_h)
|
||||
|
||||
return get_path('purelib', vars=vars)
|
||||
|
||||
def get_makefile_filename():
|
||||
"""Return full pathname of installed Makefile from the Python build."""
|
||||
if python_build:
|
||||
return os.path.join(os.path.dirname(sys.executable), "Makefile")
|
||||
lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
|
||||
return os.path.join(lib_dir, "config", "Makefile")
|
||||
"""This function is deprecated.
|
||||
|
||||
|
||||
def parse_config_h(fp, g=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.
|
||||
Return full pathname of installed Makefile from the Python build.
|
||||
"""
|
||||
if g is None:
|
||||
g = {}
|
||||
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
|
||||
g[n] = v
|
||||
else:
|
||||
m = undef_rx.match(line)
|
||||
if m:
|
||||
g[m.group(1)] = 0
|
||||
return g
|
||||
|
||||
warn(_DEPRECATION_MSG % 'get_makefile_filename', DeprecationWarning)
|
||||
return _sysconfig._get_makefile_filename()
|
||||
|
||||
# Regexes needed for parsing Makefile (and similar syntaxes,
|
||||
# like old-style Setup files).
|
||||
|
@ -264,91 +119,29 @@ _findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
|
|||
_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
|
||||
|
||||
def parse_makefile(fn, g=None):
|
||||
"""Parse a Makefile-style file.
|
||||
"""This function is deprecated.
|
||||
|
||||
Parse a Makefile-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.
|
||||
"""
|
||||
from distutils.text_file import TextFile
|
||||
fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1)
|
||||
|
||||
if g is None:
|
||||
g = {}
|
||||
done = {}
|
||||
notdone = {}
|
||||
|
||||
while True:
|
||||
line = fp.readline()
|
||||
if line is None: # eof
|
||||
break
|
||||
m = _variable_rx.match(line)
|
||||
if m:
|
||||
n, v = m.group(1, 2)
|
||||
v = v.strip()
|
||||
# `$$' is a literal `$' in make
|
||||
tmpv = v.replace('$$', '')
|
||||
|
||||
if "$" in tmpv:
|
||||
notdone[n] = v
|
||||
else:
|
||||
try:
|
||||
v = int(v)
|
||||
except ValueError:
|
||||
# insert literal `$'
|
||||
done[n] = v.replace('$$', '$')
|
||||
else:
|
||||
done[n] = v
|
||||
|
||||
# do variable interpolation here
|
||||
while notdone:
|
||||
for name in list(notdone):
|
||||
value = notdone[name]
|
||||
m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
|
||||
if m:
|
||||
n = m.group(1)
|
||||
found = True
|
||||
if n in done:
|
||||
item = str(done[n])
|
||||
elif n in notdone:
|
||||
# get it on a subsequent round
|
||||
found = False
|
||||
elif n in os.environ:
|
||||
# do it like make: fall back to environment
|
||||
item = os.environ[n]
|
||||
else:
|
||||
done[n] = item = ""
|
||||
if found:
|
||||
after = value[m.end():]
|
||||
value = value[:m.start()] + item + after
|
||||
if "$" in after:
|
||||
notdone[name] = value
|
||||
else:
|
||||
try: value = int(value)
|
||||
except ValueError:
|
||||
done[name] = value.strip()
|
||||
else:
|
||||
done[name] = value
|
||||
del notdone[name]
|
||||
else:
|
||||
# bogus variable reference; just drop it since we can't deal
|
||||
del notdone[name]
|
||||
|
||||
fp.close()
|
||||
|
||||
# save the results in the global dictionary
|
||||
g.update(done)
|
||||
return g
|
||||
|
||||
warn(_DEPRECATION_MSG % 'parse_makefile', DeprecationWarning)
|
||||
return _sysconfig._parse_makefile(fn, g)
|
||||
|
||||
def expand_makefile_vars(s, vars):
|
||||
"""Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
|
||||
"""This function is deprecated.
|
||||
|
||||
Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
|
||||
'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'.
|
||||
"""
|
||||
warn('this function will be removed in then next version of Python',
|
||||
DeprecationWarning)
|
||||
|
||||
# This algorithm does multiple expansion, so if vars['foo'] contains
|
||||
# "${bar}", it will expand ${foo} to ${bar}, and then expand
|
||||
|
@ -364,220 +157,3 @@ def expand_makefile_vars(s, vars):
|
|||
else:
|
||||
break
|
||||
return s
|
||||
|
||||
|
||||
_config_vars = None
|
||||
|
||||
def _init_posix():
|
||||
"""Initialize the module as appropriate for POSIX systems."""
|
||||
g = {}
|
||||
# load the installed Makefile:
|
||||
try:
|
||||
filename = get_makefile_filename()
|
||||
parse_makefile(filename, g)
|
||||
except IOError as msg:
|
||||
my_msg = "invalid Python installation: unable to open %s" % filename
|
||||
if hasattr(msg, "strerror"):
|
||||
my_msg = my_msg + " (%s)" % msg.strerror
|
||||
|
||||
raise DistutilsPlatformError(my_msg)
|
||||
|
||||
# load the installed pyconfig.h:
|
||||
try:
|
||||
filename = get_config_h_filename()
|
||||
parse_config_h(io.open(filename), g)
|
||||
except IOError as msg:
|
||||
my_msg = "invalid Python installation: unable to open %s" % filename
|
||||
if hasattr(msg, "strerror"):
|
||||
my_msg = my_msg + " (%s)" % msg.strerror
|
||||
|
||||
raise DistutilsPlatformError(my_msg)
|
||||
|
||||
# On MacOSX we need to check the setting of the environment variable
|
||||
# MACOSX_DEPLOYMENT_TARGET: configure bases some choices on it so
|
||||
# it needs to be compatible.
|
||||
# If it isn't set we set it to the configure-time value
|
||||
if sys.platform == 'darwin' and 'MACOSX_DEPLOYMENT_TARGET' in g:
|
||||
cfg_target = g['MACOSX_DEPLOYMENT_TARGET']
|
||||
cur_target = os.getenv('MACOSX_DEPLOYMENT_TARGET', '')
|
||||
if cur_target == '':
|
||||
cur_target = cfg_target
|
||||
os.putenv('MACOSX_DEPLOYMENT_TARGET', cfg_target)
|
||||
elif [int(x) for x in cfg_target.split('.')] > [int(x) for x in cur_target.split('.')]:
|
||||
my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" during configure'
|
||||
% (cur_target, cfg_target))
|
||||
raise DistutilsPlatformError(my_msg)
|
||||
|
||||
# On AIX, there are wrong paths to the linker scripts in the Makefile
|
||||
# -- these paths are relative to the Python source, but when installed
|
||||
# the scripts are in another directory.
|
||||
if python_build:
|
||||
g['LDSHARED'] = g['BLDSHARED']
|
||||
|
||||
elif get_python_version() < '2.1':
|
||||
# The following two branches are for 1.5.2 compatibility.
|
||||
if sys.platform == 'aix4': # what about AIX 3.x ?
|
||||
# Linker script is in the config directory, not in Modules as the
|
||||
# Makefile says.
|
||||
python_lib = get_python_lib(standard_lib=1)
|
||||
ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
|
||||
python_exp = os.path.join(python_lib, 'config', 'python.exp')
|
||||
|
||||
g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp)
|
||||
|
||||
global _config_vars
|
||||
_config_vars = g
|
||||
|
||||
|
||||
def _init_nt():
|
||||
"""Initialize the module as appropriate for NT"""
|
||||
g = {}
|
||||
# set basic install directories
|
||||
g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
|
||||
g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
|
||||
|
||||
# XXX hmmm.. a normal install puts include files here
|
||||
g['INCLUDEPY'] = get_python_inc(plat_specific=0)
|
||||
|
||||
g['SO'] = '.pyd'
|
||||
g['EXE'] = ".exe"
|
||||
g['VERSION'] = get_python_version().replace(".", "")
|
||||
g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
|
||||
|
||||
global _config_vars
|
||||
_config_vars = g
|
||||
|
||||
|
||||
def _init_mac():
|
||||
"""Initialize the module as appropriate for Macintosh systems"""
|
||||
g = {}
|
||||
# set basic install directories
|
||||
g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
|
||||
g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
|
||||
|
||||
# XXX hmmm.. a normal install puts include files here
|
||||
g['INCLUDEPY'] = get_python_inc(plat_specific=0)
|
||||
|
||||
import MacOS
|
||||
if not hasattr(MacOS, 'runtimemodel'):
|
||||
g['SO'] = '.ppc.slb'
|
||||
else:
|
||||
g['SO'] = '.%s.slb' % MacOS.runtimemodel
|
||||
|
||||
# XXX are these used anywhere?
|
||||
g['install_lib'] = os.path.join(EXEC_PREFIX, "Lib")
|
||||
g['install_platlib'] = os.path.join(EXEC_PREFIX, "Mac", "Lib")
|
||||
|
||||
# These are used by the extension module build
|
||||
g['srcdir'] = ':'
|
||||
global _config_vars
|
||||
_config_vars = g
|
||||
|
||||
|
||||
def _init_os2():
|
||||
"""Initialize the module as appropriate for OS/2"""
|
||||
g = {}
|
||||
# set basic install directories
|
||||
g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
|
||||
g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
|
||||
|
||||
# XXX hmmm.. a normal install puts include files here
|
||||
g['INCLUDEPY'] = get_python_inc(plat_specific=0)
|
||||
|
||||
g['SO'] = '.pyd'
|
||||
g['EXE'] = ".exe"
|
||||
|
||||
global _config_vars
|
||||
_config_vars = g
|
||||
|
||||
|
||||
def get_config_vars(*args):
|
||||
"""With no arguments, return a dictionary of all configuration
|
||||
variables relevant for the current platform. Generally this includes
|
||||
everything needed to build extensions and install both pure modules and
|
||||
extensions. On Unix, this means every variable defined in Python's
|
||||
installed Makefile; on Windows and Mac OS it's a much smaller set.
|
||||
|
||||
With arguments, return a list of values that result from looking up
|
||||
each argument in the configuration variable dictionary.
|
||||
"""
|
||||
global _config_vars
|
||||
if _config_vars is None:
|
||||
func = globals().get("_init_" + os.name)
|
||||
if func:
|
||||
func()
|
||||
else:
|
||||
_config_vars = {}
|
||||
|
||||
# Normalized versions of prefix and exec_prefix are handy to have;
|
||||
# in fact, these are the standard versions used most places in the
|
||||
# Distutils.
|
||||
_config_vars['prefix'] = PREFIX
|
||||
_config_vars['exec_prefix'] = EXEC_PREFIX
|
||||
|
||||
# Convert srcdir into an absolute path if it appears necessary.
|
||||
# Normally it is relative to the build directory. However, during
|
||||
# testing, for example, we might be running a non-installed python
|
||||
# from a different directory.
|
||||
if python_build and os.name == "posix":
|
||||
base = os.path.dirname(os.path.abspath(sys.executable))
|
||||
if (not os.path.isabs(_config_vars['srcdir']) and
|
||||
base != os.getcwd()):
|
||||
# srcdir is relative and we are not in the same directory
|
||||
# as the executable. Assume executable is in the build
|
||||
# directory and make srcdir absolute.
|
||||
srcdir = os.path.join(base, _config_vars['srcdir'])
|
||||
_config_vars['srcdir'] = os.path.normpath(srcdir)
|
||||
|
||||
if sys.platform == 'darwin':
|
||||
kernel_version = os.uname()[2] # Kernel version (8.4.3)
|
||||
major_version = int(kernel_version.split('.')[0])
|
||||
|
||||
if major_version < 8:
|
||||
# On Mac OS X before 10.4, check if -arch and -isysroot
|
||||
# are in CFLAGS or LDFLAGS and remove them if they are.
|
||||
# This is needed when building extensions on a 10.3 system
|
||||
# using a universal build of python.
|
||||
for key in ('LDFLAGS', 'BASECFLAGS',
|
||||
# a number of derived variables. These need to be
|
||||
# patched up as well.
|
||||
'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
|
||||
flags = _config_vars[key]
|
||||
flags = re.sub('-arch\s+\w+\s', ' ', flags, re.ASCII)
|
||||
flags = re.sub('-isysroot [^ \t]*', ' ', flags)
|
||||
_config_vars[key] = flags
|
||||
|
||||
else:
|
||||
|
||||
# Allow the user to override the architecture flags using
|
||||
# an environment variable.
|
||||
# NOTE: This name was introduced by Apple in OSX 10.5 and
|
||||
# is used by several scripting languages distributed with
|
||||
# that OS release.
|
||||
|
||||
if 'ARCHFLAGS' in os.environ:
|
||||
arch = os.environ['ARCHFLAGS']
|
||||
for key in ('LDFLAGS', 'BASECFLAGS',
|
||||
# a number of derived variables. These need to be
|
||||
# patched up as well.
|
||||
'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
|
||||
|
||||
flags = _config_vars[key]
|
||||
flags = re.sub('-arch\s+\w+\s', ' ', flags)
|
||||
flags = flags + ' ' + arch
|
||||
_config_vars[key] = flags
|
||||
|
||||
if args:
|
||||
vals = []
|
||||
for name in args:
|
||||
vals.append(_config_vars.get(name))
|
||||
return vals
|
||||
else:
|
||||
return _config_vars
|
||||
|
||||
def get_config_var(name):
|
||||
"""Return the value of a single variable using the dictionary
|
||||
returned by 'get_config_vars()'. Equivalent to
|
||||
get_config_vars().get(name)
|
||||
"""
|
||||
return get_config_vars().get(name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue