Commit efc2ae7c authored by Tarek Ziadé's avatar Tarek Ziadé

taking sysconfig out of distutils

parent aa70d631
...@@ -18,6 +18,58 @@ from distutils.dep_util import newer_group ...@@ -18,6 +18,58 @@ from distutils.dep_util import newer_group
from distutils.util import split_quoted, execute from distutils.util import split_quoted, execute
from distutils import log 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: class CCompiler:
"""Abstract base class to define the interface that must be implemented """Abstract base class to define the interface that must be implemented
by real compiler classes. Also has some utility methods used by by real compiler classes. Also has some utility methods used by
......
...@@ -6,10 +6,10 @@ distribution).""" ...@@ -6,10 +6,10 @@ distribution)."""
__revision__ = "$Id$" __revision__ = "$Id$"
import os import os
from sysconfig import get_platform
from distutils.core import Command from distutils.core import Command
from distutils.errors import DistutilsPlatformError, DistutilsOptionError from distutils.errors import DistutilsPlatformError, DistutilsOptionError
from distutils.util import get_platform
def show_formats(): def show_formats():
......
...@@ -8,11 +8,11 @@ __revision__ = "$Id$" ...@@ -8,11 +8,11 @@ __revision__ = "$Id$"
import os import os
from sysconfig import get_python_version, get_platform
from distutils.core import Command from distutils.core import Command
from distutils.util import get_platform
from distutils.dir_util import remove_tree, ensure_relative from distutils.dir_util import remove_tree, ensure_relative
from distutils.errors import DistutilsPlatformError from distutils.errors import DistutilsPlatformError
from distutils.sysconfig import get_python_version
from distutils import log from distutils import log
class bdist_dumb (Command): class bdist_dumb (Command):
......
...@@ -9,11 +9,11 @@ import sys ...@@ -9,11 +9,11 @@ import sys
import os import os
import string import string
from sysconfig import get_python_version, get_platform
from distutils.core import Command from distutils.core import Command
from distutils.util import get_platform
from distutils.dir_util import remove_tree from distutils.dir_util import remove_tree
from distutils.errors import DistutilsOptionError, DistutilsPlatformError from distutils.errors import DistutilsOptionError, DistutilsPlatformError
from distutils.sysconfig import get_python_version
from distutils import log from distutils import log
class bdist_wininst (Command): class bdist_wininst (Command):
......
...@@ -5,9 +5,10 @@ Implements the Distutils 'build' command.""" ...@@ -5,9 +5,10 @@ Implements the Distutils 'build' command."""
__revision__ = "$Id$" __revision__ = "$Id$"
import sys, os import sys, os
from sysconfig import get_platform
from distutils.core import Command from distutils.core import Command
from distutils.errors import DistutilsOptionError from distutils.errors import DistutilsOptionError
from distutils.util import get_platform
def show_compilers(): def show_compilers():
from distutils.ccompiler import show_compilers from distutils.ccompiler import show_compilers
......
...@@ -19,7 +19,7 @@ __revision__ = "$Id$" ...@@ -19,7 +19,7 @@ __revision__ = "$Id$"
import os import os
from distutils.core import Command from distutils.core import Command
from distutils.errors import DistutilsSetupError from distutils.errors import DistutilsSetupError
from distutils.sysconfig import customize_compiler from distutils.ccompiler import customize_compiler
from distutils import log from distutils import log
def show_compilers(): def show_compilers():
......
...@@ -9,13 +9,14 @@ __revision__ = "$Id$" ...@@ -9,13 +9,14 @@ __revision__ = "$Id$"
import sys, os, re import sys, os, re
from warnings import warn from warnings import warn
from sysconfig import get_platform
from distutils.core import Command from distutils.core import Command
from distutils.errors import (CCompilerError, DistutilsError, CompileError, from distutils.errors import *
DistutilsSetupError, DistutilsPlatformError) from distutils.ccompiler import customize_compiler
from distutils.sysconfig import customize_compiler, get_python_version
from distutils.dep_util import newer_group from distutils.dep_util import newer_group
from distutils.extension import Extension from distutils.extension import Extension
from distutils.util import get_platform
from distutils import log from distutils import log
# this keeps compatibility from 2.3 to 2.5 # this keeps compatibility from 2.3 to 2.5
...@@ -173,8 +174,7 @@ class build_ext(Command): ...@@ -173,8 +174,7 @@ class build_ext(Command):
self.user = None self.user = None
def finalize_options(self): def finalize_options(self):
from distutils import sysconfig _sysconfig = __import__('sysconfig')
self.set_undefined_options('build', self.set_undefined_options('build',
('build_lib', 'build_lib'), ('build_lib', 'build_lib'),
('build_temp', 'build_temp'), ('build_temp', 'build_temp'),
...@@ -191,8 +191,8 @@ class build_ext(Command): ...@@ -191,8 +191,8 @@ class build_ext(Command):
# Make sure Python's include directories (for Python.h, pyconfig.h, # Make sure Python's include directories (for Python.h, pyconfig.h,
# etc.) are in the include search path. # etc.) are in the include search path.
py_include = sysconfig.get_python_inc() py_include = _sysconfig.get_path('include')
plat_py_include = sysconfig.get_python_inc(plat_specific=1) plat_py_include = _sysconfig.get_path('platinclude')
if self.include_dirs is None: if self.include_dirs is None:
self.include_dirs = self.distribution.include_dirs or [] self.include_dirs = self.distribution.include_dirs or []
if isinstance(self.include_dirs, str): if isinstance(self.include_dirs, str):
...@@ -270,7 +270,7 @@ class build_ext(Command): ...@@ -270,7 +270,7 @@ class build_ext(Command):
if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")): if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
# building third party extensions # building third party extensions
self.library_dirs.append(os.path.join(sys.prefix, "lib", self.library_dirs.append(os.path.join(sys.prefix, "lib",
"python" + get_python_version(), "python" + _sysconfig.get_python_version(),
"config")) "config"))
else: else:
# building python standard extensions # building python standard extensions
...@@ -278,13 +278,13 @@ class build_ext(Command): ...@@ -278,13 +278,13 @@ class build_ext(Command):
# for extensions under Linux or Solaris with a shared Python library, # for extensions under Linux or Solaris with a shared Python library,
# Python's library directory must be appended to library_dirs # 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') if ((sys.platform.startswith('linux') or sys.platform.startswith('gnu')
or sys.platform.startswith('sunos')) 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")): if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
# building third party extensions # building third party extensions
self.library_dirs.append(sysconfig.get_config_var('LIBDIR')) self.library_dirs.append(_sysconfig.get_config_var('LIBDIR'))
else: else:
# building python standard extensions # building python standard extensions
self.library_dirs.append('.') self.library_dirs.append('.')
...@@ -719,13 +719,13 @@ class build_ext(Command): ...@@ -719,13 +719,13 @@ class build_ext(Command):
of the file from which it will be loaded (eg. "foo/bar.so", or of the file from which it will be loaded (eg. "foo/bar.so", or
"foo\bar.pyd"). "foo\bar.pyd").
""" """
from distutils.sysconfig import get_config_var _sysconfig = __import__('sysconfig')
ext_path = ext_name.split('.') ext_path = ext_name.split('.')
# OS/2 has an 8 character module (extension) limit :-( # OS/2 has an 8 character module (extension) limit :-(
if os.name == "os2": if os.name == "os2":
ext_path[len(ext_path) - 1] = ext_path[len(ext_path) - 1][:8] ext_path[len(ext_path) - 1] = ext_path[len(ext_path) - 1][:8]
# extensions in debug_mode are named 'module_d.pyd' under windows # 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: if os.name == 'nt' and self.debug:
return os.path.join(*ext_path) + '_d' + so_ext return os.path.join(*ext_path) + '_d' + so_ext
return os.path.join(*ext_path) + so_ext return os.path.join(*ext_path) + so_ext
...@@ -785,14 +785,13 @@ class build_ext(Command): ...@@ -785,14 +785,13 @@ class build_ext(Command):
# extensions, it is a reference to the original list # extensions, it is a reference to the original list
return ext.libraries + [pythonlib] return ext.libraries + [pythonlib]
elif sys.platform[:6] == "atheos": elif sys.platform[:6] == "atheos":
from distutils import sysconfig _sysconfig = __import__('sysconfig')
template = "python%d.%d" template = "python%d.%d"
pythonlib = (template % pythonlib = (template %
(sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
# Get SHLIBS from Makefile # Get SHLIBS from Makefile
extra = [] extra = []
for lib in sysconfig.get_config_var('SHLIBS').split(): for lib in _sysconfig.get_config_var('SHLIBS').split():
if lib.startswith('-l'): if lib.startswith('-l'):
extra.append(lib[2:]) extra.append(lib[2:])
else: else:
...@@ -806,8 +805,8 @@ class build_ext(Command): ...@@ -806,8 +805,8 @@ class build_ext(Command):
return ext.libraries return ext.libraries
else: else:
from distutils import sysconfig _sysconfig = __import__('sysconfig')
if sysconfig.get_config_var('Py_ENABLE_SHARED'): if _sysconfig.get_config_var('Py_ENABLE_SHARED'):
template = "python%d.%d" template = "python%d.%d"
pythonlib = (template % pythonlib = (template %
(sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
......
...@@ -6,7 +6,6 @@ __revision__ = "$Id$" ...@@ -6,7 +6,6 @@ __revision__ = "$Id$"
import os, re import os, re
from stat import ST_MODE from stat import ST_MODE
from distutils import sysconfig
from distutils.core import Command from distutils.core import Command
from distutils.dep_util import newer from distutils.dep_util import newer
from distutils.util import convert_path from distutils.util import convert_path
...@@ -57,6 +56,7 @@ class build_scripts (Command): ...@@ -57,6 +56,7 @@ class build_scripts (Command):
ie. starts with "\#!" and contains "python"), then adjust the first ie. starts with "\#!" and contains "python"), then adjust the first
line to refer to the current Python interpreter as we copy. line to refer to the current Python interpreter as we copy.
""" """
_sysconfig = __import__('sysconfig')
self.mkpath(self.build_dir) self.mkpath(self.build_dir)
outfiles = [] outfiles = []
for script in self.scripts: for script in self.scripts:
...@@ -94,16 +94,16 @@ class build_scripts (Command): ...@@ -94,16 +94,16 @@ class build_scripts (Command):
self.build_dir) self.build_dir)
if not self.dry_run: if not self.dry_run:
outf = open(outfile, "w") outf = open(outfile, "w")
if not sysconfig.python_build: if not _sysconfig.is_python_build():
outf.write("#!%s%s\n" % outf.write("#!%s%s\n" %
(self.executable, (self.executable,
post_interp)) post_interp))
else: else:
outf.write("#!%s%s\n" % outf.write("#!%s%s\n" %
(os.path.join( (os.path.join(
sysconfig.get_config_var("BINDIR"), _sysconfig.get_config_var("BINDIR"),
"python%s%s" % (sysconfig.get_config_var("VERSION"), "python%s%s" % (_sysconfig.get_config_var("VERSION"),
sysconfig.get_config_var("EXE"))), _sysconfig.get_config_var("EXE"))),
post_interp)) post_interp))
outf.writelines(f.readlines()) outf.writelines(f.readlines())
outf.close() outf.close()
......
...@@ -16,7 +16,7 @@ import re ...@@ -16,7 +16,7 @@ import re
from distutils.core import Command from distutils.core import Command
from distutils.errors import DistutilsExecError from distutils.errors import DistutilsExecError
from distutils.sysconfig import customize_compiler from distutils.ccompiler import customize_compiler
from distutils import log from distutils import log
LANG_EXT = {'c': '.c', 'c++': '.cxx'} LANG_EXT = {'c': '.c', 'c++': '.cxx'}
......
...@@ -7,115 +7,25 @@ __revision__ = "$Id$" ...@@ -7,115 +7,25 @@ __revision__ = "$Id$"
import sys import sys
import os import os
from sysconfig import (get_config_vars, get_platform, get_paths, get_path,
get_config_var)
from distutils import log from distutils import log
from distutils.core import Command from distutils.core import Command
from distutils.debug import DEBUG from distutils.debug import DEBUG
from distutils.sysconfig import get_config_vars
from distutils.errors import DistutilsPlatformError from distutils.errors import DistutilsPlatformError
from distutils.file_util import write_file from distutils.file_util import write_file
from distutils.util import convert_path, subst_vars, change_root from distutils.util import convert_path, change_root
from distutils.util import get_platform
from distutils.errors import DistutilsOptionError from distutils.errors import DistutilsOptionError
# this keeps compatibility from 2.3 to 2.5 def _subst_vars(s, local_vars):
if sys.version < "2.6": try:
USER_BASE = None return s.format(**local_vars)
USER_SITE = None except KeyError:
HAS_USER_SITE = False try:
else: return s.format(**os.environ)
from site import USER_BASE except KeyError, var:
from site import USER_SITE raise AttributeError('{%s}' % var)
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')
class install(Command): class install(Command):
...@@ -182,11 +92,10 @@ class install(Command): ...@@ -182,11 +92,10 @@ class install(Command):
boolean_options = ['compile', 'force', 'skip-build'] boolean_options = ['compile', 'force', 'skip-build']
if HAS_USER_SITE: user_options.append(('user', None,
user_options.append(('user', None, "install in user site-package '%s'" % \
"install in user site-package '%s'" % USER_SITE)) get_path('purelib', '%s_user' % os.name)))
boolean_options.append('user') boolean_options.append('user')
negative_opt = {'no-compile' : 'compile'} negative_opt = {'no-compile' : 'compile'}
...@@ -216,8 +125,8 @@ class install(Command): ...@@ -216,8 +125,8 @@ class install(Command):
self.install_lib = None # set to either purelib or platlib self.install_lib = None # set to either purelib or platlib
self.install_scripts = None self.install_scripts = None
self.install_data = None self.install_data = None
self.install_userbase = USER_BASE self.install_userbase = get_config_var('userbase')
self.install_usersite = USER_SITE self.install_usersite = get_path('purelib', '%s_user' % os.name)
self.compile = None self.compile = None
self.optimize = None self.optimize = None
...@@ -327,7 +236,9 @@ class install(Command): ...@@ -327,7 +236,9 @@ class install(Command):
# about needing recursive variable expansion (shudder). # about needing recursive variable expansion (shudder).
py_version = sys.version.split()[0] 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(), self.config_vars = {'dist_name': self.distribution.get_name(),
'dist_version': self.distribution.get_version(), 'dist_version': self.distribution.get_version(),
'dist_fullname': self.distribution.get_fullname(), 'dist_fullname': self.distribution.get_fullname(),
...@@ -338,12 +249,11 @@ class install(Command): ...@@ -338,12 +249,11 @@ class install(Command):
'prefix': prefix, 'prefix': prefix,
'sys_exec_prefix': exec_prefix, 'sys_exec_prefix': exec_prefix,
'exec_prefix': exec_prefix, 'exec_prefix': exec_prefix,
'srcdir': srcdir,
} }
if HAS_USER_SITE: self.config_vars['userbase'] = self.install_userbase
self.config_vars['userbase'] = self.install_userbase self.config_vars['usersite'] = self.install_usersite
self.config_vars['usersite'] = self.install_usersite
self.expand_basedirs() self.expand_basedirs()
self.dump_dirs("post-expand_basedirs()") self.dump_dirs("post-expand_basedirs()")
...@@ -447,10 +357,10 @@ class install(Command): ...@@ -447,10 +357,10 @@ class install(Command):
raise DistutilsPlatformError( raise DistutilsPlatformError(
"User base directory is not specified") "User base directory is not specified")
self.install_base = self.install_platbase = self.install_userbase 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: elif self.home is not None:
self.install_base = self.install_platbase = self.home self.install_base = self.install_platbase = self.home
self.select_scheme("unix_home") self.select_scheme("posix_home")
else: else:
if self.prefix is None: if self.prefix is None:
if self.exec_prefix is not None: if self.exec_prefix is not None:
...@@ -466,7 +376,7 @@ class install(Command): ...@@ -466,7 +376,7 @@ class install(Command):
self.install_base = self.prefix self.install_base = self.prefix
self.install_platbase = self.exec_prefix self.install_platbase = self.exec_prefix
self.select_scheme("unix_prefix") self.select_scheme("posix_prefix")
def finalize_other(self): def finalize_other(self):
"""Finalizes options for non-posix platforms""" """Finalizes options for non-posix platforms"""
...@@ -478,7 +388,7 @@ class install(Command): ...@@ -478,7 +388,7 @@ class install(Command):
self.select_scheme(os.name + "_user") self.select_scheme(os.name + "_user")
elif self.home is not None: elif self.home is not None:
self.install_base = self.install_platbase = self.home self.install_base = self.install_platbase = self.home
self.select_scheme("unix_home") self.select_scheme("posix_home")
else: else:
if self.prefix is None: if self.prefix is None:
self.prefix = os.path.normpath(sys.prefix) self.prefix = os.path.normpath(sys.prefix)
...@@ -493,11 +403,15 @@ class install(Command): ...@@ -493,11 +403,15 @@ class install(Command):
def select_scheme(self, name): def select_scheme(self, name):
"""Sets the install directories by applying the install schemes.""" """Sets the install directories by applying the install schemes."""
# it's the caller's problem if they supply a bad name! # it's the caller's problem if they supply a bad name!
scheme = INSTALL_SCHEMES[name] scheme = get_paths(name, expand=False)
for key in SCHEME_KEYS: for key, value in scheme.items():
if key == 'platinclude':
key = 'headers'
value = os.path.join(value, self.distribution.get_name())
attrname = 'install_' + key attrname = 'install_' + key
if getattr(self, attrname) is None: if hasattr(self, attrname):
setattr(self, attrname, scheme[key]) if getattr(self, attrname) is None:
setattr(self, attrname, value)
def _expand_attrs(self, attrs): def _expand_attrs(self, attrs):
for attr in attrs: for attr in attrs:
...@@ -505,7 +419,10 @@ class install(Command): ...@@ -505,7 +419,10 @@ class install(Command):
if val is not None: if val is not None:
if os.name == 'posix' or os.name == 'nt': if os.name == 'posix' or os.name == 'nt':
val = os.path.expanduser(val) 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) setattr(self, attr, val)
def expand_basedirs(self): def expand_basedirs(self):
......
...@@ -35,7 +35,7 @@ usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] ...@@ -35,7 +35,7 @@ usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
def gen_usage(script_name): def gen_usage(script_name):
script = os.path.basename(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()'. # Some mild magic to control the behaviour of 'setup()' from 'run_setup()'.
......
...@@ -337,7 +337,7 @@ def check_config_h(): ...@@ -337,7 +337,7 @@ def check_config_h():
# XXX since this function also checks sys.version, it's not strictly a # XXX since this function also checks sys.version, it's not strictly a
# "pyconfig.h" check -- should probably be renamed... # "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 # if sys.version contains GCC then python was compiled with GCC, and the
# pyconfig.h file should be OK # pyconfig.h file should be OK
...@@ -345,7 +345,7 @@ def check_config_h(): ...@@ -345,7 +345,7 @@ def check_config_h():
return CONFIG_H_OK, "sys.version mentions 'GCC'" return CONFIG_H_OK, "sys.version mentions 'GCC'"
# let's see if __GNUC__ is mentioned in python.h # let's see if __GNUC__ is mentioned in python.h
fn = sysconfig.get_config_h_filename() fn = _sysconfig.get_config_h_filename()
try: try:
with open(fn) as config_h: with open(fn) as config_h:
if "__GNUC__" in config_h.read(): if "__GNUC__" in config_h.read():
......
...@@ -134,14 +134,17 @@ class Extension: ...@@ -134,14 +134,17 @@ class Extension:
def read_setup_file(filename): def read_setup_file(filename):
"""Reads a Setup file and returns Extension instances.""" """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) _variable_rx)
from distutils.text_file import TextFile from distutils.text_file import TextFile
from distutils.util import split_quoted from distutils.util import split_quoted
# First pass over the file to gather "VAR = VALUE" assignments. # 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 # Second pass to gobble up the real content: lines of the form
# <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...] # <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...]
...@@ -161,7 +164,10 @@ def read_setup_file(filename): ...@@ -161,7 +164,10 @@ def read_setup_file(filename):
file.warn("'%s' lines not handled yet" % line) file.warn("'%s' lines not handled yet" % line)
continue continue
line = expand_makefile_vars(line, vars) with warnings.catch_warnings():
warnings.simplefilter("ignore")
line = expand_makefile_vars(line, vars)
words = split_quoted(line) words = split_quoted(line)
# NB. this parses a slightly different syntax than the old # NB. this parses a slightly different syntax than the old
......
...@@ -23,10 +23,10 @@ from distutils.errors import (DistutilsExecError, DistutilsPlatformError, ...@@ -23,10 +23,10 @@ from distutils.errors import (DistutilsExecError, DistutilsPlatformError,
CompileError, LibError, LinkError) CompileError, LibError, LinkError)
from distutils.ccompiler import CCompiler, gen_lib_options from distutils.ccompiler import CCompiler, gen_lib_options
from distutils import log from distutils import log
from distutils.util import get_platform
import _winreg import _winreg
_sysconfig = __import__('sysconfig')
RegOpenKeyEx = _winreg.OpenKeyEx RegOpenKeyEx = _winreg.OpenKeyEx
RegEnumKey = _winreg.EnumKey RegEnumKey = _winreg.EnumKey
RegEnumValue = _winreg.EnumValue RegEnumValue = _winreg.EnumValue
...@@ -327,7 +327,7 @@ class MSVCCompiler(CCompiler) : ...@@ -327,7 +327,7 @@ class MSVCCompiler(CCompiler) :
# multi-init means we would need to check platform same each time... # multi-init means we would need to check platform same each time...
assert not self.initialized, "don't init multiple times" assert not self.initialized, "don't init multiple times"
if plat_name is None: if plat_name is None:
plat_name = get_platform() plat_name = _sysconfig.get_platform()
# sanity check for platforms to prevent obscure errors later. # sanity check for platforms to prevent obscure errors later.
ok_plats = 'win32', 'win-amd64', 'win-ia64' ok_plats = 'win32', 'win-amd64', 'win-ia64'
if plat_name not in ok_plats: if plat_name not in ok_plats:
...@@ -348,12 +348,12 @@ class MSVCCompiler(CCompiler) : ...@@ -348,12 +348,12 @@ class MSVCCompiler(CCompiler) :
# On AMD64, 'vcvars32.bat amd64' is a native build env; to cross # On AMD64, 'vcvars32.bat amd64' is a native build env; to cross
# compile use 'x86' (ie, it runs the x86 compiler directly) # compile use 'x86' (ie, it runs the x86 compiler directly)
# No idea how itanium handles this, if at all. # 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 # native build or cross-compile to win32
plat_spec = PLAT_TO_VCVARS[plat_name] plat_spec = PLAT_TO_VCVARS[plat_name]
else: else:
# cross compile from win32 -> some 64bit # 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] PLAT_TO_VCVARS[plat_name]
vc_env = query_vcvarsall(VERSION, plat_spec) vc_env = query_vcvarsall(VERSION, plat_spec)
......
This diff is collapsed.
...@@ -3,11 +3,19 @@ import os ...@@ -3,11 +3,19 @@ import os
import shutil import shutil
import tempfile import tempfile
from copy import deepcopy from copy import deepcopy
import warnings
from distutils import log from distutils import log
from distutils.log import DEBUG, INFO, WARN, ERROR, FATAL from distutils.log import DEBUG, INFO, WARN, ERROR, FATAL
from distutils.core import Distribution 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): class LoggingSilencer(object):
def setUp(self): def setUp(self):
......
...@@ -5,7 +5,7 @@ import sys ...@@ -5,7 +5,7 @@ import sys
from distutils.command.build import build from distutils.command.build import build
from distutils.tests import support from distutils.tests import support
from distutils.util import get_platform from sysconfig import get_platform
class BuildTestCase(support.TempdirManager, class BuildTestCase(support.TempdirManager,
support.LoggingSilencer, support.LoggingSilencer,
......
...@@ -120,8 +120,7 @@ class BuildCLibTestCase(support.TempdirManager, ...@@ -120,8 +120,7 @@ class BuildCLibTestCase(support.TempdirManager,
# before we run the command, we want to make sure # before we run the command, we want to make sure
# all commands are present on the system # all commands are present on the system
# by creating a compiler and checking its executables # by creating a compiler and checking its executables
from distutils.ccompiler import new_compiler from distutils.ccompiler import new_compiler, customize_compiler
from distutils.sysconfig import customize_compiler
compiler = new_compiler() compiler = new_compiler()
customize_compiler(compiler) customize_compiler(compiler)
......
...@@ -9,7 +9,7 @@ from test.test_support import captured_stdout ...@@ -9,7 +9,7 @@ from test.test_support import captured_stdout
from distutils.core import Extension, Distribution from distutils.core import Extension, Distribution
from distutils.command.build_ext import build_ext from distutils.command.build_ext import build_ext
from distutils import sysconfig import sysconfig
from distutils.tests import support from distutils.tests import support
from distutils.extension import Extension from distutils.extension import Extension
from distutils.errors import (UnknownFileError, DistutilsSetupError, from distutils.errors import (UnknownFileError, DistutilsSetupError,
...@@ -105,17 +105,17 @@ class BuildExtTestCase(support.TempdirManager, ...@@ -105,17 +105,17 @@ class BuildExtTestCase(support.TempdirManager,
old = sys.platform old = sys.platform
sys.platform = 'sunos' # fooling finalize_options sys.platform = 'sunos' # fooling finalize_options
from distutils.sysconfig import _config_vars from sysconfig import _CONFIG_VARS
old_var = _config_vars.get('Py_ENABLE_SHARED') old_var = _CONFIG_VARS.get('Py_ENABLE_SHARED')
_config_vars['Py_ENABLE_SHARED'] = 1 _CONFIG_VARS['Py_ENABLE_SHARED'] = 1
try: try:
cmd.ensure_finalized() cmd.ensure_finalized()
finally: finally:
sys.platform = old sys.platform = old
if old_var is None: if old_var is None:
del _config_vars['Py_ENABLE_SHARED'] del _CONFIG_VARS['Py_ENABLE_SHARED']
else: else:
_config_vars['Py_ENABLE_SHARED'] = old_var _CONFIG_VARS['Py_ENABLE_SHARED'] = old_var
# make sure we get some library dirs under solaris # make sure we get some library dirs under solaris
self.assertTrue(len(cmd.library_dirs) > 0) self.assertTrue(len(cmd.library_dirs) > 0)
...@@ -177,11 +177,10 @@ class BuildExtTestCase(support.TempdirManager, ...@@ -177,11 +177,10 @@ class BuildExtTestCase(support.TempdirManager,
cmd = build_ext(dist) cmd = build_ext(dist)
cmd.finalize_options() cmd.finalize_options()
from distutils import sysconfig py_include = sysconfig.get_path('include')
py_include = sysconfig.get_python_inc()
self.assertTrue(py_include in cmd.include_dirs) 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) self.assertTrue(plat_py_include in cmd.include_dirs)
# make sure cmd.libraries is turned into a list # make sure cmd.libraries is turned into a list
......
...@@ -5,7 +5,7 @@ import unittest ...@@ -5,7 +5,7 @@ import unittest
from distutils.command.build_scripts import build_scripts from distutils.command.build_scripts import build_scripts
from distutils.core import Distribution from distutils.core import Distribution
from distutils import sysconfig import sysconfig
from distutils.tests import support from distutils.tests import support
...@@ -91,12 +91,12 @@ class BuildScriptsTestCase(support.TempdirManager, ...@@ -91,12 +91,12 @@ class BuildScriptsTestCase(support.TempdirManager,
# --with-suffix=3`, python is compiled okay but the build scripts # --with-suffix=3`, python is compiled okay but the build scripts
# failed when writing the name of the executable # failed when writing the name of the executable
old = sysconfig.get_config_vars().get('VERSION') old = sysconfig.get_config_vars().get('VERSION')
sysconfig._config_vars['VERSION'] = 4 sysconfig._CONFIG_VARS['VERSION'] = 4
try: try:
cmd.run() cmd.run()
finally: finally:
if old is not None: if old is not None:
sysconfig._config_vars['VERSION'] = old sysconfig._CONFIG_VARS['VERSION'] = old
built = os.listdir(target) built = os.listdir(target)
for name in expected: for name in expected:
......
...@@ -3,8 +3,10 @@ import os ...@@ -3,8 +3,10 @@ import os
import unittest import unittest
from test.test_support import captured_stdout from test.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 import debug
from distutils.tests import support
class FakeCompiler(object): class FakeCompiler(object):
def library_dir_option(self, dir): def library_dir_option(self, dir):
...@@ -19,7 +21,7 @@ class FakeCompiler(object): ...@@ -19,7 +21,7 @@ class FakeCompiler(object):
def library_option(self, lib): def library_option(self, lib):
return "-l" + lib return "-l" + lib
class CCompilerTestCase(unittest.TestCase): class CCompilerTestCase(support.EnvironGuard, unittest.TestCase):
def test_gen_lib_options(self): def test_gen_lib_options(self):
compiler = FakeCompiler() compiler = FakeCompiler()
...@@ -52,6 +54,26 @@ class CCompilerTestCase(unittest.TestCase): ...@@ -52,6 +54,26 @@ class CCompilerTestCase(unittest.TestCase):
finally: finally:
debug.DEBUG = False 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(): def test_suite():
return unittest.makeSuite(CCompilerTestCase) return unittest.makeSuite(CCompilerTestCase)
......
...@@ -3,6 +3,7 @@ import unittest ...@@ -3,6 +3,7 @@ import unittest
import sys import sys
import os import os
import warnings import warnings
import sysconfig
from test.test_support import check_warnings from test.test_support import check_warnings
from test.test_support import captured_stdout from test.test_support import captured_stdout
...@@ -22,13 +23,11 @@ class CygwinCCompilerTestCase(support.TempdirManager, ...@@ -22,13 +23,11 @@ class CygwinCCompilerTestCase(support.TempdirManager,
super(CygwinCCompilerTestCase, self).setUp() super(CygwinCCompilerTestCase, self).setUp()
self.version = sys.version self.version = sys.version
self.python_h = os.path.join(self.mkdtemp(), 'python.h') 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 self.old_get_config_h_filename = sysconfig.get_config_h_filename
sysconfig.get_config_h_filename = self._get_config_h_filename sysconfig.get_config_h_filename = self._get_config_h_filename
def tearDown(self): def tearDown(self):
sys.version = self.version sys.version = self.version
from distutils import sysconfig
sysconfig.get_config_h_filename = self.old_get_config_h_filename sysconfig.get_config_h_filename = self.old_get_config_h_filename
super(CygwinCCompilerTestCase, self).tearDown() super(CygwinCCompilerTestCase, self).tearDown()
......
...@@ -5,9 +5,11 @@ import warnings ...@@ -5,9 +5,11 @@ import warnings
from test.test_support import check_warnings from test.test_support import check_warnings
from distutils.extension import read_setup_file, Extension from distutils.extension import read_setup_file, Extension
from distutils.tests.support import capture_warnings
class ExtensionTestCase(unittest.TestCase): class ExtensionTestCase(unittest.TestCase):
@capture_warnings
def test_read_setup_file(self): def test_read_setup_file(self):
# trying to read a Setup file # trying to read a Setup file
# (sample extracted from the PyGame project) # (sample extracted from the PyGame project)
......
...@@ -5,12 +5,14 @@ import os.path ...@@ -5,12 +5,14 @@ import os.path
import sys import sys
import unittest import unittest
import site import site
import sysconfig
from sysconfig import (get_scheme_names, _CONFIG_VARS, _INSTALL_SCHEMES,
get_config_var, get_path)
from test.test_support import captured_stdout from test.test_support import captured_stdout
from distutils.command.install import install from distutils.command.install import install
from distutils.command import install as install_module from distutils.command import install as install_module
from distutils.command.install import INSTALL_SCHEMES
from distutils.core import Distribution from distutils.core import Distribution
from distutils.errors import DistutilsOptionError from distutils.errors import DistutilsOptionError
...@@ -36,9 +38,23 @@ class InstallTestCase(support.TempdirManager, ...@@ -36,9 +38,23 @@ class InstallTestCase(support.TempdirManager,
build_lib=os.path.join(builddir, "lib"), 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_base, destination)
self.assertEqual(cmd.install_platbase, destination) self.assertEqual(cmd.install_platbase, destination)
...@@ -63,18 +79,19 @@ class InstallTestCase(support.TempdirManager, ...@@ -63,18 +79,19 @@ class InstallTestCase(support.TempdirManager,
return return
# preparing the environement for the test # preparing the environement for the test
self.old_user_base = site.USER_BASE self.old_user_base = get_config_var('userbase')
self.old_user_site = site.USER_SITE self.old_user_site = get_path('purelib', '%s_user' % os.name)
self.tmpdir = self.mkdtemp() self.tmpdir = self.mkdtemp()
self.user_base = os.path.join(self.tmpdir, 'B') self.user_base = os.path.join(self.tmpdir, 'B')
self.user_site = os.path.join(self.tmpdir, 'S') self.user_site = os.path.join(self.tmpdir, 'S')
site.USER_BASE = self.user_base _CONFIG_VARS['userbase'] = self.user_base
site.USER_SITE = self.user_site scheme = _INSTALL_SCHEMES['%s_user' % os.name]
install_module.USER_BASE = self.user_base scheme['purelib'] = self.user_site
install_module.USER_SITE = self.user_site
def _expanduser(path): 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 self.old_expand = os.path.expanduser
os.path.expanduser = _expanduser os.path.expanduser = _expanduser
...@@ -82,19 +99,17 @@ class InstallTestCase(support.TempdirManager, ...@@ -82,19 +99,17 @@ class InstallTestCase(support.TempdirManager,
# this is the actual test # this is the actual test
self._test_user_site() self._test_user_site()
finally: finally:
site.USER_BASE = self.old_user_base _CONFIG_VARS['userbase'] = self.old_user_base
site.USER_SITE = self.old_user_site scheme['purelib'] = self.old_user_site
install_module.USER_BASE = self.old_user_base
install_module.USER_SITE = self.old_user_site
os.path.expanduser = self.old_expand os.path.expanduser = self.old_expand
def _test_user_site(self): def _test_user_site(self):
for key in ('nt_user', 'unix_user', 'os2_home'): schemes = get_scheme_names()
self.assertTrue(key in INSTALL_SCHEMES) for key in ('nt_user', 'posix_user', 'os2_home'):
self.assertTrue(key in schemes)
dist = Distribution({'name': 'xx'}) dist = Distribution({'name': 'xx'})
cmd = install(dist) cmd = install(dist)
# making sure the user option is there # making sure the user option is there
options = [name for name, short, lable in options = [name for name, short, lable in
cmd.user_options] cmd.user_options]
...@@ -185,7 +200,7 @@ class InstallTestCase(support.TempdirManager, ...@@ -185,7 +200,7 @@ class InstallTestCase(support.TempdirManager,
with open(cmd.record) as f: with open(cmd.record) as f:
self.assertEquals(len(f.readlines()), 1) 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 # this covers the code called when DEBUG is set
old_logs_len = len(self.logs) old_logs_len = len(self.logs)
install_module.DEBUG = True install_module.DEBUG = True
......
...@@ -4,7 +4,6 @@ import test ...@@ -4,7 +4,6 @@ import test
import unittest import unittest
from distutils import sysconfig from distutils import sysconfig
from distutils.ccompiler import get_default_compiler
from distutils.tests import support from distutils.tests import support
from test.test_support import TESTFN from test.test_support import TESTFN
...@@ -27,10 +26,6 @@ class SysconfigTestCase(support.EnvironGuard, ...@@ -27,10 +26,6 @@ class SysconfigTestCase(support.EnvironGuard,
elif os.path.isdir(path): elif os.path.isdir(path):
shutil.rmtree(path) shutil.rmtree(path)
def test_get_config_h_filename(self):
config_h = sysconfig.get_config_h_filename()
self.assertTrue(os.path.isfile(config_h), config_h)
def test_get_python_lib(self): def test_get_python_lib(self):
lib_dir = sysconfig.get_python_lib() lib_dir = sysconfig.get_python_lib()
# XXX doesn't work on Linux when Python was never installed before # XXX doesn't work on Linux when Python was never installed before
...@@ -38,6 +33,9 @@ class SysconfigTestCase(support.EnvironGuard, ...@@ -38,6 +33,9 @@ class SysconfigTestCase(support.EnvironGuard,
# test for pythonxx.lib? # test for pythonxx.lib?
self.assertNotEqual(sysconfig.get_python_lib(), self.assertNotEqual(sysconfig.get_python_lib(),
sysconfig.get_python_lib(prefix=TESTFN)) sysconfig.get_python_lib(prefix=TESTFN))
_sysconfig = __import__('sysconfig')
res = sysconfig.get_python_lib(True, True)
self.assertEquals(_sysconfig.get_path('platstdlib'), res)
def test_get_python_inc(self): def test_get_python_inc(self):
inc_dir = sysconfig.get_python_inc() inc_dir = sysconfig.get_python_inc()
...@@ -48,31 +46,6 @@ class SysconfigTestCase(support.EnvironGuard, ...@@ -48,31 +46,6 @@ class SysconfigTestCase(support.EnvironGuard,
python_h = os.path.join(inc_dir, "Python.h") python_h = os.path.join(inc_dir, "Python.h")
self.assertTrue(os.path.isfile(python_h), 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')
def test_parse_makefile_base(self): def test_parse_makefile_base(self):
self.makefile = test.test_support.TESTFN self.makefile = test.test_support.TESTFN
fd = open(self.makefile, 'w') fd = open(self.makefile, 'w')
......
"""Tests for distutils.unixccompiler.""" """Tests for distutils.unixccompiler."""
import sys import sys
import unittest import unittest
import sysconfig
from distutils import sysconfig
from distutils.unixccompiler import UnixCCompiler from distutils.unixccompiler import UnixCCompiler
class UnixCCompilerTestCase(unittest.TestCase): class UnixCCompilerTestCase(unittest.TestCase):
......
...@@ -6,15 +6,14 @@ from copy import copy ...@@ -6,15 +6,14 @@ from copy import copy
from StringIO import StringIO from StringIO import StringIO
import subprocess import subprocess
from sysconfig import get_config_vars, get_platform
from distutils.errors import DistutilsPlatformError, DistutilsByteCompileError 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, check_environ, split_quoted, strtobool,
rfc822_escape, get_compiler_versions, rfc822_escape, get_compiler_versions,
_find_exe_version, _MAC_OS_X_LD_VERSION, _find_exe_version, _MAC_OS_X_LD_VERSION,
byte_compile) byte_compile)
from distutils import util from distutils import util
from distutils.sysconfig import get_config_vars
from distutils import sysconfig
from distutils.tests import support from distutils.tests import support
from distutils.version import LooseVersion from distutils.version import LooseVersion
...@@ -44,7 +43,7 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase): ...@@ -44,7 +43,7 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
self.join = os.path.join self.join = os.path.join
self.isabs = os.path.isabs self.isabs = os.path.isabs
self.splitdrive = os.path.splitdrive self.splitdrive = os.path.splitdrive
self._config_vars = copy(sysconfig._config_vars) #self._config_vars = copy(sysconfig._config_vars)
# patching os.uname # patching os.uname
if hasattr(os, 'uname'): if hasattr(os, 'uname'):
...@@ -78,7 +77,7 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase): ...@@ -78,7 +77,7 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
os.uname = self.uname os.uname = self.uname
else: else:
del os.uname del os.uname
sysconfig._config_vars = copy(self._config_vars) #sysconfig._config_vars = copy(self._config_vars)
util.find_executable = self.old_find_executable util.find_executable = self.old_find_executable
subprocess.Popen = self.old_popen subprocess.Popen = self.old_popen
sys.old_stdout = self.old_stdout sys.old_stdout = self.old_stdout
...@@ -91,7 +90,7 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase): ...@@ -91,7 +90,7 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
def _get_uname(self): def _get_uname(self):
return self._uname return self._uname
def test_get_platform(self): def _test_get_platform(self):
# windows XP, 32bits # windows XP, 32bits
os.name = 'nt' os.name = 'nt'
...@@ -119,26 +118,6 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase): ...@@ -119,26 +118,6 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
sys.version = ('2.5 (r25:51918, Sep 19 2006, 08:49:13) ' sys.version = ('2.5 (r25:51918, Sep 19 2006, 08:49:13) '
'\n[GCC 4.0.1 (Apple Computer, Inc. build 5341)]') '\n[GCC 4.0.1 (Apple Computer, Inc. build 5341)]')
sys.platform = 'darwin' 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; '
'root:xnu-792.25.20~1/RELEASE_I386'), 'PowerPC'))
os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.3'
get_config_vars()['CFLAGS'] = ('-fno-strict-aliasing -DNDEBUG -g '
'-fwrapv -O3 -Wall -Wstrict-prototypes')
maxint = sys.maxint
try:
sys.maxint = 2147483647
self.assertEquals(get_platform(), 'macosx-10.3-ppc')
sys.maxint = 9223372036854775807
self.assertEquals(get_platform(), 'macosx-10.3-ppc64')
finally:
sys.maxint = maxint
self._set_uname(('Darwin', 'macziade', '8.11.1', self._set_uname(('Darwin', 'macziade', '8.11.1',
('Darwin Kernel Version 8.11.1: ' ('Darwin Kernel Version 8.11.1: '
'Wed Oct 10 18:23:28 PDT 2007; ' 'Wed Oct 10 18:23:28 PDT 2007; '
...@@ -148,15 +127,7 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase): ...@@ -148,15 +127,7 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
get_config_vars()['CFLAGS'] = ('-fno-strict-aliasing -DNDEBUG -g ' get_config_vars()['CFLAGS'] = ('-fno-strict-aliasing -DNDEBUG -g '
'-fwrapv -O3 -Wall -Wstrict-prototypes') '-fwrapv -O3 -Wall -Wstrict-prototypes')
maxint = sys.maxint self.assertEquals(get_platform(), 'macosx-10.3-i386')
try:
sys.maxint = 2147483647
self.assertEquals(get_platform(), 'macosx-10.3-i386')
sys.maxint = 9223372036854775807
self.assertEquals(get_platform(), 'macosx-10.3-x86_64')
finally:
sys.maxint = maxint
# macbook with fat binaries (fat, universal or fat64) # macbook with fat binaries (fat, universal or fat64)
os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.4' os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.4'
...@@ -201,7 +172,6 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase): ...@@ -201,7 +172,6 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
self.assertEquals(get_platform(), 'macosx-10.4-%s'%(arch,)) self.assertEquals(get_platform(), 'macosx-10.4-%s'%(arch,))
# linux debian sarge # linux debian sarge
os.name = 'posix' os.name = 'posix'
sys.version = ('2.3.5 (#1, Jul 4 2007, 17:28:59) ' sys.version = ('2.3.5 (#1, Jul 4 2007, 17:28:59) '
......
...@@ -18,7 +18,6 @@ __revision__ = "$Id$" ...@@ -18,7 +18,6 @@ __revision__ = "$Id$"
import os, sys import os, sys
from types import StringType, NoneType from types import StringType, NoneType
from distutils import sysconfig
from distutils.dep_util import newer from distutils.dep_util import newer
from distutils.ccompiler import \ from distutils.ccompiler import \
CCompiler, gen_preprocess_options, gen_lib_options CCompiler, gen_preprocess_options, gen_lib_options
...@@ -26,6 +25,7 @@ from distutils.errors import \ ...@@ -26,6 +25,7 @@ from distutils.errors import \
DistutilsExecError, CompileError, LibError, LinkError DistutilsExecError, CompileError, LibError, LinkError
from distutils import log from distutils import log
# XXX Things not currently handled: # XXX Things not currently handled:
# * optimization/debug/warning flags; we just use whatever's in Python's # * optimization/debug/warning flags; we just use whatever's in Python's
# Makefile and live with it. Is this adequate? If not, we might # Makefile and live with it. Is this adequate? If not, we might
...@@ -75,7 +75,7 @@ def _darwin_compiler_fixup(compiler_so, cc_args): ...@@ -75,7 +75,7 @@ def _darwin_compiler_fixup(compiler_so, cc_args):
if 'ARCHFLAGS' in os.environ and not stripArch: if 'ARCHFLAGS' in os.environ and not stripArch:
# User specified different -arch flags in the environ, # User specified different -arch flags in the environ,
# see also distutils.sysconfig # see also the sysconfig
compiler_so = compiler_so + os.environ['ARCHFLAGS'].split() compiler_so = compiler_so + os.environ['ARCHFLAGS'].split()
if stripSysroot: if stripSysroot:
...@@ -283,7 +283,9 @@ class UnixCCompiler(CCompiler): ...@@ -283,7 +283,9 @@ class UnixCCompiler(CCompiler):
# this time, there's no way to determine this information from # this time, there's no way to determine this information from
# the configuration data stored in the Python installation, so # the configuration data stored in the Python installation, so
# we use this hack. # 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": if sys.platform[:6] == "darwin":
# MacOSX's linker doesn't understand the -R flag at all # MacOSX's linker doesn't understand the -R flag at all
return "-L" + dir return "-L" + dir
...@@ -298,7 +300,7 @@ class UnixCCompiler(CCompiler): ...@@ -298,7 +300,7 @@ class UnixCCompiler(CCompiler):
# use it anyway. Since distutils has always passed in # use it anyway. Since distutils has always passed in
# -Wl whenever gcc was used in the past it is probably # -Wl whenever gcc was used in the past it is probably
# safest to keep doing so. # 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 # GNU ld needs an extra option to get a RUNPATH
# instead of just an RPATH. # instead of just an RPATH.
return "-Wl,--enable-new-dtags,-R" + dir return "-Wl,--enable-new-dtags,-R" + dir
......
...@@ -15,173 +15,7 @@ from distutils import log ...@@ -15,173 +15,7 @@ from distutils import log
from distutils.version import LooseVersion from distutils.version import LooseVersion
from distutils.errors import DistutilsByteCompileError from distutils.errors import DistutilsByteCompileError
def get_platform(): _sysconfig = __import__('sysconfig')
"""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.]+')
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.maxint >= 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.maxint >= 2**32:
machine = 'ppc64'
return "%s-%s-%s" % (osname, release, machine)
def convert_path(pathname): def convert_path(pathname):
"""Return 'pathname' as a name that will work on the native filesystem. """Return 'pathname' as a name that will work on the native filesystem.
...@@ -269,7 +103,7 @@ def check_environ(): ...@@ -269,7 +103,7 @@ def check_environ():
os.environ['HOME'] = pwd.getpwuid(os.getuid())[5] os.environ['HOME'] = pwd.getpwuid(os.getuid())[5]
if 'PLAT' not in os.environ: if 'PLAT' not in os.environ:
os.environ['PLAT'] = get_platform() os.environ['PLAT'] = _sysconfig.get_platform()
_environ_checked = 1 _environ_checked = 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment