Python distutils.msvc9compiler 模块,query_vcvarsall() 实例源码
我们从Python开源项目中,提取了以下27个代码示例,用于说明如何使用distutils.msvc9compiler.query_vcvarsall()。
def test_no_compiler(self):
# makes sure query_vcvarsall raises
# a distutilsPlatformError if the compiler
# is not found
from distutils.msvc9compiler import query_vcvarsall
def _find_vcvarsall(version):
return None
from distutils import msvc9compiler
old_find_vcvarsall = msvc9compiler.find_vcvarsall
msvc9compiler.find_vcvarsall = _find_vcvarsall
try:
self.assertRaises(distutilsPlatformError, query_vcvarsall,
'wont find this version')
finally:
msvc9compiler.find_vcvarsall = old_find_vcvarsall
def test_no_compiler(self):
# makes sure query_vcvarsall raises
# a distutilsPlatformError if the compiler
# is not found
from distutils.msvc9compiler import query_vcvarsall
def _find_vcvarsall(version):
return None
from distutils import msvc9compiler
old_find_vcvarsall = msvc9compiler.find_vcvarsall
msvc9compiler.find_vcvarsall = _find_vcvarsall
try:
self.assertRaises(distutilsPlatformError,
'wont find this version')
finally:
msvc9compiler.find_vcvarsall = old_find_vcvarsall
def test_no_compiler(self):
# makes sure query_vcvarsall raises
# a distutilsPlatformError if the compiler
# is not found
from distutils.msvc9compiler import query_vcvarsall
def _find_vcvarsall(version):
return None
from distutils import msvc9compiler
old_find_vcvarsall = msvc9compiler.find_vcvarsall
msvc9compiler.find_vcvarsall = _find_vcvarsall
try:
self.assertRaises(distutilsPlatformError,
'wont find this version')
finally:
msvc9compiler.find_vcvarsall = old_find_vcvarsall
def test_no_compiler(self):
# makes sure query_vcvarsall raises
# a distutilsPlatformError if the compiler
# is not found
from distutils.msvc9compiler import query_vcvarsall
def _find_vcvarsall(version):
return None
from distutils import msvc9compiler
old_find_vcvarsall = msvc9compiler.find_vcvarsall
msvc9compiler.find_vcvarsall = _find_vcvarsall
try:
self.assertRaises(distutilsPlatformError,
'wont find this version')
finally:
msvc9compiler.find_vcvarsall = old_find_vcvarsall
def test_no_compiler(self):
# makes sure query_vcvarsall raises
# a distutilsPlatformError if the compiler
# is not found
from distutils.msvc9compiler import query_vcvarsall
def _find_vcvarsall(version):
return None
from distutils import msvc9compiler
old_find_vcvarsall = msvc9compiler.find_vcvarsall
msvc9compiler.find_vcvarsall = _find_vcvarsall
try:
self.assertRaises(distutilsPlatformError,
'wont find this version')
finally:
msvc9compiler.find_vcvarsall = old_find_vcvarsall
def test_no_compiler(self):
# makes sure query_vcvarsall raises
# a distutilsPlatformError if the compiler
# is not found
from distutils.msvc9compiler import query_vcvarsall
def _find_vcvarsall(version):
return None
from distutils import msvc9compiler
old_find_vcvarsall = msvc9compiler.find_vcvarsall
msvc9compiler.find_vcvarsall = _find_vcvarsall
try:
self.assertRaises(distutilsPlatformError,
'wont find this version')
finally:
msvc9compiler.find_vcvarsall = old_find_vcvarsall
def test_no_compiler(self):
# makes sure query_vcvarsall raises
# a distutilsPlatformError if the compiler
# is not found
from distutils.msvc9compiler import query_vcvarsall
def _find_vcvarsall(version):
return None
from distutils import msvc9compiler
old_find_vcvarsall = msvc9compiler.find_vcvarsall
msvc9compiler.find_vcvarsall = _find_vcvarsall
try:
self.assertRaises(distutilsPlatformError,
'wont find this version')
finally:
msvc9compiler.find_vcvarsall = old_find_vcvarsall
def test_no_compiler(self):
# makes sure query_vcvarsall raises
# a distutilsPlatformError if the compiler
# is not found
from distutils.msvc9compiler import query_vcvarsall
def _find_vcvarsall(version):
return None
from distutils import msvc9compiler
old_find_vcvarsall = msvc9compiler.find_vcvarsall
msvc9compiler.find_vcvarsall = _find_vcvarsall
try:
self.assertRaises(distutilsPlatformError,
'wont find this version')
finally:
msvc9compiler.find_vcvarsall = old_find_vcvarsall
def patch_for_specialized_compiler():
"""
Patch functions in distutils to use standalone Microsoft Visual C++
compilers.
KNown supported compilers:
--------------------------
Microsoft Visual C++ 9.0:
Microsoft Visual C++ Compiler for Python 2.7 (x86,amd64);
Microsoft Windows SDK 7.0 (x86,x64,ia64);
Microsoft Windows SDK 6.1 (x86,ia64)
Microsoft Visual C++ 10.0:
Microsoft Windows SDK 7.1 (x86,ia64)
Microsoft Visual C++ 14.0:
Microsoft Visual C++ Build Tools 2015 (x86,arm)
"""
if platform.system() != 'Windows':
# Compilers only availables on Microsoft Windows
return
if 'distutils' not in globals():
# The module isn't available to be patched
return
if unpatched:
# Already patched
return
try:
# Patch distutils.msvc9compiler
unpatched['msvc9_find_vcvarsall'] = msvc9compiler.find_vcvarsall
msvc9compiler.find_vcvarsall = msvc9_find_vcvarsall
unpatched['msvc9_query_vcvarsall'] = msvc9compiler.query_vcvarsall
msvc9compiler.query_vcvarsall = msvc9_query_vcvarsall
except Exception:
pass
try:
# Patch distutils._msvccompiler._get_vc_env
unpatched['msvc14_get_vc_env'] = msvc14compiler._get_vc_env
msvc14compiler._get_vc_env = msvc14_get_vc_env
except Exception:
pass
def msvc9_query_vcvarsall(ver, arch='x86', *args, **kwargs):
"""
Patched "distutils.msvc9compiler.query_vcvarsall" for support standalones
compilers.
Set environment without use of "vcvarsall.bat".
KNown supported compilers
-------------------------
Microsoft Visual C++ 9.0:
Microsoft Visual C++ Compiler for Python 2.7 (x86,ia64)
Parameters
----------
ver: float
required Microsoft Visual C++ version.
arch: str
Target architecture.
Return
------
environment: dict
"""
# Try to get environement from vcvarsall.bat (Classical way)
try:
return unpatched['msvc9_query_vcvarsall'](ver, arch, **kwargs)
except distutils.errors.distutilsPlatformError:
# Pass error if Vcvarsall.bat is missing
pass
except ValueError:
# Pass error if environment not set after executing vcvarsall.bat
pass
# If error,try to set environment directly
try:
return EnvironmentInfo(arch, ver).return_env()
except distutils.errors.distutilsPlatformError as exc:
_augment_exception(exc, ver, arch)
raise
def patch_for_msvc_specialized_compiler():
"""
Patch functions in distutils to use standalone Microsoft Visual C++
compilers.
"""
from . import msvc
try:
# distutil file for MSVC++ 9.0 and upper (Python 2.7 to 3.4)
import distutils.msvc9compiler as msvc9compiler
except ImportError:
pass
try:
# distutil file for MSVC++ 14.0 and upper (Python 3.5+)
import distutils._msvccompiler as msvc14compiler
except ImportError:
pass
if platform.system() != 'Windows':
# Compilers only availables on Microsoft Windows
return
if unpatched:
# Already patched
return
try:
# Patch distutils.msvc9compiler
unpatched['msvc9_find_vcvarsall'] = msvc9compiler.find_vcvarsall
msvc9compiler.find_vcvarsall = msvc.msvc9_find_vcvarsall
unpatched['msvc9_query_vcvarsall'] = msvc9compiler.query_vcvarsall
msvc9compiler.query_vcvarsall = msvc.msvc9_query_vcvarsall
except NameError:
pass
try:
# Patch distutils._msvccompiler._get_vc_env
unpatched['msvc14_get_vc_env'] = msvc14compiler._get_vc_env
msvc14compiler._get_vc_env = msvc.msvc14_get_vc_env
except NameError:
pass
try:
# Patch distutils._msvccompiler.gen_lib_options for Numpy
unpatched['msvc14_gen_lib_options'] = msvc14compiler.gen_lib_options
msvc14compiler.gen_lib_options = msvc.msvc14_gen_lib_options
except NameError:
pass
def patch_for_specialized_compiler():
"""
Patch functions in distutils to use standalone Microsoft Visual C++
compilers.
KNown supported compilers:
--------------------------
Microsoft Visual C++ 9.0:
Microsoft Visual C++ Compiler for Python 2.7 (x86,arm)
"""
if platform.system() != 'Windows':
# Compilers only availables on Microsoft Windows
return
if 'distutils' not in globals():
# The module isn't available to be patched
return
if unpatched:
# Already patched
return
try:
# Patch distutils.msvc9compiler
unpatched['msvc9_find_vcvarsall'] = msvc9compiler.find_vcvarsall
msvc9compiler.find_vcvarsall = msvc9_find_vcvarsall
unpatched['msvc9_query_vcvarsall'] = msvc9compiler.query_vcvarsall
msvc9compiler.query_vcvarsall = msvc9_query_vcvarsall
except Exception:
pass
try:
# Patch distutils._msvccompiler._get_vc_env
unpatched['msvc14_get_vc_env'] = msvc14compiler._get_vc_env
msvc14compiler._get_vc_env = msvc14_get_vc_env
except Exception:
pass
def patch_for_specialized_compiler():
"""
Patch functions in distutils to use standalone Microsoft Visual C++
compilers.
KNown supported compilers:
--------------------------
Microsoft Visual C++ 9.0:
Microsoft Visual C++ Compiler for Python 2.7 (x86,arm)
"""
if platform.system() != 'Windows':
# Compilers only availables on Microsoft Windows
return
if 'distutils' not in globals():
# The module isn't available to be patched
return
if unpatched:
# Already patched
return
try:
# Patch distutils.msvc9compiler
unpatched['msvc9_find_vcvarsall'] = msvc9compiler.find_vcvarsall
msvc9compiler.find_vcvarsall = msvc9_find_vcvarsall
unpatched['msvc9_query_vcvarsall'] = msvc9compiler.query_vcvarsall
msvc9compiler.query_vcvarsall = msvc9_query_vcvarsall
except Exception:
pass
try:
# Patch distutils._msvccompiler._get_vc_env
unpatched['msvc14_get_vc_env'] = msvc14compiler._get_vc_env
msvc14compiler._get_vc_env = msvc14_get_vc_env
except Exception:
pass
def patch_for_specialized_compiler():
"""
Patch functions in distutils to use standalone Microsoft Visual C++
compilers.
KNown supported compilers:
--------------------------
Microsoft Visual C++ 9.0:
Microsoft Visual C++ Compiler for Python 2.7 (x86,arm)
"""
if platform.system() != 'Windows':
# Compilers only availables on Microsoft Windows
return
if 'distutils' not in globals():
# The module isn't available to be patched
return
if unpatched:
# Already patched
return
try:
# Patch distutils.msvc9compiler
unpatched['msvc9_find_vcvarsall'] = msvc9compiler.find_vcvarsall
msvc9compiler.find_vcvarsall = msvc9_find_vcvarsall
unpatched['msvc9_query_vcvarsall'] = msvc9compiler.query_vcvarsall
msvc9compiler.query_vcvarsall = msvc9_query_vcvarsall
except Exception:
pass
try:
# Patch distutils._msvccompiler._get_vc_env
unpatched['msvc14_get_vc_env'] = msvc14compiler._get_vc_env
msvc14compiler._get_vc_env = msvc14_get_vc_env
except Exception:
pass
def patch_for_specialized_compiler():
"""
Patch functions in distutils to use standalone Microsoft Visual C++
compilers.
KNown supported compilers:
--------------------------
Microsoft Visual C++ 9.0:
Microsoft Visual C++ Compiler for Python 2.7 (x86,arm)
"""
if platform.system() != 'Windows':
# Compilers only availables on Microsoft Windows
return
if 'distutils' not in globals():
# The module isn't available to be patched
return
if unpatched:
# Already patched
return
try:
# Patch distutils.msvc9compiler
unpatched['msvc9_find_vcvarsall'] = msvc9compiler.find_vcvarsall
msvc9compiler.find_vcvarsall = msvc9_find_vcvarsall
unpatched['msvc9_query_vcvarsall'] = msvc9compiler.query_vcvarsall
msvc9compiler.query_vcvarsall = msvc9_query_vcvarsall
except Exception:
pass
try:
# Patch distutils._msvccompiler._get_vc_env
unpatched['msvc14_get_vc_env'] = msvc14compiler._get_vc_env
msvc14compiler._get_vc_env = msvc14_get_vc_env
except Exception:
pass
def patch_for_specialized_compiler():
"""
Patch functions in distutils to use standalone Microsoft Visual C++
compilers.
KNown supported compilers:
--------------------------
Microsoft Visual C++ 9.0:
Microsoft Visual C++ Compiler for Python 2.7 (x86,arm)
"""
if platform.system() != 'Windows':
# Compilers only availables on Microsoft Windows
return
if 'distutils' not in globals():
# The module isn't available to be patched
return
if unpatched:
# Already patched
return
try:
# Patch distutils.msvc9compiler
unpatched['msvc9_find_vcvarsall'] = msvc9compiler.find_vcvarsall
msvc9compiler.find_vcvarsall = msvc9_find_vcvarsall
unpatched['msvc9_query_vcvarsall'] = msvc9compiler.query_vcvarsall
msvc9compiler.query_vcvarsall = msvc9_query_vcvarsall
except Exception:
pass
try:
# Patch distutils._msvccompiler._get_vc_env
unpatched['msvc14_get_vc_env'] = msvc14compiler._get_vc_env
msvc14compiler._get_vc_env = msvc14_get_vc_env
except Exception:
pass
def patch_for_specialized_compiler():
"""
Patch functions in distutils to use standalone Microsoft Visual C++
compilers.
KNown supported compilers:
--------------------------
Microsoft Visual C++ 9.0:
Microsoft Visual C++ Compiler for Python 2.7 (x86,arm)
"""
if platform.system() != 'Windows':
# Compilers only availables on Microsoft Windows
return
if 'distutils' not in globals():
# The module isn't available to be patched
return
if unpatched:
# Already patched
return
try:
# Patch distutils.msvc9compiler
unpatched['msvc9_find_vcvarsall'] = msvc9compiler.find_vcvarsall
msvc9compiler.find_vcvarsall = msvc9_find_vcvarsall
unpatched['msvc9_query_vcvarsall'] = msvc9compiler.query_vcvarsall
msvc9compiler.query_vcvarsall = msvc9_query_vcvarsall
except Exception:
pass
try:
# Patch distutils._msvccompiler._get_vc_env
unpatched['msvc14_get_vc_env'] = msvc14compiler._get_vc_env
msvc14compiler._get_vc_env = msvc14_get_vc_env
except Exception:
pass
def patch_for_specialized_compiler():
"""
Patch functions in distutils to use standalone Microsoft Visual C++
compilers.
KNown supported compilers:
--------------------------
Microsoft Visual C++ 9.0:
Microsoft Visual C++ Compiler for Python 2.7 (x86,arm)
"""
if platform.system() != 'Windows':
# Compilers only availables on Microsoft Windows
return
if 'distutils' not in globals():
# The module isn't available to be patched
return
if unpatched:
# Already patched
return
try:
# Patch distutils.msvc9compiler
unpatched['msvc9_find_vcvarsall'] = msvc9compiler.find_vcvarsall
msvc9compiler.find_vcvarsall = msvc9_find_vcvarsall
unpatched['msvc9_query_vcvarsall'] = msvc9compiler.query_vcvarsall
msvc9compiler.query_vcvarsall = msvc9_query_vcvarsall
except Exception:
pass
try:
# Patch distutils._msvccompiler._get_vc_env
unpatched['msvc14_get_vc_env'] = msvc14compiler._get_vc_env
msvc14compiler._get_vc_env = msvc14_get_vc_env
except Exception:
pass
try:
# Patch distutils._msvccompiler.MSVCCompiler.library_dir_option
unpatched['msvc14_library_dir_option'] = msvc14compiler.MSVCCompiler.library_dir_option
msvc14compiler.MSVCCompiler.library_dir_option = msvc14_library_dir_option
except Exception:
pass
def patch_for_specialized_compiler():
"""
Patch functions in distutils to use standalone Microsoft Visual C++
compilers.
KNown supported compilers:
--------------------------
Microsoft Visual C++ 9.0:
Microsoft Visual C++ Compiler for Python 2.7 (x86,arm)
"""
if platform.system() != 'Windows':
# Compilers only availables on Microsoft Windows
return
if 'distutils' not in globals():
# The module isn't available to be patched
return
if unpatched:
# Already patched
return
try:
# Patch distutils.msvc9compiler
unpatched['msvc9_find_vcvarsall'] = msvc9compiler.find_vcvarsall
msvc9compiler.find_vcvarsall = msvc9_find_vcvarsall
unpatched['msvc9_query_vcvarsall'] = msvc9compiler.query_vcvarsall
msvc9compiler.query_vcvarsall = msvc9_query_vcvarsall
except NameError:
pass
try:
# Patch distutils._msvccompiler._get_vc_env
unpatched['msvc14_get_vc_env'] = msvc14compiler._get_vc_env
msvc14compiler._get_vc_env = msvc14_get_vc_env
except NameError:
pass
try:
# Patch distutils._msvccompiler.gen_lib_options for Numpy
unpatched['msvc14_gen_lib_options'] = msvc14compiler.gen_lib_options
msvc14compiler.gen_lib_options = msvc14_gen_lib_options
except NameError:
pass
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。