diff options
-rw-r--r-- | Lib/distutils/command/bdist.py | 2 | ||||
-rw-r--r-- | Lib/distutils/command/bdist_dumb.py | 3 | ||||
-rw-r--r-- | Lib/distutils/command/bdist_msi.py | 3 | ||||
-rw-r--r-- | Lib/distutils/command/bdist_wininst.py | 3 | ||||
-rw-r--r-- | Lib/distutils/command/build.py | 2 | ||||
-rw-r--r-- | Lib/distutils/command/build_ext.py | 4 | ||||
-rw-r--r-- | Lib/distutils/command/install.py | 5 | ||||
-rw-r--r-- | Lib/distutils/msvc9compiler.py | 10 | ||||
-rw-r--r-- | Lib/distutils/sysconfig.py | 9 | ||||
-rw-r--r-- | Lib/distutils/tests/test_util.py | 125 | ||||
-rw-r--r-- | Lib/distutils/util.py | 21 | ||||
-rw-r--r-- | Lib/test/test_sysconfig.py | 28 |
12 files changed, 80 insertions, 135 deletions
diff --git a/Lib/distutils/command/bdist.py b/Lib/distutils/command/bdist.py index a79982b..72b0cef 100644 --- a/Lib/distutils/command/bdist.py +++ b/Lib/distutils/command/bdist.py @@ -6,8 +6,8 @@ distribution).""" __revision__ = "$Id$" import os -from sysconfig import get_platform +from distutils.util import get_platform from distutils.core import Command from distutils.errors import DistutilsPlatformError, DistutilsOptionError diff --git a/Lib/distutils/command/bdist_dumb.py b/Lib/distutils/command/bdist_dumb.py index c16125f..c2af95f 100644 --- a/Lib/distutils/command/bdist_dumb.py +++ b/Lib/distutils/command/bdist_dumb.py @@ -8,8 +8,9 @@ __revision__ = "$Id$" import os -from sysconfig import get_python_version, get_platform +from sysconfig import get_python_version +from distutils.util import get_platform from distutils.core import Command from distutils.dir_util import remove_tree, ensure_relative from distutils.errors import DistutilsPlatformError diff --git a/Lib/distutils/command/bdist_msi.py b/Lib/distutils/command/bdist_msi.py index f920548..404f215 100644 --- a/Lib/distutils/command/bdist_msi.py +++ b/Lib/distutils/command/bdist_msi.py @@ -6,6 +6,8 @@ """ Implements the bdist_msi command. """ +import sys, os +from sysconfig import get_python_version import sys, os from distutils.core import Command @@ -15,6 +17,7 @@ from distutils.version import StrictVersion from distutils.errors import DistutilsOptionError from distutils.util import get_platform from distutils import log + import msilib from msilib import schema, sequence, text from msilib import Directory, Feature, Dialog, add_data diff --git a/Lib/distutils/command/bdist_wininst.py b/Lib/distutils/command/bdist_wininst.py index 2cf2823..71cc798 100644 --- a/Lib/distutils/command/bdist_wininst.py +++ b/Lib/distutils/command/bdist_wininst.py @@ -8,12 +8,13 @@ __revision__ = "$Id$" import sys import os -from sysconfig import get_python_version, get_platform +from sysconfig import get_python_version from distutils.core import Command from distutils.dir_util import remove_tree from distutils.errors import DistutilsOptionError, DistutilsPlatformError from distutils import log +from distutils.util import get_platform class bdist_wininst(Command): diff --git a/Lib/distutils/command/build.py b/Lib/distutils/command/build.py index d7b0e3c..4d30f8f 100644 --- a/Lib/distutils/command/build.py +++ b/Lib/distutils/command/build.py @@ -5,8 +5,8 @@ Implements the Distutils 'build' command.""" __revision__ = "$Id$" import sys, os -from sysconfig import get_platform +from distutils.util import get_platform from distutils.core import Command from distutils.errors import DistutilsOptionError diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py index 39d37da..8f41fac 100644 --- a/Lib/distutils/command/build_ext.py +++ b/Lib/distutils/command/build_ext.py @@ -9,14 +9,12 @@ __revision__ = "$Id$" import sys, os, re from warnings import warn -from sysconfig import get_platform - +from distutils.util import get_platform from distutils.core import Command from distutils.errors import * from distutils.ccompiler import customize_compiler from distutils.dep_util import newer_group from distutils.extension import Extension - from distutils import log # this keeps compatibility from 2.3 to 2.5 diff --git a/Lib/distutils/command/install.py b/Lib/distutils/command/install.py index 1f8d238..2a6d4dd 100644 --- a/Lib/distutils/command/install.py +++ b/Lib/distutils/command/install.py @@ -7,15 +7,14 @@ __revision__ = "$Id$" import sys import os -from sysconfig import (get_config_vars, get_platform, get_paths, get_path, - get_config_var) +from sysconfig import get_config_vars, get_paths, get_path, get_config_var from distutils import log from distutils.core import Command from distutils.debug import DEBUG from distutils.errors import DistutilsPlatformError from distutils.file_util import write_file -from distutils.util import convert_path, change_root +from distutils.util import convert_path, change_root, get_platform from distutils.errors import DistutilsOptionError def _subst_vars(s, local_vars): diff --git a/Lib/distutils/msvc9compiler.py b/Lib/distutils/msvc9compiler.py index 38fc96f..6455fff 100644 --- a/Lib/distutils/msvc9compiler.py +++ b/Lib/distutils/msvc9compiler.py @@ -23,9 +23,9 @@ from distutils.errors import (DistutilsExecError, DistutilsPlatformError, CompileError, LibError, LinkError) from distutils.ccompiler import CCompiler, gen_lib_options from distutils import log -import winreg +from distutils.util import get_platform -_sysconfig = __import__('sysconfig') +import winreg RegOpenKeyEx = winreg.OpenKeyEx RegEnumKey = winreg.EnumKey @@ -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 = _sysconfig.get_platform() + plat_name = 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 == _sysconfig.get_platform() or plat_name == 'win32': + if plat_name == 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[_sysconfig.get_platform()] + '_' + \ + plat_spec = PLAT_TO_VCVARS[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 48f22ad..2561f57 100644 --- a/Lib/distutils/sysconfig.py +++ b/Lib/distutils/sysconfig.py @@ -25,6 +25,15 @@ from distutils.errors import DistutilsPlatformError # to avoid this module to shadow it _sysconfig = __import__('sysconfig') +# names defined here to keep backward compatibility +# for APIs that were relocated +get_python_version = _sysconfig.get_python_version +get_config_h_filename = _sysconfig.get_config_h_filename +parse_config_h = _sysconfig.parse_config_h +get_config_vars = _sysconfig.get_config_vars +get_config_var = _sysconfig.get_config_var +from distutils.ccompiler import customize_compiler + _DEPRECATION_MSG = ("distutils.sysconfig.%s is deprecated. " "Use the APIs provided by the sysconfig module instead") diff --git a/Lib/distutils/tests/test_util.py b/Lib/distutils/tests/test_util.py index ae6671d..896e1e0 100644 --- a/Lib/distutils/tests/test_util.py +++ b/Lib/distutils/tests/test_util.py @@ -90,125 +90,12 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase): def _get_uname(self): return self._uname - def _test_get_platform(self): - - # windows XP, 32bits - os.name = 'nt' - sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) ' - '[MSC v.1310 32 bit (Intel)]') - sys.platform = 'win32' - self.assertEquals(get_platform(), 'win32') - - # windows XP, amd64 - os.name = 'nt' - sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) ' - '[MSC v.1310 32 bit (Amd64)]') - sys.platform = 'win32' - self.assertEquals(get_platform(), 'win-amd64') - - # windows XP, itanium - os.name = 'nt' - sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) ' - '[MSC v.1310 32 bit (Itanium)]') - sys.platform = 'win32' - self.assertEquals(get_platform(), 'win-ia64') - - # macbook - os.name = 'posix' - 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; ' - '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') - - maxsize = sys.maxsize - try: - sys.maxsize = 2147483647 - self.assertEquals(get_platform(), 'macosx-10.3-ppc') - sys.maxsize = 9223372036854775807 - self.assertEquals(get_platform(), 'macosx-10.3-ppc64') - finally: - sys.maxsize = maxsize - - - 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'), 'i386')) - os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.3' - - get_config_vars()['CFLAGS'] = ('-fno-strict-aliasing -DNDEBUG -g ' - '-fwrapv -O3 -Wall -Wstrict-prototypes') - - maxsize = sys.maxsize - try: - sys.maxsize = 2147483647 - self.assertEquals(get_platform(), 'macosx-10.3-i386') - sys.maxsize = 9223372036854775807 - self.assertEquals(get_platform(), 'macosx-10.3-x86_64') - 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 ' - '/Developer/SDKs/MacOSX10.4u.sdk ' - '-fno-strict-aliasing -fno-common ' - '-dynamic -DNDEBUG -g -O3') - - self.assertEquals(get_platform(), 'macosx-10.4-fat') - - get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch i386 -isysroot ' - '/Developer/SDKs/MacOSX10.4u.sdk ' - '-fno-strict-aliasing -fno-common ' - '-dynamic -DNDEBUG -g -O3') - - self.assertEquals(get_platform(), 'macosx-10.4-intel') - - get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch ppc -arch i386 -isysroot ' - '/Developer/SDKs/MacOSX10.4u.sdk ' - '-fno-strict-aliasing -fno-common ' - '-dynamic -DNDEBUG -g -O3') - self.assertEquals(get_platform(), 'macosx-10.4-fat3') - - get_config_vars()['CFLAGS'] = ('-arch ppc64 -arch x86_64 -arch ppc -arch i386 -isysroot ' - '/Developer/SDKs/MacOSX10.4u.sdk ' - '-fno-strict-aliasing -fno-common ' - '-dynamic -DNDEBUG -g -O3') - self.assertEquals(get_platform(), 'macosx-10.4-universal') - - get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch ppc64 -isysroot ' - '/Developer/SDKs/MacOSX10.4u.sdk ' - '-fno-strict-aliasing -fno-common ' - '-dynamic -DNDEBUG -g -O3') - - self.assertEquals(get_platform(), 'macosx-10.4-fat64') - - for arch in ('ppc', 'i386', 'x86_64', 'ppc64'): - get_config_vars()['CFLAGS'] = ('-arch %s -isysroot ' - '/Developer/SDKs/MacOSX10.4u.sdk ' - '-fno-strict-aliasing -fno-common ' - '-dynamic -DNDEBUG -g -O3'%(arch,)) - - 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) ' - '\n[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)]') - sys.platform = 'linux2' - self._set_uname(('Linux', 'aglae', '2.6.21.1dedibox-r7', - '#1 Mon Apr 30 17:25:38 CEST 2007', 'i686')) - - self.assertEquals(get_platform(), 'linux-i686') - - # XXX more platforms to tests here + def test_get_platform(self): + platform = util.get_platform() + self.assertEquals(platform, get_platform()) + util.set_platform('MyOwnPlatform') + self.assertEquals('MyOwnPlatform', util.get_platform()) + util.set_platform(platform) def test_convert_path(self): # linux/mac diff --git a/Lib/distutils/util.py b/Lib/distutils/util.py index 0515fef..8fd2ca0 100644 --- a/Lib/distutils/util.py +++ b/Lib/distutils/util.py @@ -16,6 +16,27 @@ from distutils.version import LooseVersion from distutils.errors import DistutilsByteCompileError _sysconfig = __import__('sysconfig') +_PLATFORM = None + +def get_platform(): + """Return a string that identifies the current platform. + + By default, will return the value returned by sysconfig.get_platform(), + but it can be changed by calling set_platform(). + """ + global _PLATFORM + if _PLATFORM is None: + _PLATFORM = _sysconfig.get_platform() + return _PLATFORM + +def set_platform(identifier): + """Sets the platform string identifier returned by get_platform(). + + Note that this change doesn't impact the value returned by + sysconfig.get_platform() and is local to Distutils + """ + global _PLATFORM + _PLATFORM = identifier def convert_path(pathname): """Return 'pathname' as a name that will work on the native filesystem. diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py index c451b74..8222aaf 100644 --- a/Lib/test/test_sysconfig.py +++ b/Lib/test/test_sysconfig.py @@ -138,6 +138,25 @@ class TestSysConfig(unittest.TestCase): 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') + + maxsize = sys.maxsize + try: + sys.maxsize = 2147483647 + self.assertEquals(get_platform(), 'macosx-10.3-ppc') + sys.maxsize = 9223372036854775807 + self.assertEquals(get_platform(), 'macosx-10.3-ppc64') + finally: + sys.maxsize = maxsize + + + 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'), 'i386')) get_config_vars()['MACOSX_DEPLOYMENT_TARGET'] = '10.3' os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.3' @@ -145,7 +164,14 @@ class TestSysConfig(unittest.TestCase): get_config_vars()['CFLAGS'] = ('-fno-strict-aliasing -DNDEBUG -g ' '-fwrapv -O3 -Wall -Wstrict-prototypes') - self.assertEquals(get_platform(), 'macosx-10.3-i386') + maxsize = sys.maxsize + try: + sys.maxsize = 2147483647 + self.assertEquals(get_platform(), 'macosx-10.3-i386') + sys.maxsize = 9223372036854775807 + self.assertEquals(get_platform(), 'macosx-10.3-x86_64') + finally: + sys.maxsize = maxsize # macbook with fat binaries (fat, universal or fat64) os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.4' |