summaryrefslogtreecommitdiffstats
path: root/Lib/distutils
diff options
context:
space:
mode:
authorTarek Ziadé <ziade.tarek@gmail.com>2010-01-29 11:41:03 (GMT)
committerTarek Ziadé <ziade.tarek@gmail.com>2010-01-29 11:41:03 (GMT)
commitedacea30e457e151611a9fe560120cedb3bdc527 (patch)
tree3227e5e1c060cce48b00d34b9ae46571f079e2fb /Lib/distutils
parent82b83985832a0b1922aa86261f764b12a7237ac5 (diff)
downloadcpython-edacea30e457e151611a9fe560120cedb3bdc527.zip
cpython-edacea30e457e151611a9fe560120cedb3bdc527.tar.gz
cpython-edacea30e457e151611a9fe560120cedb3bdc527.tar.bz2
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 ........
Diffstat (limited to 'Lib/distutils')
-rw-r--r--Lib/distutils/ccompiler.py52
-rw-r--r--Lib/distutils/command/bdist.py2
-rw-r--r--Lib/distutils/command/bdist_dumb.py4
-rw-r--r--Lib/distutils/command/bdist_wininst.py4
-rw-r--r--Lib/distutils/command/build.py3
-rw-r--r--Lib/distutils/command/build_clib.py2
-rw-r--r--Lib/distutils/command/build_ext.py32
-rw-r--r--Lib/distutils/command/build_scripts.py10
-rw-r--r--Lib/distutils/command/config.py2
-rw-r--r--Lib/distutils/command/install.py163
-rw-r--r--Lib/distutils/core.py2
-rw-r--r--Lib/distutils/cygwinccompiler.py4
-rw-r--r--Lib/distutils/extension.py12
-rw-r--r--Lib/distutils/msvc9compiler.py10
-rw-r--r--Lib/distutils/sysconfig.py562
-rw-r--r--Lib/distutils/tests/support.py8
-rw-r--r--Lib/distutils/tests/test_build.py2
-rw-r--r--Lib/distutils/tests/test_build_clib.py3
-rw-r--r--Lib/distutils/tests/test_build_ext.py17
-rw-r--r--Lib/distutils/tests/test_build_scripts.py6
-rw-r--r--Lib/distutils/tests/test_ccompiler.py26
-rw-r--r--Lib/distutils/tests/test_cygwinccompiler.py3
-rwxr-xr-xLib/distutils/tests/test_extension.py2
-rw-r--r--Lib/distutils/tests/test_install.py53
-rw-r--r--Lib/distutils/tests/test_sysconfig.py36
-rw-r--r--Lib/distutils/tests/test_unixccompiler.py2
-rw-r--r--Lib/distutils/tests/test_util.py14
-rw-r--r--Lib/distutils/unixccompiler.py10
-rw-r--r--Lib/distutils/util.py170
29 files changed, 310 insertions, 906 deletions
diff --git a/Lib/distutils/ccompiler.py b/Lib/distutils/ccompiler.py
index 5a6bef4..1a4e8fb 100644
--- a/Lib/distutils/ccompiler.py
+++ b/Lib/distutils/ccompiler.py
@@ -18,6 +18,58 @@ from distutils.dep_util import newer_group
from distutils.util import split_quoted, execute
from distutils import log
+_sysconfig = __import__('sysconfig')
+
+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) = \
+ _sysconfig.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']
+ 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
+
class CCompiler:
"""Abstract base class to define the interface that must be implemented
by real compiler classes. Also has some utility methods used by
diff --git a/Lib/distutils/command/bdist.py b/Lib/distutils/command/bdist.py
index dd202ff..a79982b 100644
--- a/Lib/distutils/command/bdist.py
+++ b/Lib/distutils/command/bdist.py
@@ -6,10 +6,10 @@ distribution)."""
__revision__ = "$Id$"
import os
+from sysconfig import get_platform
from distutils.core import Command
from distutils.errors import DistutilsPlatformError, DistutilsOptionError
-from distutils.util import get_platform
def show_formats():
diff --git a/Lib/distutils/command/bdist_dumb.py b/Lib/distutils/command/bdist_dumb.py
index 49fd653..c16125f 100644
--- a/Lib/distutils/command/bdist_dumb.py
+++ b/Lib/distutils/command/bdist_dumb.py
@@ -8,11 +8,11 @@ __revision__ = "$Id$"
import os
+from sysconfig import get_python_version, get_platform
+
from distutils.core import Command
-from distutils.util import get_platform
from distutils.dir_util import remove_tree, ensure_relative
from distutils.errors import DistutilsPlatformError
-from distutils.sysconfig import get_python_version
from distutils import log
class bdist_dumb(Command):
diff --git a/Lib/distutils/command/bdist_wininst.py b/Lib/distutils/command/bdist_wininst.py
index 0b7044a..2cf2823 100644
--- a/Lib/distutils/command/bdist_wininst.py
+++ b/Lib/distutils/command/bdist_wininst.py
@@ -8,11 +8,11 @@ __revision__ = "$Id$"
import sys
import os
+from sysconfig import get_python_version, get_platform
+
from distutils.core import Command
-from distutils.util import get_platform
from distutils.dir_util import remove_tree
from distutils.errors import DistutilsOptionError, DistutilsPlatformError
-from distutils.sysconfig import get_python_version
from distutils import log
class bdist_wininst(Command):
diff --git a/Lib/distutils/command/build.py b/Lib/distutils/command/build.py
index 715621e..d7b0e3c 100644
--- a/Lib/distutils/command/build.py
+++ b/Lib/distutils/command/build.py
@@ -5,9 +5,10 @@ Implements the Distutils 'build' command."""
__revision__ = "$Id$"
import sys, os
+from sysconfig import get_platform
+
from distutils.core import Command
from distutils.errors import DistutilsOptionError
-from distutils.util import get_platform
def show_compilers():
from distutils.ccompiler import show_compilers
diff --git a/Lib/distutils/command/build_clib.py b/Lib/distutils/command/build_clib.py
index 12bf1d2..4c6443c 100644
--- a/Lib/distutils/command/build_clib.py
+++ b/Lib/distutils/command/build_clib.py
@@ -19,7 +19,7 @@ __revision__ = "$Id$"
import os
from distutils.core import Command
from distutils.errors import DistutilsSetupError
-from distutils.sysconfig import customize_compiler
+from distutils.ccompiler import customize_compiler
from distutils import log
def show_compilers():
diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py
index de980bd..39d37da 100644
--- a/Lib/distutils/command/build_ext.py
+++ b/Lib/distutils/command/build_ext.py
@@ -9,13 +9,14 @@ __revision__ = "$Id$"
import sys, os, re
from warnings import warn
+from sysconfig import get_platform
+
from distutils.core import Command
-from distutils.errors import (CCompilerError, DistutilsError, CompileError,
- DistutilsSetupError, DistutilsPlatformError)
-from distutils.sysconfig import customize_compiler, get_python_version
+from distutils.errors import *
+from distutils.ccompiler import customize_compiler
from distutils.dep_util import newer_group
from distutils.extension import Extension
-from distutils.util import get_platform
+
from distutils import log
# this keeps compatibility from 2.3 to 2.5
@@ -172,8 +173,7 @@ class build_ext(Command):
self.user = None
def finalize_options(self):
- from distutils import sysconfig
-
+ _sysconfig = __import__('sysconfig')
self.set_undefined_options('build',
('build_lib', 'build_lib'),
('build_temp', 'build_temp'),
@@ -190,8 +190,8 @@ class build_ext(Command):
# Make sure Python's include directories (for Python.h, pyconfig.h,
# etc.) are in the include search path.
- py_include = sysconfig.get_python_inc()
- plat_py_include = sysconfig.get_python_inc(plat_specific=1)
+ py_include = _sysconfig.get_path('include')
+ plat_py_include = _sysconfig.get_path('platinclude')
if self.include_dirs is None:
self.include_dirs = self.distribution.include_dirs or []
if isinstance(self.include_dirs, str):
@@ -269,7 +269,7 @@ class build_ext(Command):
if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
# building third party extensions
self.library_dirs.append(os.path.join(sys.prefix, "lib",
- "python" + get_python_version(),
+ "python" + _sysconfig.get_python_version(),
"config"))
else:
# building python standard extensions
@@ -277,13 +277,13 @@ class build_ext(Command):
# for extensions under Linux or Solaris with a shared Python library,
# Python's library directory must be appended to library_dirs
- sysconfig.get_config_var('Py_ENABLE_SHARED')
+ _sysconfig.get_config_var('Py_ENABLE_SHARED')
if ((sys.platform.startswith('linux') or sys.platform.startswith('gnu')
or sys.platform.startswith('sunos'))
- and sysconfig.get_config_var('Py_ENABLE_SHARED')):
+ and _sysconfig.get_config_var('Py_ENABLE_SHARED')):
if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
# building third party extensions
- self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
+ self.library_dirs.append(_sysconfig.get_config_var('LIBDIR'))
else:
# building python standard extensions
self.library_dirs.append('.')
@@ -712,13 +712,13 @@ class build_ext(Command):
of the file from which it will be loaded (eg. "foo/bar.so", or
"foo\bar.pyd").
"""
- from distutils.sysconfig import get_config_var
+ _sysconfig = __import__('sysconfig')
ext_path = ext_name.split('.')
# OS/2 has an 8 character module (extension) limit :-(
if os.name == "os2":
ext_path[len(ext_path) - 1] = ext_path[len(ext_path) - 1][:8]
# extensions in debug_mode are named 'module_d.pyd' under windows
- so_ext = get_config_var('SO')
+ so_ext = _sysconfig.get_config_var('SO')
if os.name == 'nt' and self.debug:
return os.path.join(*ext_path) + '_d' + so_ext
return os.path.join(*ext_path) + so_ext
@@ -781,8 +781,8 @@ class build_ext(Command):
# Don't use the default code below
return ext.libraries
else:
- from distutils import sysconfig
- if sysconfig.get_config_var('Py_ENABLE_SHARED'):
+ _sysconfig = __import__('sysconfig')
+ if _sysconfig.get_config_var('Py_ENABLE_SHARED'):
template = "python%d.%d"
pythonlib = (template %
(sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
diff --git a/Lib/distutils/command/build_scripts.py b/Lib/distutils/command/build_scripts.py
index 8b08bfe..a54d6ed 100644
--- a/Lib/distutils/command/build_scripts.py
+++ b/Lib/distutils/command/build_scripts.py
@@ -6,7 +6,6 @@ __revision__ = "$Id$"
import os, re
from stat import ST_MODE
-from distutils import sysconfig
from distutils.core import Command
from distutils.dep_util import newer
from distutils.util import convert_path, Mixin2to3
@@ -57,6 +56,7 @@ class build_scripts(Command):
ie. starts with "\#!" and contains "python"), then adjust the first
line to refer to the current Python interpreter as we copy.
"""
+ _sysconfig = __import__('sysconfig')
self.mkpath(self.build_dir)
outfiles = []
updated_files = []
@@ -96,16 +96,16 @@ class build_scripts(Command):
updated_files.append(outfile)
if not self.dry_run:
outf = open(outfile, "w")
- if not sysconfig.python_build:
+ if not _sysconfig.is_python_build():
outf.write("#!%s%s\n" %
(self.executable,
post_interp))
else:
outf.write("#!%s%s\n" %
(os.path.join(
- sysconfig.get_config_var("BINDIR"),
- "python%s%s" % (sysconfig.get_config_var("VERSION"),
- sysconfig.get_config_var("EXE"))),
+ _sysconfig.get_config_var("BINDIR"),
+ "python%s%s" % (_sysconfig.get_config_var("VERSION"),
+ _sysconfig.get_config_var("EXE"))),
post_interp))
outf.writelines(f.readlines())
outf.close()
diff --git a/Lib/distutils/command/config.py b/Lib/distutils/command/config.py
index 830552c..56f643c 100644
--- a/Lib/distutils/command/config.py
+++ b/Lib/distutils/command/config.py
@@ -16,7 +16,7 @@ import re
from distutils.core import Command
from distutils.errors import DistutilsExecError
-from distutils.sysconfig import customize_compiler
+from distutils.ccompiler import customize_compiler
from distutils import log
LANG_EXT = {"c": ".c", "c++": ".cxx"}
diff --git a/Lib/distutils/command/install.py b/Lib/distutils/command/install.py
index 2a905d9..1f8d238 100644
--- a/Lib/distutils/command/install.py
+++ b/Lib/distutils/command/install.py
@@ -7,115 +7,25 @@ __revision__ = "$Id$"
import sys
import os
+from sysconfig import (get_config_vars, get_platform, get_paths, get_path,
+ get_config_var)
+
from distutils import log
from distutils.core import Command
from distutils.debug import DEBUG
-from distutils.sysconfig import get_config_vars
from distutils.errors import DistutilsPlatformError
from distutils.file_util import write_file
-from distutils.util import convert_path, subst_vars, change_root
-from distutils.util import get_platform
+from distutils.util import convert_path, change_root
from distutils.errors import DistutilsOptionError
-# this keeps compatibility from 2.3 to 2.5
-if sys.version < "2.6":
- USER_BASE = None
- USER_SITE = None
- HAS_USER_SITE = False
-else:
- from site import USER_BASE
- from site import USER_SITE
- HAS_USER_SITE = True
-
-if sys.version < "2.2":
- WINDOWS_SCHEME = {
- 'purelib': '$base',
- 'platlib': '$base',
- 'headers': '$base/Include/$dist_name',
- 'scripts': '$base/Scripts',
- 'data' : '$base',
- }
-else:
- WINDOWS_SCHEME = {
- 'purelib': '$base/Lib/site-packages',
- 'platlib': '$base/Lib/site-packages',
- 'headers': '$base/Include/$dist_name',
- 'scripts': '$base/Scripts',
- 'data' : '$base',
- }
-
-INSTALL_SCHEMES = {
- 'unix_prefix': {
- 'purelib': '$base/lib/python$py_version_short/site-packages',
- 'platlib': '$platbase/lib/python$py_version_short/site-packages',
- 'headers': '$base/include/python$py_version_short/$dist_name',
- 'scripts': '$base/bin',
- 'data' : '$base',
- },
- 'unix_home': {
- 'purelib': '$base/lib/python',
- 'platlib': '$base/lib/python',
- 'headers': '$base/include/python/$dist_name',
- 'scripts': '$base/bin',
- 'data' : '$base',
- },
- 'nt': WINDOWS_SCHEME,
- 'mac': {
- 'purelib': '$base/Lib/site-packages',
- 'platlib': '$base/Lib/site-packages',
- 'headers': '$base/Include/$dist_name',
- 'scripts': '$base/Scripts',
- 'data' : '$base',
- },
-
- 'os2': {
- 'purelib': '$base/Lib/site-packages',
- 'platlib': '$base/Lib/site-packages',
- 'headers': '$base/Include/$dist_name',
- 'scripts': '$base/Scripts',
- 'data' : '$base',
- },
- }
-
-# user site schemes
-if HAS_USER_SITE:
- INSTALL_SCHEMES['nt_user'] = {
- 'purelib': '$usersite',
- 'platlib': '$usersite',
- 'headers': '$userbase/Python$py_version_nodot/Include/$dist_name',
- 'scripts': '$userbase/Scripts',
- 'data' : '$userbase',
- }
-
- INSTALL_SCHEMES['unix_user'] = {
- 'purelib': '$usersite',
- 'platlib': '$usersite',
- 'headers': '$userbase/include/python$py_version_short/$dist_name',
- 'scripts': '$userbase/bin',
- 'data' : '$userbase',
- }
-
- INSTALL_SCHEMES['mac_user'] = {
- 'purelib': '$usersite',
- 'platlib': '$usersite',
- 'headers': '$userbase/$py_version_short/include/$dist_name',
- 'scripts': '$userbase/bin',
- 'data' : '$userbase',
- }
-
- INSTALL_SCHEMES['os2_home'] = {
- 'purelib': '$usersite',
- 'platlib': '$usersite',
- 'headers': '$userbase/include/python$py_version_short/$dist_name',
- 'scripts': '$userbase/bin',
- 'data' : '$userbase',
- }
-
-# The keys to an installation scheme; if any new types of files are to be
-# installed, be sure to add an entry to every installation scheme above,
-# and to SCHEME_KEYS here.
-SCHEME_KEYS = ('purelib', 'platlib', 'headers', 'scripts', 'data')
-
+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)
class install(Command):
@@ -182,11 +92,10 @@ class install(Command):
boolean_options = ['compile', 'force', 'skip-build']
- if HAS_USER_SITE:
- user_options.append(('user', None,
- "install in user site-package '%s'" % USER_SITE))
- boolean_options.append('user')
-
+ user_options.append(('user', None,
+ "install in user site-package '%s'" % \
+ get_path('purelib', '%s_user' % os.name)))
+ boolean_options.append('user')
negative_opt = {'no-compile' : 'compile'}
@@ -216,8 +125,8 @@ class install(Command):
self.install_lib = None # set to either purelib or platlib
self.install_scripts = None
self.install_data = None
- self.install_userbase = USER_BASE
- self.install_usersite = USER_SITE
+ self.install_userbase = get_config_var('userbase')
+ self.install_usersite = get_path('purelib', '%s_user' % os.name)
self.compile = None
self.optimize = None
@@ -327,7 +236,9 @@ class install(Command):
# about needing recursive variable expansion (shudder).
py_version = sys.version.split()[0]
- (prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix')
+ prefix, exec_prefix, srcdir = get_config_vars('prefix', 'exec_prefix',
+ 'srcdir')
+
self.config_vars = {'dist_name': self.distribution.get_name(),
'dist_version': self.distribution.get_version(),
'dist_fullname': self.distribution.get_fullname(),
@@ -338,12 +249,11 @@ class install(Command):
'prefix': prefix,
'sys_exec_prefix': exec_prefix,
'exec_prefix': exec_prefix,
+ 'srcdir': srcdir,
}
- if HAS_USER_SITE:
- self.config_vars['userbase'] = self.install_userbase
- self.config_vars['usersite'] = self.install_usersite
-
+ self.config_vars['userbase'] = self.install_userbase
+ self.config_vars['usersite'] = self.install_usersite
self.expand_basedirs()
self.dump_dirs("post-expand_basedirs()")
@@ -447,10 +357,10 @@ class install(Command):
raise DistutilsPlatformError(
"User base directory is not specified")
self.install_base = self.install_platbase = self.install_userbase
- self.select_scheme("unix_user")
+ self.select_scheme("posix_user")
elif self.home is not None:
self.install_base = self.install_platbase = self.home
- self.select_scheme("unix_home")
+ self.select_scheme("posix_home")
else:
if self.prefix is None:
if self.exec_prefix is not None:
@@ -466,7 +376,7 @@ class install(Command):
self.install_base = self.prefix
self.install_platbase = self.exec_prefix
- self.select_scheme("unix_prefix")
+ self.select_scheme("posix_prefix")
def finalize_other(self):
"""Finalizes options for non-posix platforms"""
@@ -478,7 +388,7 @@ class install(Command):
self.select_scheme(os.name + "_user")
elif self.home is not None:
self.install_base = self.install_platbase = self.home
- self.select_scheme("unix_home")
+ self.select_scheme("posix_home")
else:
if self.prefix is None:
self.prefix = os.path.normpath(sys.prefix)
@@ -493,11 +403,15 @@ class install(Command):
def select_scheme(self, name):
"""Sets the install directories by applying the install schemes."""
# it's the caller's problem if they supply a bad name!
- scheme = INSTALL_SCHEMES[name]
- for key in SCHEME_KEYS:
+ scheme = get_paths(name, expand=False)
+ for key, value in scheme.items():
+ if key == 'platinclude':
+ key = 'headers'
+ value = os.path.join(value, self.distribution.get_name())
attrname = 'install_' + key
- if getattr(self, attrname) is None:
- setattr(self, attrname, scheme[key])
+ if hasattr(self, attrname):
+ if getattr(self, attrname) is None:
+ setattr(self, attrname, value)
def _expand_attrs(self, attrs):
for attr in attrs:
@@ -505,7 +419,10 @@ class install(Command):
if val is not None:
if os.name == 'posix' or os.name == 'nt':
val = os.path.expanduser(val)
- val = subst_vars(val, self.config_vars)
+ try:
+ val = _subst_vars(val, self.config_vars)
+ except:
+ import pdb; pdb.set_trace()
setattr(self, attr, val)
def expand_basedirs(self):
diff --git a/Lib/distutils/core.py b/Lib/distutils/core.py
index c820a42..6ed3e8f 100644
--- a/Lib/distutils/core.py
+++ b/Lib/distutils/core.py
@@ -35,7 +35,7 @@ usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
def gen_usage(script_name):
script = os.path.basename(script_name)
- return USAGE % vars()
+ return USAGE % {'script': script}
# Some mild magic to control the behaviour of 'setup()' from 'run_setup()'.
diff --git a/Lib/distutils/cygwinccompiler.py b/Lib/distutils/cygwinccompiler.py
index 3e2a634..f381f60 100644
--- a/Lib/distutils/cygwinccompiler.py
+++ b/Lib/distutils/cygwinccompiler.py
@@ -337,7 +337,7 @@ def check_config_h():
# XXX since this function also checks sys.version, it's not strictly a
# "pyconfig.h" check -- should probably be renamed...
- from distutils import sysconfig
+ _sysconfig = __import__('sysconfig')
# if sys.version contains GCC then python was compiled with GCC, and the
# pyconfig.h file should be OK
@@ -345,7 +345,7 @@ def check_config_h():
return CONFIG_H_OK, "sys.version mentions 'GCC'"
# let's see if __GNUC__ is mentioned in python.h
- fn = sysconfig.get_config_h_filename()
+ fn = _sysconfig.get_config_h_filename()
try:
with open(fn) as config_h:
if "__GNUC__" in config_h.read():
diff --git a/Lib/distutils/extension.py b/Lib/distutils/extension.py
index 10aaf7c..ebe5437 100644
--- a/Lib/distutils/extension.py
+++ b/Lib/distutils/extension.py
@@ -134,14 +134,17 @@ class Extension:
def read_setup_file(filename):
"""Reads a Setup file and returns Extension instances."""
- from distutils.sysconfig import (parse_makefile, expand_makefile_vars,
+ warnings.warn('distutils.extensions.read_setup_file is deprecated. '
+ 'It will be removed in the next Python release.')
+ _sysconfig = __import__('sysconfig')
+ from distutils.sysconfig import (expand_makefile_vars,
_variable_rx)
from distutils.text_file import TextFile
from distutils.util import split_quoted
# First pass over the file to gather "VAR = VALUE" assignments.
- vars = parse_makefile(filename)
+ vars = _sysconfig._parse_makefile(filename)
# Second pass to gobble up the real content: lines of the form
# <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...]
@@ -161,7 +164,10 @@ def read_setup_file(filename):
file.warn("'%s' lines not handled yet" % line)
continue
- line = expand_makefile_vars(line, vars)
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore")
+ line = expand_makefile_vars(line, vars)
+
words = split_quoted(line)
# NB. this parses a slightly different syntax than the old
diff --git a/Lib/distutils/msvc9compiler.py b/Lib/distutils/msvc9compiler.py
index 6455fff..38fc96f 100644
--- a/Lib/distutils/msvc9compiler.py
+++ b/Lib/distutils/msvc9compiler.py
@@ -23,10 +23,10 @@ from distutils.errors import (DistutilsExecError, DistutilsPlatformError,
CompileError, LibError, LinkError)
from distutils.ccompiler import CCompiler, gen_lib_options
from distutils import log
-from distutils.util import get_platform
-
import winreg
+_sysconfig = __import__('sysconfig')
+
RegOpenKeyEx = winreg.OpenKeyEx
RegEnumKey = winreg.EnumKey
RegEnumValue = winreg.EnumValue
@@ -327,7 +327,7 @@ class MSVCCompiler(CCompiler) :
# multi-init means we would need to check platform same each time...
assert not self.initialized, "don't init multiple times"
if plat_name is None:
- plat_name = get_platform()
+ plat_name = _sysconfig.get_platform()
# sanity check for platforms to prevent obscure errors later.
ok_plats = 'win32', 'win-amd64', 'win-ia64'
if plat_name not in ok_plats:
@@ -348,12 +348,12 @@ class MSVCCompiler(CCompiler) :
# On AMD64, 'vcvars32.bat amd64' is a native build env; to cross
# compile use 'x86' (ie, it runs the x86 compiler directly)
# No idea how itanium handles this, if at all.
- if plat_name == get_platform() or plat_name == 'win32':
+ if plat_name == _sysconfig.get_platform() or plat_name == 'win32':
# native build or cross-compile to win32
plat_spec = PLAT_TO_VCVARS[plat_name]
else:
# cross compile from win32 -> some 64bit
- plat_spec = PLAT_TO_VCVARS[get_platform()] + '_' + \
+ plat_spec = PLAT_TO_VCVARS[_sysconfig.get_platform()] + '_' + \
PLAT_TO_VCVARS[plat_name]
vc_env = query_vcvarsall(VERSION, plat_spec)
diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
index 0fbd541..48f22ad 100644
--- a/Lib/distutils/sysconfig.py
+++ b/Lib/distutils/sysconfig.py
@@ -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 .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)
-
-# 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))
-
-# 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
-python_build = _python_build()
+from warnings import warn
-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]
+from distutils.errors import DistutilsPlatformError
+
+# importing sysconfig from Lib
+# to avoid this module to shadow it
+_sysconfig = __import__('sysconfig')
+_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__()
+
+def _python_build():
+ return _DeprecatedBool(_sysconfig.is_python_build())
+
+python_build = _python_build()
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']
- 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")
+ if plat_specific:
+ return get_path('platlib', vars=vars)
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)
diff --git a/Lib/distutils/tests/support.py b/Lib/distutils/tests/support.py
index e258d2e..d60da85 100644
--- a/Lib/distutils/tests/support.py
+++ b/Lib/distutils/tests/support.py
@@ -3,11 +3,19 @@ import os
import shutil
import tempfile
from copy import deepcopy
+import warnings
from distutils import log
from distutils.log import DEBUG, INFO, WARN, ERROR, FATAL
from distutils.core import Distribution
+def capture_warnings(func):
+ def _capture_warnings(*args, **kw):
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore")
+ return func(*args, **kw)
+ return _capture_warnings
+
class LoggingSilencer(object):
def setUp(self):
diff --git a/Lib/distutils/tests/test_build.py b/Lib/distutils/tests/test_build.py
index 6bca27e..2418e16 100644
--- a/Lib/distutils/tests/test_build.py
+++ b/Lib/distutils/tests/test_build.py
@@ -5,7 +5,7 @@ import sys
from distutils.command.build import build
from distutils.tests import support
-from distutils.util import get_platform
+from sysconfig import get_platform
class BuildTestCase(support.TempdirManager,
support.LoggingSilencer,
diff --git a/Lib/distutils/tests/test_build_clib.py b/Lib/distutils/tests/test_build_clib.py
index 536cd67..145eff5 100644
--- a/Lib/distutils/tests/test_build_clib.py
+++ b/Lib/distutils/tests/test_build_clib.py
@@ -120,8 +120,7 @@ class BuildCLibTestCase(support.TempdirManager,
# before we run the command, we want to make sure
# all commands are present on the system
# by creating a compiler and checking its executables
- from distutils.ccompiler import new_compiler
- from distutils.sysconfig import customize_compiler
+ from distutils.ccompiler import new_compiler, customize_compiler
compiler = new_compiler()
customize_compiler(compiler)
diff --git a/Lib/distutils/tests/test_build_ext.py b/Lib/distutils/tests/test_build_ext.py
index ebbb399..d097183 100644
--- a/Lib/distutils/tests/test_build_ext.py
+++ b/Lib/distutils/tests/test_build_ext.py
@@ -9,7 +9,7 @@ from test.support import captured_stdout
from distutils.core import Extension, Distribution
from distutils.command.build_ext import build_ext
-from distutils import sysconfig
+import sysconfig
from distutils.tests.support import TempdirManager
from distutils.tests.support import LoggingSilencer
from distutils.extension import Extension
@@ -105,17 +105,17 @@ class BuildExtTestCase(TempdirManager,
old = sys.platform
sys.platform = 'sunos' # fooling finalize_options
- from distutils.sysconfig import _config_vars
- old_var = _config_vars.get('Py_ENABLE_SHARED')
- _config_vars['Py_ENABLE_SHARED'] = 1
+ from sysconfig import _CONFIG_VARS
+ old_var = _CONFIG_VARS.get('Py_ENABLE_SHARED')
+ _CONFIG_VARS['Py_ENABLE_SHARED'] = 1
try:
cmd.ensure_finalized()
finally:
sys.platform = old
if old_var is None:
- del _config_vars['Py_ENABLE_SHARED']
+ del _CONFIG_VARS['Py_ENABLE_SHARED']
else:
- _config_vars['Py_ENABLE_SHARED'] = old_var
+ _CONFIG_VARS['Py_ENABLE_SHARED'] = old_var
# make sure we get some library dirs under solaris
self.assertTrue(len(cmd.library_dirs) > 0)
@@ -177,11 +177,10 @@ class BuildExtTestCase(TempdirManager,
cmd = build_ext(dist)
cmd.finalize_options()
- from distutils import sysconfig
- py_include = sysconfig.get_python_inc()
+ py_include = sysconfig.get_path('include')
self.assertTrue(py_include in cmd.include_dirs)
- plat_py_include = sysconfig.get_python_inc(plat_specific=1)
+ plat_py_include = sysconfig.get_path('platinclude')
self.assertTrue(plat_py_include in cmd.include_dirs)
# make sure cmd.libraries is turned into a list
diff --git a/Lib/distutils/tests/test_build_scripts.py b/Lib/distutils/tests/test_build_scripts.py
index b1d2d07..72e8915 100644
--- a/Lib/distutils/tests/test_build_scripts.py
+++ b/Lib/distutils/tests/test_build_scripts.py
@@ -5,7 +5,7 @@ import unittest
from distutils.command.build_scripts import build_scripts
from distutils.core import Distribution
-from distutils import sysconfig
+import sysconfig
from distutils.tests import support
@@ -91,12 +91,12 @@ class BuildScriptsTestCase(support.TempdirManager,
# --with-suffix=3`, python is compiled okay but the build scripts
# failed when writing the name of the executable
old = sysconfig.get_config_vars().get('VERSION')
- sysconfig._config_vars['VERSION'] = 4
+ sysconfig._CONFIG_VARS['VERSION'] = 4
try:
cmd.run()
finally:
if old is not None:
- sysconfig._config_vars['VERSION'] = old
+ sysconfig._CONFIG_VARS['VERSION'] = old
built = os.listdir(target)
for name in expected:
diff --git a/Lib/distutils/tests/test_ccompiler.py b/Lib/distutils/tests/test_ccompiler.py
index 9db8d24..27b51a0 100644
--- a/Lib/distutils/tests/test_ccompiler.py
+++ b/Lib/distutils/tests/test_ccompiler.py
@@ -3,8 +3,10 @@ import os
import unittest
from test.support import captured_stdout
-from distutils.ccompiler import gen_lib_options, CCompiler
+from distutils.ccompiler import (gen_lib_options, CCompiler,
+ get_default_compiler, customize_compiler)
from distutils import debug
+from distutils.tests import support
class FakeCompiler(object):
def library_dir_option(self, dir):
@@ -19,7 +21,7 @@ class FakeCompiler(object):
def library_option(self, lib):
return "-l" + lib
-class CCompilerTestCase(unittest.TestCase):
+class CCompilerTestCase(support.EnvironGuard, unittest.TestCase):
def test_gen_lib_options(self):
compiler = FakeCompiler()
@@ -52,6 +54,26 @@ class CCompilerTestCase(unittest.TestCase):
finally:
debug.DEBUG = False
+ def test_customize_compiler(self):
+
+ # not testing if default compiler is not unix
+ if get_default_compiler() != 'unix':
+ return
+
+ os.environ['AR'] = 'my_ar'
+ os.environ['ARFLAGS'] = '-arflags'
+
+ # make sure AR gets caught
+ class compiler:
+ compiler_type = 'unix'
+
+ def set_executables(self, **kw):
+ self.exes = kw
+
+ comp = compiler()
+ customize_compiler(comp)
+ self.assertEquals(comp.exes['archiver'], 'my_ar -arflags')
+
def test_suite():
return unittest.makeSuite(CCompilerTestCase)
diff --git a/Lib/distutils/tests/test_cygwinccompiler.py b/Lib/distutils/tests/test_cygwinccompiler.py
index 98f0f08..4b95dfa 100644
--- a/Lib/distutils/tests/test_cygwinccompiler.py
+++ b/Lib/distutils/tests/test_cygwinccompiler.py
@@ -4,6 +4,7 @@ import sys
import os
import subprocess
import warnings
+import sysconfig
from test.support import check_warnings
from test.support import captured_stdout
@@ -23,13 +24,11 @@ class CygwinCCompilerTestCase(support.TempdirManager,
super(CygwinCCompilerTestCase, self).setUp()
self.version = sys.version
self.python_h = os.path.join(self.mkdtemp(), 'python.h')
- from distutils import sysconfig
self.old_get_config_h_filename = sysconfig.get_config_h_filename
sysconfig.get_config_h_filename = self._get_config_h_filename
def tearDown(self):
sys.version = self.version
- from distutils import sysconfig
sysconfig.get_config_h_filename = self.old_get_config_h_filename
super(CygwinCCompilerTestCase, self).tearDown()
diff --git a/Lib/distutils/tests/test_extension.py b/Lib/distutils/tests/test_extension.py
index 1ee3058..9d3cfe6 100755
--- a/Lib/distutils/tests/test_extension.py
+++ b/Lib/distutils/tests/test_extension.py
@@ -5,9 +5,11 @@ import warnings
from test.support import check_warnings
from distutils.extension import read_setup_file, Extension
+from distutils.tests.support import capture_warnings
class ExtensionTestCase(unittest.TestCase):
+ @capture_warnings
def test_read_setup_file(self):
# trying to read a Setup file
# (sample extracted from the PyGame project)
diff --git a/Lib/distutils/tests/test_install.py b/Lib/distutils/tests/test_install.py
index 76fa02a..59e9080 100644
--- a/Lib/distutils/tests/test_install.py
+++ b/Lib/distutils/tests/test_install.py
@@ -5,12 +5,14 @@ import os.path
import sys
import unittest
import site
+import sysconfig
+from sysconfig import (get_scheme_names, _CONFIG_VARS, _INSTALL_SCHEMES,
+ get_config_var, get_path)
from test.support import captured_stdout
from distutils.command.install import install
from distutils.command import install as install_module
-from distutils.command.install import INSTALL_SCHEMES
from distutils.core import Distribution
from distutils.errors import DistutilsOptionError
@@ -36,9 +38,23 @@ class InstallTestCase(support.TempdirManager,
build_lib=os.path.join(builddir, "lib"),
)
- cmd = install(dist)
- cmd.home = destination
- cmd.ensure_finalized()
+
+
+ posix_prefix = _INSTALL_SCHEMES['posix_prefix']
+ old_posix_prefix = posix_prefix['platinclude']
+ posix_prefix['platinclude'] = \
+ '{platbase}/include/python{py_version_short}'
+
+ posix_home = _INSTALL_SCHEMES['posix_home']
+ old_posix_home = posix_home['platinclude']
+ posix_home['platinclude'] = '{base}/include/python'
+ try:
+ cmd = install(dist)
+ cmd.home = destination
+ cmd.ensure_finalized()
+ finally:
+ posix_home['platinclude'] = old_posix_home
+ posix_prefix['platinclude'] = old_posix_prefix
self.assertEqual(cmd.install_base, destination)
self.assertEqual(cmd.install_platbase, destination)
@@ -63,18 +79,19 @@ class InstallTestCase(support.TempdirManager,
return
# preparing the environement for the test
- self.old_user_base = site.USER_BASE
- self.old_user_site = site.USER_SITE
+ self.old_user_base = get_config_var('userbase')
+ self.old_user_site = get_path('purelib', '%s_user' % os.name)
self.tmpdir = self.mkdtemp()
self.user_base = os.path.join(self.tmpdir, 'B')
self.user_site = os.path.join(self.tmpdir, 'S')
- site.USER_BASE = self.user_base
- site.USER_SITE = self.user_site
- install_module.USER_BASE = self.user_base
- install_module.USER_SITE = self.user_site
+ _CONFIG_VARS['userbase'] = self.user_base
+ scheme = _INSTALL_SCHEMES['%s_user' % os.name]
+ scheme['purelib'] = self.user_site
def _expanduser(path):
- return self.tmpdir
+ if path[0] == '~':
+ path = os.path.normpath(self.tmpdir) + path[1:]
+ return path
self.old_expand = os.path.expanduser
os.path.expanduser = _expanduser
@@ -82,19 +99,17 @@ class InstallTestCase(support.TempdirManager,
# this is the actual test
self._test_user_site()
finally:
- site.USER_BASE = self.old_user_base
- site.USER_SITE = self.old_user_site
- install_module.USER_BASE = self.old_user_base
- install_module.USER_SITE = self.old_user_site
+ _CONFIG_VARS['userbase'] = self.old_user_base
+ scheme['purelib'] = self.old_user_site
os.path.expanduser = self.old_expand
def _test_user_site(self):
- for key in ('nt_user', 'unix_user', 'os2_home'):
- self.assertTrue(key in INSTALL_SCHEMES)
+ schemes = get_scheme_names()
+ for key in ('nt_user', 'posix_user', 'os2_home'):
+ self.assertTrue(key in schemes)
dist = Distribution({'name': 'xx'})
cmd = install(dist)
-
# making sure the user option is there
options = [name for name, short, lable in
cmd.user_options]
@@ -185,7 +200,7 @@ class InstallTestCase(support.TempdirManager,
with open(cmd.record) as f:
self.assertEquals(len(f.readlines()), 1)
- def test_debug_mode(self):
+ def _test_debug_mode(self):
# this covers the code called when DEBUG is set
old_logs_len = len(self.logs)
install_module.DEBUG = True
diff --git a/Lib/distutils/tests/test_sysconfig.py b/Lib/distutils/tests/test_sysconfig.py
index edc755e..e7df803 100644
--- a/Lib/distutils/tests/test_sysconfig.py
+++ b/Lib/distutils/tests/test_sysconfig.py
@@ -4,7 +4,6 @@ import test
import unittest
from distutils import sysconfig
-from distutils.ccompiler import get_default_compiler
from distutils.tests import support
from test.support import TESTFN, run_unittest
@@ -26,10 +25,7 @@ class SysconfigTestCase(support.EnvironGuard,
elif os.path.isdir(TESTFN):
shutil.rmtree(TESTFN)
- def test_get_config_h_filename(self):
- config_h = sysconfig.get_config_h_filename()
- self.assertTrue(os.path.isfile(config_h), config_h)
-
+ @support.capture_warnings
def test_get_python_lib(self):
lib_dir = sysconfig.get_python_lib()
# XXX doesn't work on Linux when Python was never installed before
@@ -37,7 +33,11 @@ class SysconfigTestCase(support.EnvironGuard,
# test for pythonxx.lib?
self.assertNotEqual(sysconfig.get_python_lib(),
sysconfig.get_python_lib(prefix=TESTFN))
+ _sysconfig = __import__('sysconfig')
+ res = sysconfig.get_python_lib(True, True)
+ self.assertEquals(_sysconfig.get_path('platstdlib'), res)
+ @support.capture_warnings
def test_get_python_inc(self):
inc_dir = sysconfig.get_python_inc()
# This is not much of a test. We make sure Python.h exists
@@ -47,31 +47,7 @@ class SysconfigTestCase(support.EnvironGuard,
python_h = os.path.join(inc_dir, "Python.h")
self.assertTrue(os.path.isfile(python_h), python_h)
- def test_get_config_vars(self):
- cvars = sysconfig.get_config_vars()
- self.assertTrue(isinstance(cvars, dict))
- self.assertTrue(cvars)
-
- def test_customize_compiler(self):
-
- # not testing if default compiler is not unix
- if get_default_compiler() != 'unix':
- return
-
- os.environ['AR'] = 'my_ar'
- os.environ['ARFLAGS'] = '-arflags'
-
- # make sure AR gets caught
- class compiler:
- compiler_type = 'unix'
-
- def set_executables(self, **kw):
- self.exes = kw
-
- comp = compiler()
- sysconfig.customize_compiler(comp)
- self.assertEquals(comp.exes['archiver'], 'my_ar -arflags')
-
+ @support.capture_warnings
def test_parse_makefile_base(self):
self.makefile = TESTFN
fd = open(self.makefile, 'w')
diff --git a/Lib/distutils/tests/test_unixccompiler.py b/Lib/distutils/tests/test_unixccompiler.py
index 008ae5d..6976dd5 100644
--- a/Lib/distutils/tests/test_unixccompiler.py
+++ b/Lib/distutils/tests/test_unixccompiler.py
@@ -1,8 +1,8 @@
"""Tests for distutils.unixccompiler."""
import sys
import unittest
+import sysconfig
-from distutils import sysconfig
from distutils.unixccompiler import UnixCCompiler
class UnixCCompilerTestCase(unittest.TestCase):
diff --git a/Lib/distutils/tests/test_util.py b/Lib/distutils/tests/test_util.py
index 8f8d4a1..ae6671d 100644
--- a/Lib/distutils/tests/test_util.py
+++ b/Lib/distutils/tests/test_util.py
@@ -6,15 +6,14 @@ from copy import copy
from io import BytesIO
import subprocess
+from sysconfig import get_config_vars, get_platform
from distutils.errors import DistutilsPlatformError, DistutilsByteCompileError
-from distutils.util import (get_platform, convert_path, change_root,
+from distutils.util import (convert_path, change_root,
check_environ, split_quoted, strtobool,
rfc822_escape, get_compiler_versions,
_find_exe_version, _MAC_OS_X_LD_VERSION,
byte_compile)
from distutils import util
-from distutils.sysconfig import get_config_vars
-from distutils import sysconfig
from distutils.tests import support
from distutils.version import LooseVersion
@@ -44,7 +43,7 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
self.join = os.path.join
self.isabs = os.path.isabs
self.splitdrive = os.path.splitdrive
- self._config_vars = copy(sysconfig._config_vars)
+ #self._config_vars = copy(sysconfig._config_vars)
# patching os.uname
if hasattr(os, 'uname'):
@@ -78,7 +77,7 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
os.uname = self.uname
else:
del os.uname
- sysconfig._config_vars = copy(self._config_vars)
+ #sysconfig._config_vars = copy(self._config_vars)
util.find_executable = self.old_find_executable
subprocess.Popen = self.old_popen
sys.old_stdout = self.old_stdout
@@ -91,7 +90,7 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
def _get_uname(self):
return self._uname
- def test_get_platform(self):
+ def _test_get_platform(self):
# windows XP, 32bits
os.name = 'nt'
@@ -119,7 +118,6 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
sys.version = ('2.5 (r25:51918, Sep 19 2006, 08:49:13) '
'\n[GCC 4.0.1 (Apple Computer, Inc. build 5341)]')
sys.platform = 'darwin'
-
self._set_uname(('Darwin', 'macziade', '8.11.1',
('Darwin Kernel Version 8.11.1: '
'Wed Oct 10 18:23:28 PDT 2007; '
@@ -157,7 +155,6 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
finally:
sys.maxsize = maxsize
-
# macbook with fat binaries (fat, universal or fat64)
os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.4'
get_config_vars()['CFLAGS'] = ('-arch ppc -arch i386 -isysroot '
@@ -201,7 +198,6 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
self.assertEquals(get_platform(), 'macosx-10.4-%s'%(arch,))
-
# linux debian sarge
os.name = 'posix'
sys.version = ('2.3.5 (#1, Jul 4 2007, 17:28:59) '
diff --git a/Lib/distutils/unixccompiler.py b/Lib/distutils/unixccompiler.py
index 51f6349..c14a5d3 100644
--- a/Lib/distutils/unixccompiler.py
+++ b/Lib/distutils/unixccompiler.py
@@ -17,7 +17,6 @@ __revision__ = "$Id$"
import os, sys
-from distutils import sysconfig
from distutils.dep_util import newer
from distutils.ccompiler import \
CCompiler, gen_preprocess_options, gen_lib_options
@@ -25,6 +24,7 @@ from distutils.errors import \
DistutilsExecError, CompileError, LibError, LinkError
from distutils import log
+
# XXX Things not currently handled:
# * optimization/debug/warning flags; we just use whatever's in Python's
# Makefile and live with it. Is this adequate? If not, we might
@@ -74,7 +74,7 @@ def _darwin_compiler_fixup(compiler_so, cc_args):
if 'ARCHFLAGS' in os.environ and not stripArch:
# User specified different -arch flags in the environ,
- # see also distutils.sysconfig
+ # see also the sysconfig
compiler_so = compiler_so + os.environ['ARCHFLAGS'].split()
if stripSysroot:
@@ -281,7 +281,9 @@ class UnixCCompiler(CCompiler):
# this time, there's no way to determine this information from
# the configuration data stored in the Python installation, so
# we use this hack.
- compiler = os.path.basename(sysconfig.get_config_var("CC"))
+ _sysconfig = __import__('sysconfig')
+
+ compiler = os.path.basename(_sysconfig.get_config_var("CC"))
if sys.platform[:6] == "darwin":
# MacOSX's linker doesn't understand the -R flag at all
return "-L" + dir
@@ -296,7 +298,7 @@ class UnixCCompiler(CCompiler):
# use it anyway. Since distutils has always passed in
# -Wl whenever gcc was used in the past it is probably
# safest to keep doing so.
- if sysconfig.get_config_var("GNULD") == "yes":
+ if _sysconfig.get_config_var("GNULD") == "yes":
# GNU ld needs an extra option to get a RUNPATH
# instead of just an RPATH.
return "-Wl,--enable-new-dtags,-R" + dir
diff --git a/Lib/distutils/util.py b/Lib/distutils/util.py
index 8adf6e0..0515fef 100644
--- a/Lib/distutils/util.py
+++ b/Lib/distutils/util.py
@@ -15,173 +15,7 @@ from distutils import log
from distutils.version import LooseVersion
from distutils.errors import DistutilsByteCompileError
-def get_platform():
- """Return a string that identifies the current platform.
-
- This is used mainly to distinguish platform-specific build directories and
- platform-specific built distributions. Typically includes the OS name
- and version and the architecture (as supplied by 'os.uname()'),
- although the exact information included depends on the OS; eg. for IRIX
- the architecture isn't particularly important (IRIX only runs on SGI
- hardware), but for Linux the kernel version isn't particularly
- important.
-
- Examples of returned values:
- linux-i586
- linux-alpha (?)
- solaris-2.6-sun4u
- irix-5.3
- irix64-6.2
-
- Windows will return one of:
- win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc)
- win-ia64 (64bit Windows on Itanium)
- win32 (all others - specifically, sys.platform is returned)
-
- For other non-POSIX platforms, currently just returns 'sys.platform'.
- """
- if os.name == 'nt':
- # sniff sys.version for architecture.
- prefix = " bit ("
- i = sys.version.find(prefix)
- if i == -1:
- return sys.platform
- j = sys.version.find(")", i)
- look = sys.version[i+len(prefix):j].lower()
- if look == 'amd64':
- return 'win-amd64'
- if look == 'itanium':
- return 'win-ia64'
- return sys.platform
-
- if os.name != "posix" or not hasattr(os, 'uname'):
- # XXX what about the architecture? NT is Intel or Alpha,
- # Mac OS is M68k or PPC, etc.
- return sys.platform
-
- # Try to distinguish various flavours of Unix
-
- (osname, host, release, version, machine) = os.uname()
-
- # Convert the OS name to lowercase, remove '/' characters
- # (to accommodate BSD/OS), and translate spaces (for "Power Macintosh")
- osname = osname.lower().replace('/', '')
- machine = machine.replace(' ', '_')
- machine = machine.replace('/', '-')
-
- if osname[:5] == "linux":
- # At least on Linux/Intel, 'machine' is the processor --
- # i386, etc.
- # XXX what about Alpha, SPARC, etc?
- return "%s-%s" % (osname, machine)
- elif osname[:5] == "sunos":
- if release[0] >= "5": # SunOS 5 == Solaris 2
- osname = "solaris"
- release = "%d.%s" % (int(release[0]) - 3, release[2:])
- # fall through to standard osname-release-machine representation
- elif osname[:4] == "irix": # could be "irix64"!
- return "%s-%s" % (osname, release)
- elif osname[:3] == "aix":
- return "%s-%s.%s" % (osname, version, release)
- elif osname[:6] == "cygwin":
- osname = "cygwin"
- rel_re = re.compile (r'[\d.]+', re.ASCII)
- m = rel_re.match(release)
- if m:
- release = m.group()
- elif osname[:6] == "darwin":
- #
- # For our purposes, we'll assume that the system version from
- # distutils' perspective is what MACOSX_DEPLOYMENT_TARGET is set
- # to. This makes the compatibility story a bit more sane because the
- # machine is going to compile and link as if it were
- # MACOSX_DEPLOYMENT_TARGET.
- from distutils.sysconfig import get_config_vars
- cfgvars = get_config_vars()
-
- macver = os.environ.get('MACOSX_DEPLOYMENT_TARGET')
- if not macver:
- macver = cfgvars.get('MACOSX_DEPLOYMENT_TARGET')
-
- if 1:
- # Always calculate the release of the running machine,
- # needed to determine if we can build fat binaries or not.
-
- macrelease = macver
- # Get the system version. Reading this plist is a documented
- # way to get the system version (see the documentation for
- # the Gestalt Manager)
- try:
- f = open('/System/Library/CoreServices/SystemVersion.plist')
- except IOError:
- # We're on a plain darwin box, fall back to the default
- # behaviour.
- pass
- else:
- m = re.search(
- r'<key>ProductUserVisibleVersion</key>\s*' +
- r'<string>(.*?)</string>', f.read())
- f.close()
- if m is not None:
- macrelease = '.'.join(m.group(1).split('.')[:2])
- # else: fall back to the default behaviour
-
- if not macver:
- macver = macrelease
-
- if macver:
- from distutils.sysconfig import get_config_vars
- release = macver
- osname = "macosx"
-
- if (macrelease + '.') >= '10.4.' and \
- '-arch' in get_config_vars().get('CFLAGS', '').strip():
- # The universal build will build fat binaries, but not on
- # systems before 10.4
- #
- # Try to detect 4-way universal builds, those have machine-type
- # 'universal' instead of 'fat'.
-
- machine = 'fat'
- cflags = get_config_vars().get('CFLAGS')
-
- archs = re.findall('-arch\s+(\S+)', cflags)
- archs.sort()
- archs = tuple(archs)
-
- if len(archs) == 1:
- machine = archs[0]
- elif archs == ('i386', 'ppc'):
- machine = 'fat'
- elif archs == ('i386', 'x86_64'):
- machine = 'intel'
- elif archs == ('i386', 'ppc', 'x86_64'):
- machine = 'fat3'
- elif archs == ('ppc64', 'x86_64'):
- machine = 'fat64'
- elif archs == ('i386', 'ppc', 'ppc64', 'x86_64'):
- machine = 'universal'
- else:
- raise ValueError(
- "Don't know machine value for archs=%r"%(archs,))
-
- elif machine == 'i386':
- # On OSX the machine type returned by uname is always the
- # 32-bit variant, even if the executable architecture is
- # the 64-bit variant
- if sys.maxsize >= 2**32:
- machine = 'x86_64'
-
- elif machine in ('PowerPC', 'Power_Macintosh'):
- # Pick a sane name for the PPC architecture.
- machine = 'ppc'
-
- # See 'i386' case
- if sys.maxsize >= 2**32:
- machine = 'ppc64'
-
- return "%s-%s-%s" % (osname, release, machine)
-
+_sysconfig = __import__('sysconfig')
def convert_path(pathname):
"""Return 'pathname' as a name that will work on the native filesystem.
@@ -269,7 +103,7 @@ def check_environ():
os.environ['HOME'] = pwd.getpwuid(os.getuid())[5]
if 'PLAT' not in os.environ:
- os.environ['PLAT'] = get_platform()
+ os.environ['PLAT'] = _sysconfig.get_platform()
_environ_checked = 1