def test_remove_visual_c_ref(self): from distutils2.compiler.msvccompiler import get_build_version if get_build_version() < 8.0: raise unittest.SkipTest("requires MSVC 8.0 or later") from distutils2.compiler.msvc9compiler import MSVCCompiler tempdir = self.mkdtemp() manifest = os.path.join(tempdir, 'manifest') f = open(manifest, 'w') try: f.write(_MANIFEST) finally: f.close() compiler = MSVCCompiler() compiler._remove_visual_c_ref(manifest) # see what we got f = open(manifest) try: # removing trailing spaces content = '\n'.join(line.rstrip() for line in f.readlines()) finally: f.close() # makes sure the manifest was properly cleaned self.assertEqual(content, _CLEANED_MANIFEST)
def get_exe_bytes(self): from distutils2.compiler.msvccompiler import get_build_version # If a target-version other than the current version has been # specified, then using the MSVC version from *this* build is no good. # Without actually finding and executing the target version and parsing # its sys.version, we just hard-code our knowledge of old versions. # NOTE: Possible alternative is to allow "--target-version" to # specify a Python executable rather than a simple version string. # We can then execute this program to obtain any info we need, such # as the real sys.version string for the build. cur_version = get_python_version() if self.target_version and self.target_version != cur_version: # If the target version is *later* than us, then we assume they # use what we use # string compares seem wrong, but are what sysconfig.py itself uses if self.target_version > cur_version: bv = get_build_version() else: if self.target_version < "2.4": bv = 6.0 else: bv = 7.1 else: # for current version - use authoritative check. bv = get_build_version() # wininst-x.y.exe is in the same directory as this file directory = os.path.dirname(__file__) # we must use a wininst-x.y.exe built with the same C compiler # used for python. XXX What about mingw, borland, and so on? # if plat_name starts with "win" but is not "win32" # we want to strip "win" and leave the rest (e.g. -amd64) # for all other cases, we don't want any suffix if self.plat_name != 'win32' and self.plat_name[:3] == 'win': sfix = self.plat_name[3:] else: sfix = '' filename = os.path.join(directory, "wininst-%.1f%s.exe" % (bv, sfix)) fp = open(filename, "rb") try: content = fp.read() finally: fp.close() return content
def get_exe_bytes(self): from distutils2.compiler.msvccompiler import get_build_version # If a target-version other than the current version has been # specified, then using the MSVC version from *this* build is no good. # Without actually finding and executing the target version and parsing # its sys.version, we just hard-code our knowledge of old versions. # NOTE: Possible alternative is to allow "--target-version" to # specify a Python executable rather than a simple version string. # We can then execute this program to obtain any info we need, such # as the real sys.version string for the build. cur_version = get_python_version() if self.target_version and self.target_version != cur_version: # If the target version is *later* than us, then we assume they # use what we use # string compares seem wrong, but are what sysconfig.py itself uses if self.target_version > cur_version: bv = get_build_version() else: if self.target_version < "2.4": bv = 6.0 else: bv = 7.1 else: # for current version - use authoritative check. bv = get_build_version() # wininst-x.y.exe is in the same directory as this file directory = os.path.dirname(__file__) # we must use a wininst-x.y.exe built with the same C compiler # used for python. XXX What about mingw, borland, and so on? # if plat_name starts with "win" but is not "win32" # we want to strip "win" and leave the rest (e.g. -amd64) # for all other cases, we don't want any suffix if self.plat_name != 'win32' and self.plat_name[:3] == 'win': sfix = self.plat_name[3:] else: sfix = '' filename = os.path.join(directory, "wininst-%.1f%s.exe" % (bv, sfix)) with open(filename, "rb") as fp: return fp.read()
def test_no_compiler(self): # make sure query_vcvarsall raises a PackagingPlatformError if # the compiler is not found from distutils2.compiler.msvccompiler import get_build_version if get_build_version() < 8.0: raise unittest.SkipTest('only for MSVC8.0 or above') from distutils2.compiler import msvc9compiler from distutils2.compiler.msvc9compiler import query_vcvarsall def _find_vcvarsall(version): return None old_find_vcvarsall = msvc9compiler.find_vcvarsall msvc9compiler.find_vcvarsall = _find_vcvarsall try: self.assertRaises(PackagingPlatformError, query_vcvarsall, 'wont find this version') finally: msvc9compiler.find_vcvarsall = old_find_vcvarsall
def test_reg_class(self): from distutils2.compiler.msvccompiler import get_build_version if get_build_version() < 8.0: raise unittest.SkipTest("requires MSVC 8.0 or later") from distutils2.compiler.msvc9compiler import Reg self.assertRaises(KeyError, Reg.get_value, 'xxx', 'xxx') # looking for values that should exist on all # windows registeries versions. path = r'Control Panel\Desktop' v = Reg.get_value(path, 'dragfullwindows') self.assertIn(v, ('0', '1', '2')) import _winreg as winreg HKCU = winreg.HKEY_CURRENT_USER keys = Reg.read_keys(HKCU, 'xxxx') self.assertEqual(keys, None) keys = Reg.read_keys(HKCU, r'Control Panel') self.assertIn('Desktop', keys)
def test_remove_visual_c_ref(self): from distutils2.compiler.msvccompiler import get_build_version if get_build_version() < 8.0: raise unittest.SkipTest("requires MSVC 8.0 or later") from distutils2.compiler.msvc9compiler import MSVCCompiler tempdir = self.mkdtemp() manifest = os.path.join(tempdir, 'manifest') with open(manifest, 'w') as f: f.write(_MANIFEST) compiler = MSVCCompiler() compiler._remove_visual_c_ref(manifest) # see what we got with open(manifest) as f: # removing trailing spaces content = '\n'.join(line.rstrip() for line in f.readlines()) # makes sure the manifest was properly cleaned self.assertEqual(content, _CLEANED_MANIFEST)
from distutils2.errors import (CCompilerError, CompileError, PackagingError, PackagingPlatformError, PackagingSetupError) from distutils2.compiler import customize_compiler, show_compilers from distutils2.util import newer_group from distutils2.compiler.extension import Extension from distutils2 import logger import site if sys.version_info[:2] >= (2, 6): HAS_USER_SITE = True else: HAS_USER_SITE = False if os.name == 'nt': from distutils2.compiler.msvccompiler import get_build_version MSVC_VERSION = int(get_build_version()) # An extension name is just a dot-separated list of Python NAMEs (ie. # the same as a fully-qualified module name). extension_name_re = re.compile \ (r'^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$') class build_ext(Command): description = "build C/C++ extension modules (compile/link to build directory)" # XXX thoughts on how to deal with complex command-line options like # these, i.e. how to make it so fancy_getopt can suck them off the # command line and turn them into the appropriate # lists of tuples of what-have-you.
import sys import site from distutils2._backport import sysconfig from distutils2.util import get_platform from distutils2.command.cmd import Command from distutils2.errors import (CCompilerError, CompileError, PackagingError, PackagingPlatformError, PackagingSetupError) from distutils2.compiler import customize_compiler, show_compilers from distutils2.util import newer_group from distutils2.compiler.extension import Extension from distutils2 import logger if os.name == 'nt': from distutils2.compiler.msvccompiler import get_build_version MSVC_VERSION = int(get_build_version()) # An extension name is just a dot-separated list of Python NAMEs (ie. # the same as a fully-qualified module name). extension_name_re = re.compile \ (r'^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$') class build_ext(Command): description = "build C/C++ extension modules (compile/link to build directory)" # XXX thoughts on how to deal with complex command-line options like # these, i.e. how to make it so fancy_getopt can suck them off the # command line and turn them into the appropriate # lists of tuples of what-have-you.